This repository has been archived by the owner on Aug 21, 2019. It is now read-only.
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
0 parents
commit 4d1dc6e
Showing
7 changed files
with
171 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
target |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Florian Cassayre | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,54 @@ | ||
_My solutions to the 2018 edition of [Advent Of Code](https://adventofcode.com)._ | ||
|
||
Check out [my 2017 participation](https://github.com/FlorianCassayre/AdventOfCode-2017)! | ||
|
||
|
||
## Problems & Solutions | ||
|
||
* [Day 1](https://adventofcode.com/day/1): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day01.scala) | ||
* [Day 2](https://adventofcode.com/day/2): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day02.scala) | ||
* [Day 3](https://adventofcode.com/day/3): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day03.scala) | ||
* [Day 4](https://adventofcode.com/day/4): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day04.scala) | ||
* [Day 5](https://adventofcode.com/day/5): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day05.scala) | ||
* [Day 6](https://adventofcode.com/day/6): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day06.scala) | ||
* [Day 7](https://adventofcode.com/day/7): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day07.scala) | ||
* [Day 8](https://adventofcode.com/day/8): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day08.scala) | ||
* [Day 9](https://adventofcode.com/day/9): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day09.scala) | ||
* [Day 10](https://adventofcode.com/day/10): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day10.scala) | ||
* [Day 11](https://adventofcode.com/day/11): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day11.scala) | ||
* [Day 12](https://adventofcode.com/day/12): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day12.scala) | ||
* [Day 13](https://adventofcode.com/day/13): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day13.scala) | ||
* [Day 14](https://adventofcode.com/day/14): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day14.scala) | ||
* [Day 15](https://adventofcode.com/day/15): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day15.scala) | ||
* [Day 16](https://adventofcode.com/day/16): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day16.scala) | ||
* [Day 17](https://adventofcode.com/day/17): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day17.scala) | ||
* [Day 18](https://adventofcode.com/day/18): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day18.scala) | ||
* [Day 19](https://adventofcode.com/day/19): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day19.scala) | ||
* [Day 20](https://adventofcode.com/day/20): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day20.scala) | ||
* [Day 21](https://adventofcode.com/day/21): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day21.scala) | ||
* [Day 22](https://adventofcode.com/day/22): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day22.scala) | ||
* [Day 23](https://adventofcode.com/day/23): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day23.scala) | ||
* [Day 24](https://adventofcode.com/day/24): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day24.scala) | ||
* [Day 25](https://adventofcode.com/day/25): –[](https://github.com/FlorianCassayre/AdventOfCode-2018/blob/master/src/main/scala/adventofcode/solutions/Day25.scala) | ||
|
||
|
||
## Testing | ||
|
||
You'll need Scala `2.12.7` and sbt `1.2.6`. | ||
|
||
Start by entering the sbt shell: | ||
``` | ||
$ sbt | ||
``` | ||
|
||
To run a solution - for instance **day 1** - you can conveniently use the following command: | ||
``` | ||
> day 1 | ||
``` | ||
|
||
The output will be printed to the console and stored to the corresponding file in `output/`. | ||
|
||
|
||
## License | ||
|
||
This repository is licensed under the MIT License, please refer to the `LICENSE` file. |
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,17 @@ | ||
lazy val root = project | ||
.in(file(".")) | ||
.settings( | ||
name := "AdventOfCode-2018", | ||
description := "Advent of Code 2018", | ||
version := "0.1.0", | ||
|
||
scalaVersion := "2.12.7" | ||
) | ||
|
||
commands += Command("day") { _ => | ||
import complete.DefaultParsers._ | ||
(' ' ~ charClass(_.isDigit, "digit").+.map(_.mkString.toInt)).map(_._2) | ||
} { case (previousState, i: Int) => | ||
val formatted = "%02d".format(i) | ||
Command.process(s"runMain adventofcode.solutions.Day$formatted", previousState) | ||
} |
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 @@ | ||
sbt.version = 1.2.6 |
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,64 @@ | ||
package adventofcode | ||
|
||
import java.io.PrintWriter | ||
|
||
import scala.io.Source | ||
import scala.util.{Failure, Success, Try} | ||
|
||
abstract class Day(day: Int) extends App { | ||
|
||
sealed abstract class SubProblem(val name: String) | ||
case object A extends SubProblem("A") | ||
case object B extends SubProblem("B") | ||
|
||
require(day >= 1 && day <= 25, "Invalid day number") | ||
|
||
protected val lineSeparator: String = "\n" | ||
|
||
private val formatted = "%02d".format(day) | ||
|
||
private def readInput(): String = Source.fromFile(s"input/$formatted.txt").getLines().mkString(lineSeparator) | ||
|
||
private def writeOutput(output: String, subProblem: SubProblem): Unit = { | ||
val sub = subProblem.name | ||
new PrintWriter(s"output/$formatted$sub.txt") { | ||
write(output) | ||
close() | ||
} | ||
} | ||
|
||
protected val input: String = readInput() | ||
protected val lines: IndexedSeq[String] = input.split(lineSeparator).toIndexedSeq | ||
|
||
|
||
def solutionA: Any | ||
def solutionB: Any | ||
|
||
|
||
// To be called at the end | ||
|
||
var submitted: Boolean = false | ||
|
||
protected def submit(): Unit = { | ||
assert(!submitted, "Solution has already been submitted") | ||
submitted = true | ||
|
||
submitSolution(solutionA, A) | ||
submitSolution(solutionB, B) | ||
} | ||
|
||
private def submitSolution(function: => Any, subProblem: SubProblem): Unit = { | ||
Try(function.toString) match { | ||
case Success(string) => | ||
writeOutput(string, subProblem) | ||
println(string) | ||
println() | ||
case Failure(_: NotImplementedError) => | ||
println(s"(ignored solution ${subProblem.name})") | ||
println() | ||
case Failure(exception) => | ||
throw new RuntimeException(exception) | ||
} | ||
} | ||
|
||
} |
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,12 @@ | ||
package adventofcode.solutions | ||
|
||
import adventofcode.Day | ||
|
||
object Day01 extends Day(1) { | ||
|
||
override def solutionA = ??? | ||
|
||
override def solutionB = ??? | ||
|
||
submit() | ||
} |