Day01 2021
This commit is contained in:
parent
ae327a4928
commit
ccfcf5a259
18
2021/build.gradle.kts
Normal file
18
2021/build.gradle.kts
Normal file
@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
id("kotlin-convention")
|
||||
kotlin("kapt")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":utils"))
|
||||
|
||||
kapt(Libs.Micronaut.processor)
|
||||
|
||||
implementation(Libs.Slf4J.api)
|
||||
runtimeOnly(Libs.Slf4J.simple)
|
||||
|
||||
implementation(Libs.eclipseCollections)
|
||||
|
||||
testImplementation(Libs.Jmh.core)
|
||||
kaptTest(Libs.Jmh.processor)
|
||||
}
|
||||
28
2021/src/main/kotlin/Day01.kt
Normal file
28
2021/src/main/kotlin/Day01.kt
Normal file
@ -0,0 +1,28 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
|
||||
@Day(1)
|
||||
class Day01(@Lines input: Input<IntArray>) {
|
||||
private val items = input.value
|
||||
|
||||
fun part1(): Int {
|
||||
var count = 0
|
||||
for (i in 0 until items.size - 1) {
|
||||
if (items[i] < items[i + 1]) count++
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
fun part2(): Int {
|
||||
var count = 0
|
||||
for (i in 0 until items.size - 3) {
|
||||
val a = items.drop(i).take(3).sum()
|
||||
val b = items.drop(i + 1).take(3).sum()
|
||||
if (b > a) count++
|
||||
}
|
||||
return count
|
||||
}
|
||||
}
|
||||
7
2021/src/main/kotlin/Main.kt
Normal file
7
2021/src/main/kotlin/Main.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.factory.createDay
|
||||
|
||||
fun main() = with(createDay<Day01>()) {
|
||||
println(part2())
|
||||
}
|
||||
2000
2021/src/main/resources/day01.txt
Normal file
2000
2021/src/main/resources/day01.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,5 @@ plugins {
|
||||
}
|
||||
|
||||
adventOfCode {
|
||||
year = 2020
|
||||
session = file(".session").readText().trim()
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ import org.gradle.kotlin.dsl.getByType
|
||||
|
||||
open class AdventOfCodeExtension {
|
||||
var session: String? = null
|
||||
var year: Int = 2020
|
||||
}
|
||||
|
||||
class AdventOfCodeDownloaderPlugin : Plugin<Project> {
|
||||
@ -26,8 +25,12 @@ class AdventOfCodeDownloaderPlugin : Plugin<Project> {
|
||||
throw GradleException("advent of code session not set")
|
||||
}
|
||||
|
||||
val now = LocalDateTime.now()
|
||||
val year = now.year
|
||||
val currentDay = now.dayOfMonth.toString()
|
||||
|
||||
val resourceDir: File = project
|
||||
.project(":days")
|
||||
.project(":$year")
|
||||
.extensions
|
||||
.getByType<SourceSetContainer>()
|
||||
.getByName("main")
|
||||
@ -35,9 +38,9 @@ class AdventOfCodeDownloaderPlugin : Plugin<Project> {
|
||||
.srcDirs
|
||||
.first()
|
||||
|
||||
val currentDay = LocalDateTime.now().dayOfMonth.toString()
|
||||
|
||||
val outFile = File(resourceDir, "day" + currentDay.padStart(length = 2, padChar = '0') + ".txt")
|
||||
val url = "https://adventofcode.com/${extension.year}/day/$currentDay/input"
|
||||
val url = "https://adventofcode.com/$year/day/$currentDay/input"
|
||||
|
||||
Unirest.get(url)
|
||||
.cookie("session", extension.session)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
rootProject.name = "Advent of Code"
|
||||
include("utils")
|
||||
include("2020")
|
||||
include("2019")
|
||||
include("2020")
|
||||
include("2021")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user