Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Commit

Permalink
Solved day 14.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianCassayre committed Dec 14, 2018
1 parent eaeec4f commit bef99c4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -18,7 +18,7 @@ Check out [my 2017 participation](https://github.com/FlorianCassayre/AdventOfCod
* [Day 11](https://adventofcode.com/2018/day/11): [solution](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day11.scala)
* [Day 12](https://adventofcode.com/2018/day/12): [solution](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day12.scala)
* [Day 13](https://adventofcode.com/2018/day/13): [solution](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day13.scala)
* [Day 14](https://adventofcode.com/2018/day/14): [](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day14.scala)
* [Day 14](https://adventofcode.com/2018/day/14): [solution](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day14.scala)
* [Day 15](https://adventofcode.com/2018/day/15): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day15.scala)
* [Day 16](https://adventofcode.com/2018/day/16): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day16.scala)
* [Day 17](https://adventofcode.com/2018/day/17): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day17.scala)
Expand Down
1 change: 1 addition & 0 deletions input/14.txt
@@ -0,0 +1 @@
409551
1 change: 1 addition & 0 deletions output/14A.txt
@@ -0,0 +1 @@
1631191756
1 change: 1 addition & 0 deletions output/14B.txt
@@ -0,0 +1 @@
20219475
31 changes: 31 additions & 0 deletions src/main/scala/adventofcode/solutions/Day14.scala
@@ -0,0 +1,31 @@
package adventofcode.solutions

import adventofcode.Day

object Day14 extends Day(14) {

val inputSeq = input.map(_.asDigit)

val ten = 10

def recipes(list: Vector[Int] = Vector(3, 7), a: Int = 0, b: Int = 1, i: Int = input.toInt, reverse: Boolean): Seq[Int] = {
if(reverse && list.slice(list.size - input.length, list.size) == inputSeq)
list.dropRight(input.length)
else if(reverse && list.slice(list.size - input.length - 1, list.size - 1) == inputSeq)
list.dropRight(input.length + 1)
else {
if (reverse || !reverse && list.size - ten <= i) {
val newList = list ++ (list(a) + list(b)).toString.map(_.asDigit)
recipes(newList, (a + newList(a) + 1) % newList.size, (b + newList(b) + 1) % newList.size, i, reverse)
} else {
list.slice(i, i + ten)
}
}
}

override def solutionA = recipes(reverse = false).mkString

override def solutionB = recipes(reverse = true).size

submit()
}

0 comments on commit bef99c4

Please sign in to comment.