-
• #27
Was a quick one today.
https://gist.github.com/dmckennell/bcb6db60d0150bfc877b21492d4f0f78
...prints:
Solving puzzle for Day 2 (Year 2020) Loading input from 2020/Day02.txt Part 1 took 0.030277581 seconds Part 2 took 0.021179534 seconds Part 1: 528 Part 2: 497
-
• #29
Doing this for the first time this year - in js / node
-
• #31
What are you doing for importing the data? I really don't want to go through and edit 1000 lines of strings into an array of objects.
-
• #32
using fs.readFile and a separate textfile where I copied the input.
Did debate trying to fetch it directly from the server but then realised everyones input is different so I would need to deal with auth and I cba. -
• #33
Yeah I've given up trying to be clever and just used find and replace to turn it into an array of strings
-
• #35
410 passwords out of 1000 were valid for part 1
694 passwords out of 1000 were valid for part 2
0.18user 0.05system 0:00.11elapsed 212%CPU (0avgtext+0avgdata 39420maxresident)k
0inputs+64outputs (0major+11049minor)pagefaults 0swapCode incredibly inelegant, and no tests. MUST.DO.BETTER :-)
-
• #36
And now it's my python version too.
Congratulations - you have now become my python tutor!
I did this in bash - because box of hammers, and I didn't want to suffer the ignominy of doing it in excel or vba.
#!/bin/bash # Advent of Code - Day 1, Puzzle 1 inputfile=$1 # numbercount=$(cat $1 | wc -l) # Edit because numbers numbercount=$(( $(cat $1 | wc -l) + 1 )) start=$SECONDS for ((i = 1 ; i < $numbercount ; i++)); do for ((j = $i + 1 ; j < $numbercount ; j++)); do ivalue=$(awk "NR == $i" $inputfile) jvalue=$(awk "NR == $j" $inputfile) if [[ $(( $ivalue + $jvalue )) -eq 2020 ]] ; then echo "$ivalue + $jvalue = $(( $ivalue + $jvalue )), $ivalue * $jvalue = $(( $ivalue * $jvalue ))" fi done done duration=$(( SECONDS - start )) echo $duration
:: tiswas@laptop2:/home/tiswas/Temp :: $ ./sum_to_2020.sh input1.txt 1632 + 388 = 2020, 1632 * 388 = 633216 76 seconds 19900 records
Seeing working python code for this is useful though, as I'm learning that from scratch at the moment.
[Edit] because missing a number in the loop
-
• #37
Google Sheets Day 1:
https://docs.google.com/spreadsheets/d/1joA1oMsoGaDCwX0u8CAK7IUuMeFqyfLEYzzIWzGB1d0/edit#gid=0Google Sheets Day 2:
https://docs.google.com/spreadsheets/d/17LXRC-kEewCl3K1mvA1dzWJE8geZx9bK78o2fClZc0g/edit?ouid=113006542528071116740&usp=sheets_home&ths=trueThere's probably a neater way to count characters in a string than deleting them and comparing the length
=len(B2)-len(SUBSTITUTE(B2,C2,""))
but it's not obvious what. -
• #38
My java did that too.
I toyed with using a regex, but didn't -
• #39
Done both, I got hung on the first one today a bit due to stupid copy and paste errors. Can share vanilla JS answers if anyone needs help
-
• #40
Every day's a school day - learned about arrays in bash.
#!/bin/bash start=$SECONDS inputfile=$1 mapfile -t < $inputfile # Part 1 - 2 numbers for i in "${MAPFILE[@]}"; do mycount=$(( mycount + 1 )) if [[ " ${MAPFILE[@]} " =~ " $(( 2020 - $i )) " ]] ; then echo "$i, $(( 2020 -$i)), $(( $i * (2020 - $i)))" duration=$(( SECONDS - start )) echo "$duration seconds $mycount records" break fi done # Part 2 - 3 numbers mycount=0 start=$seconds for i in "${MAPFILE[@]}"; do for j in "${MAPFILE[@]}"; do mycount=$(( mycount + 1 )) if [[ " ${MAPFILE[@]} " =~ " $(( 2020 - $i -$j )) " ]] ; then echo "$i, $j, $(( 2020 -$i - $j )), $(( $i * $j * (2020 - $i - $j) ))" duration=$(( SECONDS - start )) echo "$duration seconds $mycount records" exit fi done done
$ ./array_test.sh input1.txt 1632, 388, 633216 0 seconds 82 records 1607, 196, 217, 68348924 3 seconds 14573 records
-
• #41
Anyone else doing this is Haskell? I'm pretty new to it and had to fight my way through the first two days!
-
• #42
Another delay to submitting part 2 because I SIMPLY DID NOT READ THE WORDING.
When will I learn.
-
• #43
Not this year (as I want to focus on just getting to the end of the advent this time), but I'd like to see your solutions as you go as I'm curious!
Have seen a few GitHub projects with some Haskell advent GitHub projects with file reading scaffolding in place, so will likely clone one of those before next year's challenge.
-
• #44
The best prep is going back and completing previous years, gives you a good idea of what scaffolding may be useful.
Reading in maps into arrays (like today) is a common theme.
(I don't bother with any pre-written code or scaffolding but I will go and copy/paste from previous submissions if I realise there's a useful chunk of time that could be saved.)
If this year is like any of the previous ones they'll be some form of a pseudo computer that you need to implement that will come back again and again (and slowly be built up), so there will be some reuse built in.
-
• #45
Another eminently spreadsheetable one:
https://docs.google.com/spreadsheets/d/17_5yPJ8oNENFlRtqBnbCOLqE50RDK5QlLC_3p1v8Csg/edit?usp=sharing -
• #46
First three days in Python
https://gist.github.com/wence-/7d2a722fba29c94149a75beebfd5333c
Will try and update as I go. Thought about using the opportunity to teach myself Rust, but that will wait.
-
• #47
I'm usually put off by these "visual" challenges but stuck with it this time. Made a few mistakes with the indexing, offsets and getting my rows and columns mixed up but got there in the end.
-
• #48
TIL about enumerate!
-
• #49
404 on link (private visibility?)
-
• #50
I have an idea how to do this in JS but it's not going to be pretty.
Messing around with indexes always trips me up, but I've got them both.