Discussion of challenges you have already solved
karategeek6
Posts: 1 Joined: Sat Jun 18, 2011 6:50 am
Post
by karategeek6 » 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))])
Pi.txt is a text file containing pi to a million decimal places. Found the number at 3.141592653589793238462643383279502884197169399375105820974944592.com, copy pasted into a text file and used vim to clean it up.
PainKeeper
Posts: 4 Joined: Tue Jul 19, 2011 7:30 pm
Location: Germany
Post
by PainKeeper » Tue Jul 26, 2011 10:42 am
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];
Taurath
Posts: 5 Joined: Mon Feb 06, 2012 7:15 pm
Post
by Taurath » Tue Mar 20, 2012 2:22 am
Mine in Ruby:
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]
avrrobot
Posts: 51 Joined: Fri Mar 04, 2011 2:54 pm
Location: Germany
Post
by avrrobot » Mon May 28, 2012 10:01 am
[code]
int main()
{
uint64_t counts[10];
char a[200],s[200];
for(uint8_t o=0;o<200;o++)
{
a[o]=0;
s[o]= 0;
}
for(uint8_t i=0;i<10;i++)counts[i] = 0;
FILE *f;
f = fopen("pi_data.txt","r");
char c;
int anz = 0;
int nine_seq = 0,long_seq = 0;
do
{
c = fgetc(f);
if(c >= 48 && c <= 57)
{
counts[c-48]++;
if(c == 57)
{
if(nine_seq > long_seq)
{
long_seq = nine_seq;
for(uint8_t i=0;i<200;i++)s[i] = a[i];
}
for(uint8_t o=0;o<200;o++)
{
a[o]=0;
}
nine_seq = 0;
}
else
{
a[nine_seq] = c;
nine_seq++;
}
}
anz = 0;
for(uint8_t i=0;i<10;i++) anz += counts[i];
}while(c != EOF);
fclose(f);
FILE *sf;
sf = fopen("erg.txt","w");
for(uint8_t i=0;i<124;i++)
{
fputc(s[i],sf);
}
fclose(sf);
return 0;
}
[/code]
xenonr
Posts: 1 Joined: Wed May 11, 2011 9:59 am
Post
by xenonr » Tue Mar 19, 2013 2:15 pm
another PHP
$array = explode("9", $pi);
function sortByLength($a,$b){
return strlen($b)-strlen($a);
}
usort($array,'sortByLength');
echo $array[0];
net-fabrikken
Posts: 1 Joined: Thu Jan 30, 2014 9:44 pm
Post
by net-fabrikken » Tue Apr 08, 2014 1:42 pm
Yet another php code ^^
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;
?>
CptObvious
Posts: 3 Joined: Wed Apr 16, 2014 2:53 pm
Post
by CptObvious » Fri Apr 25, 2014 10:47 am
Another Java approach
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);
}
xiexun162534
Posts: 4 Joined: Fri Jul 26, 2013 1:26 pm
Contact:
Post
by xiexun162534 » Wed Jul 13, 2016 9:49 am
C
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;
}
I'm boring.
Mad Mike
Posts: 11 Joined: Tue Jun 21, 2011 4:38 pm
Post
by Mad Mike » Fri Dec 02, 2016 8:32 pm
Search & replace 9 to \n in Notepad++
Look for a line with over 100 characters
Adapt and search on.
Not very hack-y but my Python script sorta failed me. I have no idea how so few lines can fail so badly. For the record:
(stripped out all whitespaces from pi file after first failure)
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
chown -R us ./base
eulerscheZahl
Posts: 58 Joined: Thu Nov 29, 2012 7:45 pm
Location: Germany
Post
by eulerscheZahl » Sat Dec 03, 2016 6:46 am
@Mad Mike
did you want to print seq instead of tseq?
and tseq = [] sould not be inside if len(tseq) > len(seq), as it applies for all '9' characters.
th4wri
Posts: 8 Joined: Tue Mar 29, 2016 10:27 am
Location: TuNiSiA
Post
by th4wri » Tue Aug 14, 2018 12:10 pm
emm java code also
but i hav another method not mentionned here
we can use one of the regex tester tools to find the chain
https://www.freeformatter.com/regex-tester.html
regex : 9[^9]{120,}9
why 120 ?
i tested with 50,70,100,110,120 until the msg
Found 1 match. Match is highlighted below.
986065706615844070167350646845510834483041034071433068861350648161231335008442336241417442522038471620685815778003440744224089
that's it.