array-symmetries 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/array.rb +7 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49ea03047cf748c0cfad24e2d2c98bad6aeeac841b7ee7c10a5a3eba9bd858dc
4
- data.tar.gz: 76db02d721b3a571879bd29acc277e058da00c00c6c422aba056809fb6e3ee95
3
+ metadata.gz: a9842cec8943393c58825134c143058f6f4f8d464179f06db6f628b11a20a4c8
4
+ data.tar.gz: 5e8dae59ed50454965fc892b1d934684d04cdcb35a2ce743cb2727c6a3aa1ca0
5
5
  SHA512:
6
- metadata.gz: d08b9adeb7cb6f908641ee19c5b5226423efca083e2cfecbe5f2ac0820141af14cea2187753ac416499fa247cb7e03815f6b7305ab8631d055df2abf12f652d6
7
- data.tar.gz: 60cd51edae458292160236c50d6750c69932a84b2a2bb5f97fedbefd02b4e3c5214d325493fcc92435eb2897be2d2412a15ff0ca89ac7760b860ca83d53d95b8
6
+ metadata.gz: 40a35fca610a50f47c84e8ca41d15a8923eaaf56282fe9008d0fa057773271b5aa7266db5ebabdfd0fba9c1440ed96e69edc62b073ae3de3560701763a652683
7
+ data.tar.gz: 92ebf86744bae7ace0831f795526fec94fae4823d36596b3c309ebc20fd3e01566edcad8f52259cbba8f76c464dd6510c87e7c915c74e5ed950336c1c10046b2
data/lib/array.rb CHANGED
@@ -1,20 +1,26 @@
1
+ # see https://en.wikipedia.org/wiki/Examples_of_groups#The_symmetry_group_of_a_square:_dihedral_group_of_order_8
2
+
1
3
  class Array # yeah it's a monkey patch
4
+ # Returns `true` if the array is square, which is to say, the length of each
5
+ # row is equal to the number of rows. Otherwise returns `false`.
2
6
  def square?
3
7
  all? {|e| e.length == length}
4
8
  end
5
9
 
6
- # see https://en.wikipedia.org/wiki/Examples_of_groups#The_symmetry_group_of_a_square:_dihedral_group_of_order_8
7
10
 
11
+ # Returns the array obtained by flipping the square array vertically.
8
12
  def b
9
13
  raise ArgumentError unless square?
10
14
  reverse
11
15
  end
12
16
 
17
+ # Returns the array obtained by rotating the square 90° clockwise.
13
18
  def a
14
19
  raise ArgumentError unless square?
15
20
  b.transpose
16
21
  end
17
22
 
23
+ # Returns an array containing the eight symmetries of the square array.
18
24
  def symmetries
19
25
  raise ArgumentError unless square?
20
26
  [self, b, a, a.a, a.a.a, a.b, a.a.b, a.a.a.b]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: array-symmetries
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorraine Lee