Advent of Code 2018


Reading time: about 1 minute

Below are some notes/solutions for Advent of Code 2018.

Day 1 - Part 1

The first part of the problem is basically summing up all the numbers in the input file. It can be solved in Python like this.

freq = sum([int(x) for x in day_input(1)])

print(freq)

Day 1 - Part 2

On the second part, we need to keep track of the changes to the frequency, and find out which one is repeated twice. The problem description also tells us that we might have to loop through the input data multiple times until it repeats.

def day1_part2():
    freq = 0
    seen_freq = set([0])
    while True:
        for change in day_input(1):
            freq += int(change)
            if freq in seen_freq:
                return freq
            seen_freq.add(freq)

print(day1_part2())

Day 2 - Part 1

On this puzzle we have a list of Box IDs, and we’re trying to calculate a checksum from those. The problem description says we should count how many boxes have two repeating letters, how many of them have three repeating letters and multiply these numbers together.

def check_repeat(box, count):
    for c in box:
        if box.count(c) == count:
            return True
    return False

total_two = sum(map(lambda box: check_repeat(box, 2), day_input(2)))
total_three = sum(map(lambda box: check_repeat(box, 3), day_input(2)))

print(total_two * total_three)

The following pages link here

Citation

If you find this work useful, please cite it as:
@article{yaltirakliwikiadventofcode2018,
  title   = "Advent of Code 2018",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2024",
  url     = "https://www.gkbrk.com/wiki/advent_of_code_2018/"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "Advent of Code 2018", December, 2024. [Online]. Available: https://www.gkbrk.com/wiki/advent_of_code_2018/. [Accessed Dec. 17, 2024].
APA Style
Yaltirakli, G. (2024, December 17). Advent of Code 2018. https://www.gkbrk.com/wiki/advent_of_code_2018/
Bluebook Style
Gokberk Yaltirakli, Advent of Code 2018, GKBRK.COM (Dec. 17, 2024), https://www.gkbrk.com/wiki/advent_of_code_2018/

Comments

Comment by admin
2024-06-29 at 22:23
Spam probability: 0.021%

Wow, I did not expect that to print anything sensible @Jan. How did you come up with the parameters? Do you use a numerical optimization algorithm? Or just try random values until the output you're looking for comes up?

Comment by Jan
2018-12-19 at 18:36
Spam probability: 1.935%

Do You know Ruby? 5.downto(1) { |i| print (81 + 7.3 * Math::sin(i - 5.75)).floor.chr }

© 2024 Gokberk Yaltirakli