-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate
executable file
·82 lines (69 loc) · 2.05 KB
/
generate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
if [[ $# != 1 ]]; then
echo "Usage: generate packagename"
exit 1
fi
package="$1"
basedir="$(dirname "$0")/${package}"
day="$(echo "${package}" | tr -d -c 0-9)"
main="$(tr '[a-z]' '[A-Z]' <<< ${package:0:1})${package:1}"
mkdir -p "${basedir}"
touch "${basedir}/input.example.txt" "${basedir}/input.actual.txt"
cat > "${basedir}/${package}.kt" <<EOKOTLIN
// Copyright 2021 Google LLC
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
package ${package}
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource
import kotlin.time.measureTimedValue
object Part1 {
fun solve(input: Sequence<String>): String {
return TODO("Implement part 1")
}
}
object Part2 {
fun solve(input: Sequence<String>): String {
return TODO("Implement part 2")
}
}
@ExperimentalTime
@Suppress("UNUSED_PARAMETER")
fun main(args: Array<String>) {
val lines = generateSequence(::readLine).toList()
println("Part 1:")
TimeSource.Monotonic.measureTimedValue { Part1.solve(lines.asSequence()) }.let {
println(it.value)
println("Completed in \${it.duration}")
}
println("Part 2:")
TimeSource.Monotonic.measureTimedValue { Part2.solve(lines.asSequence()) }.let {
println(it.value)
println("Completed in \${it.duration}")
}
}
EOKOTLIN
cat > "${basedir}/Makefile" <<EOBUILD
# Copyright 2021 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
# https://adventofcode.com/2020/day/${day}
KOTLIN = kotlin
KOTLINC = kotlinc
CLASSES = classes
PACKAGE = ${package}
MAIN_CLASS = ${main}Kt
compile: \$(CLASSES)/\$(PACKAGE)/\$(MAIN_CLASS).class
\$(CLASSES)/\$(PACKAGE)/\$(MAIN_CLASS).class: \$(PACKAGE).kt
@mkdir -p \$(CLASSES)
\$(KOTLINC) -d \$(CLASSES) \$(PACKAGE).kt
output.%.txt: input.%.txt compile
\$(KOTLIN) -cp \$(CLASSES) \$(PACKAGE).\$(MAIN_CLASS) < \$< | tee \$@
out: output.example.txt output.actual.txt
clean:
rm -r \$(CLASSES)
EOBUILD