gettc 1.8.2 → 1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 248e85dd98ec679999209b8148373b71ca96b70c
4
- data.tar.gz: e9cd8061bf69f561a8f2945f8fa47de2a48b53b0
3
+ metadata.gz: 65b3906b3f1f4b5bda986b7134f8cb8e5ca12206
4
+ data.tar.gz: 92ae49546cf3188d71ec91ace589a7f854ffa38c
5
5
  SHA512:
6
- metadata.gz: 97383359ec7189209c3d88be0de62d2ba73106e6abdb75eb164d3d17a4b68e020eccdb2d7e9c800fe57bc5f51f4e533482cf550da59dfaa219c448da3a97fe4d
7
- data.tar.gz: 134603c5baca851d3248b55a16014625ce74c52569187adb383c589d5f762e5d7484aaf091c3a2156355a8136944f3b1d56aea950a53af6d292905cc93dc69fe
6
+ metadata.gz: af342b43c1c2638f604f11a65c8450808fabb7ea187a9807d7f1d5465607f2f5848324a2a23ed69a4b04118b6aa534cf0dac325f0c2b39ba440658dcefbafd77
7
+ data.tar.gz: 72621691d2e5f6c22d7c3eeb9d951748d3463a15715e4135b8867c9e96850b3ae556a5dfd3e912868fe7b56b482385864f0427de9c4286eecc05b5a1519b47fd
data/bin/gettc CHANGED
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require "gettc"
4
4
  include Gettc
@@ -15,23 +15,27 @@ module Gettc
15
15
  return @is_object
16
16
  end
17
17
  def to_s
18
- if self == TInt then
18
+ if is_a? TArray then
19
+ return subtype.to_s + "[]"
20
+ end
21
+
22
+ case self
23
+ when TInt
19
24
  return "int"
20
- elsif self == TLong then
25
+ when TLong
21
26
  return "long"
22
- elsif self == TFloat then
27
+ when TFloat
23
28
  return "float"
24
- elsif self == TDouble then
29
+ when TDouble
25
30
  return "double"
26
- elsif self == TChar then
31
+ when TChar
27
32
  return "char"
28
- elsif self == TString then
33
+ when TString
29
34
  return "String"
30
- elsif self == TBoolean then
35
+ when TBoolean
31
36
  return "boolean"
32
- elsif is_a? TArray then
33
- return subtype.to_s + "[]"
34
37
  end
38
+
35
39
  return "unknown"
36
40
  end
37
41
  end
@@ -76,4 +80,4 @@ module Gettc
76
80
  end
77
81
  raise UnrecognizedType.new str
78
82
  end
79
- end
83
+ end
@@ -1,3 +1,3 @@
1
1
  module Gettc
2
- VERSION = "1.8.2"
2
+ VERSION = "1.9"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require "test/unit"
2
- require "topcoder/download"
3
- include TopCoder
2
+ require "gettc/download"
3
+ include Gettc
4
4
 
5
5
  class DownloadTest < Test::Unit::TestCase
6
6
  def setup
@@ -26,4 +26,4 @@ class DownloadTest < Test::Unit::TestCase
26
26
  assert_match "<h3>Problem Statement</h3>", html
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -2,12 +2,12 @@ require "test/unit"
2
2
  require "fileutils"
3
3
  require "tmpdir"
4
4
 
5
- require "topcoder/generate"
6
- include TopCoder
5
+ require "gettc/generate"
6
+ include Gettc
7
7
 
8
8
  class GenerateTest < Test::Unit::TestCase
9
9
  def setup
10
- @source_d = File.join File.dirname(__FILE__), "../../dist/template"
10
+ @source_d = File.join File.dirname(__FILE__), "../../dist"
11
11
  @target_d = File.join Dir.tmpdir, "gettc"
12
12
  FileUtils.mkdir @target_d unless File.directory? @target_d
13
13
  @generator = Generator.new @source_d, @target_d
@@ -28,4 +28,4 @@ class GenerateTest < Test::Unit::TestCase
28
28
  assert_raise ProblemDirExists do @generator.generate prob end
29
29
  FileUtils.rmdir prob_d
30
30
  end
31
- end
31
+ end
@@ -1,6 +1,6 @@
1
1
  require "test/unit"
2
- require "topcoder/parse"
3
- include TopCoder
2
+ require "gettc/parse"
3
+ include Gettc
4
4
 
5
5
  class ParseTest < Test::Unit::TestCase
6
6
  def setup
@@ -12,18 +12,18 @@ class ParseTest < Test::Unit::TestCase
12
12
  return File.read File.join @data_d, prob + ".htm"
13
13
  end
14
14
  def test_indexes
15
- assert_equal [0, 3], @parser.indexes("abcde", "bc")
16
- assert_equal nil, @parser.indexes("abcde", "f")
15
+ assert_equal [0, 3], @parser.send(:indexes, "abcde", "bc")
16
+ assert_equal nil, @parser.send(:indexes, "abcde", "f")
17
17
  end
18
18
  def test_filter
19
- assert_equal "Lorem Ipsum", @parser.filter("<xml> Lorem Ipsum </xml> ")
20
- assert_equal "2^(3)", @parser.filter("2<sup>3</sup>")
21
- assert_equal "*hi*", @parser.filter(" <b>hi</b>")
19
+ assert_equal "Lorem Ipsum", @parser.send(:filter, "<xml> Lorem Ipsum </xml> ")
20
+ assert_equal "2^(3)", @parser.send(:filter, "2<sup>3</sup>")
21
+ assert_equal "*hi*", @parser.send(:filter, " <b>hi</b>")
22
22
  html = <<-END
23
23
  <img src=
24
24
  "http://www.topcoder.com/contest/problem/CirclesCountry/case1.gif">
25
25
  END
26
- assert_equal "![image](images/case1.gif)", @parser.filter(html)
26
+ assert_equal "![image](images/case1.gif)", @parser.send(:filter, html)
27
27
  end
28
28
  def test_PageNumbers
29
29
  html = get_problem_raw "PageNumbers"
@@ -101,4 +101,4 @@ class ParseTest < Test::Unit::TestCase
101
101
  assert_equal 6, prob.examples.size
102
102
  assert_equal 2, prob.images.size
103
103
  end
104
- end
104
+ end
@@ -1,6 +1,6 @@
1
1
  require "test/unit"
2
- require "topcoder/signature"
3
- include TopCoder
2
+ require "gettc/signature"
3
+ include Gettc
4
4
 
5
5
  class SignatureTest < Test::Unit::TestCase
6
6
  def test_parse_signature
@@ -51,4 +51,4 @@ class SignatureTest < Test::Unit::TestCase
51
51
  assert_equal TArray.new(TArray.new(TInt)), sigs[7].type
52
52
  assert_equal "y2", sigs[7].name
53
53
  end
54
- end
54
+ end
@@ -1,6 +1,6 @@
1
1
  require "test/unit"
2
- require "topcoder/types"
3
- include TopCoder
2
+ require "gettc/types"
3
+ include Gettc
4
4
 
5
5
  class TypesTest < Test::Unit::TestCase
6
6
  def test_parse_type
@@ -21,4 +21,8 @@ class TypesTest < Test::Unit::TestCase
21
21
  assert_equal TArray.new(TInt), parse_type("int[]")
22
22
  assert_equal TArray.new(TArray.new(TString)), parse_type("String[][]")
23
23
  end
24
- end
24
+ def test_type_to_s
25
+ assert_equal "String", TString.to_s
26
+ assert_equal "boolean[][]", TArray.new(TArray.new(TBoolean)).to_s
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  username: gettc
2
2
  password: algorithm
3
- version: 1.8.2
3
+ version: 1.9
@@ -3,49 +3,49 @@ require "gettc/types"
3
3
  module Gettc
4
4
  class Type
5
5
  def to_cpp
6
- if self == TInt then
6
+ if is_a? TArray then
7
+ ret = "vector<" << subtype.to_cpp
8
+ ret << " " if subtype.is_a? TArray
9
+ ret << ">"
10
+ return ret
11
+ end
12
+
13
+ case self
14
+ when TInt
7
15
  return "int"
8
- elsif self == TLong then
16
+ when TLong
9
17
  return "int64"
10
- elsif self == TFloat then
18
+ when TFloat
11
19
  return "float"
12
- elsif self == TDouble then
20
+ when TDouble
13
21
  return "double"
14
- elsif self == TChar then
22
+ when TChar
15
23
  return "char"
16
- elsif self == TString then
24
+ when TString
17
25
  return "string"
18
- elsif self == TBoolean then
26
+ when TBoolean
19
27
  return "bool"
20
- elsif is_a? TArray then
21
- ret = "vector<" << subtype.to_cpp
22
- ret << " " if subtype.is_a? TArray
23
- ret << ">"
24
- return ret
25
- else
26
- return "unknown"
27
- end
28
+ end
29
+
30
+ return "unknown"
28
31
  end
29
32
  def dumb_cpp
30
- if self == TInt then
31
- return "0"
32
- elsif self == TLong then
33
- return "0"
34
- elsif self == TFloat then
35
- return "0"
36
- elsif self == TDouble then
33
+ if is_a? TArray then
34
+ return "#{to_cpp}()"
35
+ end
36
+
37
+ case self
38
+ when TInt, TLong, TFloat, TDouble
37
39
  return "0"
38
- elsif self == TChar then
39
- return "\"$\""
40
- elsif self == TString then
41
- return "\"$\""
42
- elsif self == TBoolean then
40
+ when TChar
41
+ return "'$'"
42
+ when TString
43
+ return '"$"'
44
+ when TBoolean then
43
45
  return "true"
44
- elsif is_a? TArray then
45
- return "#{to_cpp}()"
46
- else
47
- return "Nil"
48
46
  end
47
+
48
+ return "Nil"
49
49
  end
50
50
  end
51
51
  class Signature
@@ -3,46 +3,46 @@ require "gettc/types"
3
3
  module Gettc
4
4
  class Type
5
5
  def to_go
6
- if self == TInt then
6
+ if is_a? TArray
7
+ return "[]#{subtype.to_go}"
8
+ end
9
+
10
+ case self
11
+ when TInt
7
12
  return "int"
8
- elsif self == TLong then
13
+ when TLong
9
14
  return "int64"
10
- elsif self == TFloat then
15
+ when TFloat
11
16
  return "float32"
12
- elsif self == TDouble then
17
+ when TDouble
13
18
  return "float64"
14
- elsif self == TChar then
19
+ when TChar
15
20
  return "byte"
16
- elsif self == TString then
21
+ when TString
17
22
  return "string"
18
- elsif self == TBoolean then
23
+ when TBoolean
19
24
  return "bool"
20
- elsif is_a? TArray then
21
- return "[]#{subtype.to_go}"
22
- else
23
- return "unknown"
24
25
  end
26
+
27
+ return "unknown"
25
28
  end
26
29
  def dumb_go
27
- if self == TInt then
28
- return "0"
29
- elsif self == TLong then
30
- return "0"
31
- elsif self == TFloat then
32
- return "0"
33
- elsif self == TDouble then
30
+ if is_a? TArray
31
+ return to_go + " {}"
32
+ end
33
+
34
+ case self
35
+ when TInt, TLong, TDouble, TFloat
34
36
  return "0"
35
- elsif self == TChar then
37
+ when TChar
36
38
  return "'$'"
37
- elsif self == TString then
39
+ when TString
38
40
  return '"$"'
39
- elsif self == TBoolean then
41
+ when TBoolean
40
42
  return "true"
41
- elsif is_a? TArray then
42
- return self.to_go + " {}"
43
- else
44
- return "nil"
45
43
  end
44
+
45
+ return "nil"
46
46
  end
47
47
  end
48
48
  class Signature
@@ -3,67 +3,70 @@ require "gettc/types"
3
3
  module Gettc
4
4
  class Type
5
5
  def to_haskell
6
- if self == TInt then
6
+ if is_a? TArray then
7
+ return "[" + subtype.to_haskell + "]"
8
+ end
9
+
10
+ case self
11
+ when TInt
7
12
  return "Int"
8
- elsif self == TLong then
13
+ when TLong
9
14
  return "Integer"
10
- elsif self == TFloat then
15
+ when TFloat
11
16
  return "Float"
12
- elsif self == TDouble then
17
+ when TDouble
13
18
  return "Double"
14
- elsif self == TChar then
19
+ when TChar
15
20
  return "Char"
16
- elsif self == TString then
21
+ when TString
17
22
  return "String"
18
- elsif self == TBoolean then
23
+ when TBoolean
19
24
  return "Bool"
20
- elsif is_a? TArray then
21
- return "[" + subtype.to_haskell + "]"
22
- else
23
- return "Unknown"
24
25
  end
26
+
27
+ return "Unknown"
25
28
  end
26
29
  def get_haskell_parser
27
- if self == TInt then
30
+ if is_a? TArray then
31
+ return "(TC.parseList " + subtype.get_haskell_parser + ")"
32
+ end
33
+
34
+ case self
35
+ when TInt
28
36
  return "TC.parseInt"
29
- elsif self == TLong then
37
+ when TLong
30
38
  return "TC.parseLong"
31
- elsif self == TFloat then
39
+ when TFloat
32
40
  return "TC.parseFloat"
33
- elsif self == TDouble then
41
+ when TDouble
34
42
  return "TC.parseDouble"
35
- elsif self == TChar then
43
+ when TChar
36
44
  return "TC.parseChar"
37
- elsif self == TString then
45
+ when TString
38
46
  return "TC.parseString"
39
- elsif self == TBoolean then
47
+ when TBoolean
40
48
  return "TC.parseBool"
41
- elsif is_a? TArray then
42
- return "(TC.parseList " + subtype.get_haskell_parser + ")"
43
- else
44
- return "unknown"
45
49
  end
50
+
51
+ return "unknown"
46
52
  end
47
53
  def dumb_haskell
48
- if self == TInt then
49
- return "0"
50
- elsif self == TLong then
51
- return "0"
52
- elsif self == TFloat then
53
- return "0"
54
- elsif self == TDouble then
54
+ if is_a? TArray
55
+ return "[]"
56
+ end
57
+
58
+ case self
59
+ when TInt, TLong, TFloat, TDouble
55
60
  return "0"
56
- elsif self == TChar then
57
- return "\"$\""
58
- elsif self == TString then
59
- return "\"$\""
60
- elsif self == TBoolean then
61
+ when TChar
62
+ return "'$'"
63
+ when TString
64
+ return '"$"'
65
+ when TBoolean
61
66
  return "True"
62
- elsif is_a? TArray then
63
- return "[]"
64
- else
65
- return "Nil"
66
67
  end
68
+
69
+ return "Nil"
67
70
  end
68
71
  end
69
72
  class HaskellEngine
@@ -3,67 +3,49 @@ require "gettc/types"
3
3
  module Gettc
4
4
  class Type
5
5
  def to_java
6
- if self == TInt then
7
- return "int"
8
- elsif self == TLong then
9
- return "long"
10
- elsif self == TFloat then
11
- return "float"
12
- elsif self == TDouble then
13
- return "double"
14
- elsif self == TChar then
15
- return "char"
16
- elsif self == TString then
17
- return "String"
18
- elsif self == TBoolean then
19
- return "boolean"
20
- elsif is_a? TArray then
21
- return "#{subtype.to_java}[]"
22
- else
23
- return "unknown"
24
- end
6
+ return to_s
25
7
  end
26
8
  def to_java_boxed
27
- if self == TInt then
9
+ if is_a? TArray then
10
+ return "List<#{subtype.to_java_boxed}>"
11
+ end
12
+
13
+ case self
14
+ when TInt
28
15
  return "Integer"
29
- elsif self == TLong then
16
+ when TLong
30
17
  return "Long"
31
- elsif self == TFloat then
18
+ when TFloat
32
19
  return "Float"
33
- elsif self == TDouble then
20
+ when TDouble
34
21
  return "Double"
35
- elsif self == TChar then
22
+ when TChar
36
23
  return "Character"
37
- elsif self == TString then
24
+ when TString
38
25
  return "String"
39
- elsif self == TBoolean then
26
+ when TBoolean
40
27
  return "Boolean"
41
- elsif self.is_a? TArray then
42
- return "List<#{subtype.to_java_boxed}>"
43
- else
44
- return "Unknown"
45
28
  end
29
+
30
+ return "Unknown"
46
31
  end
47
32
  def dumb_java
48
- if self == TInt then
49
- return "0"
50
- elsif self == TLong then
51
- return "0"
52
- elsif self == TFloat then
53
- return "0"
54
- elsif self == TDouble then
33
+ if self.is_a? TArray then
34
+ return "new #{subtype.to_java}[1]"
35
+ end
36
+
37
+ case self
38
+ when TInt, TLong, TFloat, TDouble
55
39
  return "0"
56
- elsif self == TChar then
57
- return "\"$\""
58
- elsif self == TString then
59
- return "\"$\""
60
- elsif self == TBoolean then
40
+ when TChar
41
+ return "'$'"
42
+ when TString
43
+ return '"$"'
44
+ when TBoolean
61
45
  return "true"
62
- elsif self.is_a? TArray then
63
- return "new #{subtype.to_java}[1]"
64
- else
65
- return "Nil"
66
46
  end
47
+
48
+ return "Nil"
67
49
  end
68
50
  end
69
51
  class Signature
@@ -3,25 +3,22 @@ require "gettc/types"
3
3
  module Gettc
4
4
  class Type
5
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
6
+ if self.is_a? TArray then
7
+ return "[]"
8
+ end
9
+
10
+ case self
11
+ when TInt, TLong, TFloat, TDouble
13
12
  return "0"
14
- elsif self == TChar then
13
+ when TChar
15
14
  return "'$'"
16
- elsif self == TString then
15
+ when TString
17
16
  return '"$"'
18
- elsif self == TBoolean then
17
+ when TBoolean
19
18
  return "True"
20
- elsif self.is_a? TArray then
21
- return "[]"
22
- else
23
- return "None"
24
19
  end
20
+
21
+ return "None"
25
22
  end
26
23
  end
27
24
  class PythonEngine
@@ -119,7 +119,7 @@ class ReaderInternal(object):
119
119
  elif self.text[self.pos:self.pos + 5].upper() == "FALSE":
120
120
  self.pos += 5
121
121
  return False
122
- self.raise_here("expecting either true or false)")
122
+ self.raise_here("expecting either true or false")
123
123
 
124
124
  def next_string(self):
125
125
  self.spaces()
@@ -0,0 +1,62 @@
1
+ require "gettc/types"
2
+
3
+ module Gettc
4
+ class Type
5
+ def to_ruby
6
+ if is_a? TArray
7
+ return "TArray.new(#{subtype.to_ruby})"
8
+ end
9
+
10
+ case self
11
+ when TInt
12
+ return "TInt"
13
+ when TLong
14
+ return "TLong"
15
+ when TFloat
16
+ return "TFloat"
17
+ when TDouble
18
+ return "TDouble"
19
+ when TChar
20
+ return "TChar"
21
+ when TString
22
+ return "TString"
23
+ when TBoolean
24
+ return "TBoolean"
25
+ end
26
+
27
+ return "Object"
28
+ end
29
+ def dumb_ruby
30
+ if is_a? TArray then
31
+ return "[]"
32
+ end
33
+
34
+ case self
35
+ when TInt, TLong, TFloat, TDouble
36
+ return "0"
37
+ when TChar
38
+ return "?$"
39
+ when TString
40
+ return '"$"'
41
+ when TBoolean
42
+ return "true"
43
+ end
44
+
45
+ return "nil"
46
+ end
47
+ end
48
+ class RubyEngine
49
+ attr_reader :arglist, :input
50
+ def initialize func, vars
51
+ temp = vars.map do |var|
52
+ var.name
53
+ end
54
+ @arglist = temp.join ", "
55
+
56
+ temp = vars.map do |var|
57
+ var.name + " = reader.next(" + var.type.to_ruby + ")"
58
+ end
59
+ @input = temp.join "\nreader.next()\n"
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,2 @@
1
+ require "topcoder/reader"
2
+ require "topcoder/writer"
@@ -0,0 +1,213 @@
1
+ require "gettc/types"
2
+ include Gettc
3
+
4
+ module TopCoder
5
+ class ParseError < StandardError
6
+ def initialize text, pos, info = ""
7
+ message = text
8
+ if pos < text.size && pos >= 0
9
+ message = text[0..pos]
10
+ message << "|"
11
+ message << text[pos]
12
+ message << "|"
13
+ message << text[(pos + 1)..(-1)]
14
+ end
15
+ message = "<#{message}>"
16
+ if info
17
+ message += " (" + info + ")"
18
+ end
19
+ super message
20
+ end
21
+ end
22
+
23
+ class Reader
24
+ def initialize text
25
+ if !text.is_a? String
26
+ raise TypeError.new "need a string to construct a Reader"
27
+ end
28
+ @text = text
29
+ @pos = 0
30
+ @len = @text.size
31
+ end
32
+ def next typ = nil
33
+ if typ.nil?
34
+ spaces
35
+ expect ?,
36
+ return
37
+ end
38
+
39
+ case typ
40
+ when TBoolean
41
+ return next_boolean
42
+ when TInt, TLong
43
+ return next_int
44
+ when TFloat, TDouble
45
+ return next_float
46
+ when TChar
47
+ return next_char
48
+ when TString
49
+ return next_string
50
+ else
51
+ if typ.is_a? TArray
52
+ return next_array typ.subtype
53
+ end
54
+ end
55
+
56
+ raise UnrecognizedType.new typ
57
+ end
58
+
59
+ private
60
+ def raise_here message = nil
61
+ raise ParseError.new @text, @pos, message
62
+ end
63
+ def check_pos
64
+ if @pos >= @len
65
+ raise_here "unexpected end of input"
66
+ end
67
+ end
68
+
69
+ def token
70
+ check_pos
71
+ return @text[@pos]
72
+ end
73
+ def spaces
74
+ while @pos < @len && @text[@pos] =~ /\s/ do
75
+ @pos += 1
76
+ end
77
+ end
78
+ def expect char
79
+ if token == char
80
+ @pos += 1
81
+ else
82
+ raise_here "expecting <#{char}>"
83
+ end
84
+ end
85
+
86
+ def next_boolean
87
+ spaces
88
+ if @text[@pos, 4].upcase == "TRUE"
89
+ @pos += 4
90
+ return true
91
+ elsif @text[@pos, 5].upcase == "FALSE"
92
+ @pos += 5
93
+ return false
94
+ end
95
+ raise_here "expecting either true or false"
96
+ end
97
+
98
+ def is_digit
99
+ return @text[@pos] =~ /\d/
100
+ end
101
+ def next_digits
102
+ check_pos
103
+ if !is_digit
104
+ raise_here "expecting a digit"
105
+ end
106
+ start = @pos
107
+ while true do
108
+ @pos += 1
109
+ if @pos == @len || !is_digit
110
+ break
111
+ end
112
+ end
113
+ return @text[start..(@pos - 1)]
114
+ end
115
+
116
+ def next_positive_int
117
+ return next_digits.to_i
118
+ end
119
+ def next_int
120
+ spaces
121
+ if token == ?-
122
+ @pos += 1
123
+ return -next_positive_int
124
+ end
125
+ return next_positive_int
126
+ end
127
+
128
+ def next_positive_float
129
+ str = next_digits
130
+ if @pos < @len
131
+ if @text[@pos] == ?.
132
+ @pos += 1
133
+ str << "." << next_digits
134
+ end
135
+ end
136
+ return str.to_f
137
+ end
138
+ def next_float
139
+ spaces
140
+ if token == ?-
141
+ @pos += 1
142
+ return -next_positive_float
143
+ end
144
+ return next_positive_float
145
+ end
146
+
147
+ def next_char
148
+ spaces
149
+ char = token
150
+ if char == ?'
151
+ @pos += 1
152
+ ret = token
153
+ @pos += 1
154
+ expect ?'
155
+ return ret
156
+ end
157
+ @pos += 1
158
+ return char
159
+ end
160
+
161
+ def next_string
162
+ spaces
163
+ expect ?"
164
+ start = @pos
165
+ while true do
166
+ if @pos >= @len
167
+ raise_here "expecting a closing quote when reading a string"
168
+ end
169
+ if token == ?"
170
+ @pos += 1
171
+ saved = @pos
172
+ spaces
173
+ if @pos == @len || @text[@pos] == ?, || @text[@pos] == ?]
174
+ @pos = saved
175
+ return @text[start..(@pos - 2)]
176
+ end
177
+ else
178
+ @pos += 1
179
+ end
180
+ end
181
+ end
182
+
183
+ def next_elems elem_type, arr
184
+ spaces
185
+ char = token
186
+ case char
187
+ when ?]
188
+ @pos += 1
189
+ return
190
+ when ?,
191
+ @pos += 1
192
+ arr << self.next(elem_type)
193
+ next_elems elem_type, arr
194
+ else
195
+ raise_here "expecting either <,> or <]>"
196
+ end
197
+ end
198
+
199
+ def next_array elem_type
200
+ arr = []
201
+ spaces
202
+ expect ?[
203
+ spaces
204
+ if token == ?]
205
+ @pos += 1
206
+ return arr
207
+ end
208
+ arr << self.next(elem_type)
209
+ next_elems elem_type, arr
210
+ return arr
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,41 @@
1
+ require "gettc/types"
2
+ include Gettc
3
+
4
+ module TopCoder
5
+ class Writer
6
+ def initialize
7
+ @text = ""
8
+ end
9
+ def next value = nil, typ = nil
10
+ if value.nil? && typ.nil?
11
+ @text << ", "
12
+ return
13
+ end
14
+
15
+ case typ
16
+ when TBoolean, TInt, TLong, TFloat, TDouble
17
+ @text << value.to_s
18
+ when TChar
19
+ @text << ?' << value << ?'
20
+ when TString
21
+ @text << ?" << value << ?"
22
+ else
23
+ if typ.is_a? TArray
24
+ @text << ?[
25
+ value.each_index do |i|
26
+ self.next value[i], typ.subtype
27
+ if i < value.size - 1
28
+ self.next
29
+ end
30
+ end
31
+ @text << ?]
32
+ else
33
+ raise UnrecognizedType.new typ
34
+ end
35
+ end
36
+ end
37
+ def to_s
38
+ return @text
39
+ end
40
+ end
41
+ end
@@ -4,5 +4,5 @@ OUTPUT_D = ../../build/python
4
4
  SOLVER = ./<%= prob.name %>Solver.py
5
5
 
6
6
  main: setup
7
- chmod +x $(SOLVER)
7
+ @chmod +x $(SOLVER)
8
8
 
@@ -0,0 +1,8 @@
1
+ include ../Makefile.common
2
+
3
+ OUTPUT_D = ../../build/ruby
4
+ SOLVER = ./<%= prob.name %>Solver.rb
5
+
6
+ main: setup
7
+ @chmod +x $(SOLVER)
8
+
@@ -0,0 +1,7 @@
1
+ <%
2
+ engine = RubyEngine.new func, vars
3
+ %>class <%= prob.name %>
4
+ def <%= func.name %>(<%= engine.arglist %>)
5
+ return <%= func.type.dumb_ruby %>
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ #! /usr/bin/env ruby
2
+ <% engine = RubyEngine.new func, vars %>
3
+ require_relative "<%= prob.name %>"
4
+
5
+ require "gettc/types"
6
+ include Gettc
7
+
8
+ def init()
9
+ gettc_home = File.join(ENV["HOME"], ".gettc")
10
+ if ENV.has_key?("GETTC_HOME")
11
+ gettc_home = ENV["GETTC_HOME"]
12
+ end
13
+ gettc_home = File.expand_path(gettc_home)
14
+ $LOAD_PATH << File.join(gettc_home, "include", "ruby")
15
+ require "topcoder"
16
+ include TopCoder
17
+ end
18
+
19
+ def main()
20
+ reader = Reader.new(IO.read(ARGV[0]))
21
+ <%= engine.input.gsub(/^/, " " * 4) %>
22
+
23
+ result = <%= prob.name %>.new().<%= func.name %>(<%= engine.arglist %>)
24
+ IO.write(ARGV[1], Writer.new().next(result, <%= func.type.to_ruby %>).to_s())
25
+ end
26
+ init()
27
+ main()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: '1.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-09 00:00:00.000000000 Z
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hpricot
@@ -85,6 +85,10 @@ files:
85
85
  - dist/include/python/topcoder/reader.pyc
86
86
  - dist/include/python/topcoder/writer.py
87
87
  - dist/include/python/topcoder/writer.pyc
88
+ - dist/include/ruby/engine.rb
89
+ - dist/include/ruby/topcoder.rb
90
+ - dist/include/ruby/topcoder/reader.rb
91
+ - dist/include/ruby/topcoder/writer.rb
88
92
  - dist/template/bin/runner.rb
89
93
  - dist/template/bin/runner.sh
90
94
  - dist/template/data/demo/{examples_d}
@@ -109,6 +113,9 @@ files:
109
113
  - dist/template/solve/python/Makefile
110
114
  - dist/template/solve/python/{name}.py
111
115
  - dist/template/solve/python/{name}Solver.py
116
+ - dist/template/solve/ruby/Makefile
117
+ - dist/template/solve/ruby/{name}.rb
118
+ - dist/template/solve/ruby/{name}Solver.rb
112
119
  - dist/template/util/check/Makefile
113
120
  - dist/template/util/check/check.cpp
114
121
  - dist/usage