gettc 1.5 → 1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/gettc +45 -29
- data/core/lib/gettc.rb +7 -0
- data/core/lib/{topcoder → gettc}/download.rb +53 -45
- data/core/lib/gettc/generate.rb +145 -0
- data/core/lib/{topcoder → gettc}/parse.rb +104 -102
- data/core/lib/{topcoder → gettc}/print.rb +11 -11
- data/core/lib/{topcoder → gettc}/problem.rb +11 -11
- data/core/lib/{topcoder → gettc}/signature.rb +8 -8
- data/core/lib/{topcoder → gettc}/types.rb +34 -17
- data/core/test/{topcoder → gettc}/download_test.rb +6 -6
- data/core/test/gettc/generate_test.rb +31 -0
- data/core/test/{topcoder → gettc}/parse_test.rb +26 -26
- data/core/test/gettc/signature_test.rb +54 -0
- data/core/test/gettc/types_test.rb +24 -0
- data/dist/config.yml +1 -0
- data/dist/include/cpp/engine.rb +32 -32
- data/dist/include/cpp/topcoder +89 -25
- data/dist/include/haskell/TopCoder.hs +72 -53
- data/dist/include/haskell/engine.rb +49 -47
- data/dist/include/java/TopCoder.jar +0 -0
- data/dist/include/java/engine.rb +71 -71
- data/dist/include/python/engine.rb +46 -0
- data/dist/include/python/topcoder/__init__.py +3 -0
- data/dist/include/python/topcoder/errors.py +4 -0
- data/dist/include/python/topcoder/reader.py +160 -0
- data/dist/include/python/topcoder/writer.py +13 -0
- data/dist/template/bin/runner.sh +16 -6
- data/dist/template/solve/cpp/Makefile +9 -5
- data/dist/template/solve/cpp/{name}.cpp +8 -8
- data/dist/template/solve/cpp/{name}Runner.cpp +8 -8
- data/dist/template/solve/haskell/Makefile +9 -5
- data/dist/template/solve/haskell/{name}.hs +1 -1
- data/dist/template/solve/haskell/{name}Runner.hs +5 -5
- data/dist/template/solve/java/Makefile +18 -0
- data/dist/template/solve/java/build.xml +7 -3
- data/dist/template/solve/java/{name}.java +1 -1
- data/dist/template/solve/java/{name}Runner.java +1 -1
- data/dist/template/solve/python/Makefile +27 -0
- data/dist/template/solve/python/{name}.py +4 -0
- data/dist/template/solve/python/{name}Runner.py +27 -0
- data/dist/template/util/check/Makefile +3 -1
- data/dist/usage +5 -0
- metadata +30 -24
- data/Rakefile +0 -41
- data/core/lib/topcoder.rb +0 -3
- data/core/lib/topcoder/generate.rb +0 -131
- data/core/test/topcoder/generate_test.rb +0 -31
- data/core/test/topcoder/signature_test.rb +0 -52
- data/core/test/topcoder/types_test.rb +0 -24
- data/dist/template/solve/cpp/{name}Test.cpp +0 -8
- data/dist/template/solve/haskell/{name}Test.hs +0 -10
- data/dist/template/solve/java/{name}Test.java +0 -8
@@ -1,72 +1,74 @@
|
|
1
|
-
require
|
1
|
+
require "gettc/types"
|
2
|
+
|
2
3
|
class String
|
3
4
|
def uncapitalize
|
4
5
|
return self[0, 1].downcase + self[1..-1]
|
5
6
|
end
|
6
7
|
end
|
7
|
-
|
8
|
+
|
9
|
+
module Gettc
|
8
10
|
class Type
|
9
11
|
def to_haskell
|
10
12
|
if self == TInt then
|
11
|
-
return
|
13
|
+
return "Int"
|
12
14
|
elsif self == TLong then
|
13
|
-
return
|
15
|
+
return "Integer"
|
14
16
|
elsif self == TFloat then
|
15
|
-
return
|
17
|
+
return "Float"
|
16
18
|
elsif self == TDouble then
|
17
|
-
return
|
19
|
+
return "Double"
|
18
20
|
elsif self == TChar then
|
19
|
-
return
|
21
|
+
return "Char"
|
20
22
|
elsif self == TString then
|
21
|
-
return
|
23
|
+
return "String"
|
22
24
|
elsif self == TBoolean then
|
23
|
-
return
|
25
|
+
return "Bool"
|
24
26
|
elsif is_a? TArray then
|
25
|
-
return
|
27
|
+
return "[" + subtype.to_haskell + "]"
|
26
28
|
else
|
27
|
-
return
|
29
|
+
return "Unknown"
|
28
30
|
end
|
29
31
|
end
|
30
32
|
def get_haskell_parser
|
31
33
|
if self == TInt then
|
32
|
-
return
|
34
|
+
return "TC.parseInt"
|
33
35
|
elsif self == TLong then
|
34
|
-
return
|
36
|
+
return "TC.parseLong"
|
35
37
|
elsif self == TFloat then
|
36
|
-
return
|
38
|
+
return "TC.parseFloat"
|
37
39
|
elsif self == TDouble then
|
38
|
-
return
|
40
|
+
return "TC.parseDouble"
|
39
41
|
elsif self == TChar then
|
40
|
-
return
|
42
|
+
return "TC.parseChar"
|
41
43
|
elsif self == TString then
|
42
|
-
return
|
44
|
+
return "TC.parseString"
|
43
45
|
elsif self == TBoolean then
|
44
|
-
return
|
46
|
+
return "TC.parseBool"
|
45
47
|
elsif is_a? TArray then
|
46
|
-
return
|
48
|
+
return "(TC.parseList " + subtype.get_haskell_parser + ")"
|
47
49
|
else
|
48
|
-
return
|
50
|
+
return "unknown"
|
49
51
|
end
|
50
52
|
end
|
51
53
|
def dumb_haskell
|
52
54
|
if self == TInt then
|
53
|
-
return
|
55
|
+
return "0"
|
54
56
|
elsif self == TLong then
|
55
|
-
return
|
57
|
+
return "0"
|
56
58
|
elsif self == TFloat then
|
57
|
-
return
|
59
|
+
return "0"
|
58
60
|
elsif self == TDouble then
|
59
|
-
return
|
61
|
+
return "0"
|
60
62
|
elsif self == TChar then
|
61
|
-
return "
|
63
|
+
return "\"$\""
|
62
64
|
elsif self == TString then
|
63
|
-
return
|
65
|
+
return "\"$\""
|
64
66
|
elsif self == TBoolean then
|
65
|
-
return
|
67
|
+
return "True"
|
66
68
|
elsif is_a? TArray then
|
67
|
-
return
|
69
|
+
return "[]"
|
68
70
|
else
|
69
|
-
return
|
71
|
+
return "Nil"
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
@@ -79,43 +81,43 @@ module TopCoder
|
|
79
81
|
end
|
80
82
|
end
|
81
83
|
def declare
|
82
|
-
ret =
|
83
|
-
ret << func.name <<
|
84
|
+
ret = ""
|
85
|
+
ret << func.name << " :: "
|
84
86
|
|
85
87
|
temp = vars.map do |var| var.type.to_haskell end
|
86
|
-
ret << temp.join(
|
88
|
+
ret << temp.join(" -> ") << " -> " << func.type.to_haskell << "\n"
|
87
89
|
|
88
|
-
ret << func.name <<
|
90
|
+
ret << func.name << " "
|
89
91
|
temp = vars.map do |var| var.name end
|
90
|
-
ret << temp.join(
|
92
|
+
ret << temp.join(" ") << " = " << func.type.dumb_haskell
|
91
93
|
|
92
94
|
return ret
|
93
95
|
end
|
94
96
|
def input
|
95
|
-
ret =
|
97
|
+
ret = "getVars :: TC.Parser ("
|
96
98
|
temp = @vars.map do |var| var.type.to_haskell end
|
97
|
-
ret << temp.join(
|
98
|
-
temp =
|
99
|
+
ret << temp.join(", ") << ")\n"
|
100
|
+
temp = "getVars = do "
|
99
101
|
ret << temp
|
100
|
-
indent =
|
102
|
+
indent = " " * temp.size
|
101
103
|
temp = @vars.map do |var|
|
102
|
-
x =
|
104
|
+
x = ""
|
103
105
|
x << var.name
|
104
|
-
x <<
|
106
|
+
x << " <- TC.spaces >> "
|
105
107
|
x << var.type.get_haskell_parser
|
106
108
|
end
|
107
|
-
ret << temp.join(" ; next\n#{indent}") << "\n"
|
108
|
-
ret << indent <<
|
109
|
+
ret << temp.join(" ; TC.spaces >> TC.next\n#{indent}") << "\n"
|
110
|
+
ret << indent << "return ("
|
109
111
|
temp = @vars.map do |var| var.name end
|
110
|
-
ret << temp.join(
|
111
|
-
ret <<
|
112
|
+
ret << temp.join(", ")
|
113
|
+
ret << ")"
|
112
114
|
return ret
|
113
115
|
end
|
114
116
|
def output
|
115
|
-
ret =
|
116
|
-
ret << @func.name <<
|
117
|
+
ret = ""
|
118
|
+
ret << @func.name << " "
|
117
119
|
temp = vars.map do |var| var.name end
|
118
|
-
ret << temp.join(
|
120
|
+
ret << temp.join(" ")
|
119
121
|
return ret
|
120
122
|
end
|
121
123
|
end
|
Binary file
|
data/dist/include/java/engine.rb
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
require
|
1
|
+
require "gettc/types"
|
2
2
|
|
3
|
-
module
|
3
|
+
module Gettc
|
4
4
|
class Type
|
5
5
|
def to_java
|
6
6
|
if self == TInt then
|
7
|
-
return
|
7
|
+
return "int"
|
8
8
|
elsif self == TLong then
|
9
|
-
return
|
9
|
+
return "long"
|
10
10
|
elsif self == TFloat then
|
11
|
-
return
|
11
|
+
return "float"
|
12
12
|
elsif self == TDouble then
|
13
|
-
return
|
13
|
+
return "double"
|
14
14
|
elsif self == TChar then
|
15
|
-
return
|
15
|
+
return "char"
|
16
16
|
elsif self == TString then
|
17
|
-
return
|
17
|
+
return "String"
|
18
18
|
elsif self == TBoolean then
|
19
|
-
return
|
19
|
+
return "boolean"
|
20
20
|
elsif is_a? TArray then
|
21
21
|
return "#{subtype.to_java}[]"
|
22
22
|
else
|
23
|
-
return
|
23
|
+
return "unknown"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
def to_java_boxed
|
27
27
|
if self == TInt then
|
28
|
-
return
|
28
|
+
return "Integer"
|
29
29
|
elsif self == TLong then
|
30
|
-
return
|
30
|
+
return "Long"
|
31
31
|
elsif self == TFloat then
|
32
|
-
return
|
32
|
+
return "Float"
|
33
33
|
elsif self == TDouble then
|
34
|
-
return
|
34
|
+
return "Double"
|
35
35
|
elsif self == TChar then
|
36
|
-
return
|
36
|
+
return "Character"
|
37
37
|
elsif self == TString then
|
38
|
-
return
|
38
|
+
return "String"
|
39
39
|
elsif self == TBoolean then
|
40
|
-
return
|
40
|
+
return "Boolean"
|
41
41
|
elsif self.is_a? TArray then
|
42
42
|
return "List<#{subtype.to_java_boxed}>"
|
43
43
|
else
|
44
|
-
return
|
44
|
+
return "Unknown"
|
45
45
|
end
|
46
46
|
end
|
47
47
|
def dumb_java
|
48
48
|
if self == TInt then
|
49
|
-
return
|
49
|
+
return "0"
|
50
50
|
elsif self == TLong then
|
51
|
-
return
|
51
|
+
return "0"
|
52
52
|
elsif self == TFloat then
|
53
|
-
return
|
53
|
+
return "0"
|
54
54
|
elsif self == TDouble then
|
55
|
-
return
|
55
|
+
return "0"
|
56
56
|
elsif self == TChar then
|
57
|
-
return "
|
57
|
+
return "\"$\""
|
58
58
|
elsif self == TString then
|
59
|
-
return
|
59
|
+
return "\"$\""
|
60
60
|
elsif self == TBoolean then
|
61
|
-
return
|
61
|
+
return "true"
|
62
62
|
elsif self.is_a? TArray then
|
63
63
|
return "new #{subtype.to_java}[1]"
|
64
64
|
else
|
65
|
-
return
|
65
|
+
return "Nil"
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -73,11 +73,11 @@ module TopCoder
|
|
73
73
|
end
|
74
74
|
class JavaArray
|
75
75
|
def self.get_depth type
|
76
|
-
return 0
|
76
|
+
return 0 unless type.is_a? TArray
|
77
77
|
return 1 + get_depth(type.subtype)
|
78
78
|
end
|
79
79
|
def self.get_elem_type type
|
80
|
-
return type
|
80
|
+
return type unless type.is_a? TArray
|
81
81
|
return get_elem_type type.subtype
|
82
82
|
end
|
83
83
|
attr_accessor :name, :boxed_name, :type, :boxed_type
|
@@ -91,47 +91,47 @@ module TopCoder
|
|
91
91
|
@elem_type = self.class.get_elem_type(sig.type).to_java
|
92
92
|
end
|
93
93
|
def unbox_code
|
94
|
-
counters = @depth.times.map do |i|
|
95
|
-
indents = 0.upto(@depth).map do |i|
|
94
|
+
counters = @depth.times.map do |i| "_" + ("i"[0].ord + i).chr end
|
95
|
+
indents = 0.upto(@depth).map do |i| " " * 4 * i end
|
96
96
|
sizes = @depth.times.map do |i|
|
97
|
-
@boxed_name + (
|
97
|
+
@boxed_name + (".get(0)" * i) + ".size()"
|
98
98
|
end
|
99
|
-
ret =
|
99
|
+
ret = ""
|
100
100
|
|
101
|
-
ret << @type <<
|
102
|
-
@depth.times do |i| ret <<
|
101
|
+
ret << @type << " " << @name << " = new " << @elem_type;
|
102
|
+
@depth.times do |i| ret << "[" << sizes[i] << "]" end
|
103
103
|
ret << ";\n"
|
104
104
|
|
105
105
|
@depth.times do |i|
|
106
|
-
ret << indents[i] <<
|
107
|
-
ret << counters[i] <<
|
108
|
-
ret <<
|
106
|
+
ret << indents[i] << "for (int " << counters[i] << " = 0; "
|
107
|
+
ret << counters[i] << " < " << sizes[i]
|
108
|
+
ret << "; ++" << counters[i] << ")\n"
|
109
109
|
end
|
110
110
|
|
111
111
|
ret << indents[@depth] << @name
|
112
|
-
@depth.times do |i| ret <<
|
113
|
-
ret <<
|
112
|
+
@depth.times do |i| ret << "[" << counters[i] << "]" end
|
113
|
+
ret << " = "
|
114
114
|
ret << @boxed_name
|
115
|
-
@depth.times do |i| ret <<
|
115
|
+
@depth.times do |i| ret << ".get(" << counters[i] << ")" end
|
116
116
|
ret << ";"
|
117
117
|
|
118
118
|
return ret
|
119
119
|
end
|
120
120
|
def box_code_recurse boxed_type, parent, boxed_name, depth, counters
|
121
|
-
ret =
|
122
|
-
index = counters.map do |counter|
|
121
|
+
ret = ""
|
122
|
+
index = counters.map do |counter| "[" + counter + "]" end
|
123
123
|
index = index.join
|
124
124
|
if depth == 0
|
125
|
-
ret << parent <<
|
125
|
+
ret << parent << ".add(" << @name << index << ");\n"
|
126
126
|
else
|
127
127
|
type_str = boxed_type.to_java_boxed
|
128
|
-
ret << type_str <<
|
129
|
-
ret <<
|
128
|
+
ret << type_str << " " << boxed_name
|
129
|
+
ret << " = new Array" << type_str << "();" << "\n"
|
130
130
|
|
131
|
-
counter =
|
132
|
-
ret <<
|
133
|
-
ret << counter <<
|
134
|
-
ret <<
|
131
|
+
counter = "_" + ("i"[0].ord + counters.size).chr
|
132
|
+
ret << "for (int " << counter << " = 0; "
|
133
|
+
ret << counter << " < " << @name << index << ".length; "
|
134
|
+
ret << "++" << counter << ") {\n"
|
135
135
|
|
136
136
|
ret << box_code_recurse(boxed_type.subtype,
|
137
137
|
boxed_name,
|
@@ -139,12 +139,12 @@ module TopCoder
|
|
139
139
|
depth - 1, counters << counter)
|
140
140
|
ret << "}\n"
|
141
141
|
|
142
|
-
|
143
|
-
ret << parent <<
|
142
|
+
unless parent.nil?
|
143
|
+
ret << parent << ".add("
|
144
144
|
ret << boxed_name << ");\n"
|
145
145
|
end
|
146
146
|
end
|
147
|
-
ret.gsub! /^/,
|
147
|
+
ret.gsub! /^/, " " * 4 unless parent.nil?
|
148
148
|
return ret
|
149
149
|
end
|
150
150
|
def box_code
|
@@ -158,50 +158,50 @@ module TopCoder
|
|
158
158
|
@vars = vars
|
159
159
|
end
|
160
160
|
def declare
|
161
|
-
ret =
|
162
|
-
ret << @func.to_java <<
|
163
|
-
indent =
|
161
|
+
ret = "public "
|
162
|
+
ret << @func.to_java << "("
|
163
|
+
indent = " " * ret.size
|
164
164
|
temp = @vars.map do |var| var.to_java end
|
165
165
|
ret << temp.join(",\n#{indent}")
|
166
|
-
ret <<
|
166
|
+
ret << ")"
|
167
167
|
return ret
|
168
168
|
end
|
169
169
|
def input
|
170
170
|
temp = @vars.map do |var|
|
171
|
-
ret =
|
171
|
+
ret = ""
|
172
172
|
if var.type.is_a? TArray
|
173
173
|
arr = JavaArray.new var
|
174
174
|
ret << arr.boxed_type
|
175
|
-
ret <<
|
176
|
-
ret <<
|
177
|
-
ret <<
|
175
|
+
ret << " " << arr.boxed_name
|
176
|
+
ret << " = (" << arr.boxed_type << ") "
|
177
|
+
ret << "reader.next(new TypeRef<" << arr.boxed_type << ">"
|
178
178
|
ret << "(){}.getType());\n"
|
179
179
|
ret << arr.unbox_code
|
180
180
|
else
|
181
181
|
ret << var.to_java
|
182
|
-
ret <<
|
183
|
-
ret <<
|
182
|
+
ret << " = (" << var.type.to_java_boxed << ") "
|
183
|
+
ret << "reader.next("
|
184
184
|
ret << var.type.to_java_boxed
|
185
|
-
ret <<
|
185
|
+
ret << ".class);"
|
186
186
|
end
|
187
187
|
ret
|
188
188
|
end
|
189
189
|
return temp.join "\nreader.next();\n\n"
|
190
190
|
end
|
191
191
|
def output
|
192
|
-
ret =
|
193
|
-
caller =
|
192
|
+
ret = ""
|
193
|
+
caller = "solver." + @func.name + "("
|
194
194
|
temp = @vars.map do |var| var.name end
|
195
|
-
caller << temp.join(
|
195
|
+
caller << temp.join(", ") << ")"
|
196
196
|
if @func.type.is_a? TArray
|
197
|
-
ret << @func.type.to_java <<
|
198
|
-
arr = JavaArray.new(Signature.new @func.type,
|
197
|
+
ret << @func.type.to_java << " result = " << caller << ";\n"
|
198
|
+
arr = JavaArray.new(Signature.new @func.type, "result")
|
199
199
|
ret << arr.box_code
|
200
|
-
ret <<
|
200
|
+
ret << "writer.write(resultBoxed);"
|
201
201
|
else
|
202
|
-
ret <<
|
202
|
+
ret << "writer.write(" << caller << ");"
|
203
203
|
end
|
204
204
|
return ret
|
205
205
|
end
|
206
206
|
end
|
207
|
-
end
|
207
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "gettc/types"
|
2
|
+
|
3
|
+
module Gettc
|
4
|
+
class Type
|
5
|
+
def dumb_python
|
6
|
+
if self == TInt then
|
7
|
+
return "0"
|
8
|
+
elsif self == TLong then
|
9
|
+
return "0"
|
10
|
+
elsif self == TFloat then
|
11
|
+
return "0"
|
12
|
+
elsif self == TDouble then
|
13
|
+
return "0"
|
14
|
+
elsif self == TChar then
|
15
|
+
return "'$'"
|
16
|
+
elsif self == TString then
|
17
|
+
return '"$"'
|
18
|
+
elsif self == TBoolean then
|
19
|
+
return "True"
|
20
|
+
elsif self.is_a? TArray then
|
21
|
+
return "[]"
|
22
|
+
else
|
23
|
+
return "None"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
class PythonEngine
|
28
|
+
attr_accessor :func, :vars
|
29
|
+
def initialize func, vars
|
30
|
+
@func = func
|
31
|
+
@vars = vars
|
32
|
+
end
|
33
|
+
def vars_list
|
34
|
+
temp = @vars.map do |var|
|
35
|
+
var.name
|
36
|
+
end
|
37
|
+
return temp.join ", "
|
38
|
+
end
|
39
|
+
def input
|
40
|
+
temp = @vars.map do |var|
|
41
|
+
var.name + ' = reader.next("' + var.type.to_s + '")'
|
42
|
+
end
|
43
|
+
return temp.join "\nreader.next()\n"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|