-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
88 lines (71 loc) · 2.04 KB
/
Rakefile
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
83
84
85
86
87
88
require 'rake/testtask'
require './app'
require 'net/http'
namespace :solve do
task :all do
ENV['SKIP_LONG_RUNNING_SOLUTIONS'] = '1'
runner = Aoc::Runner.new
(1..25).each { |i| runner.call(i) }
end
(1..25).each do |i|
desc "Run day #{i}"
task i.to_s.to_sym do
Aoc::Runner.new.call(i)
end
end
end
namespace :scaffold do
(1..25).each do |i|
task i.to_s.to_sym do
puts "🎁 Generate code for day #{i}..."
number = i.to_s.rjust(2, '0')
marker = '{DAY_NUMBER}'
ruby_file = File.join(APP_ROOT, 'lib', 'days', "#{number}.rb")
# raise '⛔ Stopping: Already exists' if File.exists?(ruby_file)
File.write(ruby_file, File.read(File.join(APP_ROOT, 'template', 'day')).sub(marker, number))
File.write(
File.join(APP_ROOT, 'test', "#{number}_test.rb"),
File.read(File.join(APP_ROOT, 'template', 'test')).gsub(marker, number)
)
File.write(File.join(APP_ROOT, 'examples', "#{number}.txt"), '')
end
end
end
namespace :download do
def download_input(number)
session_path = File.join(APP_ROOT, '.session')
unless File.exist?(session_path)
raise 'Copy your session cookie from a logged-in browser and save it to a file at `.session`!'
end
puts "⬇️ Download day #{number} input"
response = Net::HTTP.get_response(
URI("https://adventofcode.com/2023/day/#{number}/input"),
{ 'Cookie' => "session=#{File.read(session_path)}" }
)
if response.code == '200'
response.body
else
puts "💥 Download failed - #{response.message}"
end
end
(1..25).each do |i|
task i.to_s.to_sym do
number = i.to_s.rjust(2, '0')
File.write(File.join(APP_ROOT, 'inputs', "#{number}.txt"), download_input(i))
end
end
end
namespace :bench do
(1..25).each do |day|
namespace day.to_s.to_sym do
2.times do |part|
task (part + 1).to_s.to_sym do
Aoc::Bench.new.call(day, part + 1)
end
end
end
end
end
Rake::TestTask.new do |t|
t.pattern = 'test/*_test.rb'
end