mirror of
https://github.com/chylex/Advent-of-Code.git
synced 2025-07-25 21:59:06 +02:00
Move and rename input files
This commit is contained in:
parent
4407184536
commit
f4b90f89e8
2015
2020
2021
@ -16,7 +16,7 @@ extern void print(const char *format, ...) {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char *input = readFile("input/1.txt");
|
||||
char *input = readFile("input.txt");
|
||||
|
||||
if (input == NULL) {
|
||||
return 1;
|
||||
|
@ -8,7 +8,7 @@ use std::io::{BufRead, BufReader};
|
||||
use std::str::FromStr;
|
||||
|
||||
pub fn read_input_lines() -> Result<Vec<String>, io::Error> {
|
||||
let file = File::open("input/1.txt")?;
|
||||
let file = File::open("input.txt")?;
|
||||
return BufReader::new(file).lines().collect();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import java.io.File
|
||||
|
||||
fun main() {
|
||||
val lines = File("input/1.txt").readLines().map(String::toInt)
|
||||
val lines = File("input.txt").readLines().map(String::toInt)
|
||||
|
||||
val totalIncreases = lines.windowed(2).count { it[1] > it[0] }
|
||||
val windowedIncreases = lines.windowed(3).map(List<Int>::sum).windowed(2).count { it[1] > it[0] }
|
||||
|
@ -1,7 +1,7 @@
|
||||
import java.io.File
|
||||
|
||||
fun main() {
|
||||
val lines = File("input/1.txt").readLines()
|
||||
val lines = File("input.txt").readLines()
|
||||
val directions = lines.map { line -> line.split(' ', limit = 2).let { it[0] to it[1].toInt() } }
|
||||
|
||||
println("Part 1:")
|
||||
|
@ -1,7 +1,7 @@
|
||||
import java.io.File
|
||||
|
||||
fun main() {
|
||||
val lines = File("input/1.txt").readLines().filter(String::isNotEmpty)
|
||||
val lines = File("input.txt").readLines().filter(String::isNotEmpty)
|
||||
val input = Input(lines)
|
||||
part1(input)
|
||||
part2(input)
|
||||
|
@ -3,7 +3,7 @@ import java.io.File
|
||||
const val SIZE = 5
|
||||
|
||||
fun main() {
|
||||
val lineIterator = File("input/1.txt").readLines().iterator()
|
||||
val lineIterator = File("input.txt").readLines().iterator()
|
||||
val numbersToDraw = lineIterator.next().split(',').map(String::toInt).toList()
|
||||
val boards = mutableListOf<Board>()
|
||||
|
||||
|
@ -6,7 +6,7 @@ import kotlin.system.measureTimeMillis
|
||||
|
||||
fun main() {
|
||||
val lineRegex = Regex("^(\\d+),(\\d+) -> (\\d+),(\\d+)$")
|
||||
val lines = File("input/1.txt").readLines()
|
||||
val lines = File("input.txt").readLines()
|
||||
.mapNotNull(lineRegex::matchEntire)
|
||||
.map { it.groupValues.takeLast(4).map(String::toInt) }
|
||||
.map { Line(it[0], it[1], it[2], it[3]) }
|
||||
@ -15,7 +15,7 @@ fun main() {
|
||||
println("(Took ${measureTimeMillis { part2(lines) }} ms)")
|
||||
}
|
||||
|
||||
@Suppress("ProtectedInFinal", "MemberVisibilityCanBePrivate")
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
data class Line(val x1: Int, val y1: Int, val x2: Int, val y2: Int) {
|
||||
val minX = min(x1, x2)
|
||||
val minY = min(y1, y2)
|
||||
|
@ -3,7 +3,7 @@ import java.math.BigInteger
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
fun main() {
|
||||
val initialConfiguration = File("input/1.txt").readLines()
|
||||
val initialConfiguration = File("input.txt").readLines()
|
||||
.single()
|
||||
.split(',')
|
||||
.map(String::toInt)
|
||||
|
@ -2,7 +2,7 @@ import java.io.File
|
||||
import kotlin.math.abs
|
||||
|
||||
fun main() {
|
||||
val originalPositions = File("input/1.txt").readLines().single().split(',').map(String::toInt).toIntArray()
|
||||
val originalPositions = File("input.txt").readLines().single().split(',').map(String::toInt).toIntArray()
|
||||
|
||||
val p1 = originalPositions.minOrNull() ?: return
|
||||
val p2 = originalPositions.maxOrNull() ?: return
|
||||
|
@ -9,7 +9,7 @@ import java.io.File
|
||||
import java.util.EnumSet
|
||||
|
||||
fun main() {
|
||||
val records = File("input/1.txt").readLines().map { line ->
|
||||
val records = File("input.txt").readLines().map { line ->
|
||||
line.split(" | ", limit = 2).map { it.split(' ') }.let { Record(it[0], it[1]) }
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ fun main() {
|
||||
|
||||
fun part1(records: List<Record>) {
|
||||
@Suppress("ConvertLambdaToReference")
|
||||
val segmentCountToDigits = DIGITS
|
||||
val segmentCountToDigits = allDigits
|
||||
.map { it.value to it.positions.size }
|
||||
.groupBy { it.second }
|
||||
.mapValues { it.value.map { e -> e.first } }
|
||||
@ -48,7 +48,7 @@ enum class Position {
|
||||
BOTTOM
|
||||
}
|
||||
|
||||
private val DIGITS = listOf(
|
||||
private val allDigits = listOf(
|
||||
Digit(0, EnumSet.of(TOP, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, BOTTOM)),
|
||||
Digit(1, EnumSet.of(TOP_RIGHT, BOTTOM_RIGHT)),
|
||||
Digit(2, EnumSet.of(TOP, TOP_RIGHT, MIDDLE, BOTTOM_LEFT, BOTTOM)),
|
||||
@ -124,7 +124,7 @@ data class Record(val patterns: List<String>, val output: List<String>) {
|
||||
|
||||
return output.fold(0) { total, digit ->
|
||||
val positions = digit.map(mapping::getValue).toSet()
|
||||
val value = DIGITS.first { it.positions == positions }.value
|
||||
val value = allDigits.first { it.positions == positions }.value
|
||||
|
||||
(total * 10) + value
|
||||
}
|
||||
|
@ -17,30 +17,24 @@ dependencies {
|
||||
}
|
||||
|
||||
idea {
|
||||
module.excludeDirs.addAll(listOf(
|
||||
file(".gradle"),
|
||||
file("build"),
|
||||
file("gradle"),
|
||||
))
|
||||
module.excludeDirs.add(file("gradle"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
fun make(day: Int) {
|
||||
val paddedDay = day.toString().padStart(2, '0')
|
||||
|
||||
val sourceFolder = file(paddedDay)
|
||||
val resourceFolder = sourceFolder.resolve("input")
|
||||
|
||||
if (!sourceFolder.exists()) {
|
||||
sourceFolder.mkdir()
|
||||
sourceFolder.resolve("main.kt").writeText("fun main() {\n\t\n}")
|
||||
resourceFolder.mkdir()
|
||||
resourceFolder.resolve("1.txt").writeText("")
|
||||
sourceFolder.resolve("input.txt").writeText("")
|
||||
}
|
||||
|
||||
create(paddedDay) {
|
||||
java.setSrcDirs(listOf(sourceFolder))
|
||||
resources.setSrcDirs(listOf(resourceFolder))
|
||||
resources.setSrcDirs(listOf(sourceFolder))
|
||||
resources.include("*.txt")
|
||||
}
|
||||
|
||||
tasks.register<JavaExec>(paddedDay) {
|
||||
|
Loading…
Reference in New Issue
Block a user