Skip to content

Instantly share code, notes, and snippets.

@mvw
Created February 10, 2015 17:56
Show Gist options
  • Save mvw/8e935644a8dddcd0da1a to your computer and use it in GitHub Desktop.
Save mvw/8e935644a8dddcd0da1a to your computer and use it in GitHub Desktop.
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