Skip to content

Instantly share code, notes, and snippets.

@cmuller
Created February 24, 2012 08:38
Show Gist options
  • Save cmuller/1899440 to your computer and use it in GitHub Desktop.
Save cmuller/1899440 to your computer and use it in GitHub Desktop.
Testing gist.. :-). this is an impl for a dev game from google (2004).. The site found does not exist anymore.. so we get a DNS error.
set s 7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648
set len [ string len $s ]
set last [ expr $len-10 ]
set prime_not_yet_found 1
proc primetest { n } {
set max [ expr wide(sqrt($n)) ]
if { $n%2==0 } {
return [ list 2 [ expr $n/2 ] ]
}
for { set i 3 } { $i<=$max } { incr i 2 } {
if { $n%$i==0 } {
return [ list $i [ expr $n/$i ] ]
}
}
return 1
}
for { set i 0 } { $i<=$last } { incr i } {
set number [ string range $s $i [ expr $i+9 ] ]
if $prime_not_yet_found {
if { [ string index $number 0 ] == 0 } {
set n [ string range $number 1 end ]
} else {
set n $number
}
if { [ primetest $n ] == 1 } {
set prime_not_yet_found 0
set first_prime $number
puts "---> FIRST PRIME FOUND : $number at indice $i ! <---"
}
}
set total 0
for { set digit 0 } { $digit<10 } { incr digit } {
set total [ expr $total + [ string index $number $digit ] ]
}
if { $total == 49 } {
puts "sum ($number) = 49 at indice $i"
}
}
puts "\n -> [ exec host $first_prime.com ] <-\n"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment