Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 930d9a7

Browse filesBrowse files
committed
Add lint
1 parent 3f7e91a commit 930d9a7
Copy full SHA for 930d9a7

File tree

Expand file treeCollapse file tree

1 file changed

+15
-13
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-13
lines changed

‎2023/day01/main.rb

Copy file name to clipboard
+15-13Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.