Skip to content

Commit 62e43db

Browse files
committed
some golf
1 parent 49ac72e commit 62e43db

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

02/a.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
score = 0
2-
31
RESULTS = {
42
"A X" => 1 + 3,
53
"A Y" => 2 + 6,
@@ -12,6 +10,4 @@
1210
"C Z" => 3 + 3
1311
}
1412

15-
File.readlines("02/input.txt").each { |line| score += RESULTS[line.strip] }
16-
17-
p score
13+
puts File.readlines("02/input.txt").sum { |line| RESULTS[line.strip] }

02/b.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
score = 0
2-
31
RESULTS = {
42
"A X" => 3 + 0,
53
"A Y" => 1 + 3,
@@ -12,6 +10,4 @@
1210
"C Z" => 1 + 6
1311
}
1412

15-
File.readlines("02/input.txt").each { |line| score += RESULTS[line.strip] }
16-
17-
p score
13+
puts File.readlines("02/input.txt").sum { |line| RESULTS[line.strip] }

03/a.rb

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
prios = ["-"] + ("a".."z").to_a + ("A".."Z").to_a
22

3-
puts(
4-
File
5-
.readlines("03/input.txt", chomp: true)
6-
.sum do |line|
7-
chars = line.chars
8-
half1, half2 = chars.each_slice(chars.size / 2).to_a
9-
common = (half1 & half2).first
10-
prios.index(common)
11-
end
12-
)
3+
File
4+
.readlines("03/input.txt", chomp: true)
5+
.sum do |line|
6+
chars = line.chars
7+
half1, half2 = chars.each_slice(chars.size / 2).to_a
8+
common = (half1 & half2).first
9+
prios.index(common)
10+
end
11+
.then { |sum| puts sum }

03/b.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
prios = ["-"] + ("a".."z").to_a + ("A".."Z").to_a
22

3-
puts(
4-
File
5-
.readlines("03/input.txt", chomp: true)
6-
.each_slice(3)
7-
.sum { |lines| prios.index(lines.map(&:chars).reduce(&:&).first) }
8-
)
3+
File
4+
.readlines("03/input.txt", chomp: true)
5+
.each_slice(3)
6+
.sum { |lines| prios.index(lines.map(&:chars).reduce(&:&).first) }
7+
.then { |sum| puts sum }

0 commit comments

Comments
 (0)