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 +4 -4
- data/lib/twisty_puzzles/cube.rb +1 -1
- data/lib/twisty_puzzles/part_cycle.rb +20 -2
- data/lib/twisty_puzzles/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b1fabe0cc087fdf90da3e0288758f9573378371b0b3158d6a905e0830da21a1
|
4
|
+
data.tar.gz: 04f15c1397971f33565c89f852571110e13aeff1548d748874a0dc6ca364d64f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b13427c376bc2c583e02860e5834140b9d648ee97f9983906732597ad9a5d57256364231a7c759b775478b7474cf21e1188045a4ecb564e942e0b4e991f7246e
|
7
|
+
data.tar.gz: 48a547963b89c1c6a56688fdab4c094aec6934954b8555c319ddfde7a1518b787cabd62cf4b39fee37c7de19366fabbcb6debfe6b8ef00c2ee578c48fd4aeb63
|
data/lib/twisty_puzzles/cube.rb
CHANGED
@@ -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
|
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
|
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.
|
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-
|
11
|
+
date: 2021-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|