Skip to content

Commit

Permalink
use read_lines instead of read + split
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainFranceschini committed Dec 3, 2020
1 parent 9f839a9 commit 866d357
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/day01.cr
@@ -1,6 +1,5 @@
File
.read("#{__DIR__}/../input/01.dat")
.split
.read_lines("#{__DIR__}/../input/01.dat")
.map(&.to_i)
.each_combination(ARGV.first?.try(&.to_i) || 2, reuse: true) do |p|
if p.sum == 2020
Expand Down
3 changes: 1 addition & 2 deletions src/day02.1.cr
@@ -1,6 +1,5 @@
puts File
.read("#{__DIR__}/../input/02.dat")
.split('\n')
.read_lines("#{__DIR__}/../input/02.dat")
.map(&.match(/(?<x>\d+)-(?<y>\d+) (?<letter>\w): (?<password>\w+)/).not_nil!)
.count { |match|
range = (match["x"].to_i..match["y"].to_i)
Expand Down
3 changes: 1 addition & 2 deletions src/day02.2.cr
@@ -1,6 +1,5 @@
puts File
.read("#{__DIR__}/../input/02.dat")
.split('\n')
.read_lines("#{__DIR__}/../input/02.dat")
.map(&.match(/(?<x>\d+)-(?<y>\d+) (?<letter>\w): (?<password>\w+)/).not_nil!)
.count { |match|
indices = {match["x"].to_i - 1, match["y"].to_i - 1}
Expand Down
3 changes: 1 addition & 2 deletions src/day03.1.cr
@@ -1,7 +1,6 @@
i = 0
puts File
.read("#{__DIR__}/../input/03.dat")
.split('\n')
.read_lines("#{__DIR__}/../input/03.dat")
.reduce(0) { |acc, row|
cell = row[i]
i = (i + 3) % row.size
Expand Down

0 comments on commit 866d357

Please sign in to comment.