-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewday
More file actions
executable file
·66 lines (54 loc) · 1.47 KB
/
newday
File metadata and controls
executable file
·66 lines (54 loc) · 1.47 KB
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
#!/usr/bin/env ruby
#
# Usage: newday DAY SESSION [YEAR]
#
# - DAY is the puzzle day number (0 - 25)
# - SESSION is your advent of code browser session id
# - YEAR is the AoC year (4 digits)
#
raise "Missing day" unless ARGV[0] =~ /[0-9]+/
day = ARGV[0]
raise "Missing session" unless ARGV[1] =~ /[a-z0-9]+/
session = ARGV[1]
year = ARGV[2] || (Time.now.year - (Time.now.month < 12 ? 1 : 0)).to_s
dayname = "day" + day.to_s.rjust(2, '0')
unless File.exist?(File.join("puzzle", "#{dayname}.md"))
`./fetch_puzzle #{day} #{session} #{year} > puzzle/#{dayname}.md`
end
unless File.exist?(File.join("input", "#{dayname}.txt"))
`./fetch_input #{day} #{session} #{year} > input/#{dayname}.txt`
end
unless File.exist?(File.join("src", "days", "#{dayname}.rs"))
template = <<-EOF
use crate::{Solution, SolutionPair};
fn solve_part1(input: &str) -> () {
unimplemented!()
}
fn solve_part2(input: &str) -> () {
unimplemented!()
}
pub fn solve(input: String) -> SolutionPair {
let sol1 = solve_part1(&input);
let sol2 = solve_part2(&input);
(Solution::from(sol1), Solution::from(sol2))
}
#[cfg(test)]
mod tests {
use super::*;
const EXAMPLE_INPUT: &str = "";
#[test]
fn example_part1() {
unimplemented!()
//assert_eq!(solve_part1(EXAMPLE_INPUT), ());
}
#[test]
fn example_part2() {
unimplemented!()
//assert_eq!(solve_part2(EXAMPLE_INPUT), ());
}
}
EOF
File.open(File.join("src", "days", "#{dayname}.rs"), "w") do |f|
f.puts template
end
end