at_coder_friends-generator-python_ref 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e84ac238506799a393d6a5728476aacad96218b
4
- data.tar.gz: d08501d453284d7a299ab0caad8333edcc5bb585
3
+ metadata.gz: ea05cb41657896054fae4fbc7980c10b0045855a
4
+ data.tar.gz: ab907ac801f09f2e50947ee6d8c94f03dbb65840
5
5
  SHA512:
6
- metadata.gz: b8a1108c6d301523371c5185cc582cf6bc30b3a98fb2218b413ce777f05d56c94b5ad8d6fcc61c3429e3993d0b894d02d34c6833c874cd1b5694ba5903346e3f
7
- data.tar.gz: e59912f8024f5925f1442d78fd16ccb02bdbc8591fb0af1ae792c7b2968f684382c4e383182b3b427ea9a714c4523b6e56ca57b4895ba173ab18639a311ab39f
6
+ metadata.gz: 07a6667e4fa8d98b4776a79040cbcc99d004b91b03ece2568163e0e114fd10373b9e32fb5bf45d8a423b719f7c53980af9f6caa86c2972d0272d112aad1cbe8b
7
+ data.tar.gz: 9671cbdc3f4d4e90b178722aac7cab94ba72eee5c4003dd1d672ee29f698c3b1a9fb0943057575c8007e4c89e6ab2a0c2d9d45ca6ce5992d8ce6a7b154ba3fef
@@ -1,6 +1,26 @@
1
1
  # Change log
2
2
 
3
- ## master(unreleased)
3
+ ## master (unreleased)
4
+
5
+ ## 0.2.0 (2020-01-05)
6
+
7
+ ### Added
8
+ - at_coder_friends 0.6.3 support
9
+ - 'vertical array + matrix' input format support.
10
+ - 'matrix + vertical array' input format support.
11
+ - 'vertically expanded matrices' input format support.
12
+ - 'horizontally expanded matrices' input format support.
13
+ - decimal type support.
14
+ - input data with delimiter(- : /) support.
15
+
16
+ ### Changed
17
+ - Change template file format to ERB.
18
+ - Template file integration
19
+
20
+ ### Deleted
21
+ - Template file for interactive problems.
22
+ - '### OUTPUT ###' embedding pattern.
23
+ - '### URL ###' embedding pattern.
4
24
 
5
25
  ## 0.1.0 (2019-10-31)
6
26
  - Initial implementation
@@ -1,14 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- at_coder_friends-generator-python_ref (0.1.0)
4
+ at_coder_friends-generator-python_ref (0.2.0)
5
+ at_coder_friends (~> 0.6.3)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  addressable (2.7.0)
10
11
  public_suffix (>= 2.0.2, < 5.0)
11
- at_coder_friends (0.6.1)
12
+ at_coder_friends (0.6.3)
12
13
  colorize (~> 0.8.1)
13
14
  launchy (~> 2.4.3)
14
15
  mechanize (~> 2.0)
@@ -37,7 +38,7 @@ GEM
37
38
  net-http-digest_auth (1.4.1)
38
39
  net-http-persistent (3.1.0)
39
40
  connection_pool (~> 2.2)
40
- nokogiri (1.10.4)
41
+ nokogiri (1.10.5)
41
42
  mini_portile2 (~> 2.4.0)
42
43
  ntlm-http (0.1.1)
43
44
  public_suffix (4.0.1)
@@ -62,9 +63,9 @@ GEM
62
63
 
63
64
  PLATFORMS
64
65
  ruby
66
+ x64-mingw32
65
67
 
66
68
  DEPENDENCIES
67
- at_coder_friends (~> 0.6)
68
69
  at_coder_friends-generator-python_ref!
69
70
  bundler (~> 2.0)
70
71
  rake (~> 10.0)
data/README.md CHANGED
@@ -21,27 +21,28 @@ Or install it yourself as:
21
21
 
22
22
  ## Configuration
23
23
 
24
- Add ```PythonRef``` to ```generators``` setting in ```.at_coder_friends.yml```:
25
- ```YAML
26
- generators:
27
- - PythonRef
28
- ```
24
+ Add ```PythonRef``` to ```generators``` setting in ```.at_coder_friends.yml```
29
25
 
30
26
  ## Generator Options
31
27
 
32
- You can set following options to ```generator_settings/PythonRef``` setting
33
- in ```.at_coder_friends.yml```:
28
+ Following options are available
29
+ in ```generator_settings/PythonRef``` section of ```.at_coder_friends.yml```:
34
30
 
35
- | Setting | Description | Default |
31
+ | Option | Description | Default |
36
32
  |---------|-------------|---------|
37
- |default_template|Source template file path|[/templates/python_ref_default.py](/templates/python_ref_default.py)|
38
- |interactive_template|Source template file path for interactive problems|[/templates/python_ref_interactive.py](/templates/python_ref_interactive.py)|
33
+ |default_template|Source template file path|[/templates/python_ref.py.erb](/templates/python_ref.py.erb)|
39
34
 
40
- ### Example
35
+ ## ```.at_coder_friends.yml``` example for Python
41
36
  ```YAML
37
+ generators:
38
+ - PythonRef
42
39
  generator_settings:
43
40
  PythonRef:
44
41
  default_template: /path/to/template
42
+ ext_settings:
43
+ 'py':
44
+ test_cmd:
45
+ default: 'python "{dir}/{base}.py"'
45
46
  ```
46
47
 
47
48
  ## Development
@@ -6,14 +6,13 @@ require 'at_coder_friends/generator/python_ref/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'at_coder_friends-generator-python_ref'
9
- spec.version = AtCoderFriends::Generator::PythonRef::VERSION
9
+ spec.version = AtCoderFriends::Generator::PythonRefConstants::VERSION
10
10
  spec.authors = ['nejiko96']
11
11
  spec.email = ['nejiko2006@gmail.com']
12
12
 
13
13
  spec.summary = 'Python generator for AtCoderFriends'
14
14
  spec.description = <<-DESCRIPTION
15
- AtCoderFriends plugin
16
- which Generates Python source from problem description
15
+ Python source generator works as a plugin for AtCoderFriends
17
16
  (reference implementation)
18
17
  DESCRIPTION
19
18
  spec.homepage = 'https://github.com/nejiko96/at_coder_friends-generator-python_ref'
@@ -33,11 +32,14 @@ Gem::Specification.new do |spec|
33
32
 
34
33
  spec.required_ruby_version = '>= 2.3.0'
35
34
 
36
- spec.metadata['homepage_uri'] = spec.homepage
37
- spec.metadata['source_code_uri'] = spec.homepage
38
- spec.metadata['changelog_uri'] = spec.homepage + '/CHANGELOG.md'
35
+ spec.metadata = {
36
+ 'homepage_uri' => spec.homepage,
37
+ 'source_code_uri' => spec.homepage,
38
+ 'changelog_uri' => 'https://github.com/nejiko96/at_coder_friends-generator-python_ref/blob/master/CHANGELOG.md'
39
+ }
40
+
41
+ spec.add_dependency 'at_coder_friends', '~> 0.6.3'
39
42
 
40
- spec.add_development_dependency 'at_coder_friends', '~> 0.6'
41
43
  spec.add_development_dependency 'bundler', '~> 2.0'
42
44
  spec.add_development_dependency 'rake', '~> 10.0'
43
45
  spec.add_development_dependency 'rspec', '~> 3.0'
@@ -1,47 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'at_coder_friends'
3
4
  require 'at_coder_friends/generator/python_ref/version'
4
5
 
5
6
  module AtCoderFriends
6
7
  module Generator
7
8
  # generates Python source from problem description
8
- class PythonRef
9
+ class PythonRef < Base
10
+ include PythonRefConstants
11
+
9
12
  ACF_HOME = File.realpath(File.join(__dir__, '..', '..', '..'))
10
13
  TMPL_DIR = File.join(ACF_HOME, 'templates')
11
- DEFAULT_TMPL = File.join(TMPL_DIR, 'python_ref_default.py')
12
- INTERACTIVE_TMPL = File.join(TMPL_DIR, 'python_ref_interactive.py')
13
-
14
- attr_reader :cfg, :pbm
15
-
16
- def initialize(cfg = nil)
17
- @cfg = cfg || {}
18
- end
19
-
20
- def process(pbm)
21
- src = generate(pbm)
22
- pbm.add_src(:py, src)
23
- end
24
-
25
- def generate(pbm)
26
- @pbm = pbm
27
- File
28
- .read(select_template)
29
- .gsub('### URL ###', pbm.url)
30
- .gsub('### CONSTS ###', gen_consts.join("\n"))
31
- .gsub('### DCLS ###', gen_decls.join("\n"))
32
- .gsub('### OUTPUT ###', gen_output)
33
- end
34
-
35
- def select_template(interactive = pbm.options.interactive)
36
- interactive ? interactive_template : default_template
37
- end
14
+ DEFAULT_TMPL = File.join(TMPL_DIR, 'python_ref.py.erb')
15
+ ATTRS = Attributes.new(:py, DEFAULT_TMPL)
38
16
 
39
- def default_template
40
- cfg['default_template'] || DEFAULT_TMPL
17
+ def attrs
18
+ ATTRS
41
19
  end
42
20
 
43
- def interactive_template
44
- cfg['interactive_template'] || INTERACTIVE_TMPL
21
+ def render(src)
22
+ src = embed_lines(src, '### CONSTS ###', gen_consts)
23
+ src = embed_lines(src, '### DCLS ###', gen_decls)
24
+ src
45
25
  end
46
26
 
47
27
  def gen_consts(constants = pbm.constants)
@@ -67,35 +47,45 @@ module AtCoderFriends
67
47
  when :harray
68
48
  gen_harray_decl(inpdef)
69
49
  when :varray
70
- if inpdef.names.size == 1
71
- gen_varray_1_decl(inpdef)
72
- else
73
- gen_varray_n_decl(inpdef)
74
- end
50
+ gen_varray_decl(inpdef)
75
51
  when :matrix
76
52
  gen_matrix_decl(inpdef)
53
+ when :varray_matrix, :matrix_varray
54
+ gen_cmb_decl(inpdef)
55
+ when :vmatrix
56
+ gen_vmatrix_decl(inpdef)
57
+ when :hmatrix
58
+ gen_hmatrix_decl(inpdef)
77
59
  end
78
60
  end
79
61
 
80
62
  def gen_single_decl(inpdef)
81
63
  names = inpdef.names
82
64
  dcl = names.join(', ')
83
- expr = gen_expr(inpdef.item, names.size > 1)
65
+ expr = gen_expr(inpdef, names.size > 1)
84
66
  "#{dcl} = #{expr}"
85
67
  end
86
68
 
87
69
  def gen_harray_decl(inpdef)
88
70
  v = inpdef.names[0]
89
71
  dcl = "#{v}s"
90
- expr = gen_expr(inpdef.item, true)
72
+ expr = gen_expr(inpdef, true)
91
73
  "#{dcl} = #{expr}"
92
74
  end
93
75
 
76
+ def gen_varray_decl(inpdef)
77
+ if inpdef.names.size == 1
78
+ gen_varray_1_decl(inpdef)
79
+ else
80
+ gen_varray_n_decl(inpdef)
81
+ end
82
+ end
83
+
94
84
  def gen_varray_1_decl(inpdef)
95
85
  v = inpdef.names[0]
96
86
  sz = inpdef.size[0]
97
87
  dcl = "#{v}s"
98
- expr = gen_expr(inpdef.item, false)
88
+ expr = gen_expr(inpdef, false)
99
89
  "#{dcl} = [#{expr} for _ in range(#{sz})]"
100
90
  end
101
91
 
@@ -103,7 +93,7 @@ module AtCoderFriends
103
93
  names = inpdef.names
104
94
  sz = inpdef.size[0]
105
95
  dcl = names.map { |v| "#{v}s[i]" }.join(', ')
106
- expr = gen_expr(inpdef.item, true)
96
+ expr = gen_expr(inpdef, true)
107
97
  ret = []
108
98
  ret += names.map { |v| "#{v}s = [None for _ in range(#{sz})]" }
109
99
  ret << "for i in range(#{sz}):"
@@ -115,28 +105,86 @@ module AtCoderFriends
115
105
  v = inpdef.names[0]
116
106
  sz = inpdef.size[0]
117
107
  decl = "#{v}ss"
118
- expr = gen_expr(inpdef.item, true)
108
+ expr = gen_expr(inpdef, true)
119
109
  "#{decl} = [#{expr} for _ in range(#{sz})]"
120
110
  end
121
111
 
122
- def gen_expr(item, split)
123
- case item
112
+ def gen_cmb_decl(inpdef)
113
+ mx = inpdef.container == :varray_matrix ? -1 : 0
114
+ vs = inpdef.names.map { |v| "#{v}s" }
115
+ vs[mx] += 's'
116
+ sz = inpdef.size[0]
117
+ dcls = vs.map { |v| "#{v}[i]" }
118
+ dcls[mx] = '*' + dcls[mx] unless inpdef.item == :char
119
+ dcl = dcls.join(', ')
120
+ expr = gen_cmb_expr(inpdef)
121
+ ret = []
122
+ ret += vs.map { |v| "#{v} = [None for _ in range(#{sz})]" }
123
+ ret << "for i in range(#{sz}):"
124
+ ret << " #{dcl} = #{expr}"
125
+ ret
126
+ end
127
+
128
+ def gen_vmatrix_decl(inpdef)
129
+ names = inpdef.names
130
+ sz1, sz2 = inpdef.size
131
+ dcl = names.map { |v| "#{v}ss[i][j]" }.join(', ')
132
+ expr = gen_expr(inpdef, true)
133
+ ret = []
134
+ ret += names.map do |v|
135
+ "#{v}ss = [[None for _ in range(#{sz2})] for _ in range(#{sz1})]"
136
+ end
137
+ ret << "for i in range(#{sz1}):"
138
+ ret << " for j in range(#{sz2}):"
139
+ ret << " #{dcl} = #{expr}"
140
+ ret
141
+ end
142
+
143
+ def gen_hmatrix_decl(inpdef)
144
+ names = inpdef.names
145
+ sz = inpdef.size[0]
146
+ dcls = names.map { |v| "#{v}ss[i]" }
147
+ expr = gen_expr(inpdef, true)
148
+ ret = []
149
+ ret += names.map { |v| "#{v}ss = [None for _ in range(#{sz})]" }
150
+ ret << "for i in range(#{sz}):"
151
+ ret << " line = #{expr}"
152
+ ret += dcls.map.with_index do |dcl, i|
153
+ " #{dcl} = line[#{i}::#{dcls.size}]"
154
+ end
155
+ ret
156
+ end
157
+
158
+ def gen_expr(inpdef, split)
159
+ read = gen_read(inpdef.delim)
160
+ case inpdef.item
124
161
  when :number
125
- split ? 'list(map(int, input().split()))' : 'int(input())'
162
+ split ? "list(map(int, #{read}.split()))" : "int(#{read})"
163
+ when :decimal
164
+ split ? "list(map(float, #{read}.split()))" : "float(#{read})"
126
165
  when :string
127
- split ? 'input().split()' : 'input()'
166
+ split ? "#{read}.split()" : read
128
167
  when :char
129
- 'input()'
168
+ read
130
169
  end
131
170
  end
132
171
 
133
- def gen_output(vs = pbm.options.binary_values)
134
- if vs
135
- "print('#{vs[0]}' if cond else '#{vs[1]}')"
136
- else
137
- 'print(ans)'
172
+ def gen_cmb_expr(inpdef)
173
+ read = gen_read(inpdef.delim)
174
+ case inpdef.item
175
+ when :number
176
+ "list(map(int, #{read}.split()))"
177
+ when :decimal
178
+ "list(map(float, #{read}.split()))"
179
+ when :string, :char
180
+ "#{read}.split()"
138
181
  end
139
182
  end
183
+
184
+ def gen_read(delim)
185
+ sub = delim.chars.map { |d| ".replace('#{d}', ' ')" }.join
186
+ "input()#{sub}"
187
+ end
140
188
  end
141
189
  end
142
190
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module AtCoderFriends
4
4
  module Generator
5
- class PythonRef
6
- VERSION = '0.1.0'
5
+ module PythonRefConstants
6
+ VERSION = '0.2.0'
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,13 @@
1
+ # <%= pbm.url %>
2
+
3
+ ### CONSTS ###
4
+
5
+ ### DCLS ###
6
+
7
+ <%
8
+ if (vs = pbm.options.binary_values)
9
+ %>print('<%= vs[0] %>' if cond else '<%= vs[1] %>')<%
10
+ else
11
+ %>print(ans)<%
12
+ end
13
+ %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: at_coder_friends-generator-python_ref
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nejiko96
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-31 00:00:00.000000000 Z
11
+ date: 2020-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: at_coder_friends
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.6'
20
- type: :development
19
+ version: 0.6.3
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.6'
26
+ version: 0.6.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,8 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
69
  description: |2
70
- AtCoderFriends plugin
71
- which Generates Python source from problem description
70
+ Python source generator works as a plugin for AtCoderFriends
72
71
  (reference implementation)
73
72
  email:
74
73
  - nejiko2006@gmail.com
@@ -93,15 +92,14 @@ files:
93
92
  - bin/setup
94
93
  - lib/at_coder_friends/generator/python_ref.rb
95
94
  - lib/at_coder_friends/generator/python_ref/version.rb
96
- - templates/python_ref_default.py
97
- - templates/python_ref_interactive.py
95
+ - templates/python_ref.py.erb
98
96
  homepage: https://github.com/nejiko96/at_coder_friends-generator-python_ref
99
97
  licenses:
100
98
  - MIT
101
99
  metadata:
102
100
  homepage_uri: https://github.com/nejiko96/at_coder_friends-generator-python_ref
103
101
  source_code_uri: https://github.com/nejiko96/at_coder_friends-generator-python_ref
104
- changelog_uri: https://github.com/nejiko96/at_coder_friends-generator-python_ref/CHANGELOG.md
102
+ changelog_uri: https://github.com/nejiko96/at_coder_friends-generator-python_ref/blob/master/CHANGELOG.md
105
103
  post_install_message:
106
104
  rdoc_options: []
107
105
  require_paths:
@@ -1,7 +0,0 @@
1
- # ### URL ###
2
-
3
- ### CONSTS ###
4
-
5
- ### DCLS ###
6
-
7
- ### OUTPUT ###
@@ -1,7 +0,0 @@
1
- # ### URL ###
2
-
3
- ### CONSTS ###
4
-
5
- ### DCLS ###
6
-
7
- ### OUTPUT ###