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
Symbol version
Posted by: amenon | June 9, 2010 @ 6:53am
Ruby Code
[
Download
]
$primes = [] def read_primes_from_file file_loc primes_unparsed = File.new(file_loc, "r") primes_up_str = primes_unparsed.gets primes_as_strs = primes_up_str[1...-2].split(" ") $primes = primes_as_strs.collect { |prime| prime.to_sym } primes_as_strs = nil primes_up_str = nil primes_unparsed.close primes_unparsed = nil end def is_prime n return false if (0..1).include? n $primes.each { |prime| return false if n%prime == 0} true end def prime_check n $primes.include? n end def find_from_to first, last (first..last).each { |num| $primes << num if is_prime num } end def is_circular_prime n num_str = n.to_s str_len = num_str.length (0...str_len).each {|i| return false unless prime_check(num_str.to_sym) num_str = num_str[1..-1] + num_str[0...1] } true end p "Reading Primes From File" read_primes_from_file "primes.db" p "Read successfully. Last Prime: #{ $primes[0].to_s }" p "Checking for Circular Primes" $primes.reverse! count_of_circ_primes = $primes.inject(0) { |count, prime| if is_circular_prime(prime) print "." count += 1 else count end } p count_of_circ_primes
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.56 / 8
39 Votes
http://codebin.yi.org/681
page generated in 0.01 seconds