Skip to content

Instantly share code, notes, and snippets.

@masassiez
Created February 16, 2012 20:09
Show Gist options
  • Save masassiez/1847481 to your computer and use it in GitHub Desktop.
Save masassiez/1847481 to your computer and use it in GitHub Desktop.
Rubequeローカル実行確認用テンプレート ref: http://qiita.com/items/2561
require "bundler/setup"
require "sicuro"
TIMELIMIT = 1
MEMLIMIT = 1
Sicuro.setup(TIMELIMIT, MEMLIMIT)
common = <<CODE
def assert_equal(x, y, message = nil)
if x != y
raise message ? message : "The value '\#{x}' does not equal '\#{y}'."
else
return true
end
end
CODE
puts Sicuro.eval(<<CODE)
#{common}
# === Code Area ===
def prime_factorization(num)
prime = Enumerator.new do |y|
mem = []
is_prime = lambda { |e| mem.find { |_| e.gcd(_) != 1 } }
2.upto(num) do |n|
unless is_prime[n]
mem << n
y << n
end
end
end
o = []
loop do
n = prime.next
if num % n == 0
num /= n
o << n
prime.rewind
end
end
o
end
p assert_equal prime_factorization(42), [2, 3, 7]
p assert_equal prime_factorization(44), [2, 2, 11]
p assert_equal prime_factorization(75), [3, 5, 5]
p assert_equal prime_factorization(123456), [2, 2, 2, 2, 2, 2, 3, 643]
# === Code Area ===
CODE
require "bundler/setup"
require "sicuro"
TIMELIMIT = 15
MEMLIMIT = 30
Sicuro.setup(TIMELIMIT, MEMLIMIT)
common = <<CODE
def assert_equal(x, y, message = nil)
if x != y
raise message ? message : "The value '\#{x}' does not equal '\#{y}'."
else
return true
end
end
CODE
puts Sicuro.eval(<<CODE)
#{common}
# === Code Area ===
# === Code Area ===
CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment