twisty_puzzles 0.0.27 → 0.0.28
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/part_cycle.rb +15 -0
- data/lib/twisty_puzzles/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7843aac67563062698ede8d6de86b76153901bcccee07d3367863ef9e81096d4
|
4
|
+
data.tar.gz: 4fe82e4186f3c832c502279748b27310658da80b057c9ff99ce22f5b04c46308
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1df3581ec635a06f6c0ef9221a518d5174fbfa4b30e7439f27e2c3ff1b185141d7dd5e86a979c9b66610af5b21d6564f61ae8b93909e43c7e2b79976f4c3333d
|
7
|
+
data.tar.gz: cc0899a42896b078a423fb511f61b63dc3f9a327824a0a68d9cfce17857cffaa7f5288a15629ab527e6c0ebb3257ce026c139028b008dec1699fcbdb61fa02ed
|
@@ -79,6 +79,21 @@ module TwistyPuzzles
|
|
79
79
|
end.min
|
80
80
|
end
|
81
81
|
|
82
|
+
# Note that this returns the same answer for all rotations of one part.
|
83
|
+
def contains?(part)
|
84
|
+
@parts.any? { |p| p.turned_equals?(part) }
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns an equivalent cycle that starts with the given part.
|
88
|
+
# Raises an error if the cycle doesn't contain the given part.
|
89
|
+
def start_with(part)
|
90
|
+
raise ArgumentError unless contains?(part)
|
91
|
+
|
92
|
+
index = @parts.find_index { |p| p.turned_equals?(part) }
|
93
|
+
map_rotate_by_number = @parts[index].rotations.index(part)
|
94
|
+
rotate_by(@parts.length - index).map_rotate_by(map_rotate_by_number)
|
95
|
+
end
|
96
|
+
|
82
97
|
def equivalent?(other)
|
83
98
|
self == other || canonicalize == other.canonicalize
|
84
99
|
end
|