Skip to content

Commit

Permalink
day 14 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
gregawoods committed Dec 17, 2023
1 parent 5657157 commit 0a0904a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Style/ExponentialNotation:
Style/FrozenStringLiteralComment:
Enabled: false
Style/GuardClause:
MinBodyLength: 3
Enabled: false
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Expand Down
10 changes: 10 additions & 0 deletions examples/14.txt
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..#....
63 changes: 63 additions & 0 deletions lib/days/14.rb
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
18 changes: 18 additions & 0 deletions test/14_test.rb
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

0 comments on commit 0a0904a

Please sign in to comment.