Created
February 21, 2012 08:58
-
-
Save koko1000ban/1875292 to your computer and use it in GitHub Desktop.
nintendooooo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
A = [100, '*', 20, '+', 29, '+', 10, '*', 20, '+', 1, '*', 3, '+', 1, '+', 3, '*', 2] | |
ANS=7005 | |
N = A.size | |
def rep(i, j, a) | |
a.insert(i, '(') | |
a.insert(j+2, ')') | |
a[i..(j+2)]=eval(a[i..(j+2)].join('')) | |
if eval(a.join('')) == ANS | |
puts '答えはっけん' | |
return | |
else | |
n = a.size | |
(0..(n-1)).each do |ni| | |
next if ni % 2 != 0 | |
((ni+2)..n).each do |nj| | |
next if nj % 2 != 0 | |
return rep ni, nj, a.dup | |
end | |
end | |
end | |
end | |
(0..(N-1)).each do |n| | |
next if n % 2 != 0 | |
((n+2)..N).each do |m| | |
next if m % 2 != 0 | |
rep n, m, A.dup | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment