-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_day.rb
45 lines (34 loc) · 1.12 KB
/
generate_day.rb
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
require 'fileutils'
require 'date'
def filepath(filename, subfolder = '')
File.join(*[File.expand_path(__dir__), subfolder, filename].compact)
end
def get_cur_yr_day
parent_dir = Date.today.year.to_s
[parent_dir, Dir.children(filepath(nil, parent_dir)).max.succ]
end
def cur_day_dirpath(filename = nil)
parent_dir, cur_day = get_cur_yr_day
dir = File.join(parent_dir, cur_day)
filepath(filename, dir)
end
def create_file(filepath, file_content = '')
dirname = File.dirname(filepath)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
File.open(filepath, 'w') { |f| f.write(file_content) }
end
template = <<~TEMPLATE
def filepath(filename, subfolder = '')
File.join(*[File.expand_path('..', __FILE__), subfolder, filename].compact)
end
path = filepath('input.txt')
path = filepath('exinput.txt')
lines = File.read(path).split(\"\n\")
# Part 1
# Part 2
TEMPLATE
cur_year, cur_day = get_cur_yr_day
subfolder = File.join(get_cur_yr_day)
create_file(filepath(cur_day + '.rb', subfolder), template)
create_file(filepath('exinput.txt', subfolder))
create_file(filepath('input.txt', subfolder))