Commit d2e759c7 authored by David's avatar David

Day 1

parent 3c0b6664
plugins {
application
}
dependencies {
}
140170
75120
75645
134664
124948
137630
146662
116881
120030
94332
50473
59361
128237
84894
51368
128802
57275
129235
113481
66378
55842
90548
107696
53603
130458
80306
120820
131313
100303
59224
123369
140584
60642
68184
103101
82278
51968
51048
98139
60498
127082
71197
109478
71286
84840
141305
51800
72352
93147
73549
122739
62363
58453
59000
63564
63424
51053
120826
123337
130824
59053
77983
68977
67126
96051
53024
145647
139343
113236
59396
146174
148622
83384
86938
100673
80757
107675
147417
124538
136463
104609
149559
136037
54997
139674
101638
65739
70029
143847
122035
66256
78087
105045
108867
99630
127173
139021
139759
134171
104869
package is.kow.adventofcode._2019
import scala.io.Source
object Puzzle1Main extends App {
//Read in the inputs, and do all the calcs
val source = Source.fromResource("input.txt")
try {
val lines = source.getLines()
val p1 = new Puzzle1
val totalFuel = lines.foldLeft(0) { (acc, line) =>
acc + p1.calculateFuel(line.toInt)
}
println("Total fuel required for part 1: " + totalFuel)
} finally source.close()
}
class Puzzle1 {
def calculateFuel(input: Int): Int = {
val first = Math.floor(input.toFloat / 3).toInt
first - 2
}
//recursive fuel calculation function!
}
package is.kow.adventofcode._2019
import org.junit.runner.RunWith
import org.scalatest.funspec.AnyFunSpec
import org.scalatestplus.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class Puzzle1Spec extends AnyFunSpec {
val p1 = new Puzzle1
describe("part 1") {
it("returns 2 for 12"){
assert(p1.calculateFuel(12) == 2)
}
it("returns 2 for 14") {
assert(p1.calculateFuel(14) == 2)
}
it("returns 654 for 1969") {
assert(p1.calculateFuel(1969) == 654)
}
it("returns 33583 for 100756") {
assert(p1.calculateFuel(100756) == 33583)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment