Skip to content

Instantly share code, notes, and snippets.

@melborne
Created December 5, 2011 14:00
Show Gist options
  • Select an option

  • Save melborne/1433665 to your computer and use it in GitHub Desktop.

Select an option

Save melborne/1433665 to your computer and use it in GitHub Desktop.
Exclamation Factorial
require "mathn"
class Integer
def !
(1..self).inject(:*)
end
end
f1 = ->a,b,c{ a - b / c }
f2 = ->a,b,c{ (a - b) / c }
pp = ->abc{
print "(%i - %i) / %i = %i\n" % [*abc, f2[*abc]]
print " %i - %i / %i = %i! = %i\n\n" % [*abc, f2[*abc], f1[*abc]]
}
[*2..1000].repeated_permutation(3)
.select { |abc| f1[*abc] == f2[*abc].! }
.each { |abc| pp[abc] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment