My python solution
Posted: Sat Jul 02, 2011 6:14 am
Code: Select all
pi = open('pi.txt', 'r').read().split('9')
y = map(lambda x: len(x), pi)
print(pi[y.index(max(y))])
Code: Select all
pi = open('pi.txt', 'r').read().split('9')
y = map(lambda x: len(x), pi)
print(pi[y.index(max(y))])
Code: Select all
#perl
open (HD, "<pi1000000.txt") || die "file not found";
$pi = <HD>;
close (HD);
@bla = split (/9/, $pi);
@foo = reverse sort {length $a <=> length $b} @bla;
print @foo[0];
Code: Select all
file = File.open("millionpi", "r")
line = file.gets
bigdist = 0
n = 0
a = (0 .. line.length - 1).find_all {|i| line[i,1] == '9'} ##gives the location of each 9 in line
for i in 1..a.length - 1 do
dist = a[i] - a[i-1]
if bigdist < dist
bigdist = dist
n = a[i-1]
end
end
puts line[n+1..n+bigdist-1]
$array = explode("9", $pi);
function sortByLength($a,$b){
return strlen($b)-strlen($a);
}
usort($array,'sortByLength');
echo $array[0];
Code: Select all
<?php
$tmp = "";
$long = "";
$file = file_get_contents('./pi.txt', true);
for($i = 0; $i <= 1000000; $i++){
$substr = substr($file, $i, 1);
if($substr == 9){
if(strlen($tmp) > strlen($long)){
$long = $tmp;
}
$tmp = "";
} else {
$tmp .= $substr;
}
}
echo $long;
?>
Code: Select all
public static void main(String[] args) {
String pi = "put pi here";
String[] splitpi = pi.split("9");
String longest = "";
for(String s : splitpi){
if (s.length() > longest.length()){
longest = s;
}
}
System.out.println(longest);
}
Code: Select all
#include <stdio.h>
int main ()
{
char string_longest[10000];
char string[10000];
int number;
int length = 0;
int longest_length = 0;
while ((number = getchar ()) != EOF)
{
if (number == '9')
{
if (length > longest_length)
{
int i;
for (i = 0; i < length; i ++)
string_longest[i] = string[i];
longest_length = length;
}
length = 0;
}
else
{
string[length] = number;
length ++;
}
}
string_longest[longest_length] = '\0';
printf ("%s\n", string_longest);
return 0;
}
Code: Select all
seq = []
tseq = []
# usual file blah omitted here
for c in pi:
if c != '9':
tseq.append(c) # yeah. += would have been smarter
else:
if len(tseq) > len(seq):
seq = tseq
tseq = []
print tseq
that's it.986065706615844070167350646845510834483041034071433068861350648161231335008442336241417442522038471620685815778003440744224089