Searching for Pi

This text file contains the first 10000 digits of pi. Let P equal the slice of pi represented by this file.

Let L be the longest string of consecutive identical digits in P . How many digits are in L ?

Details and assumptions

For example, in this slice of pi: "3.14159265358979323846264 33 832", the longest string of consecutive identical digits is "33", and there are 2 digits in that string.


The answer is 6.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

29 solutions

James Bishop
Jul 23, 2013

Well first you copy and paste the first 1000 digits of pi into a word document. Then you hit ctl+f and take turns entering the numbers 0-9. Now carefully scan your document and look for big blocks of highlited area. Just when you thought a 4 combo was as good as it was going to get, 9 brings this one home with a whopping six combo melee.

Well-written. I enjoyed this one very much.

Edwin Ma - 7 years, 10 months ago

i too did that..

Snehdeep Arora - 7 years, 10 months ago
Em Lazzarin
Jul 22, 2013

Here's my Python solution, where I use the groupby function from the itertools module. I put notes in ambiguous parts of the code for clarity.

from itertools import groupby

pi_text = ""
for line in open('cs_pi.txt'):
    # strip newlines and replace spaces
    pi_text += line.strip().replace(" ", "")

max_len, number = 0, 0

# groupby() groups consecutive matching elements
# of an iterable into a group `g`.
# `k` is one instance of the elements being grouped,
# for convenience.

# see this link for more details:
# http://docs.python.org/2/library/itertools.html#itertools.groupby
for k, g in groupby(pi_text):

    # here, we unpack the Python generator so we can
    # get its length.
    len_g = len([i for i in g])

    # if this group is longer than the previous max,
    # it becomes our new max.
    if len_g > max_len:
        max_len = len_g
        number = k

print number, max_len
Oliver Welsh
Jul 22, 2013

The longest string of consecutive digits is 999999, so the answer is 9.

Here is a solution in python:

pi = open("digitsofpi.txt", "r")
for str in pi:
    pi = str
def common_digit(digits):
    common_list = []
    temp_list = []
    for digit in digits:
        if len(temp_list) > len(common_list):
            common_list = temp_list
        if digit != " ":
            if digit in temp_list:
                temp_list.append(digit)
            else:
                temp_list = []
                temp_list.append(digit)
        else:
            temp_list = []
        return common_list
print common_digit(pi)

This prints ['9', '9', '9', '9', '9', '9'].

Typo: 'the answer is 6.'

Oliver Welsh - 7 years, 10 months ago

int main()

{

char tem[11], cad[10000];

int tam, i, con = 1, may = 0;

while(cin >> tem)

    strcat(cad, tem);

tam = strlen(cad);

for(i = 1; i < tam; i++)

{

    if(cad[i] == cad[i - 1]) con++;

    else

    {

        if(con > may) may = con;

        con = 1;

    }

}

cout << may;

return 0;

}

strPi = open("Pi1000.txt", 'r').read() strPi = strPi.replace(" ","") strPi = strPi.replace(".","") strPi = strPi.replace(chr(10),"") iLmax = 0 for j in range(10): strN= "" while strN in strPi: strN=strN +str(j) iLj = len(strN)-1 print str(j)+" occurs in a run of maximum length " + str(iLj) if iLj>iLmax: iLmax = iLj iJmax = j

print "The maximum length is "+str(iLmax)+" for the number "+str(iJmax)

Daniel Wang
Jul 26, 2013

CTRL-F :P

Otávio Sales
Jul 26, 2013

http://www.angio.net/pi/piquery.html

Calinescu Vally
Jul 26, 2013

Well,you have to remember the last digit and read the current one. If they match, your current sum increases by 1. If not, you have the start all over again with sum=1. You compare the sum with the maximum at every single stage to determine the final maximum.

int main() { while(ka>>x)

{

if(x==ante) // ante is the last one

s++;

else

s=1;

if(s>maxim)

maxim=s;

ante=x;

}

cout<<maxim;

}

I could not type the solution here because of problems in adding/removing indentation. Here is my solution.

Sanjay Meena
Jul 24, 2013

You can use the following python code to find the answer

See below:

strPi = open("Pi1000.txt", 'r').read()

strPi = strPi.replace(" ","")

strPi = strPi.replace(".","")

strPi = strPi.replace(chr(10),"")

iLmax = 0

for j in range(10):

strN= ""

while strN in strPi:

strN=strN +str(j)

iLj = len(strN)-1

print str(j)+" occurs in a run of maximum length " + str(iLj)

if iLj>iLmax:

iLmax = iLj

iJmax = j

print "The maximum length is "+str(iLmax)+" for the number "+str(iJmax)

I hope you understand the problem

Siddharth Kannan
Jul 23, 2013

The code is:

code

What I did was:

  1. First of all remove all the spaces that are present in the text file.
  2. Now check the most number of consecutive digits that are present in the file as per the function piTest()
Kevin Larsen
Jul 23, 2013

In C++:

ifstream file;
file.open("C:\\test\\cs_pi.txt");
char current = '0';
char last = '0';
int count = 1;
int max = 1;

if (file.is_open())
{
  while ( file.good() )
  {
    file >> current;
    if (current != ' ' && current != '.' 
            && current !='\n' && current != '\t'){
        if (current == last) count++;
        else count = 1;
        if (count > max) max = count;
        last = current;
  }
}
file.close();

cout << "P == " << max << endl;
}
Harsa Mitra
Jul 23, 2013

strPi = open("Pi1000.txt", 'r').read() strPi = strPi.replace(" ","") strPi = strPi.replace(".","") strPi = strPi.replace(chr(10),"") iLmax = 0 for j in range(10): strN= "" while strN in strPi: strN=strN +str(j) iLj = len(strN)-1 print str(j)+" occurs in a run of maximum length " + str(iLj) if iLj>iLmax: iLmax = iLj iJmax = j

print "The maximum length is "+str(iLmax)+" for the number "+str(iJmax)

Evan Chien
Jul 22, 2013

6 9's appear in a row in the file. (Also I already knew for a fact that the answer was 6).

Michael Tong
Jul 22, 2013

Use Ctrl+F to activate the search function. Checking strings of 0's, 1's, 2's, 3's, 4's, 5's, 6's, 7's, 8's, and 9's, we come to 999999 as the longest string of consecutive identical digits. There are 6 digits in this string.

lol

Evan Chien - 7 years, 10 months ago

a good way w/o using Programming :)

Đức Việt Lê - 7 years, 10 months ago
Scott S
Jul 22, 2013

Python 3 solution. Thought about using regex, but it was far easier just to loop through and keep track as you go.

def get_input():
    with open('1.txt') as data:
        return ''.join(data.read().strip().split())

def solve():
    pi = get_input()
    largest = ''
    tmp = ''
    for i, c in enumerate(pi[:-1], 1):
        tmp += c
        if c != pi[i]:
            if len(tmp) > len(largest):
                largest = tmp
            tmp = ''

    return largest, len(largest)

if __name__ == '__main__':
    print (solve())
Tanishq Aggarwal
Jul 22, 2013

My code basically iterates as follows: consider i, which begins as 0. Find all instances of i repeating k times, which begins as 1. If this number is not 0, increment k by 1. Otherwise, increment i by 1 and reset k to 1. Do this until i=10, at which point you must stop. The program returned the value of k at each check, and I searched for the largest k in the text file manually (which is simple with the find tool in most text editors).

Adrian Obleton
Jul 22, 2013
pi = "31415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164 0628620899 8628034825 3421170679 8214808651 3282306647 0938446095 5058223172 5359408128 4811174502 8410270193 8521105559 6446229489 5493038196 4428810975 6659334461 2847564823 3786783165 2712019091 4564856692 3460348610 4543266482 1339360726 0249141273 7245870066 0631558817 4881520920 9628292540 9171536436 7892590360 0113305305 4882046652 1384146951 9415116094 3305727036 5759591953 0921861173 8193261179 3105118548 0744623799 6274956735 1885752724 8912279381 8301194912 9833673362 4406566430 8602139494 6395224737 1907021798 6094370277 0539217176 2931767523 8467481846 7669405132 0005681271 4526356082 7785771342 7577896091 7363717872 1468440901 2249534301 4654958537 1050792279 6892589235 4201995611 2129021960 8640344181 5981362977 4771309960 5187072113 4999999837 2978049951 0597317328 1609631859 5024459455 3469083026 4252230825 3344685035 2619311881 7101000313 7838752886 5875332083 8142061717 7669147303 5982534904 2875546873 1159562863 8823537875 9375195778 1857780532 1712268066 1300192787 6611195909 2164201989 3809525720 1065485863 2788659361 5338182796 8230301952 0353018529 6899577362 2599413891 2497217752 8347913151 5574857242 4541506959 5082953311 6861727855 8890750983 8175463746 4939319255 0604009277 0167113900 9848824012 8583616035 6370766010 4710181942 9555961989 4676783744 9448255379 7747268471 0404753464 6208046684 2590694912 9331367702 8989152104 7521620569 6602405803 8150193511 2533824300 3558764024 7496473263 9141992726 0426992279 6782354781 6360093417 2164121992 4586315030 2861829745 5570674983 8505494588 5869269956 9092721079 7509302955 3211653449 8720275596 0236480665 4991198818 3479775356 6369807426 5425278625 5181841757 4672890977 7727938000 8164706001 6145249192 1732172147 7235014144 1973568548 1613611573 5255213347 5741849468 4385233239 0739414333 4547762416 8625189835 6948556209 9219222184 2725502542 5688767179 0494601653 4668049886 2723279178 6085784383 8279679766 8145410095 3883786360 9506800642 2512520511 7392984896 0841284886 2694560424 1965285022 2106611863 0674427862 2039194945 0471237137 8696095636 4371917287 4677646575 7396241389 0865832645 9958133904 7802759009 9465764078 9512694683 9835259570 9825822620 5224894077 2671947826 8482601476 9909026401 3639443745 5305068203 4962524517 4939965143 1429809190 6592509372 2169646151 5709858387 4105978859 5977297549 8930161753 9284681382 6868386894 2774155991 8559252459 5395943104 9972524680 8459872736 4469584865 3836736222 6260991246 0805124388 4390451244 1365497627 8079771569 1435997700 1296160894 4169486855 5848406353 4220722258 2848864815 8456028506 0168427394 5226746767 8895252138 5225499546 6672782398 6456596116 3548862305 7745649803 5593634568 1743241125 1507606947 9451096596 0940252288 7971089314 5669136867 2287489405 6010150330 8617928680 9208747609 1782493858 9009714909 6759852613 6554978189 3129784821 6829989487 2265880485 7564014270 4775551323 7964145152 3746234364 5428584447 9526586782 1051141354 7357395231 1342716610 2135969536 2314429524 8493718711 0145765403 5902799344 0374200731 0578539062 1983874478 0847848968 3321445713 8687519435 0643021845 3191048481 0053706146 8067491927 8191197939 9520614196 6342875444 0643745123 7181921799 9839101591 9561814675 1426912397 4894090718 6494231961\
5679452080 9514655022 5231603881 9301420937 6213785595 6638937787 0830390697 9207734672 2182562599 6615014215 0306803844 7734549202 6054146659 2520149744 2850732518 6660021324 3408819071 0486331734 6496514539 0579626856 1005508106 6587969981 6357473638 4052571459 1028970641 4011097120 6280439039 7595156771 5770042033 7869936007 2305587631 7635942187 3125147120 5329281918 2618612586 7321579198 4148488291 6447060957 5270695722 0917567116 7229109816 9091528017 3506712748 5832228718 3520935396 5725121083 5791513698 8209144421 0067510334 6711031412 6711136990 8658516398 3150197016 5151168517 1437657618 3515565088 4909989859 9823873455 2833163550 7647918535 8932261854 8963213293 3089857064 2046752590 7091548141 6549859461 6371802709 8199430992 4488957571 2828905923 2332609729 9712084433 5732654893 8239119325 9746366730 5836041428 1388303203 8249037589 8524374417 0291327656 1809377344 4030707469 2112019130 2033038019 7621101100 4492932151 6084244485 9637669838 9522868478 3123552658 2131449576 8572624334 4189303968 6426243410 7732269780 2807318915 4411010446 8232527162 0105265227 2111660396 6655730925 4711055785 3763466820 6531098965 2691862056 4769312570 5863566201 8558100729 3606598764 8611791045 3348850346 1136576867 5324944166 8039626579 7877185560 8455296541 2665408530 6143444318 5867697514 5661406800 7002378776 5913440171 2749470420 5622305389 9456131407 1127000407 8547332699 3908145466 4645880797 2708266830 6343285878 5698305235 8089330657 5740679545 7163775254 2021149557 6158140025 0126228594 1302164715 5097925923 0990796547 3761255176 5675135751 7829666454 7791745011 2996148903 0463994713 2962107340 4375189573 5961458901 9389713111 7904297828 5647503203 1986915140 2870808599 0480109412 1472213179 4764777262 2414254854 5403321571 8530614228 8137585043 0633217518 2979866223 7172159160 7716692547 4873898665 4949450114 6540628433 6639379003 9769265672 1463853067 3609657120 9180763832 7166416274 8888007869 2560290228 4721040317 2118608204 1900042296 6171196377 9213375751 1495950156 6049631862 9472654736 4252308177 0367515906 7350235072 8354056704 0386743513 6222247715 8915049530 9844489333 0963408780 7693259939 7805419341 4473774418 4263129860 8099888687 4132604721 5695162396 5864573021 6315981931 9516735381 2974167729 4786724229 2465436680 0980676928 2382806899 6400482435 4037014163 1496589794 0924323789 6907069779 4223625082 2168895738 3798623001 5937764716 5122893578 6015881617 5578297352 3344604281 5126272037 3431465319 7777416031 9906655418 7639792933 4419521541 3418994854 4473456738 3162499341 9131814809 2777710386 3877343177 2075456545 3220777092 1201905166 0962804909 2636019759 8828161332 3166636528 6193266863 3606273567 6303544776 2803504507 7723554710 5859548702 7908143562 4014517180 6246436267 9456127531 8134078330 3362542327 8394497538 2437205835 3114771199 2606381334 6776879695 9703098339 1307710987 0408591337 4641442822 7726346594 7047458784 7787201927 7152807317 6790770715 7213444730 6057007334 9243693113 8350493163 1284042512 1925651798 0694113528 0131470130 4781643788 5185290928 5452011658 3934196562 1349143415 9562586586 5570552690 4965209858 0338507224 2648293972 8584783163 0577775606 8887644624 8246857926 0395352773 4803048029 0058760758 2510474709 1643961362 6760449256 2742042083 2085661190 6254543372 1315359584 5068772460\
2901618766 7952406163 4252257719 5429162991 9306455377 9914037340 4328752628 8896399587 9475729174 6426357455 2540790914 5135711136 9410911939 3251910760 2082520261 8798531887 7058429725 9167781314 9699009019 2116971737 2784768472 6860849003 3770242429 1651300500 5168323364 3503895170 2989392233 4517220138 1280696501 1784408745 1960121228 5993716231 3017114448 4640903890 6449544400 6198690754 8516026327 5052983491 8740786680 8818338510 2283345085 0486082503 9302133219 7155184306 3545500766 8282949304 1377655279 3975175461 3953984683 3936383047 4611996653 8581538420 5685338621 8672523340 2830871123 2827892125 0771262946 3229563989 8989358211 6745627010 2183564622 0134967151 8819097303 8119800497 3407239610 3685406643 1939509790 1906996395 5245300545 0580685501 9567302292 1913933918 5680344903 9820595510 0226353536 1920419947 4553859381 0234395544 9597783779 0237421617 2711172364 3435439478 2218185286 2408514006 6604433258 8856986705 4315470696 5747458550 3323233421 0730154594 0516553790 6866273337 9958511562 5784322988 2737231989 8757141595 7811196358 3300594087 3068121602 8764962867 4460477464 9159950549 7374256269 0104903778 1986835938 1465741268 0492564879 8556145372 3478673303 9046883834 3634655379 4986419270 5638729317 4872332083 7601123029 9113679386 2708943879 9362016295 1541337142 4892830722 0126901475 4668476535 7616477379 4675200490 7571555278 1965362132 3926406160 1363581559 0742202020 3187277605 2772190055 6148425551 8792530343 5139844253 2234157623 3610642506 3904975008 6562710953 5919465897 5141310348 2276930624 7435363256 9160781547 8181152843 6679570611 0861533150 4452127473 9245449454 2368288606 1340841486 3776700961 2071512491 4043027253 8607648236 3414334623 5189757664 5216413767 9690314950 1910857598 4423919862 9164219399 4907236234 6468441173 9403265918 4044378051 3338945257 4239950829 6591228508 5558215725 0310712570 1266830240 2929525220 1187267675 6220415420 5161841634 8475651699 9811614101 0029960783 8690929160 3028840026 9104140792 8862150784 2451670908 7000699282 1206604183 7180653556 7252532567 5328612910 4248776182 5829765157 9598470356 2226293486 0034158722 9805349896 5022629174 8788202734 2092222453 3985626476 6914905562 8425039127 5771028402 7998066365 8254889264 8802545661 0172967026 6407655904 2909945681 5065265305 3718294127 0336931378 5178609040 7086671149 6558343434 7693385781 7113864558 7367812301 4587687126 6034891390 9562009939 3610310291 6161528813 8437909904 2317473363 9480457593 1493140529 7634757481 1935670911 0137751721 0080315590 2485309066 9203767192 2033229094 3346768514 2214477379 3937517034 4366199104 0337511173 5471918550 4644902636 5512816228 8244625759 1633303910 7225383742 1821408835 0865739177 1509682887 4782656995 9957449066 1758344137 5223970968 3408005355 9849175417 3818839994 4697486762 6551658276 5848358845 3142775687 9002909517 0283529716 3445621296 4043523117 6006651012 4120065975 5851276178 5838292041 9748442360 8007193045 7618932349 2292796501 9875187212 7267507981 2554709589 0455635792 1221033346 6974992356 3025494780 2490114195 2123828153 0911407907 3860251522 7429958180 7247162591 6685451333 1239480494 7079119153 2673430282 4418604142 6363954800 0448002670 4962482017 9289647669 7583183271 3142517029 6923488962 7668440323 2609275249 6035799646 9256504936 8183609003 2380929345\
9588970695 3653494060 3402166544 3755890045 6328822505 4525564056 4482465151 8754711962 1844396582 5337543885 6909411303 1509526179 3780029741 2076651479 3942590298 9695946995 5657612186 5619673378 6236256125 2163208628 6922210327 4889218654 3648022967 8070576561 5144632046 9279068212 0738837781 4233562823 6089632080 6822246801 2248261177 1858963814 0918390367 3672220888 3215137556 0037279839 4004152970 0287830766 7094447456 0134556417 2543709069 7939612257 1429894671 5435784687 8861444581 2314593571 9849225284 7160504922 1242470141 2147805734 5510500801 9086996033 0276347870 8108175450 1193071412 2339086639 3833952942 5786905076 4310063835 1983438934 1596131854 3475464955 6978103829 3097164651 4384070070 7360411237 3599843452 2516105070 2705623526 6012764848 3084076118 3013052793 2054274628 6540360367 4532865105 7065874882 2569815793 6789766974 2205750596 8344086973 5020141020 6723585020 0724522563 2651341055 9240190274 2162484391 4035998953 5394590944 0704691209 1409387001 2645600162 3742880210 9276457931 0657922955 2498872758 4610126483 6999892256 9596881592 0560010165 5256375678"
pi = pi.replace("\n", "")
pi = pi.replace(" ", "")
highestValue = 0
numCount = 1
def digitCount(str):
    global highestValue
    global numCount
    for i in range(0, len(str)+1):
        if str[i:(i+1)] == str[(i+1):(i+2)]:
            numCount += 1
        elif str[i:(i+1)] != str[(i+1):(i+2)]:
            if numCount > highestValue:
                highestValue = numCount
                numCount = 1
            else:
                numCount = 1
    return highestValue
print(digitCount(pi))

I originally tried to use recursion, but the string was to long and it returned a recursion depth error.

i think we should remove the spaces between digits to have a chain with 10000 characters.

Đức Việt Lê - 7 years, 10 months ago

Log in to reply

The spaces were removed in this line:

pi = pi.replace("\n", "")

pi = pi.replace(" ", "")

Sreejato Bhattacharya - 7 years, 10 months ago
Yun Kai Lim
Jul 22, 2013

Also do as what problem said, my C++ code. In int main()

freopen("cs_pi.txt", "r", stdin);
string pi;
int max_length = 1, length = 1;
char pre = '.';
while(cin >> pi){
    for(int i = 0; i < pi.size(); i++){
        if(pi[i] == pre){
            length++;
        }
        else{
            max_length = max(length, max_length);
            length = 1;
        }
        pre = pi[i];
    }
}
max_length = max(length, max_length);
cout << max_length << endl;

return 0;
David Nolasco
Jul 22, 2013

Here is the secret formula: 1. Open the text file in another tab

  1. Click the view raw button so you can view the whole text.

  2. Press CTRL + F and enter each digit from 0 - 9 one at a time.

  3. The last step is, look for the longest repeating digits which are marked yellow.

  4. In this case, there are 6 consecutive 9n's in a string, so the answer must be 6.

Robbert Westerink
Jul 22, 2013

It is possible to use a regular expression to find identical substrings, I used: (\d)\1{2,} to find identical substrings of at least 2 digits and then used a loop to look for the largest number.

Ayush Saini
Jul 22, 2013

copy all the digits to notepad and find for 11 ,22 ,33,44,55,66,77,88.....999999 !! u get 999999 and it has 6 digits !!

lol

Evan Chien - 7 years, 10 months ago
Vitaly Breyev
Jul 22, 2013

Take the file, parse it into a string with no spaces and newlines. Then iterate over the list while checking if the previous character is the same as the current one while keeping track of how many previous consecutive characters were also the same -- if this number is greater than the previous maximum, then take current value to be the new maximum.

You can see the code here .

Yihang Ho
Jul 22, 2013

Just use a text editor to look for contiguous strings of 1 , 2 , 3 , , 9 , 0 1, 2, 3, \dots, 9, 0 of increasing length until none is found.

Yeah this is what I did originally to find the answer. I later said "you know what, I'll write a program just for fun."

Tanishq Aggarwal - 7 years, 10 months ago
Mayank Kaushik
Jul 22, 2013

pi =[]

f =open("m.txt","r")

for i in f:

for j in i:
    if j!= ' ' and j!='.':
        pi.append(j)

maxlength , templength = 0, 0

j = pi[0]

for i in range(0,len(pi)):

if j == pi[i]:
    templength += 1
else:
    j = pi[i]
    if maxlength < templength:
        maxlength = templength
    templength = 1

print(maxlength)

One Up
Jul 21, 2013
#!/usr/bin/env python2
s = #blob
s = ''.join(s[2:].split())
last = 'x'
m = 0
cur = 1
for c in s:
    if c == l:
        cur += 1
    else:
        last = c
        m = max(m,cur)
        cur = 1
print m
pi = ''.join(open('pi.txt', 'r').read().split()).replace('.', '')
maxlength = 0

for i, val in enumerate(pi):
    iterator = 1
    try:
        while pi[i + iterator] == val:
            iterator += 1
            if iterator > maxlength:
                maxlength = iterator
            if iterator == 6:
                print(pi[i - 3: i + 9])
    except:
        print(i)

print(maxlength)

Basically, parse file into pi, rid it of the dot, whitespace and newlines.

Iterate over pi with enumerate() If the next digit is the same as the current digit, increment second iterator. If second next digit is also same as current digit, increment again (repeat to get the value). If false, the for loop will run over the remaining digits, until it finds the biggest sequential value.

Using mathematica, this code creates a list pied of the first 10,000 digits of pi (forget that provided file). It then works its way up through the elements of pied storing the sizes of consecutive identical digits to value , and then changing high if a larger value is found:

pied = IntegerDigits[IntegerPart[\[Pi] * 10^10000]];
high = 1;
Do[
    j = 1;
    value = 1;
    While[pied[[i + j]] == pied[[i]],
        value++;
        j++;
    ]
    If[value > high,
        high = value;
    ]
, {i, 1, 10000}]
high
Maedhros 777
Jul 21, 2013

In Python (with file named pi.txt)

pi = open('pi.txt').read().replace(' ', '')    # remove spaces
longest = 0
for i in range(len(pi)):
    consecutive = 0
    for j in range(i, len(pi)):
        if pi[j] != pi[i]:
            break
        consecutive += 1
    longest = max(longest, consecutive)
print longest

Sorry Maedhros, having trouble following the logic, there's actually a function to open up pi in python? and the loops are a little confusing...

David Kroell - 7 years, 10 months ago

Log in to reply

Oh sorry about that, "pi.txt" is the text file given in the problem which should be in the same directory as the Python program. longest is a variable which keeps track of the longest string of consecutive identical digits. The first loop iterates through each of the characters in the variable pi and for each one calculates the number of consecutive digits equal to the current character, starting with the current character. For example, in the string "aabbbcd" the variable consecutive would be 2 (aa) on first iteration of the main loop, 1 (a) on the second, 3 (bbb) on the third, etc. If this value is greater than longest then longest is updated.

Maedhros 777 - 7 years, 10 months ago

Will you Please tell me how you format the code in Latex ? means which syntax you used to put your code here in box

Mayank Kaushik - 7 years, 10 months ago

Log in to reply

You can post code by starting a new paragraph (press enter twice) and then indent all of the code by 4 spaces

Maedhros 777 - 7 years, 10 months ago

Log in to reply

Thanx

Mayank Kaushik - 7 years, 10 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...