make10 0.1.0
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 +15 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/lib/make10.rb +40 -0
- data/make10.gemspec +24 -0
- data/test/helper.rb +29 -0
- data/test/test_make10.rb +16 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjFhYmQ0NmRhNTNkZTAwYTk1MjExZWZiMTc3MGQwYTA1NGQyOGY2NQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTlkNjE4MmNlMjdiMjY4NGQ5NjQyNGUxZDU1ZmI4ODYyNDhkY2IwZg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTZlMTEzYzFhYzg3NjllYjJlNzUyZWQxZmJkNTdhMjcyYjQ0MzAzOWIyMGI3
|
10
|
+
NjE0OWMwYjg5NmViOTU5MDE2YTgxMzYxZDViNTJiYjdhNDkwOWY4NmNlOTRk
|
11
|
+
M2VlNmZjZTVjZmNiZmI0N2QwMDMwMzk2NmJiNzAyMjJiNTQzZDI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDFhYTc4YzUxZGEwMjA4N2ViMzU0MDY4N2MxODU5MmMxM2Y3ZjAwYmUwZGQ5
|
14
|
+
ODFhYzAxMzcwMDg2ZjMyYjExYzk5ZTQyYmViZWZhOGY3MjdmZjdiOWVmMzIz
|
15
|
+
ZGE5ZGRmZDBlNWIyNjM4YTQ2ZjQzNTQ0NDYxMTY2NzRkZDAzODY=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 karahiyo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Make10
|
2
|
+
|
3
|
+
Solve Make10 problem.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
You can solve "Make10" problem by the following way.
|
8
|
+
|
9
|
+
`1, 2, 3, 4` case,
|
10
|
+
|
11
|
+
```
|
12
|
+
irb(main):005:0> Make10.solve(1,2,3,4)
|
13
|
+
=> ["1+2+3+4", "(1+2)+(3+4)", "((1+2)+3)+4", "(1+(2+3))+4", "1+((2+3)+4)", "1+(2+(3+4))", "1*2*3+4", "((1*2)*3)+4", "(1*(2*3))+4", "1*((2*3)+4)", "1+2+4+3", "(1+2)+(4+3)", "((1+2)+4)+3", "(1+(2+4))+3", "1+((2+4)+3)", "1+(2+(4+3))", "1+3+2+4", "(1+3)+(2+4)", "((1+3)+2)+4", "(1+(3+2))+4", "1+((3+2)+4)", "1+(3+(2+4))", "(1+(3/2))*4", "1*3*2+4", "((1*3)*2)+4", "(1*(3*2))+4", "1*((3*2)+4)", "1+3+4+2", "(1+3)+(4+2)", "((1+3)+4)+2", "(1+(3+4))+2", "1+((3+4)+2)", "1+(3+(4+2))", "1*3*4-2", "((1*3)*4)-2", "(1*(3*4))-2", "1*((3*4)-2)", "1+4+2+3", "(1+4)+(2+3)", "((1+4)+2)+3", "(1+(4+2))+3", "1+((4+2)+3)", "1+(4+(2+3))", "1*4+2*3", "(1*4)+(2*3)", "1*(4+(2*3))", "1+4+3+2", "(1+4)+(3+2)", "((1+4)+3)+2", "(1+(4+3))+2", "1+((4+3)+2)", "1+(4+(3+2))", "1*4+3*2", "(1*4)+(3*2)", "1*(4+(3*2))", "1*4*3-2", "((1*4)*3)-2", "(1*(4*3))-2", "1*((4*3)-2)", "2+1+3+4", "(2+1)+(3+4)", "((2+1)+3)+4", "(2+(1+3))+4", "2+((1+3)+4)", "2+(1+(3+4))", "2-((1-3)*4)", "2*1*3+4", "((2*1)*3)+4", "(2*(1*3))+4", "2/1*3+4", "((2/1)*3)+4", "(2/(1/3))+4", "2+1+4+3", "(2+1)+(4+3)", "((2+1)+4)+3", "(2+(1+4))+3", "2+((1+4)+3)", "2+(1+(4+3))", "2+3+1+4", "(2+3)+(1+4)", "((2+3)+1)+4", "(2+(3+1))+4", "2+((3+1)+4)", "2+(3+(1+4))", "2+((3-1)*4)", "2*3+1*4", "(2*3)+(1*4)", "2*3*1+4", "((2*3)*1)+4", "(2*(3*1))+4", "2*3/1+4", "((2*3)/1)+4", "(2*(3/1))+4", "2+3+4+1", "(2+3)+(4+1)", "((2+3)+4)+1", "(2+(3+4))+1", "2+((3+4)+1)", "2+(3+(4+1))", "2*3+4*1", "(2*3)+(4*1)", "((2*3)+4)*1", "2*3+4/1", "(2*3)+(4/1)", "((2*3)+4)/1", "2+4+1+3", "(2+4)+(1+3)", "((2+4)+1)+3", "(2+(4+1))+3", "2+((4+1)+3)", "2+(4+(1+3))", "2-(4*(1-3))", "2*4-1+3", "((2*4)-1)+3", "(2*4)-(1-3)", "2+4+3+1", "(2+4)+(3+1)", "((2+4)+3)+1", "(2+(4+3))+1", "2+((4+3)+1)", "2+(4+(3+1))", "2+(4*(3-1))", "2*4+3-1", "(2*4)+(3-1)", "((2*4)+3)-1", "3+1+2+4", "(3+1)+(2+4)", "((3+1)+2)+4", "(3+(1+2))+4", "3+((1+2)+4)", "3+(1+(2+4))", "3-1+2*4", "(3-1)+(2*4)", "3-(1-(2*4))", "(3-(1/2))*4", "3*1*2+4", "((3*1)*2)+4", "(3*(1*2))+4", "3/1*2+4", "((3/1)*2)+4", "(3/(1/2))+4", "3+1+4+2", "(3+1)+(4+2)", "((3+1)+4)+2", "(3+(1+4))+2", "3+((1+4)+2)", "3+(1+(4+2))", "3-1+4*2", "(3-1)+(4*2)", "3-(1-(4*2))", "((3-1)*4)+2", "3*1*4-2", "((3*1)*4)-2", "(3*(1*4))-2", "3/1*4-2", "((3/1)*4)-2", "(3/(1/4))-2", "3+2+1+4", "(3+2)+(1+4)", "((3+2)+1)+4", "(3+(2+1))+4", "3+((2+1)+4)", "3+(2+(1+4))", "3*2+1*4", "(3*2)+(1*4)", "3*2*1+4", "((3*2)*1)+4", "(3*(2*1))+4", "3*2/1+4", "((3*2)/1)+4", "(3*(2/1))+4", "((3/2)+1)*4", "3+2+4+1", "(3+2)+(4+1)", "((3+2)+4)+1", "(3+(2+4))+1", "3+((2+4)+1)", "3+(2+(4+1))", "3+2*4-1", "(3+(2*4))-1", "3+((2*4)-1)", "3*2+4*1", "(3*2)+(4*1)", "((3*2)+4)*1", "3*2+4/1", "(3*2)+(4/1)", "((3*2)+4)/1", "3+4+1+2", "(3+4)+(1+2)", "((3+4)+1)+2", "(3+(4+1))+2", "3+((4+1)+2)", "3+(4+(1+2))", "3*4-1*2", "(3*4)-(1*2)", "3*4*1-2", "((3*4)*1)-2", "(3*(4*1))-2", "3*4/1-2", "((3*4)/1)-2", "(3*(4/1))-2", "3+4+2+1", "(3+4)+(2+1)", "((3+4)+2)+1", "(3+(4+2))+1", "3+((4+2)+1)", "3+(4+(2+1))", "3+4*2-1", "(3+(4*2))-1", "3+((4*2)-1)", "3*4-2*1", "(3*4)-(2*1)", "((3*4)-2)*1", "3*4-2/1", "(3*4)-(2/1)", "((3*4)-2)/1", "4+1+2+3", "(4+1)+(2+3)", "((4+1)+2)+3", "(4+(1+2))+3", "4+((1+2)+3)", "4+(1+(2+3))", "4+1*2*3", "4+((1*2)*3)", "4+(1*(2*3))", "4*1+2*3", "(4*1)+(2*3)", "4/1+2*3", "(4/1)+(2*3)", "4+1+3+2", "(4+1)+(3+2)", "((4+1)+3)+2", "(4+(1+3))+2", "4+((1+3)+2)", "4+(1+(3+2))", "4+1*3*2", "4+((1*3)*2)", "4+(1*(3*2))", "4*1+3*2", "(4*1)+(3*2)", "4*(1+(3/2))", "4*1*3-2", "((4*1)*3)-2", "(4*(1*3))-2", "4/1+3*2", "(4/1)+(3*2)", "4/1*3-2", "((4/1)*3)-2", "(4/(1/3))-2", "4+2+1+3", "(4+2)+(1+3)", "((4+2)+1)+3", "(4+(2+1))+3", "4+((2+1)+3)", "4+(2+(1+3))", "4+2*1*3", "4+((2*1)*3)", "4+(2*(1*3))", "4+2/1*3", "4+((2/1)*3)", "4+(2/(1/3))", "4*2-1+3", "((4*2)-1)+3", "(4*2)-(1-3)", "4+2+3+1", "(4+2)+(3+1)", "((4+2)+3)+1", "(4+(2+3))+1", "4+((2+3)+1)", "4+(2+(3+1))", "4+2*3*1", "(4+(2*3))*1", "4+((2*3)*1)", "4+(2*(3*1))", "4+2*3/1", "(4+(2*3))/1", "4+((2*3)/1)", "4+(2*(3/1))", "4*2+3-1", "(4*2)+(3-1)", "((4*2)+3)-1", "4+3+1+2", "(4+3)+(1+2)", "((4+3)+1)+2", "(4+(3+1))+2", "4+((3+1)+2)", "4+(3+(1+2))", "4+3*1*2", "4+((3*1)*2)", "4+(3*(1*2))", "4+3/1*2", "4+((3/1)*2)", "4+(3/(1/2))", "(4*(3-1))+2", "4*3-1*2", "(4*3)-(1*2)", "4*(3-(1/2))", "4*3*1-2", "((4*3)*1)-2", "(4*(3*1))-2", "4*3/1-2", "((4*3)/1)-2", "(4*(3/1))-2", "4+3+2+1", "(4+3)+(2+1)", "((4+3)+2)+1", "(4+(3+2))+1", "4+((3+2)+1)", "4+(3+(2+1))", "4+3*2*1", "(4+(3*2))*1", "4+((3*2)*1)", "4+(3*(2*1))", "4+3*2/1", "(4+(3*2))/1", "4+((3*2)/1)", "4+(3*(2/1))", "4*3-2*1", "(4*3)-(2*1)", "((4*3)-2)*1", "4*3-2/1", "(4*3)-(2/1)", "((4*3)-2)/1", "4*((3/2)+1)"]
|
14
|
+
irb(main):007:0> Make10.solve(1,2,3,4).size
|
15
|
+
=> 324
|
16
|
+
```
|
17
|
+
Uh, actually they are all?w
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
gem 'make10'
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install make10
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
TODO: Write usage instructions here
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/make10.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Make10
|
2
|
+
|
3
|
+
@ans_format = "%f%c%f%c%f%c%f"
|
4
|
+
@ops = ["+", "-", "*", "/"]
|
5
|
+
@parentheses_patterns = ["%f%c%f%c%f%c%f",
|
6
|
+
"(%f%c%f)%c(%f%c%f)",
|
7
|
+
"((%f%c%f)%c%f)%c%f",
|
8
|
+
"(%f%c(%f%c%f))%c%f",
|
9
|
+
"%f%c((%f%c%f)%c%f)",
|
10
|
+
"%f%c(%f%c(%f%c%f))", ]
|
11
|
+
|
12
|
+
def solve(*inputs)
|
13
|
+
nums_list = make_all_pattern(inputs)
|
14
|
+
ans = []
|
15
|
+
nums_list.each do |nums|
|
16
|
+
@ops.each do |o1|
|
17
|
+
@ops.each do |o2|
|
18
|
+
@ops.each do |o3|
|
19
|
+
@parentheses_patterns.each do |pattern|
|
20
|
+
exp = sprintf(pattern, nums[0] , o1, nums[1], o2, nums[2], o3, nums[3])
|
21
|
+
ans << exp.gsub(/0|\./, "") if eval(exp) == 10.0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
return ans.uniq
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def make_all_pattern(nums)
|
33
|
+
nums_list = []
|
34
|
+
nums.permutation.each {|d| nums_list << d}
|
35
|
+
nums_list
|
36
|
+
end
|
37
|
+
|
38
|
+
module_function :solve, :make_all_pattern
|
39
|
+
|
40
|
+
end
|
data/make10.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "make10"
|
7
|
+
spec.version = "0.1.0"
|
8
|
+
spec.authors = ["karahiyo"]
|
9
|
+
spec.email = ["a.ryuklnm@gmail.com"]
|
10
|
+
spec.description = %q{Solve Make10 problem.}
|
11
|
+
spec.summary = %q{Solve Make10 problem.}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.rubyforge_project = "Make10"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'test/unit'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../lib', ))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
unless ENV.has_key? 'VERBOSE'
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|logj|
|
18
|
+
def method_missing(methos, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'make10'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
|
29
|
+
end
|
data/test/test_make10.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Make10Test < Test::Unit::TestCase
|
4
|
+
def test_solve
|
5
|
+
ret = Make10.solve(1, 2, 3, 4)
|
6
|
+
# solve problem without sorting and parentheses
|
7
|
+
assert_equal(true, ret.include?(sprintf("%d+%d+%d+%d", 1, 2, 3, 4)));
|
8
|
+
assert_equal(true, ret.include?(sprintf("%d*%d*%d+%d", 1, 2, 3, 4)));
|
9
|
+
# solve problem with sort, but without parentheses
|
10
|
+
ret = Make10.solve(1, 1, 5, 7)
|
11
|
+
assert_equal(true, ret.include?(sprintf("%d-%d-%d+%d", 5, 1, 1, 7)));
|
12
|
+
# solve problem with sort and parentheses
|
13
|
+
ret = Make10.solve(1, 1, 5, 8)
|
14
|
+
assert_equal(true, ret.size == 1);
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: make10
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- karahiyo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-28 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Solve Make10 problem.
|
42
|
+
email:
|
43
|
+
- a.ryuklnm@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/make10.rb
|
54
|
+
- make10.gemspec
|
55
|
+
- test/helper.rb
|
56
|
+
- test/test_make10.rb
|
57
|
+
homepage: ''
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project: Make10
|
77
|
+
rubygems_version: 2.1.9
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Solve Make10 problem.
|
81
|
+
test_files:
|
82
|
+
- test/helper.rb
|
83
|
+
- test/test_make10.rb
|