Skip to content

enikesha/aoc2020

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code 2020

I’m planning to implement each day with new programming language from the sorted list [25/25]

  • [X] 1.12 Assembler
  • [X] 2.12 AWK
  • [X] 3.12 Bash
  • [X] 4.12 C
  • [X] 5.12 C#
  • [X] 6.12 C++
  • [X] 7.12 Clojure
  • [X] 8.12 Common Lisp
  • [X] 9.12 Erlang
  • [X] 10.12 F#
  • [X] 11.12 Go
  • [X] 12.12 Haskell
  • [X] 13.12 Java
  • [X] 14.12 JS
  • [X] 15.12 Kotlin
  • [X] 16.12 Lua
  • [X] 17.12 Pascal
  • [X] 18.12 Perl
  • [X] 19.12 PHP
  • [X] 20.12 Python
  • [X] 21.12 Ruby
  • [X] 22.12 Rust
  • [X] 23.12 Scala
  • [X] 24.12 Scheme
  • [X] 25.12 T-SQL

1.12: x86_64 assembler

Part 1: O(nlogn), quicksort with double-sided search

as --64 day1_1.s -o day1_1.o && ld -melf_x86_64 -s day1_1.o -o day1_1
./day1_1 < day1_input.txt

Part 2: O(n2logn), same algo as part 1 but with outer loop of third term which is skipped in the main algo

as --64 day1_2.s -o day1_2.o && ld -melf_x86_64 -s day1_2.o -o day1_2
./day1_2 < day1_input.txt

2.12: AWK

Part 1: Regex cut out other chars then regex match repeated char

awk -f day2_1.awk day2_input.txt

Part 2: Basic check string elements

awk -f day2_2.awk day2_input.txt

3.12: bash

Part 1: Iterate over lines with offset modulus

bash day3_1.sh 3 1 day3_input.txt

Part 2: Run part 1 with different slopes

bash day3_2.sh day3_input.txt

4.12: C

Part 1: Use bitmask as fields set, pointer math to split fields

gcc day4_1.c -o day4_1
./day4_1 < day4_input.txt

Part 2: Validation over part 1

gcc day4_2.c -o day4_2
./day4_2 < day4_input.txt

5.12: C#

Parse binary, use sequence sum formula to find missing element

cd day5
dotnet run < input.txt

6.12: C++

std set with map

gcc day6.cpp -lstdc++ -o day6
./day6 < input.txt

7.12: Clojure

Stupid mashup of bfs and dfs

clj -X day7/part1 < day7_input.txt
clj -X day7/part2 < day7_input.txt

8.12: Common lisp

Plain execution with history tracking and brute part2

sbcl --load day8.lisp --eval '(day8)' < day8_input.txt
sbcl --load day8.lisp --eval '(day8-2)' < day8_input.txt

9.12: Erlang

Linear with pre-sorted/pre-summed lists with fifo queues.

erl
> c(day9).
> day9:part1("day9_input.txt", 25).
> day9:part2("day9_input.txt", 69316178).

10.12: F#

Calc continious ranges, manual calculated permutations based on range lenght

cd day10
dotnet run

11.12

Go

Simple loops

go run day11.go

Assembler

Tried to optimize on assembly level. Multiple tricks are used.

as --64 day11.s -o day11.o && ld -melf_x86_64 -s day11.o -o day11_as
./day11_as day111_input.txt

This gives the following result looping the both parts 100 times:

enikesha@enikesha-desktop:~/dev/aoc2020$ time ./day11_as day11_input.txt > /dev/null

real	0m5.127s
user	0m5.125s
sys	0m0.000s
enikesha@enikesha-desktop:~/dev/aoc2020$ time ./day11_go > /dev/null

real	0m12.658s
user	0m13.009s
sys	0m0.157s

12.12: Haskell

Ok, haskell’s learning curve is quite steep. Otherwise simple instruction processing

ghci
> :l day12
*Day12> day12
*Day12> day12_1

13.12: Java

Chinese reminder theorem implementation.

javac day13.java && java day13

14.12: ECMA Script

BigInt, reduce and explode masked addresses

paste in FF/Chrome console on advent day page

15.12:

Kotlin

Unboxed IntArray for perf optimization

kotlinc day15.kt -include-runtime -d day15.jar && java -jar day15.jar

Assembler

All I could get out of it

as --64 day15.s -o day15.o && ld -melf_x86_64 -s day15.o -o day15

With the following results

enikesha@enikesha-desktop:~/dev/aoc2020$ time java -jar day15.jar
30000000: 689

real	0m0.759s
user	0m0.791s
sys	0m0.100s
enikesha@enikesha-desktop:~/dev/aoc2020$ time ./day15
689

real	0m0.597s
user	0m0.544s
sys	0m0.052s

16.12: Lua

Good ol’ imperative

lua day16.lua < day16_input.txt

17.12: Pascal

Optimized generic solution. 100 times faster than the prevous one. On simulation iterates through bounding n-orthotope with direct flat array index calculation.

fpc day17.pas && ./day17 < day17_input.txt

18.12: Perl

Shit-crafted calculator. Char level parse into reverse polish notation with evaluation as a second step.

perl day18.pl day18_input.txt

19.12: PHP

More shit :) I think it’s kinda general, no any ties to my input or special 8/11 handling.

php day19.php day19_input.txt

20.12: Python

I’m not proud of it at all :( But at least it works. It took me more time than any other day by a big margin.

python day20.py < day20_input.txt

21.12: Ruby

Set’s intersections for elimination

ruby day21.rb < day21_input.txt

22.12: Rust

Direct rules implementation. Quite nice language, but borrow checker needs some time to get used to.

rustc day22.rs && ./day22 < day22_input.txt

23.12: Scala

Imperative one due to performance. Using Array[Int] as label->next index.

scalac day23.scala && scala day23

24.12: Scheme

Unoptimized hash tables over complex numbers as position

guile day24.scm < day24_input.txt

25.12: T-SQL

Plpgsql imperative procedural bruteforce :( But that finishes the whole story)

sudo -u postgres psql -f day25.sql

About

Advent of Code 2020

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published