I would love to be part of some DEV leaderboards! I'm not showing myself as part of any right now, and am more than willing to use my own private one as a DEV-centric one if we need it. :) Do we have a way to share those so we can start joining?
I'll be doing my solutions in JavaScript - they're usually fairly verbose, since it helps me think better that way. lol :) So likely pretty beginner-friendly!
Here's day 1's solutions:
constfs=require('fs');constdata=fs.readFileSync('../2019 Solutions/inputs/day01input.txt').toString();constinput=data.split('\r\n').map(Number);consttestInput=[14,1969,100756];// mass / 3, round down, -2functionformula(mass){returnMath.floor(mass/3)-2;}// Part 1constfuelOfMass=input.map((curr)=>{returnformula(curr);});consttotalFuel=fuelOfMass.reduce((acc,curr)=>{returnacc+curr;},0);console.log(`Part 1: ${totalFuel}`);// Part 2consttotalFuelOfMass=input.map((curr)=>{letvalue=curr;letaccumulator=[];do{value=formula(value);if(value>0){accumulator.push(value);}}while(value>0);returnaccumulator.reduce((acc,curr)=>{returnacc+curr;},0);});constnewTotalFuel=totalFuelOfMass.reduce((acc,curr)=>{returnacc+curr;},0);console.log(`Part 2: ${newTotalFuel}`);
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
I’m a web developer & data visualizer working at a think tank in D.C. I'm a self-taught dev trying to better my skills. I spend most of my time on the front end of the stack.
Location
Washington, D.C.
Work
Lead Developer at Center for Strategic and International Studies
constdata=[148216,142030,129401,74642,108051,54128,145495,67818,120225,67113,107672,101032,147714,55788,87732,73681,114646,76586,116436,139788,125150,136675,90527,74674,105505,146059,52735,101389,108121,62897,132337,51963,129188,122308,84677,66433,118374,66822,94714,101162,54030,136580,55677,114051,133898,95026,112964,68662,85139,53559,84703,92053,132197,60130,63184,86182,113038,52659,140463,123234,97887,70216,131832,108162,116759,111828,132815,113476,127734,134545,99643,141911,74705,65720,95640,51581,66787,147590,72937,148774,119881,139875,131976,68238,100342,134691,112320,86107,100045,120458,54459,52047,108226,102138,141233,54452,67859,105132,81903,104282];functioncalculateFuel(mass){returnMath.floor(mass/3)-2;}functiongetTotalFuel(mass){letfuel=calculateFuel(mass);returnfuel>0?fuel+=getTotalFuel(fuel):0;}functionoutputTestResults(index,testCase,result){console.log(`Test ${index+1}\n`+`Input: ${testCase.input}\n`+`Expected Result: ${testCase.output}\n`+`Result: ${result}\n`+`Passes Test: ${testCase.output===result}\n\n`);}// Part Oneconsole.log(`Begin Part One`);letpartOneResult=0;constpartOneTestCases=[{input:12,output:2},{input:14,output:2},{input:1969,output:654},{input:100756,output:33583},];// part one test casespartOneTestCases.forEach(function(testCase,index){outputTestResults(index,testCase,calculateFuel(testCase.input));});// part one do workdata.forEach(function(mass){partOneResult+=calculateFuel(mass);});console.log(`Part One Answer: ${partOneResult}`);// Part Twoconsole.log(`Begin Part Two`);letpartTwoResult=0;constpartTwoTestCases=[{input:14,output:2},{input:1969,output:966},{input:100756,output:50346}];// part two test casespartTwoTestCases.forEach(function(testCase,index){outputTestResults(index,testCase,getTotalFuel(testCase.input));});// do workdata.forEach(function(mass){partTwoResult+=getTotalFuel(mass);});console.log(`Part Two Answer: ${partTwoResult}`);
Also, I couldn't resist the idea of the poem challenge they're doing on the subreddit, so I wrote an acrostic. :) Sharing here as well!
Adventure awaits!
Discover the cosmos
Venture into the unknown
Earn fifty stars to save Christmas!
No one goes alone, however
There's friendly folks to help
Overly dramatic situations await
Find Santa and bring him home!
Come code with us!
Outer space is calling
Don't be afraid
Elves will guide the way!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I would love to be part of some DEV leaderboards! I'm not showing myself as part of any right now, and am more than willing to use my own private one as a DEV-centric one if we need it. :) Do we have a way to share those so we can start joining?
I'll be doing my solutions in JavaScript - they're usually fairly verbose, since it helps me think better that way. lol :) So likely pretty beginner-friendly!
Here's day 1's solutions:
Post it here and I'll add it to the post and on further days posts! Go to you private leaderboard page and copy the code into a reply.
Alright, here's the code - 120635-5c140b9a.
We can make it for basically anyone on DEV, or we can focus it towards more beginner-friendly if we'd like - whatever works best for everyone!
Updated the post to include it! Thank you!
Awesome! Thanks for creating a leaderboard for DEV.
I'm in.
This post may help you regarding DEV leaderboards -
Want to Run DEV's Advent of Code?
Ryan Palo ・ Nov 11 ・ 1 min read
Ooh this is a great use of
do...while
. I went with the less elegant nestedif
for mine 😅Part 1 (JavaScript)
Part 2 (JavaScript)
Still works well! As long as it gets you the answer, it's good! :)
I saw someone use a ternary operator, and was super impressed. Might refactor mine later today to test that. :) Didn't even think of it!
Very nice, I need to step my JS game up!
Also, I couldn't resist the idea of the poem challenge they're doing on the subreddit, so I wrote an acrostic. :) Sharing here as well!