balanced_ternary_integer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/balanced_ternary_integer.gemspec +35 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/balanced_ternary_integer.rb +27 -0
- data/lib/balanced_ternary_integer/version.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 89fc746a8c8f70b887b76558ccb40303dbf0726c806524b3419c52429f4a6f62
|
4
|
+
data.tar.gz: 2ba8bef0b752cac8e05c4ad4d644978feb98c6f0291ad2877cb0c735c8bbaa5a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 241674df581118d7ff24a4ac29bbb9a77ae5daa15c08c77e0203a104825bb07064b718345ceaf9e43702c741b498944a4cec0887d9733e2e2b7a93215ffbe775
|
7
|
+
data.tar.gz: d987b8e3c144ced047e21e768bede2dede04730e9f39243362c5f1a4391d1bfdb29670654ec2cad0873d7abb5d766ceaf04cbda6ff7b69bffb8ca4c7b190895a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Vasiliy Petrov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# BalancedTernaryInteger
|
2
|
+
|
3
|
+
Conversion integers from/to balanced ternary and decimal numeral system. For -1 symbol 'T' is used.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'balanced_ternary_integer'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install balanced_ternary_integer
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Conversion from decimal into ternary:
|
24
|
+
```ruby
|
25
|
+
BalancedTernaryInteger.from_int(11) # => '11T'
|
26
|
+
```
|
27
|
+
|
28
|
+
Conversion from ternary into decimal:
|
29
|
+
```ruby
|
30
|
+
BalancedTernaryInteger.to_int('TT') # => -4
|
31
|
+
```
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Saugardas/balanced_ternary_integer.
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "balanced_ternary_integer/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "balanced_ternary_integer"
|
8
|
+
spec.version = BalancedTernaryInteger::VERSION
|
9
|
+
spec.authors = ["Vasiliy Petrov"]
|
10
|
+
spec.email = ["saugardas@yandex.ru"]
|
11
|
+
|
12
|
+
spec.summary = %q{Conversion integers from/to balanced ternary and decimal numeral system.}
|
13
|
+
spec.description = %q{Conversion integers from/to balanced ternary and decimal numeral system.}
|
14
|
+
spec.homepage = "https://github.com/Saugardas/balanced_ternary_integer"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.metadata = {
|
18
|
+
'changelog_uri' => 'https://github.com/Saugardas/balanced_ternary_integer/blob/master/CHANGELOG.md'
|
19
|
+
}
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
31
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
|
34
|
+
spec.required_ruby_version = '>= 2.4.0'
|
35
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "balanced_ternary_integer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'balanced_ternary_integer/version'
|
2
|
+
|
3
|
+
module BalancedTernaryInteger
|
4
|
+
class << self
|
5
|
+
def from_int(number)
|
6
|
+
raise ArgumentError, "Integer expected, got #{number.class}" unless number.instance_of?(Integer)
|
7
|
+
|
8
|
+
digits = ''
|
9
|
+
begin
|
10
|
+
quotient, modulus = number.divmod(3)
|
11
|
+
digits.prepend(modulus == 2 ? 'T' : modulus.to_s)
|
12
|
+
number = modulus == 2 ? quotient + 1 : quotient
|
13
|
+
end until number.zero?
|
14
|
+
digits
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_int(string)
|
18
|
+
raise ArgumentError, "String expected, got #{string.class}" unless string.instance_of?(String)
|
19
|
+
raise ArgumentError, 'String must contain only 0, 1, T symbols' unless string.match?(/\A[01T]*\z/)
|
20
|
+
|
21
|
+
string.chars.reverse.map.with_index.sum do |char, index|
|
22
|
+
num = char == 'T' ? -1 : char.to_i
|
23
|
+
num * 3**index
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: balanced_ternary_integer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vasiliy Petrov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-20 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.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 12.3.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Conversion integers from/to balanced ternary and decimal numeral system.
|
56
|
+
email:
|
57
|
+
- saugardas@yandex.ru
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- CHANGELOG.md
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- balanced_ternary_integer.gemspec
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/balanced_ternary_integer.rb
|
73
|
+
- lib/balanced_ternary_integer/version.rb
|
74
|
+
homepage: https://github.com/Saugardas/balanced_ternary_integer
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata:
|
78
|
+
changelog_uri: https://github.com/Saugardas/balanced_ternary_integer/blob/master/CHANGELOG.md
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.4.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubygems_version: 3.0.3
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Conversion integers from/to balanced ternary and decimal numeral system.
|
98
|
+
test_files: []
|