[+] Opti day24
SMAGGHE Tristan authored
2b8ee6db

Advent of Go-de (do not remove the dash)

Day 01

Task 01 :

Elves have a certain amount of calories in their inventories, we need to find the one with the most calories and return its amount.

Task 02 :

Now we need to look at the top three and sum their inventories.

Benchmark :

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                457218              2517 ns/op
BenchmarkPartTwo-8                164950              7094 ns/op
BenchmarkPartOneParsing-8           4881            260884 ns/op
BenchmarkPartTwoParsing-8           4897            274166 ns/op
PASS
ok      day01   5.752s

Day 02

Task 01 :

Elves are asking you to cheat on an exam of RPS, you basically have to calculate your score based on what you play.

Task 02 :

You must guess what you're playing based on what the opponent is playing & if you should win,lose or tie.

Benchmark :

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                 62136             20623 ns/op
BenchmarkPartTwo-8                 89295             14364 ns/op
BenchmarkPartOneParsing-8           2335            675594 ns/op
BenchmarkPartTwoParsing-8           2116            641149 ns/op
PASS
ok      day02   5.954s

Day 03

Task 01 :

Elves have sacks separated in half (two compartments), you must find the common element for each sack and add it to the score

Task 02

Now you have to take triplets of elves and determine what's in common in their sack then add it to the score

Benchmark :

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                 22147             55916 ns/op
BenchmarkPartTwo-8                  7866            187932 ns/op
BenchmarkPartOneParsing-8           1212           1538274 ns/op
BenchmarkPartTwoParsing-8            770           1614195 ns/op

Day 04

Task 01:

Each elves is assigned sections in pairs, you must check that in a single pair, there is no full overlap (0-5,1-3)

Task 02:

Same, but you check if there is any overlap (1-3,2-4)

Benchmark :

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                555499              1969 ns/op
BenchmarkPartTwo-8                223914              4976 ns/op
BenchmarkPartOneParsing-8           3098            601322 ns/op
BenchmarkPartTwoParsing-8           3079            616802 ns/op
PASS
ok      day04   6.137s

Day 05

Task 01:

There is a stack and you must do the operations as told, nothing weird

Task 02:

Same but now when you move n crates, they are kept in order in the new stack

Benchmark :

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8              309489396                3.979 ns/op
BenchmarkPartTwo-8              312265954                3.938 ns/op
BenchmarkPartOneParsing-8           3834            337322 ns/op
BenchmarkPartTwoParsing-8           5392            229971 ns/op
PASS
ok      day05   6.421s

Day 06

Task 01:

You receive a datastream and must find the first 4 successive different letters

Task 02

Same but 14. (yes i hardcoded that too)

Benchmark :

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                 35900             34408 ns/op
BenchmarkPartTwo-8                 28593             49288 ns/op
BenchmarkPartOneParsing-8          23482             55460 ns/op
BenchmarkPartTwoParsing-8          18830             61197 ns/op
PASS
ok      day05   7.038s

Day 07

Task 01:

You receive a list of linux command with output, you must add up the sum of the sizes of directories that are lower than 100000 in size

Task 02:

Your system has 70000000 available and needs 30000000 for an update, find the best directory to delete

Benchmark with tree :

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                144146             15783 ns/op
BenchmarkPartTwo-8                 62810             17331 ns/op
BenchmarkPartOneParsing-8           3486            297024 ns/op
BenchmarkPartTwoParsing-8           4328            308130 ns/op
PASS
ok      day07   6.084s

Benchmark with stack :

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                  8832            135537 ns/op
BenchmarkPartTwo-8                  7822            149467 ns/op
BenchmarkPartOneParsing-8          10000            146098 ns/op
BenchmarkPartTwoParsing-8           8068            152786 ns/op
PASS
ok      day07   6.126s

Day 08

Task 01:

You have a forest of trees (represented by height), you must count the amount of trees visible from the edges.

Task 02:

You need to score each tree using a scoring function based on how many trees are visible from this one and return the highest scoring tree. (next day is building the treehouse day ?)

Benchmark (used for solve)

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                    24          44952036 ns/op
BenchmarkPartTwo-8                     3         658020533 ns/op
BenchmarkPartOneParsing-8             20          64924849 ns/op
BenchmarkPartTwoParsing-8              3         416787680 ns/op
PASS
ok      day07   9.295s

Benchmark (after optimization) 58 times faster

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                  1783            773497 ns/op
BenchmarkPartTwo-8                  2654            386745 ns/op
BenchmarkPartOneParsing-8            699           2121763 ns/op
BenchmarkPartTwoParsing-8            597           1960319 ns/op
PASS
ok      day08   6.539s

Day 09

Benchmark :

Day 10

Task 01:

Follow the instructions and every 40 cycles after the 20th, calculate the signal strength.

Task 02:

While doing the register thingie, draw on the screen accordingly.

Benchmark :

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                 46833             26544 ns/op
BenchmarkPartTwo-8                 17043             71853 ns/op
BenchmarkPartOneParsing-8          25417             50252 ns/op
BenchmarkPartTwoParsing-8          13784             92582 ns/op
PASS
ok      day10   6.983s

Day 11

Task 01:

Monkeys are passing each other items of value, each time they do, their value increases but is then divided by 3. You must find the monkeys that are inspecting the most times in 20 rounds.

Task 02:

Same but you don't divide by 3 but still gotta keep the values in acceptable range. Also this time is 10000 rounds.

Benchmark :

cpu: Intel(R) Core(TM) i7-9700KF CPU @ 3.60GHz
BenchmarkPartOne-6                 70126             16997 ns/op
BenchmarkPartTwo-6                   100          10854682 ns/op (10.8ms)
BenchmarkPartOneParsing-6          37323             32178 ns/op
BenchmarkPartTwoParsing-6            100          10929978 ns/op (10.9ms)
PASS
ok      day11   5.105s

Day 12

Benchmark :

cpu: AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx  
BenchmarkPartOne-8                   218           5193754 ns/op
BenchmarkPartTwo-8                     6         289020196 ns/op
BenchmarkPartOneParsing-8            164           6524547 ns/op
BenchmarkPartTwoParsing-8              3         342185991 ns/op
PASS
ok      day12   7.529s

Day 24

Benchmark :

cpu: 12th Gen Intel(R) Core(TM) i5-1240P
BenchmarkPartOneParsing-16            10         104578046 ns/op
BenchmarkPartTwoParsing-16             4         289115490 ns/op
PASS
ok      day24   4.426s

Day 25

Benchmark :

cpu: 12th Gen Intel(R) Core(TM) i5-1240P
BenchmarkPartOne-16                35608             32420 ns/op
BenchmarkPartOneParsing-16         25650             44559 ns/op
PASS
ok      day12   3.120s