-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
387c976
commit b718d6c
Showing
10 changed files
with
59 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "ruby_lsp", | ||
"name": "Debug script", | ||
"request": "launch", | ||
"program": "ruby ${file}" | ||
}, | ||
{ | ||
"type": "ruby_lsp", | ||
"name": "Debug test", | ||
"request": "launch", | ||
"program": "ruby -Itest ${relativeFile}" | ||
}, | ||
{ | ||
"type": "ruby_lsp", | ||
"name": "Attach debugger", | ||
"request": "attach" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,3 @@ gem 'debug' | |
gem 'minitest' | ||
gem 'rake' | ||
gem 'rubocop' | ||
gem 'solargraph' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1abc2 | ||
pqr3stu8vwx | ||
a1b2c3d4e5f | ||
treb7uchet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
two1nine | ||
eightwothree | ||
abcone2threexyz | ||
xtwone3four | ||
4nineeightseven2 | ||
zoneight234 | ||
7pqrstsixteen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
class Day01 | ||
|
||
def part1(input) | ||
'TODO' | ||
input.split("\n").map do |line| | ||
nums = line.chars.grep(/\d/) | ||
(nums.first + nums.last).to_i | ||
end.sum | ||
end | ||
|
||
DIGITS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'].freeze | ||
|
||
def part2(input) | ||
'TODO' | ||
regex = Regexp.new("(?=(#{DIGITS.join('|')}|\\d))") | ||
|
||
input.split("\n").map do |line| | ||
nums = line.scan(regex).flatten.map do |m| | ||
DIGITS.include?(m) ? DIGITS.index(m) : m | ||
end | ||
|
||
"#{nums.first}#{nums.last}".to_i | ||
end.sum | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative '../app' | ||
|
||
class TestDay01 < Minitest::Test | ||
def setup | ||
@data = File.read(File.join(APP_ROOT, 'examples', '01.txt')).rstrip | ||
@data_a = File.read(File.join(APP_ROOT, 'examples', '01_a.txt')).rstrip | ||
@data_b = File.read(File.join(APP_ROOT, 'examples', '01_b.txt')).rstrip | ||
@day = Day01.new | ||
end | ||
|
||
def test_part1 | ||
assert_equal @day.part1(@data), '' | ||
assert_equal @day.part1(@data_a), 142 | ||
end | ||
|
||
def test_part2 | ||
assert_equal @day.part2(@data), '' | ||
assert_equal @day.part2(@data_b), 281 | ||
end | ||
end |