diff --git a/day1.cr b/day1.cr index 6373b06..731691c 100644 --- a/day1.cr +++ b/day1.cr @@ -1,4 +1,5 @@ -INPUT = File.read("day1.txt").lines.map(&.chomp.to_i32) +require "advent" +INPUT = input(2020, 1).lines.map(&.chomp.to_i32) def part1 input = INPUT.clone.sort! diff --git a/day2.cr b/day2.cr index f411574..c03b2c5 100644 --- a/day2.cr +++ b/day2.cr @@ -1,4 +1,5 @@ -INPUT = File.read("day2.txt").lines.map(&.chomp) +require "advent" +INPUT = input(2020, 2).lines.map(&.chomp) def parse(line) data = line.match(/([0-9]+)-([0-9]+) ([a-z]): ([a-z]+)/) diff --git a/day3.cr b/day3.cr index f1c6fa2..f1e5cf4 100644 --- a/day3.cr +++ b/day3.cr @@ -1,4 +1,5 @@ -INPUT = File.read("day3.txt").lines.map(&.chomp) +require "advent" +INPUT = input(2020, 3).lines.map(&.chomp) def run(input, slopes) prod = 1_i64 diff --git a/day4.cr b/day4.cr index 626920e..2ceb401 100644 --- a/day4.cr +++ b/day4.cr @@ -1,5 +1,6 @@ require "./passports.cr" -INPUT = File.read("day4.txt") +require "advent" +INPUT = input(2020, 4) def part1 input = INPUT.clone diff --git a/day5.cr b/day5.cr index 9e91049..9044c2c 100644 --- a/day5.cr +++ b/day5.cr @@ -1,4 +1,5 @@ -INPUT = File.read("day5.txt").lines.map(&.chomp) +require "advent" +INPUT = input(2020, 5).lines.map(&.chomp) def partition(choices, list) b = 0 diff --git a/day5g.cr b/day5g.cr new file mode 100644 index 0000000..85731f5 --- /dev/null +++ b/day5g.cr @@ -0,0 +1,2 @@ +i=File.read_lines("day5.txt").map &.tr("FBLR", "0101").to_i32(2); +puts({i.max,(i.min..i.max).select{|n|!i.includes? n}}) diff --git a/template.cr b/template.cr index 0dd8481..3f209c6 100644 --- a/template.cr +++ b/template.cr @@ -1,4 +1,5 @@ -INPUT = File.read("dayN.txt")#.lines.map(&.chomp) +require "advent" +INPUT = input(2020, n)#.lines.map(&.chomp) def part1 input = INPUT.clone