-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·76 lines (65 loc) · 1.19 KB
/
setup.sh
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
#!/bin/bash
set -e
while getopts ":d:y:" opt; do
case $opt in
d)
day="$OPTARG"
;;
y)
year="$OPTARG"
;;
\?)
echo "Invalid option -$OPTARG" >&2
exit 1
;;
esac
case $OPTARG in
-*)
echo "Option $opt needs a valid argument"
exit 1
;;
esac
done
if [ -z ${year} ]; then
year=$(date +"%Y")
fi
if [ -z ${day} ]; then
day=$(date +"%d")
fi
echo "AoC: Setting up day $day in $year"
aoc2md -y $year -d $day
FILE=./$year/day-$day/main.rb
if [ -f "$FILE" ]; then
echo "AoC: $FILE already exists. Skipping."
else
echo "AoC: Creating template file for day $day in $year"
cat <<EOF >$FILE
# frozen_string_literal: true
require "pry"
require "minitest/autorun"
def read_file(filename)
# Get the directory of the currently executing script
# Join the script directory with the filename
# Read the content of the file
File.read(File.join(__dir__, filename))
end
def solve(filename)
read_file(filename)
0
end
def solve2(filename)
read_file(filename)
0
end
class AoCTest < Minitest::Test
def test_solve
assert solve("test.txt") == 0
end
def test_solve2
assert solve2("test.txt") == 0
end
end
puts 'Part1', solve('input.txt')
puts 'Part2', solve2('input.txt')
EOF
fi