-
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
5657157
commit 0a0904a
Showing
4 changed files
with
92 additions
and
1 deletion.
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
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,10 @@ | ||
O....#.... | ||
O.OO#....# | ||
.....##... | ||
OO.#O....O | ||
.O.....O#. | ||
O.#..O.#.# | ||
..O..#O..O | ||
.......O.. | ||
#....###.. | ||
#OO..#.... |
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,63 @@ | ||
class Day14 | ||
|
||
def part1(input) | ||
lines = input.split("\n") | ||
|
||
columns = [] | ||
|
||
lines.length.times do |n| | ||
lines[n].chars.each_with_index do |char, i| | ||
columns[i] ||= [] | ||
columns[i] << char | ||
end | ||
end | ||
|
||
columns = columns.map do |c| | ||
shift_column(c) | ||
end | ||
|
||
value = 0 | ||
|
||
columns.each do |col| | ||
col.each_with_index do |obj, index| | ||
if obj == 'O' | ||
value += (col.length - index) | ||
end | ||
end | ||
end | ||
|
||
value | ||
end | ||
|
||
def shift_column(column) | ||
column.length.times do |n| | ||
next if n.zero? | ||
|
||
n.times do |i| | ||
position = n - i | ||
|
||
char = column[position] | ||
prev_char = column[position - 1] | ||
|
||
if char == 'O' && prev_char == '.' | ||
column[position] = '.' | ||
column[position - 1] = 'O' | ||
else | ||
break | ||
end | ||
end | ||
end | ||
|
||
column | ||
end | ||
|
||
def rotate_clockwise(columns) | ||
new_columns = [] | ||
|
||
end | ||
|
||
def part2(input) | ||
'TODO' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative '../app' | ||
|
||
class TestDay14 < Minitest::Test | ||
def setup | ||
@data = File.read(File.join(APP_ROOT, 'examples', '14.txt')).rstrip | ||
@day = Day14.new | ||
end | ||
|
||
def test_part1 | ||
assert_equal @day.part1(@data), 136 | ||
end | ||
|
||
def test_part2 | ||
assert_equal @day.part2(@data), '' | ||
end | ||
end |