twisty_puzzles 0.0.14 → 0.0.15

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
  SHA256:
3
- metadata.gz: f95cf6c568aab20bad9dd5d48222afd5261215984a5da7c2c18b9d3bdf315763
4
- data.tar.gz: 713e3825d332a49805f4938b8bc2be924f3813d49e25e9997278966409bb73fe
3
+ metadata.gz: d5631e9c30819f3520d04ed81aa9b1ceebbee7a3da5c3b51bf2a81947f8fb3a1
4
+ data.tar.gz: fc4769b6c1ebab5d14cb64ddb3e39356a408750d1d0c7954d4929156296b9f9e
5
5
  SHA512:
6
- metadata.gz: 2e0ba5a01642a11c57a1d83aeb6b22aa4de037fcbbd6a062a2aff29028f37260cd06a38e009fe5683949a65509a899acd925bbe3b58fdf1552760d5664631ade
7
- data.tar.gz: 3b2d41b1b10065029813152e693f0c61c6b28557e1794d16dcb4d6c7b300fd7d0d6fa94b2b23de3e01041526ef03463a05a8854b1eec1be7cfaec7ef1943debb
6
+ metadata.gz: c941aaef4dbf2bc8d580d712d669042061c20670aadcf2ee353f353eae4eb31713de9d4791f6d8126e4427ef9e7125562e26b53c85f0a92e09bfe120e8f24f04
7
+ data.tar.gz: 5e943e567b069fd2b2e21c77fdc7a48ad3e81fb365832439cd1f402da838b5771bc7af4b2293bf635fa1b6de158ddfbea78f9981e690ce3e72a6149c6b042bd2
@@ -133,9 +133,12 @@ module TwistyPuzzles
133
133
 
134
134
  def *(other)
135
135
  raise TypeError unless other.is_a?(Integer)
136
- raise ArgumentError if other.negative?
137
136
 
138
- self.class.new(@moves * other)
137
+ if other.negative?
138
+ inverse * -other
139
+ else
140
+ self.class.new(@moves * other)
141
+ end
139
142
  end
140
143
 
141
144
  def compiled_for_skewb
@@ -83,6 +83,21 @@ module TwistyPuzzles
83
83
  end
84
84
  end
85
85
 
86
+ # Slash commutator of the form A B A2 B' A.
87
+ class SlashCommutator < PureCommutator
88
+ def inverse
89
+ SlashCommutator.new(first_part.inverse, second_part)
90
+ end
91
+
92
+ def to_s
93
+ "[#{@first_part}/#{@second_part}]"
94
+ end
95
+
96
+ def algorithm
97
+ first_part + second_part + (first_part * 2) + second_part.inverse + first_part
98
+ end
99
+ end
100
+
86
101
  # Setup commutator of the form A B A'.
87
102
  class SetupCommutator < Commutator
88
103
  def initialize(setup, inner_commutator)
@@ -16,6 +16,12 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
16
16
  OPENING_PAREN = '('
17
17
  CLOSING_BRACKET = ']'
18
18
  CLOSING_PAREN = ')'
19
+ SLASH = '/'
20
+ COMMA = ','
21
+ SETUP_SEPARATORS = %w[; :].freeze
22
+ PURE_SEPARATORS = [SLASH, COMMA].freeze
23
+ SEPARATORS = (SETUP_SEPARATORS + PURE_SEPARATORS).freeze
24
+
19
25
  TIMES = '*'
20
26
 
21
27
  def initialize(alg_string, move_parser)
@@ -156,11 +162,11 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
156
162
  parse_open_bracket
157
163
  first_part = parse_nonempty_moves_with_triggers
158
164
  skip_spaces
159
- parse_pure_separator
165
+ separator = parse_pure_separator
160
166
  second_part = parse_nonempty_moves_with_triggers
161
167
  skip_spaces
162
168
  parse_close_bracket
163
- PureCommutator.new(first_part, second_part)
169
+ pseudo_pure_commutator(separator, first_part, second_part)
164
170
  end
165
171
 
166
172
  def parse_pure_commutator_no_brackets
@@ -172,14 +178,16 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
172
178
 
173
179
  first_part = first_part_or_algorithm
174
180
  complain('move') if first_part.empty?
175
- parse_pure_separator
181
+ separator = parse_pure_separator
176
182
  second_part = parse_nonempty_moves_with_triggers
177
183
  skip_spaces
178
- PureCommutator.new(first_part, second_part)
184
+ pseudo_pure_commutator(separator, first_part, second_part)
179
185
  end
180
186
 
181
187
  def parse_pure_separator
182
- complain('middle of pure commutator') unless PURE_SEPARATORS.include?(@scanner.getch)
188
+ separator = @scanner.getch
189
+ complain('middle of pure commutator') unless PURE_SEPARATORS.include?(separator)
190
+ separator
183
191
  end
184
192
 
185
193
  def parse_commutator_internal_after_separator(setup_or_first_part, separator)
@@ -188,15 +196,21 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
188
196
  SetupCommutator.new(setup_or_first_part, inner_commutator)
189
197
  elsif PURE_SEPARATORS.include?(separator)
190
198
  second_part = parse_nonempty_moves_with_triggers
191
- PureCommutator.new(setup_or_first_part, second_part)
199
+ pseudo_pure_commutator(separator, setup_or_first_part, second_part)
192
200
  else
193
201
  complain('end of setup or middle of pure commutator') unless @scanner.eos?
194
202
  end
195
203
  end
196
204
 
197
- SETUP_SEPARATORS = %w[; :].freeze
198
- PURE_SEPARATORS = %w[/ ,].freeze
199
- SEPARATORS = (SETUP_SEPARATORS + PURE_SEPARATORS).freeze
205
+ def pseudo_pure_commutator(separator, first_part, second_part)
206
+ if separator == COMMA
207
+ PureCommutator.new(first_part, second_part)
208
+ elsif separator == SLASH
209
+ SlashCommutator.new(first_part, second_part)
210
+ else
211
+ complain('middle of pure commutator') unless PURE_SEPARATORS.include?(separator)
212
+ end
213
+ end
200
214
 
201
215
  def parse_separator
202
216
  separator = @scanner.getch
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwistyPuzzles
4
- VERSION = '0.0.14'
4
+ VERSION = '0.0.15'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twisty_puzzles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernhard F. Brodowsky