-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscover
executable file
·54 lines (40 loc) · 973 Bytes
/
discover
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
#!/usr/bin/env ruby
source, input, outfile, _ = ARGV
module ToModule
refine String do
def to_module
sub("src/", "").gsub("/", ".").sub(".hs", "")
end
end
end
using ToModule
class Solution < Struct.new(:mod, :year, :day)
MATCHER = /Y(?<year>\d{4}).D(?<day>\d+)/
class << self
def at_path(path)
match = MATCHER.match(path)
new(path.to_module, match[:year], match[:day])
end
end
def import
"import qualified #{mod}"
end
def tuple
"( (#{year}, #{day}), solve #{mod}.solution )"
end
end
solutions = Dir.
glob("src/Problems/Y*/D*/Solution.hs").
map { |path| Solution.at_path(path) }
body = <<~HS
module Problems.Problems where
import Protolude
import qualified Data.Map as Map
import Solution (solve)
#{solutions.map(&:import).sort.join("\n")}
solutions :: Map (Int, Int) (Text -> IO (Text, Text))
solutions = Map.fromList
[ #{solutions.map(&:tuple).join("\n , ")}
]
HS
File.write(outfile, body)