baseanything 0.0.1
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 +7 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +27 -0
- data/README.md +117 -0
- data/lib/baseanything.rb +1 -0
- metadata +77 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: fef9e148b30ccd4c765b8e305904f15893a05443
|
|
4
|
+
data.tar.gz: db5b829e7a0c6c404a60daf746a294c60a7ee4d7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e93f9910da66929ac06b8769fc85b7816d24e73a4771a64dc3fdf422f844f05dba470f003f0d0484dced2b33e6f77aa70350f68c2466aa29d72573d3aa329fe1
|
|
7
|
+
data.tar.gz: ffcde5e4ecadac217af354b607f17109bc7d15a31ff453435a7e2a06f205b0cac85fbab05b9d935c73bce59060c1e23f6cc5d6c4df973f58d694f35d3c642e2d
|
data/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.byebug_history
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: https://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
byebug (9.0.6)
|
|
5
|
+
diff-lcs (1.2.5)
|
|
6
|
+
rspec (3.1.0)
|
|
7
|
+
rspec-core (~> 3.1.0)
|
|
8
|
+
rspec-expectations (~> 3.1.0)
|
|
9
|
+
rspec-mocks (~> 3.1.0)
|
|
10
|
+
rspec-core (3.1.7)
|
|
11
|
+
rspec-support (~> 3.1.0)
|
|
12
|
+
rspec-expectations (3.1.2)
|
|
13
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
14
|
+
rspec-support (~> 3.1.0)
|
|
15
|
+
rspec-mocks (3.1.3)
|
|
16
|
+
rspec-support (~> 3.1.0)
|
|
17
|
+
rspec-support (3.1.2)
|
|
18
|
+
|
|
19
|
+
PLATFORMS
|
|
20
|
+
ruby
|
|
21
|
+
|
|
22
|
+
DEPENDENCIES
|
|
23
|
+
byebug
|
|
24
|
+
rspec (~> 3.1.0)
|
|
25
|
+
|
|
26
|
+
BUNDLED WITH
|
|
27
|
+
1.13.6
|
data/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#BaseAnything
|
|
2
|
+
|
|
3
|
+
BaseAnything is a Ruby Gem that allows you to create a number system of any base using any symbols you want.
|
|
4
|
+
|
|
5
|
+
##Usage
|
|
6
|
+
|
|
7
|
+
###Making your own number system
|
|
8
|
+
|
|
9
|
+
To make a number system of your choosing, first make an array of characters representing the symbols you would like to use in your number system. The index of each symbol will represent the symbol's decimal value.
|
|
10
|
+
|
|
11
|
+
Say you want to make a base5 system using characters as the symbols. You can create an array like:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
symbols = ['@', '#', '$', '%', '&']
|
|
15
|
+
```
|
|
16
|
+
And create the number system like so:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
NumberSystem.new(symbols)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
And each symbol will have the following decimal values:
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
decimal_correspondence = {
|
|
26
|
+
'@' => 0,
|
|
27
|
+
'#' => 1,
|
|
28
|
+
'$' => 2,
|
|
29
|
+
'%' => 3,
|
|
30
|
+
'&' => 4
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
So:
|
|
34
|
+
|
|
35
|
+
'#@' has the decimal value of 5.
|
|
36
|
+
'%$#' has the decimal value of 86.
|
|
37
|
+
'&&&#' has the decimal value of 621.
|
|
38
|
+
|
|
39
|
+
###Converting to other bases
|
|
40
|
+
|
|
41
|
+
You can take a number written in your base system and convert it to any base up to 35 with the to_base(num, base) method.
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
my_base_4 = NumberSystem.new(['@', '#', '$', '%', '&'])
|
|
45
|
+
my_num = '%#'
|
|
46
|
+
target_base = 4
|
|
47
|
+
|
|
48
|
+
my_base_4.to_base(my_num, target_base)
|
|
49
|
+
#returns '31'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Alternatively, you can use any of the following semantic methods:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
my_base_4.to_binary(num) #converts num to base2
|
|
56
|
+
my_base_4.to_ternary(num) #converts num to base3
|
|
57
|
+
my_base_4.to_quaternary(num) #converts num to base4
|
|
58
|
+
my_base_4.to_quinary(num) #converts num to base5
|
|
59
|
+
my_base_4.to_senary(num) #converts num to base6
|
|
60
|
+
my_base_4.to_heptary(num) #converts num to base7
|
|
61
|
+
my_base_4.to_octal(num) #converts num to base8
|
|
62
|
+
my_base_4.to_nonary(num) #converts num to base9
|
|
63
|
+
my_base_4.to_decimal(num) #converts num to base10
|
|
64
|
+
my_base_4.to_undecimal(num) #converts num to base11
|
|
65
|
+
my_base_4.to_duodecimal(num) #converts num to base12
|
|
66
|
+
my_base_4.to_tridecimal(num) #converts num to base13
|
|
67
|
+
|
|
68
|
+
my_base_4.to_tetradecimal(num) #converts num to base14
|
|
69
|
+
my_base_4.to_pentadecimal(num) #converts num to base15
|
|
70
|
+
my_base_4.to_hexadecimal(num) #converts num to base16
|
|
71
|
+
my_base_4.to_vigesimal(num) #converts num to base20
|
|
72
|
+
my_base_4.to_hexavigesimal(num) #converts num to base24
|
|
73
|
+
my_base_4.to_heptavigesimal(num) #converts num to base27
|
|
74
|
+
my_base_4.to_trigesimal(num) #converts num to base30
|
|
75
|
+
my_base_4.to_duotrigesimal(num) #converts num to base32
|
|
76
|
+
my_base_4.to_hexatrigesimal(num) #converts num to base36
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
###Converting from other bases
|
|
80
|
+
|
|
81
|
+
You can take a number written in any base system and convert it to your base system using the from_base(num, base) method.
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
my_base_4 = NumberSystem.new(['@', '#', '$', '%', '&'])
|
|
85
|
+
my_num = '100011'
|
|
86
|
+
base_of_my_num = 2
|
|
87
|
+
|
|
88
|
+
my_base_4.from_base(my_num, target_base)
|
|
89
|
+
#returns '$@%'
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Alternatively, you can use any of the following semantic methods:
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
my_base_4.to_binary(num) #converts num to base2
|
|
96
|
+
my_base_4.to_ternary(num) #converts num to base3
|
|
97
|
+
my_base_4.to_quaternary(num) #converts num to base4
|
|
98
|
+
my_base_4.to_quinary(num) #converts num to base5
|
|
99
|
+
my_base_4.to_senary(num) #converts num to base6
|
|
100
|
+
my_base_4.to_heptary(num) #converts num to base7
|
|
101
|
+
my_base_4.to_octal(num) #converts num to base8
|
|
102
|
+
my_base_4.to_nonary(num) #converts num to base9
|
|
103
|
+
my_base_4.to_decimal(num) #converts num to base10
|
|
104
|
+
my_base_4.to_undecimal(num) #converts num to base11
|
|
105
|
+
my_base_4.to_duodecimal(num) #converts num to base12
|
|
106
|
+
my_base_4.to_tridecimal(num) #converts num to base13
|
|
107
|
+
|
|
108
|
+
my_base_4.to_tetradecimal(num) #converts num to base14
|
|
109
|
+
my_base_4.to_pentadecimal(num) #converts num to base15
|
|
110
|
+
my_base_4.to_hexadecimal(num) #converts num to base16
|
|
111
|
+
my_base_4.to_vigesimal(num) #converts num to base20
|
|
112
|
+
my_base_4.to_hexavigesimal(num) #converts num to base24
|
|
113
|
+
my_base_4.to_heptavigesimal(num) #converts num to base27
|
|
114
|
+
my_base_4.to_trigesimal(num) #converts num to base30
|
|
115
|
+
my_base_4.to_duotrigesimal(num) #converts num to base32
|
|
116
|
+
my_base_4.to_hexatrigesimal(num) #converts num to base36
|
|
117
|
+
```
|
data/lib/baseanything.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'baseanything/base'
|
metadata
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: baseanything
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- DouglasTGordon
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-11-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.13'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.13'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
description: 'BaseAnything is a Ruby Gem that allows you to create a number system
|
|
42
|
+
of any base using any symbols you want. '
|
|
43
|
+
email:
|
|
44
|
+
- douglastgordon@gmail.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".gitignore"
|
|
50
|
+
- Gemfile
|
|
51
|
+
- Gemfile.lock
|
|
52
|
+
- README.md
|
|
53
|
+
- lib/baseanything.rb
|
|
54
|
+
homepage: https://github.com/douglastgordon/BaseAnything
|
|
55
|
+
licenses: []
|
|
56
|
+
metadata: {}
|
|
57
|
+
post_install_message:
|
|
58
|
+
rdoc_options: []
|
|
59
|
+
require_paths:
|
|
60
|
+
- lib
|
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
|
+
requirements:
|
|
63
|
+
- - ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '0'
|
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
71
|
+
requirements: []
|
|
72
|
+
rubyforge_project:
|
|
73
|
+
rubygems_version: 2.5.1
|
|
74
|
+
signing_key:
|
|
75
|
+
specification_version: 4
|
|
76
|
+
summary: Build your own number system.
|
|
77
|
+
test_files: []
|