binary 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/binary.rb +30 -3
- data/lib/binary/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: ec27b3cd7dfa1d2bfcf834091ba8ccdc1122242f0599460903079baee8f40a36
|
4
|
+
data.tar.gz: 769b49ac606231ff06b07eb8e1e614d8188acdea81e0ffa0c08d80dce5492e14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bda31ed4f9c3e5f737bc44d4ae688c92fec03020c7bd03e08cff05bfca8401c9419ffe13ad4f3294178f4b6f95bf533fef882e3353bc54e66cef0975bccc105
|
7
|
+
data.tar.gz: 2775541257d014f3b0347dc14f9d093e1065679ad40661daa4aa923229124dedb7a3b40d74c7b505dd3176a6d70dd274d8525ecce35ae6df78f40da0d23cc0c1
|
data/lib/binary.rb
CHANGED
@@ -1,11 +1,38 @@
|
|
1
1
|
require "binary/version"
|
2
|
+
require "prime"
|
2
3
|
|
3
4
|
module Binary
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def self.binary(input=nil)
|
6
|
+
if input.class == Array
|
7
|
+
input.map { |num| num.class == Integer ? num.to_s(2) : nil }
|
7
8
|
elsif input.class == Integer
|
9
|
+
input = input.abs if input < 0
|
8
10
|
input.to_s(2)
|
11
|
+
else
|
12
|
+
nil
|
9
13
|
end
|
10
14
|
end
|
15
|
+
|
16
|
+
def self.bits num
|
17
|
+
binary = binary(num) if num
|
18
|
+
binary.length
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.zeros num
|
22
|
+
binary = binary(num) if num
|
23
|
+
binary.count("0")
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.ones num
|
27
|
+
binary = binary(num) if num
|
28
|
+
binary.count("1")
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.prime num
|
32
|
+
binaries = []
|
33
|
+
Prime.each(num) do |prime|
|
34
|
+
binaries << binary(prime)
|
35
|
+
end
|
36
|
+
binaries
|
37
|
+
end
|
11
38
|
end
|
data/lib/binary/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mo Almishkawi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|