twisty_puzzles 0.0.27 → 0.0.31

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: 50d977c5e137d9396e79e1cf39f6143e99b457549c0cd518ada8b2c4a35c428c
4
- data.tar.gz: f092b98630606b231ecb60c6020cd6528225d9e5771229147973afe4b3312b43
3
+ metadata.gz: 4b1fabe0cc087fdf90da3e0288758f9573378371b0b3158d6a905e0830da21a1
4
+ data.tar.gz: 04f15c1397971f33565c89f852571110e13aeff1548d748874a0dc6ca364d64f
5
5
  SHA512:
6
- metadata.gz: 210297dea0bf79343a405e3d3a0f8a7c7f7bc0c680302ad25535aaefcbea3fd7e4c84e0ea6a9bc05c76e45e897d9f1a69c1199d2b4aae0e5e291c2d000e80fa2
7
- data.tar.gz: 104110df13cf554e59e9c32cad74452869a0aa628565898df000e416eaf4ebf38b02d2df39f58dc2a508148d1f42fdbd59e08d9ff37859bce7a589efd3389fb5
6
+ metadata.gz: b13427c376bc2c583e02860e5834140b9d648ee97f9983906732597ad9a5d57256364231a7c759b775478b7474cf21e1188045a4ecb564e942e0b4e991f7246e
7
+ data.tar.gz: 48a547963b89c1c6a56688fdab4c094aec6934954b8555c319ddfde7a1518b787cabd62cf4b39fee37c7de19366fabbcb6debfe6b8ef00c2ee578c48fd4aeb63
@@ -74,7 +74,7 @@ module TwistyPuzzles
74
74
 
75
75
  def self.exists_on_cube_size?(cube_size)
76
76
  cube_size >= min_cube_size && cube_size <= max_cube_size &&
77
- (cube_size % 2 == 0 ? self.exists_on_even_cube_sizes? : self.exists_on_odd_cube_sizes?)
77
+ (cube_size.even? ? exists_on_even_cube_sizes? : exists_on_odd_cube_sizes?)
78
78
  end
79
79
 
80
80
  def num_incarnations(_cube_size)
@@ -17,16 +17,19 @@ module TwistyPuzzles
17
17
 
18
18
  RAW_DATA_RESERVED = [' ', '(', ')'].freeze
19
19
 
20
- def initialize(parts)
20
+ def initialize(parts, twist = 0)
21
21
  raise ArgumentError if parts.empty?
22
+ raise TypeError unless twist.is_a?(Integer)
23
+ raise ArgumentError if twist.negative?
22
24
 
23
25
  check_types(parts, Part)
24
26
  check_type_consistency(parts)
25
27
 
26
28
  @parts = parts
29
+ @twist = twist
27
30
  end
28
31
 
29
- attr_reader :parts
32
+ attr_reader :parts, :twist
30
33
 
31
34
  def eql?(other)
32
35
  self.class.equal?(other.class) && @parts == other.parts
@@ -79,6 +82,21 @@ module TwistyPuzzles
79
82
  end.min
80
83
  end
81
84
 
85
+ # Note that this returns the same answer for all rotations of one part.
86
+ def contains?(part)
87
+ @parts.any? { |p| p.turned_equals?(part) }
88
+ end
89
+
90
+ # Returns an equivalent cycle that starts with the given part.
91
+ # Raises an error if the cycle doesn't contain the given part.
92
+ def start_with(part)
93
+ raise ArgumentError unless contains?(part)
94
+
95
+ index = @parts.find_index { |p| p.turned_equals?(part) }
96
+ map_rotate_by_number = @parts[index].rotations.index(part)
97
+ rotate_by(index).map_rotate_by(map_rotate_by_number)
98
+ end
99
+
82
100
  def equivalent?(other)
83
101
  self == other || canonicalize == other.canonicalize
84
102
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwistyPuzzles
4
- VERSION = '0.0.27'
4
+ VERSION = '0.0.31'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twisty_puzzles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 0.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernhard F. Brodowsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-20 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize