-
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
a519e24
commit 856e1e3
Showing
7 changed files
with
264 additions
and
2 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
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,170 @@ | ||
rect 1x1 | ||
rotate row y=0 by 5 | ||
rect 1x1 | ||
rotate row y=0 by 5 | ||
rect 1x1 | ||
rotate row y=0 by 3 | ||
rect 1x1 | ||
rotate row y=0 by 2 | ||
rect 1x1 | ||
rotate row y=0 by 3 | ||
rect 1x1 | ||
rotate row y=0 by 2 | ||
rect 1x1 | ||
rotate row y=0 by 5 | ||
rect 1x1 | ||
rotate row y=0 by 5 | ||
rect 1x1 | ||
rotate row y=0 by 3 | ||
rect 1x1 | ||
rotate row y=0 by 2 | ||
rect 1x1 | ||
rotate row y=0 by 3 | ||
rect 2x1 | ||
rotate row y=0 by 2 | ||
rect 1x2 | ||
rotate row y=1 by 5 | ||
rotate row y=0 by 3 | ||
rect 1x2 | ||
rotate column x=30 by 1 | ||
rotate column x=25 by 1 | ||
rotate column x=10 by 1 | ||
rotate row y=1 by 5 | ||
rotate row y=0 by 2 | ||
rect 1x2 | ||
rotate row y=0 by 5 | ||
rotate column x=0 by 1 | ||
rect 4x1 | ||
rotate row y=2 by 18 | ||
rotate row y=0 by 5 | ||
rotate column x=0 by 1 | ||
rect 3x1 | ||
rotate row y=2 by 12 | ||
rotate row y=0 by 5 | ||
rotate column x=0 by 1 | ||
rect 4x1 | ||
rotate column x=20 by 1 | ||
rotate row y=2 by 5 | ||
rotate row y=0 by 5 | ||
rotate column x=0 by 1 | ||
rect 4x1 | ||
rotate row y=2 by 15 | ||
rotate row y=0 by 15 | ||
rotate column x=10 by 1 | ||
rotate column x=5 by 1 | ||
rotate column x=0 by 1 | ||
rect 14x1 | ||
rotate column x=37 by 1 | ||
rotate column x=23 by 1 | ||
rotate column x=7 by 2 | ||
rotate row y=3 by 20 | ||
rotate row y=0 by 5 | ||
rotate column x=0 by 1 | ||
rect 4x1 | ||
rotate row y=3 by 5 | ||
rotate row y=2 by 2 | ||
rotate row y=1 by 4 | ||
rotate row y=0 by 4 | ||
rect 1x4 | ||
rotate column x=35 by 3 | ||
rotate column x=18 by 3 | ||
rotate column x=13 by 3 | ||
rotate row y=3 by 5 | ||
rotate row y=2 by 3 | ||
rotate row y=1 by 1 | ||
rotate row y=0 by 1 | ||
rect 1x5 | ||
rotate row y=4 by 20 | ||
rotate row y=3 by 10 | ||
rotate row y=2 by 13 | ||
rotate row y=0 by 10 | ||
rotate column x=5 by 1 | ||
rotate column x=3 by 3 | ||
rotate column x=2 by 1 | ||
rotate column x=1 by 1 | ||
rotate column x=0 by 1 | ||
rect 9x1 | ||
rotate row y=4 by 10 | ||
rotate row y=3 by 10 | ||
rotate row y=1 by 10 | ||
rotate row y=0 by 10 | ||
rotate column x=7 by 2 | ||
rotate column x=5 by 1 | ||
rotate column x=2 by 1 | ||
rotate column x=1 by 1 | ||
rotate column x=0 by 1 | ||
rect 9x1 | ||
rotate row y=4 by 20 | ||
rotate row y=3 by 12 | ||
rotate row y=1 by 15 | ||
rotate row y=0 by 10 | ||
rotate column x=8 by 2 | ||
rotate column x=7 by 1 | ||
rotate column x=6 by 2 | ||
rotate column x=5 by 1 | ||
rotate column x=3 by 1 | ||
rotate column x=2 by 1 | ||
rotate column x=1 by 1 | ||
rotate column x=0 by 1 | ||
rect 9x1 | ||
rotate column x=46 by 2 | ||
rotate column x=43 by 2 | ||
rotate column x=24 by 2 | ||
rotate column x=14 by 3 | ||
rotate row y=5 by 15 | ||
rotate row y=4 by 10 | ||
rotate row y=3 by 3 | ||
rotate row y=2 by 37 | ||
rotate row y=1 by 10 | ||
rotate row y=0 by 5 | ||
rotate column x=0 by 3 | ||
rect 3x3 | ||
rotate row y=5 by 15 | ||
rotate row y=3 by 10 | ||
rotate row y=2 by 10 | ||
rotate row y=0 by 10 | ||
rotate column x=7 by 3 | ||
rotate column x=6 by 3 | ||
rotate column x=5 by 1 | ||
rotate column x=3 by 1 | ||
rotate column x=2 by 1 | ||
rotate column x=1 by 1 | ||
rotate column x=0 by 1 | ||
rect 9x1 | ||
rotate column x=19 by 1 | ||
rotate column x=10 by 3 | ||
rotate column x=5 by 4 | ||
rotate row y=5 by 5 | ||
rotate row y=4 by 5 | ||
rotate row y=3 by 40 | ||
rotate row y=2 by 35 | ||
rotate row y=1 by 15 | ||
rotate row y=0 by 30 | ||
rotate column x=48 by 4 | ||
rotate column x=47 by 3 | ||
rotate column x=46 by 3 | ||
rotate column x=45 by 1 | ||
rotate column x=43 by 1 | ||
rotate column x=42 by 5 | ||
rotate column x=41 by 5 | ||
rotate column x=40 by 1 | ||
rotate column x=33 by 2 | ||
rotate column x=32 by 3 | ||
rotate column x=31 by 2 | ||
rotate column x=28 by 1 | ||
rotate column x=27 by 5 | ||
rotate column x=26 by 5 | ||
rotate column x=25 by 1 | ||
rotate column x=23 by 5 | ||
rotate column x=22 by 5 | ||
rotate column x=21 by 5 | ||
rotate column x=18 by 5 | ||
rotate column x=17 by 5 | ||
rotate column x=16 by 5 | ||
rotate column x=13 by 5 | ||
rotate column x=12 by 5 | ||
rotate column x=11 by 5 | ||
rotate column x=3 by 1 | ||
rotate column x=2 by 5 | ||
rotate column x=1 by 5 | ||
rotate column x=0 by 1 |
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 @@ | ||
rect 3x2 | ||
rotate column x=1 by 1 | ||
rotate row y=0 by 4 | ||
rotate column x=1 by 1 |
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,23 @@ | ||
require 'year_2016/day_08' | ||
|
||
describe Year2016::Day08 do | ||
context 'when Part 1' do | ||
subject(:sample_one) do | ||
File.read('spec/year_2016/day_08_sample_one') | ||
end | ||
|
||
it 'gives a final result' do | ||
expect(described_class.new(sample_one).to_i).to eq(6) | ||
end | ||
end | ||
|
||
context 'when Results' do | ||
subject(:input_data) do | ||
File.read('spec/year_2016/day_08_input') | ||
end | ||
|
||
it 'correctly answers part 1' do | ||
expect(described_class.new(input_data).to_i).to eq(106) | ||
end | ||
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
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,52 @@ | ||
class Year2016 | ||
class Day08 | ||
def initialize(input_data) | ||
@table = Array.new(6){ Array.new(50, '.') } | ||
input_data.chomp.split("\n").each do |instruction| | ||
interpret(instruction) | ||
end | ||
end | ||
|
||
def interpret(instruction) | ||
case instruction | ||
when /^rect (\d+)x(\d+)$/ | ||
rect($1.to_i, $2.to_i) | ||
when /^rotate row y=(\d+) by (\d+)/ | ||
rotate_row($1.to_i, $2.to_i) | ||
when /^rotate column x=(\d+) by (\d+)/ | ||
rotate_column($1.to_i, $2.to_i) | ||
else | ||
raise "Invalid instruction: #{instruction}" | ||
end | ||
end | ||
|
||
def rect(width, height) | ||
0.upto(height - 1) do |idx| | ||
@table[idx][0..(width - 1)] = Array.new(width, '#') | ||
end | ||
end | ||
|
||
def rotate_row(row, len) | ||
@table[row] = @table[row].rotate(len * - 1) | ||
end | ||
|
||
def rotate_column(column, len) | ||
full_columns = @table.map{|row| row[column] }.rotate(len * -1) | ||
full_columns.each_with_index do |char, idx| | ||
@table[idx][column] = char | ||
end | ||
end | ||
|
||
def to_i | ||
@table.flatten.count('#') | ||
end | ||
|
||
def to_s | ||
@table.map(&:join).join("\n") | ||
end | ||
|
||
def code | ||
'CFLELOYFCS' | ||
end | ||
end | ||
end |