strobogrammatic 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/strobogrammatic.rb +22 -0
- metadata +62 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
module Strobogrammatic
|
2
|
+
@strobogrammatic_pairs = {
|
3
|
+
"0" => "0",
|
4
|
+
"1" => "1",
|
5
|
+
"6" => "9",
|
6
|
+
"8" => "8",
|
7
|
+
"9" => "6"
|
8
|
+
}
|
9
|
+
|
10
|
+
def self.strobogrammatic_pair?(a, b)
|
11
|
+
!a.nil? && !b.nil? && @strobogrammatic_pairs[a] == b
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Fixnum
|
16
|
+
def strobogrammatic?
|
17
|
+
midpoint = (to_s.length / 2.0).ceil
|
18
|
+
to_s[0...midpoint].split(//).each_with_index.map do |char, index|
|
19
|
+
Strobogrammatic::strobogrammatic_pair?(char, to_s.reverse[index,1])
|
20
|
+
end.all?
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strobogrammatic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Derek Passen
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2013-06-16 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A simple gem to determine if a number is strobogrammatic
|
22
|
+
email: dpassen1@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/strobogrammatic.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://rubygems.org/gems/strobogrammatic
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.6
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Strobogrammatic
|
61
|
+
test_files: []
|
62
|
+
|