Part 1 for day 21.

This commit is contained in:
2017-12-21 13:55:55 +01:00
parent eee1f48629
commit 4276edc6ef
3 changed files with 191 additions and 1 deletions

View File

@@ -12,7 +12,8 @@ The current plan, in no particular order:
- [x] C++ - [Day 01](./day-01/solution.cpp)
- [x] C# - [Day 07](./day-07/solution.cs)
- [x] Clojure - [Day 03](./day-03/solution.clj)
- [ ] Coffeescript
- [ ] Coffeescript - [Day 21](./day-21/solution.coffee) (Need to finish
part 2)
- [x] Go - [Day 13](./day-13/solution.go)
- [x] Groovy - [Day 16](./day-16/solution.groovy)
- [x] Haskell - [Day 15](./day-15/solution.hs)

108
2017/day-21/input.txt Normal file
View File

@@ -0,0 +1,108 @@
../.. => .##/#../..#
#./.. => .##/#../###
##/.. => ..#/#.#/#..
.#/#. => #../#../.#.
##/#. => .#./#../#..
##/## => .##/.../.##
.../.../... => #.#./###./####/#..#
#../.../... => .###/####/##../#.##
.#./.../... => ###./.###/#..#/#.##
##./.../... => ..../..../.#../##..
#.#/.../... => ...#/.##./..../##..
###/.../... => ##../##../##.#/..##
.#./#../... => .#../###./##../####
##./#../... => ####/##.#/..../..##
..#/#../... => ..#./####/...#/#.##
#.#/#../... => #.#./##../##../.##.
.##/#../... => ##../####/..#./...#
###/#../... => #..#/#.#./##.#/#.#.
.../.#./... => .#.#/..#./#.../....
#../.#./... => ##../..##/..##/.#..
.#./.#./... => ..../##../##../#.##
##./.#./... => ...#/##../#..#/.###
#.#/.#./... => ####/##.#/###./..##
###/.#./... => ..../...#/.###/.#..
.#./##./... => #.#./#..#/.##./.#.#
##./##./... => .###/#.../#..#/#.#.
..#/##./... => .###/####/..../#.##
#.#/##./... => ...#/.###/.###/.###
.##/##./... => ..##/..##/.###/##.#
###/##./... => ####/#..#/####/#.#.
.../#.#/... => #.##/..#./.###/#.#.
#../#.#/... => ####/##.#/##.#/....
.#./#.#/... => #.../...#/#.##/#..#
##./#.#/... => .#.#/##../##../....
#.#/#.#/... => ##.#/#.../##../.#..
###/#.#/... => ...#/###./.#.#/...#
.../###/... => .###/#.##/#.../###.
#../###/... => ..##/.#../.###/..#.
.#./###/... => ..../.##./#.##/#.##
##./###/... => .#.#/##.#/#.../#.#.
#.#/###/... => ..#./#.../#.#./.##.
###/###/... => ..##/.#.#/#..#/.##.
..#/.../#.. => ..##/.#../##.#/##..
#.#/.../#.. => ..#./..../#.../...#
.##/.../#.. => .##./..##/####/#...
###/.../#.. => #.##/..../##../#.##
.##/#../#.. => .###/...#/###./....
###/#../#.. => .#.#/#.#./#.##/..#.
..#/.#./#.. => ...#/..#./..##/.#.#
#.#/.#./#.. => #.../##.#/.###/#.#.
.##/.#./#.. => ###./####/#..#/##.#
###/.#./#.. => ..../..#./..../#...
.##/##./#.. => .#.#/.##./.#.#/#.##
###/##./#.. => ..../##../###./.#.#
#../..#/#.. => ...#/#.../#.##/.###
.#./..#/#.. => #..#/.#../###./#.#.
##./..#/#.. => #.#./..#./###./###.
#.#/..#/#.. => .#.#/##.#/##../####
.##/..#/#.. => ###./..../.#../...#
###/..#/#.. => #.#./.##./.#.#/#..#
#../#.#/#.. => #.#./##.#/.#../.###
.#./#.#/#.. => ##.#/#.#./#.../####
##./#.#/#.. => .#.#/#.../..#./#.##
..#/#.#/#.. => ##.#/.##./#.../.###
#.#/#.#/#.. => ..##/..../..../####
.##/#.#/#.. => ####/#.#./###./.#.#
###/#.#/#.. => #.##/..#./##../#...
#../.##/#.. => ..##/##.#/####/.#..
.#./.##/#.. => ..##/##../.#../..##
##./.##/#.. => ..##/.#.#/#..#/....
#.#/.##/#.. => #.../##../...#/.#.#
.##/.##/#.. => ##../...#/.###/.#.#
###/.##/#.. => ####/..#./.##./#.##
#../###/#.. => .#.#/##.#/#.#./#.#.
.#./###/#.. => .###/#..#/.#.#/###.
##./###/#.. => ##../.#../###./.#.#
..#/###/#.. => #.##/..../...#/..#.
#.#/###/#.. => #.../#..#/..../.#..
.##/###/#.. => ####/#..#/..#./.#.#
###/###/#.. => .##./##../.#../..#.
.#./#.#/.#. => #.#./.###/#.#./..##
##./#.#/.#. => .##./..../..##/##..
#.#/#.#/.#. => ...#/..../.#.#/..##
###/#.#/.#. => .#../####/#.#./#.##
.#./###/.#. => #..#/.#.#/#..#/#.#.
##./###/.#. => .#../##../#..#/..##
#.#/###/.#. => #.#./.##./##.#/.#.#
###/###/.#. => #.#./...#/..##/#...
#.#/..#/##. => ..#./..#./...#/#..#
###/..#/##. => #..#/###./..../##.#
.##/#.#/##. => #.##/.#.#/...#/..##
###/#.#/##. => #.##/...#/.##./.###
#.#/.##/##. => ..../##.#/..../...#
###/.##/##. => .###/#.../###./###.
.##/###/##. => #.../#.#./.###/..#.
###/###/##. => #.##/.#../..#./.#.#
#.#/.../#.# => .##./##../###./.###
###/.../#.# => ..##/...#/###./.#..
###/#../#.# => ##.#/..#./#.##/.#..
#.#/.#./#.# => .#../#.##/...#/###.
###/.#./#.# => ..#./..../####/####
###/##./#.# => ###./#..#/..../#..#
#.#/#.#/#.# => ##.#/###./..../#...
###/#.#/#.# => ##../.###/#..#/.#..
#.#/###/#.# => #.../###./.###/..#.
###/###/#.# => ..../.##./.#../###.
###/#.#/### => ##../#.../.###/#...
###/###/### => .###/###./#.##/..#.

View File

@@ -0,0 +1,81 @@
String.prototype.count = (pattern) ->
(this.match(pattern) || []).length
stdin = process.openStdin()
stdin.setEncoding 'utf8'
data = ''
stdin.on 'data', (input) ->
data += input
stdin.on 'end', () ->
mappings = {}
rotate = (line) ->
rows = line.split '/'
newrows = []
len = rows.length
for i in [0...len]
newrows[i] = ''
for j in [0...len]
newrows[i] += rows[rows.length - 1 - j].substr i, 1
newrows.join '/'
flip = (line) ->
(row.split('').reverse().join '' for row in line.split '/').join '/'
view = (state) ->
console.log state.split('/').join "\n"
for line in data.trim().split('\n')
do (line) ->
[source, enhanced] = line.split ' => '
for i in [1..4]
mappings[source] = enhanced
mappings[flip source] = enhanced
source = rotate source
state = '.#./..#/###'
view state
for _ in [1..5]
newrows = []
oldrows = state.split '/'
if oldrows.length % 2 == 0
for i in [0...(oldrows.length / 2)]
currows = ['', '', '']
for j in [0...(oldrows.length / 2)]
curblock = (oldrows[2 * i].substr 2 * j, 2) + '/' + (oldrows[2 * i + 1].substr 2 * j, 2)
blockrows = mappings[curblock].split '/'
for r in [0..2]
currows[r] += blockrows[r]
for row in currows
newrows.push row
else
for i in [0...(oldrows.length / 3)]
currows = ['', '', '', '']
for j in [0...(oldrows.length / 3)]
curblock = (oldrows[3 * i].substr 3 * j, 3) + '/' + (oldrows[3 * i + 1].substr 3 * j, 3) + '/' + (oldrows[3 * i + 2].substr 3 * j, 3)
blockrows = mappings[curblock].split '/'
for r in [0..3]
currows[r] += blockrows[r]
for row in currows
newrows.push row
state = newrows.join '/'
console.log(state.count(/#/g))
view state