You are here: Home Blog Comments 正規表現で素数探索

Personal tools

正規表現で素数探索

Posted by はてなるせだいあり at 2006-06-19 22:31
def sieve_regex(max) table = ' ' + (2..max).map{|i|i.to_s}.join(' ') (2..Math.sqrt(max)).each do |i| 1 while table.gsub!(/^((?:\d* ){#{i-1}}(?:(?:\d* ){#{i}})+)\d+/){$1} end table end perl -le ’$,=” ”; print grep {
Parent entry キミならどう書く 2.0 - ROUND 1 -