Skip to content

Instantly share code, notes, and snippets.

@sdeming
Created January 26, 2012 03:48
Show Gist options
  • Save sdeming/1680865 to your computer and use it in GitHub Desktop.
Save sdeming/1680865 to your computer and use it in GitHub Desktop.
Use callcc for non-recursive factorials.
require 'continuation'
class FactorialsInCC
def fact(n)
factorial = 1
callcc { |fact_jmp| @fact_jmp = fact_jmp }
factorial *= n
n -= 1
@fact_jmp.call if n > 1
factorial
end
end
puts FactorialsInCC.new.fact(ARGV[0].to_i)
@sdeming
Copy link
Author

sdeming commented Jan 27, 2012

Did not! Er, where?

@jmazzi
Copy link

jmazzi commented Jan 27, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment