From 6ca700a8ef242a48e8dbc0935e7ae5e322f01988 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Wed, 20 Jul 2022 15:57:39 +0000 Subject: [PATCH] #25 completed Co-authored-by: sigonasr2 --- archives/24/src/main.c | 7 +- archives/25/current | Bin 0 -> 17136 bytes archives/25/src/main.c | 44 +++++++++++++ archives/25/src/utils.c | 140 ++++++++++++++++++++++++++++++++++++++++ archives/25/src/utils.h | 14 ++++ current | Bin 21384 -> 17136 bytes src/main.c | 99 +++++++++------------------- 7 files changed, 232 insertions(+), 72 deletions(-) create mode 100755 archives/25/current create mode 100644 archives/25/src/main.c create mode 100644 archives/25/src/utils.c create mode 100644 archives/25/src/utils.h diff --git a/archives/24/src/main.c b/archives/24/src/main.c index d4ed085..d40758e 100644 --- a/archives/24/src/main.c +++ b/archives/24/src/main.c @@ -51,9 +51,6 @@ int factorial(int numb) { int main(int argc,char**argv) { - //For permutations, we know that there are a total of N! permutations. - // Which means each individual set starts at N!/N. So we can skip ahead some permutations. - // For 10 numbers, we get 362,880 values per permutation set. So 1000000/362880 = 2. So we'll start at permutation two. int setPermutationCount=factorial(10)/10; int permutationCount=(1000000/setPermutationCount)*setPermutationCount; int digits[10]={2,0,1,3,4,5,6,7,8,9}; @@ -61,11 +58,11 @@ int main(int argc,char**argv) { incrementDigit(digits); if (allUniqueDigits(digits)) { permutationCount++; - printf("%d:",permutationCount); + /*printf("%d:",permutationCount); for (int i=0;i<10;i++) { printf(" %d ",digits[i]); } - printf("\n"); + printf("\n");*/ } } diff --git a/archives/25/current b/archives/25/current new file mode 100755 index 0000000000000000000000000000000000000000..81b15c9dec524f760f34c96cc5a603136601a160 GIT binary patch literal 17136 zcmeHO4RBP~b-t^WK-gF-I}l@&hP7i_2u2n*5HP0J3O#trEH(xdyS2%(?5?D(^_SJI z11S)k^=9;DSzB#~iP~`*ITP2Ub!ytFJtU4`C5R*wYA=|$O5?OD#mUOVE?^wXiS6xo z?z?C8_Gx8jl1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2V#ssqqKlYbfZC`eD8B zl+T2b*w6LYi^-~aS_ifZkM8(_o$bD6e_OBx$9n4ThEy=z=8JWPf}%Cn z61BFJIzpW+Dy%>rI`X!+HPyApa6HHp$)86ml=Jy^bapB~fZqxjhM8Vb2u9nigbvow)SYKs;Mnj)e&j$2t}g1EYOZv z7$@h#K?Qkg>z79TO+t#}AEste72MT^Doh%Um?aN|BAwy(wgSe7vPh`KPYNp6frwVg zI94HB)zl7_GM%A-sEUSmf~A=O>2^61szS|bE;I*WjXBeXIVnsH&Z8=SYZ%5%b;Mg# zVM4ZIlJTtmttmaBU`eCpRHk|Axt1yK$5gSD+^FoQ#Z=2iT6E>twhGE zf1j$KDgAF`P5Jd-f%TwPeSR)y>b5E)Z`Z#U7(O*=XaD*6ohjGP`%Jt4e(2L4llA#I zpQ)RIi$p$Bmi2i*7zRd7W_{idFy(zLL}XItm=#|@j`oPG&-(_ZTo3!ta!mI^pZ1*0 z^ZtTqwW`VPKRb{@hGNS4ybocTR)So=z5QQP`n5`q_ti|hE&9|JyZ#fvC?;&5Zp|_& zYJUQ^_y6M%w(7f;9@7qGj)~2@c*>^F`y{3;Kb8I=n|`lSV7i?Z6=i!&ziZRy=Mtt1 zX#-(NtjEw%WUTGy{TWk!pTqL@`29fXbN>ssl2r85ie+Ng|7R3X{j7hp+mvM5VzT*P zyZ%p5V%6_)o1#qVInfJvCH-Iew5GK^SOGOf0S5{`|?X;0bdd_B?>orTwZ9p;okJG_#r0Z=8Hdg#M&BtEI literal 0 HcmV?d00001 diff --git a/archives/25/src/main.c b/archives/25/src/main.c new file mode 100644 index 0000000..70b53f1 --- /dev/null +++ b/archives/25/src/main.c @@ -0,0 +1,44 @@ +#include +#include "utils.h" +#include + +/* + The Fibonacci sequence is defined by the recurrence relation: + + Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. + Hence the first 12 terms will be: + + F1 = 1 + F2 = 1 + F3 = 2 + F4 = 3 + F5 = 5 + F6 = 8 + F7 = 13 + F8 = 21 + F9 = 34 + F10 = 55 + F11 = 89 + F12 = 144 + The 12th term, F12, is the first term to contain three digits. + + What is the index of the first term in the Fibonacci sequence to contain 1000 digits? + + https://projecteuler.net/problem=24 +*/ + +int main(int argc,char**argv) { + struct String numb1 = BigNumber(1); + struct String numb2 = BigNumber(1); + int term=3; + while (numb2.length<1000) { + struct String oldString = numb1; + numb1 = numb2; + numb2 = add(oldString,numb1); + //free(oldString.str); + //printf("%d: %s\n",term,numb2.str); + term++; + } + printf("\n\nTerm %d has %d digits!",term,numb2.length); + return 0; +} \ No newline at end of file diff --git a/archives/25/src/utils.c b/archives/25/src/utils.c new file mode 100644 index 0000000..715c599 --- /dev/null +++ b/archives/25/src/utils.c @@ -0,0 +1,140 @@ +#include "utils.h" +#include +#include + +struct String mult(struct String numb1, struct String numb2) { + struct String n1 = numb1; + struct String n2 = numb2; + byte carryover = 0; + if (numb2.length>numb1.length) { + n1=numb2; + n2=numb1; + } + int addends[n2.length][n1.length+1]; + for (int i=0;i=0;i--) { + carryover=0; + for (int j=n1.length-1;j>=0;j--) { + int mult = (n1.str[j]-'0')*(n2.str[i]-'0')+((carryover!=0)?carryover:0); + //printf(" %d/%d\n",mult,carryover); + carryover=0; + if (mult>=10) { + carryover=mult/10; + mult=mult%10; + } + addends[(n2.length-1)-i][j+1]=mult; + } + if (carryover>0) { + addends[(n2.length-1)-i][0]=carryover; + } + } + //printIntDoubleArr(n2.length,n1.length+1,addends); + struct String sum = {1,"0"}; + for (int i=0;i=numb2.length) { + for (int offset=0;offsetoffset) { + //printf("%c %c\n",numb1.str[numb1.length-offset-1],numb2.str[numb2.length-offset-1]); + int sum=((numb1.str[numb1.length-offset-1]-'0')+(numb2.str[numb2.length-offset-1]-'0'))+((carryover>0)?carryover--:0); + if (sum>=10) { + carryover=1; + sum-=10; + } + str[offset]=sum+'0'; + } else { + str[offset]=numb1.str[numb1.length-offset-1]+((carryover>0)?carryover--:0); + } + //str[offset+1]='\0'; + } + } else { + for (int offset=0;offsetoffset) { + //printf("%c %c\n",numb1.str[numb1.length-offset-1],numb2.str[numb2.length-offset-1]); + int sum=((numb1.str[numb1.length-offset-1]-'0')+(numb2.str[numb2.length-offset-1]-'0'))+((carryover>0)?carryover--:0); + if (sum>=10) { + carryover=1; + sum-=10; + } + str[offset]=sum+'0'; + } else { + str[offset]=numb2.str[numb2.length-offset-1]+((carryover>0)?carryover--:0); + } + //str[offset+1]='\0'; + } + } + if (carryover>0) { + str = realloc(str,++digitCount); + str[digitCount-1]='1'; + //str[digitCount]='\0'; + } + for (int i=0;it&kM!+WeQ)0vq6&Q!F7D z19)ZCqPe%&n;YJ*)|m+5_MdaILNC{RUj3~UDHJv!JuGB4nqZM;M=dI`x^hD9#il<* z_K|U>J{qL|6Qth?(ti)quN&ckW`03f47So5-4-o^r5igD5>KM*hzHeQQQ%rbuZpmA z+?mL^Lk}2%)268|% z2tA<|BlKz)y6pV!GaTP^0;@1F=usI(2;a@|z5I$^j<@w8KY%^?P1C#&dH)65W$~!o z;W)RgmvcM%kR0TA$2jUf)cvSq0!N?Qf#wx`?xsPsjPqk0-{UvnhRa0?R!G^JZI>C0 zv;2iQ_Z)XSd~Vxiz6Wc+g0)X$9pcZ&)+NciGO;*>HAi?o$rB7aF$S%v&#@cEU?8=K zEggfbGzU9p40fj#vVY$9o=Vd&?A1|k&-_q^{eA>~NdJh<8i58~r=bf^mYjOkJwa%; z`NR&2Y<;`F{8~J_{?vP5(Kj2Srrf%QXSkh}-Ci4petqMTsUuSIY;~*U=X63!)>iR1 zN*q=EXvvxqe$v6U=AB1+b#=}ouK91ZUpM4!%gA63<%hTylgP+5TN-xgGwbx*Y8yqU z+rD+XvoV9@lg#?M2$G2t??|euXd5E#1sS<32p=HU4GO|}L?_~Jh}RJJA)Xx)gb~Cy zvFil9T$>*Vf)(+XNkOPX-1A5fS`ZgJ7UG016!zf@zJ@r0m2Q3Qs>F<>AtY zbRmjMaN6&JVR2SXJ9a=nu%Z)5!0E*4L4G5mGSX0Z2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53f1 100644 --- a/src/main.c +++ b/src/main.c @@ -1,79 +1,44 @@ #include #include "utils.h" +#include /* - A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are: - - 012 021 102 120 201 210 - - What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? + The Fibonacci sequence is defined by the recurrence relation: + + Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. + Hence the first 12 terms will be: + + F1 = 1 + F2 = 1 + F3 = 2 + F4 = 3 + F5 = 5 + F6 = 8 + F7 = 13 + F8 = 21 + F9 = 34 + F10 = 55 + F11 = 89 + F12 = 144 + The 12th term, F12, is the first term to contain three digits. + + What is the index of the first term in the Fibonacci sequence to contain 1000 digits? https://projecteuler.net/problem=24 */ -void carryover(int*arr,int digit) { - arr[digit]=0; - if (arr[digit-1]==9) { - carryover(arr,digit-1); - } else { - arr[digit-1]++; - } -} - -void incrementDigit(int*arr) { - int val = arr[9]; - if (arr[9]==9) { - carryover(arr,9); - } else { - arr[9]++; - } -} - -boolean allUniqueDigits(int*arr) { - boolean digits[10] = {}; - for (int i=0;i<10;i++) { - if (!digits[arr[i]]) { - digits[arr[i]]=true; - } else { - return false; - } - } - return true; -} - -int factorial(int numb) { - int final=1; - for (int i=numb;i>=1;i--) { - final*=i; - } - return final; -} - int main(int argc,char**argv) { - - //For permutations, we know that there are a total of N! permutations. - // Which means each individual set starts at N!/N. So we can skip ahead some permutations. - // For 10 numbers, we get 362,880 values per permutation set. So 1000000/362880 = 2. So we'll start at permutation two. - int setPermutationCount=factorial(10)/10; - int permutationCount=(1000000/setPermutationCount)*setPermutationCount; - int digits[10]={2,0,1,3,4,5,6,7,8,9}; - while ((digits[0]!=9||digits[1]!=8||digits[2]!=7||digits[3]!=6||digits[4]!=5||digits[5]!=4||digits[6]!=3||digits[7]!=2||digits[8]!=1||digits[9]!=0)&&permutationCount!=999999) { - incrementDigit(digits); - if (allUniqueDigits(digits)) { - permutationCount++; - printf("%d:",permutationCount); - for (int i=0;i<10;i++) { - printf(" %d ",digits[i]); - } - printf("\n"); - } + struct String numb1 = BigNumber(1); + struct String numb2 = BigNumber(1); + int term=3; + while (numb2.length<1000) { + struct String oldString = numb1; + numb1 = numb2; + numb2 = add(oldString,numb1); + //free(oldString.str); + //printf("%d: %s\n",term,numb2.str); + term++; } - - printf("\n\nThe one millionth lexicographic permutation is: \n\t"); - for (int i=0;i<10;i++) { - printf("%d",digits[i]); - } - - + printf("\n\nTerm %d has %d digits!",term,numb2.length); return 0; } \ No newline at end of file