Created
February 10, 2015 17:56
-
-
Save mvw/8e935644a8dddcd0da1a to your computer and use it in GitHub Desktop.
This file contains 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
def is_guy(s) | |
if s == 'a' or s == 'b' or s == 'c' or s == 'd' | |
return true | |
end | |
return false | |
end | |
def two_guys(p) | |
9.times do |i| | |
if is_guy(p[i]) and is_guy(p[i+1]) | |
return true | |
end | |
end | |
return false | |
end | |
n = 0 | |
ne = 0 | |
n2 = 0 | |
a = [ 1, 2, 3, 4, 5, 6, 'a', 'b', 'c', 'd' ].permutation do |p| | |
if is_guy(p.first) or is_guy(p.last) | |
ne += 1 | |
next | |
end | |
if two_guys(p) | |
n2 += 1 | |
next | |
end | |
n += 1 | |
end | |
puts "n = #{n}" | |
puts "ne = #{ne}" | |
puts "n2 = #{n2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://math.stackexchange.com/questions/1142212/can-anyone-check-if-this-is-correct