From c6ac448ad2dac1ae872b5309d1b0a17ef37e114b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 29 Dec 2020 00:50:26 -0800 Subject: [PATCH] Add day 25 solution. --- day25.cr | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 day25.cr diff --git a/day25.cr b/day25.cr new file mode 100644 index 0000000..88f82ef --- /dev/null +++ b/day25.cr @@ -0,0 +1,28 @@ +require "advent" +INPUT = input(2020, 25).lines.map(&.to_i64) + +def transform(s) + i = 1_i64 + c = 0 + loop do + c += 1 + i = (i * s) % 20201227 + yield i, c + end +end + +def find_size(s, goal) + transform(s) do |n, c| + return c if n == goal + end +end + +def part1(input) + goal = find_size(7, input[0]) + puts goal + transform(input[1]) do |n, c| + return n if c == goal + end +end + +puts part1(INPUT.clone)