Skip to content

Commit 930d9a7

Browse files
committed
Add lint
1 parent 3f7e91a commit 930d9a7

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

2023/day01/main.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
#!/usr/bin/env ruby
2-
arr_1 = File.readlines("data_1.txt")
3-
arr_2 = File.readlines("data_2.txt")
2+
# frozen_string_literal: true
43

5-
NUMBERS = %w[one two three four five six seven eight nine]
4+
arr1 = File.readlines('data_1.txt')
5+
arr2 = File.readlines('data_2.txt')
6+
7+
NUMBERS = %w[one two three four five six seven eight nine].freeze
68

79
def string_to_number(str)
8-
index = NUMBERS.find_index(str)
9-
index ? index + 1 : str.to_i
10+
index = NUMBERS.find_index(str)
11+
index ? index + 1 : str.to_i
1012
end
1113

12-
def first_and_last arr, regexp = /\d/
13-
arr.map do
14-
first = _1[/#{regexp}/]
15-
last = _1[/.*(#{regexp}).*/, 1]
16-
string_to_number(first) * 10 + string_to_number(last)
17-
end
14+
def first_and_last(arr, regexp = /\d/)
15+
arr.map do
16+
first = _1[/#{regexp}/]
17+
last = _1[/.*(#{regexp}).*/, 1]
18+
string_to_number(first) * 10 + string_to_number(last)
19+
end
1820
end
1921

20-
puts first_and_last(arr_1).sum
21-
puts first_and_last(arr_2, /\d|#{NUMBERS.join('|')}/).sum
22+
puts first_and_last(arr1).sum
23+
puts first_and_last(arr2, /\d|#{NUMBERS.join('|')}/).sum

0 commit comments

Comments
 (0)