|
| 1 | +#!/usr/bin/env raku |
| 2 | +# Copyright 2021 Google LLC |
| 3 | +# |
| 4 | +# Use of this source code is governed by an MIT-style |
| 5 | +# license that can be found in the LICENSE file or at |
| 6 | +# https://opensource.org/licenses/MIT. |
| 7 | + |
| 8 | +# Generator script for a day's Advent of Code files. Usage: |
| 9 | +# ./generate day1 |
| 10 | + |
| 11 | +sub MAIN(Str:D $day-dir-name) { |
| 12 | + my $day-dir = $day-dir-name.IO; |
| 13 | + my $class-name = $day-dir.basename.tc; |
| 14 | + my $day-num = $class-name.match(/\d+$/).Str; |
| 15 | + my $script = $day-dir.add($day-dir.basename ~ '.raku'); |
| 16 | + $day-dir.mkdir; |
| 17 | + for <input.example.txt input.actual.txt>.map({ $day-dir.add($_) }) { |
| 18 | + $_.spurt('') unless $_.f; |
| 19 | + } |
| 20 | + $script.spurt(qq:to/END/) unless $script.f; |
| 21 | + #!/usr/bin/env raku |
| 22 | + # Copyright 2021 Google LLC |
| 23 | + # |
| 24 | + # Use of this source code is governed by an MIT-style |
| 25 | + # license that can be found in the LICENSE file or at |
| 26 | + # https://opensource.org/licenses/MIT. |
| 27 | + # |
| 28 | + # https://adventofcode.com/2021/day/$day-num |
| 29 | +
|
| 30 | + class $class-name \{ |
| 31 | + has \$.input; |
| 32 | +
|
| 33 | + method solve-part1(--> Cool:D) \{ |
| 34 | + return "TODO"; |
| 35 | + } |
| 36 | +
|
| 37 | + method solve-part2(--> Cool:D) \{ |
| 38 | + return "TODO"; |
| 39 | + } |
| 40 | + } |
| 41 | +
|
| 42 | + sub MAIN(*@input-files) \{ |
| 43 | + for @input-files -> \$input-file \{ |
| 44 | + if (my \$input = \$input-file.IO.slurp) \{ |
| 45 | + say "Running $class-name part 1 on \$input-file"; |
| 46 | + my \$start1 = now; |
| 47 | + my \$solver = {$class-name}.new(:input(\$input)); |
| 48 | + say \$solver.solve-part1(); |
| 49 | + "Part 1 took %.3fms\\n".printf((now - \$start1)*1000); |
| 50 | + say ''; |
| 51 | + say "Running $class-name part 2 on \$input-file"; |
| 52 | + my \$start2 = now; |
| 53 | + \$solver = {$class-name}.new(:input(\$input)); |
| 54 | + say \$solver.solve-part2(); |
| 55 | + "Part 2 took %.3fms\\n".printf((now - \$start2)*1000); |
| 56 | + } else \{ |
| 57 | + say "EMPTY INPUT FILE: \$input-file"; |
| 58 | + } |
| 59 | + say '=' x 40; |
| 60 | + } |
| 61 | + } |
| 62 | + END |
| 63 | + $script.chmod(0o755); |
| 64 | +} |
0 commit comments