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ā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
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!
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}`);
(nsballpointcarrot.aoc(:require[clojure.string:asst]))(defnfuel-cost[value](-(Math/floor(/value3))2))(defnadj-fuel-cost[value](let[fuel(fuel-costvalue)](if(pos?fuel)fuel0)))(defnp2019-01"Calculate Fuel requirements"[input](apply+(map#(fuel-cost(Integer/parseInt%))(st/split-linesinput))))(defnrecursive-fuel-cost[value](loop[remainsvaluetotal0](if(=remains0)total(let[fuel(adj-fuel-costremains)](recurfuel(+totalfuel))))))(defnp2019-01-part2"Calculate fuel requirements, including weight of fuel"[input](apply+(map#(recursive-fuel-cost(Integer/parseInt%))(st/split-linesinput))))
I'm a Staff Software Engineer at Cisco. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
This was a good ramp into the month! Here's my Rust solution. :)
/// Day 1: The Tyranny of the Rocket Equation/// /// Calculate the amount of fuel required to launch your spaceship!usestd::fs::File;usestd::io::prelude::*;usestd::io::BufReader;/// Calculate the fuel required to lift one module, based on its massfnfuel_required(mass:&usize)->usize{(mass/3)-2}/// Calculates the fuel required to lift one module, but factors in the/// weight of the fuel as wellfnrecursive_fuel_required(mass:&usize)->usize{if*mass<=6{0}else{letnext_mass=(mass/3)-2;next_mass+recursive_fuel_required(&next_mass)}}/// Calculate the total fuel requirements for the launchfnfuel_requirements(module_masses:Vec<usize>)->usize{module_masses.iter().map(recursive_fuel_required).sum()}/// Parses the input file, which is a bunch of numbers, one per linefnparse_input()->Vec<usize>{letbuf=BufReader::new(File::open("data/day1.txt").unwrap());buf.lines().map(|result|result.unwrap()).map(|line|line.parse::<usize>().unwrap()).collect()}/// Main day 1 codepubfnrun(){letdata=parse_input();lettotal_requirements=fuel_requirements(data);println!("Total fuel required: {}",total_requirements);}
Yay, Advent of Code is back. I'm not going to stick to one programming language this year, in fact I'm going to try to use lots, even some I've not used before. I'm not quite hardcore enough to do the different-language-every-day challenge however. Not this year anyway.
And in the spirit of what I wrote at the top, I did it once more in Julia, my first ever code in that language. First impressions very positive and interestingly it came out shortest. I love the built-in unit testing.
Hey folks - for anyone who's joined the leader board so far - I have a question!
So there are two main ways to sort our leader board, and I'm wondering which option would be best for us.
Option 1 - It counts how many people belong to the leader board (n), then the first user to get each star gets N points, the second gets N-1, and the last gets 1.
Option 2 - It counts how many stars you have, and then any ties are broken by the time you got the star. So if everyone gets all of the stars, the ones who get them the fastest are higher up.
I think either way is likely fine, but feel like maybe the star sort option might be best - it seems like it would encourage completion of the challenges more so than simply getting them done fastest, but still includes some speed needed to be higher up. Would love to hear some other thoughts on this, and whichever option seems most popular is what I'll sort it by!
I like option 2 a bit better. I'd rather see the people that manage to solve the more complicated problems at the top than those who solved the first few problems the fastest.
This is my solution to Part 1 in Ruby - working on Part 2!
#advent of code day 1#lets open the input filetarget=File.open("input.txt")#part 1defcalculation(file)total=0file.each{|number|number=number.to_i/3-2total+=number}puts"Our total is - #{total}"endcalculation(target)target.close
I joined the leaderboard, but since I'm in a EU timezone and only have time to work on them in the evenings I'm expecting my scores to be quite low š
Here's my solution for day 1 with Python (explained my thinking behind it here):
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:
Ooh this is a great use of
do...while. I went with the less elegant nestediffor 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!
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!
Very nice, I need to step my JS game up!
This post may help you regarding DEV leaderboards -
Want to Run DEV's Advent of Code?
Ryan Palo ć» Nov 11 ć» 1 min read
My kotlin solution.
I'm going to clean this up to avoid imperative style and post it as a reply to this comment.
github.com/jbristow/adventofcode/t...
This part 2 solution is much more elegant, and leverages monads.
I didn't even think about using a
maxfunction - that would have been so much cleaner than making two functions!I love cleaning these up into more elegant forms almost as much as I love just getting the solution banged out!
Solution in Clojure:
My solution using Rust.
This was a good ramp into the month! Here's my Rust solution. :)
Yay, Advent of Code is back. I'm not going to stick to one programming language this year, in fact I'm going to try to use lots, even some I've not used before. I'm not quite hardcore enough to do the different-language-every-day challenge however. Not this year anyway.
Day 1 in Haskell:
Once it was solved I did it again in Python just for fun:
And in the spirit of what I wrote at the top, I did it once more in Julia, my first ever code in that language. First impressions very positive and interestingly it came out shortest. I love the built-in unit testing.
Hey folks - for anyone who's joined the leader board so far - I have a question!
So there are two main ways to sort our leader board, and I'm wondering which option would be best for us.
Option 1 - It counts how many people belong to the leader board (n), then the first user to get each star gets N points, the second gets N-1, and the last gets 1.
Option 2 - It counts how many stars you have, and then any ties are broken by the time you got the star. So if everyone gets all of the stars, the ones who get them the fastest are higher up.
I think either way is likely fine, but feel like maybe the star sort option might be best - it seems like it would encourage completion of the challenges more so than simply getting them done fastest, but still includes some speed needed to be higher up. Would love to hear some other thoughts on this, and whichever option seems most popular is what I'll sort it by!
I like option 2 a bit better. I'd rather see the people that manage to solve the more complicated problems at the top than those who solved the first few problems the fastest.
Same here, option 2 sounds better.
In the check for 5 digits or less.
This is my solution to Part 1 in Ruby - working on Part 2!
I joined the leaderboard, but since I'm in a EU timezone and only have time to work on them in the evenings I'm expecting my scores to be quite low š
Here's my solution for day 1 with Python (explained my thinking behind it here):
Part 1:
Part 2:
I'm also participating this year. I want to solve everything in JS, as I'm new to web development (mostly frontend with React) on my job, too.
gitlab.com/xgyrosx/adventofcode
Part1
Part2
It took my quiet some time, especially for the file IO as there are so many approaches.
Bit late to the party!
Here is my solution in swift. Incase anyone would like followup code can be found here in Github
Elixir way
Day 01
Day 1, always good to start nice and easy!
Solution for part two:
And here is part one
I wrote my day 1 up here:
Day 1
Written in Clojure
Here is my solution in JavaScript:
The Private Leaderboard page seems to be pointing to 2018.
Fixed! Thank you!