The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
ruby
Posted by: cday | June 23, 2009 @ 8:43pm
Ruby Code
[
Download
]
#!/bin/env ruby require 'benchmark' def phantom_five numPrimes = 0; currentTest = 2; isPrime = 1; while numPrimes<10000 for test in 2...(currentTest-1) if (currentTest%test) == 0 isPrime = 0; break; end end if isPrime == 1 numPrimes = numPrimes + 1; # puts "PF: found prime " + numPrimes.to_s + ": " + currentTest.to_s; end isPrime = 1; currentTest = currentTest + 1; end puts "%d primes found" % [numPrimes] end def check_prime n i = 2 while i < (n -1) if n % i == 0 return false end i += 1 end true end def aighy number_of_primes = 0 n = 2 while number_of_primes < 10000 number_of_primes += 1 if check_prime(n) n += 1 end puts "%d primes found" % [ number_of_primes ] end Benchmark::bm(1) do |test| # test.report("phantom_five") do # phantom_five # end test.report("aighy") do aighy end end
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.38 / 8
145 Votes
http://codebin.yi.org/313
page generated in 0.01 seconds