twisty_puzzles 0.0.22 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/twisty_puzzles/cube.rb +1 -1
- data/lib/twisty_puzzles/part_cycle.rb +33 -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: 38464f2fe484f8bf9336b02fd487750afd507060ad308f43fc7f6f77d4fdd009
|
4
|
+
data.tar.gz: 7934ea73bdbc8aa54bbc342693ab2118ca927f5ac5f4e4af2e63d0f1669c7eda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84c639c1b0d861543494f12256212a17d758e37fc2ef4099dd894a50d545c566d5c172ee839bcbb25ad1d5a76911003e93c4aaf7f1180ca4d61497ecd546c46e
|
7
|
+
data.tar.gz: 21eccbfb1040243dddaf036fa43d2b8ef54a020a23df3470dc7c18bc7ee44f404fe8df633293c80445d377db13e62d12b60305184a5b985b0e691b17d0f6da05
|
data/lib/twisty_puzzles/cube.rb
CHANGED
@@ -39,6 +39,10 @@ module TwistyPuzzles
|
|
39
39
|
@parts.first.class
|
40
40
|
end
|
41
41
|
|
42
|
+
def contains_any_part?(parts)
|
43
|
+
!(@parts & parts).empty?
|
44
|
+
end
|
45
|
+
|
42
46
|
def to_s
|
43
47
|
@parts.join(' ')
|
44
48
|
end
|
@@ -51,6 +55,35 @@ module TwistyPuzzles
|
|
51
55
|
@parts.length
|
52
56
|
end
|
53
57
|
|
58
|
+
def rotate_by(number)
|
59
|
+
self.class.new(@parts.rotate(number))
|
60
|
+
end
|
61
|
+
|
62
|
+
def map_rotate_by(number)
|
63
|
+
self.class.new(@parts.map { |p| p.rotate_by(number) })
|
64
|
+
end
|
65
|
+
|
66
|
+
def <=>(other)
|
67
|
+
@parts <=> other.parts
|
68
|
+
end
|
69
|
+
|
70
|
+
def canonicalize
|
71
|
+
@canonicalize ||=
|
72
|
+
@parts.map.with_index do |part, index|
|
73
|
+
min_part = part.rotations.min
|
74
|
+
map_rotate_by_number = part.rotations.index(min_part)
|
75
|
+
rotate_by(index).map_rotate_by(map_rotate_by_number)
|
76
|
+
end.min
|
77
|
+
end
|
78
|
+
|
79
|
+
def equivalent?(other)
|
80
|
+
self == other || canonicalize == other.canonicalize
|
81
|
+
end
|
82
|
+
|
83
|
+
def inverse
|
84
|
+
self.class.new([@parts[0]] + @parts[1..].reverse)
|
85
|
+
end
|
86
|
+
|
54
87
|
def self.from_raw_data(data)
|
55
88
|
raw_part_type, raw_parts = data.match(/(.*)\((.*)\)/).captures
|
56
89
|
part_type = PART_TYPES.find { |p| p.name == raw_part_type }
|