From 0d8758e1db95bfc2ca2b2e053568d69f946129cd Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Tue, 19 Jul 2022 13:38:45 +0000 Subject: [PATCH] #21 complete! Co-authored-by: sigonasr2 --- archives/21/current | Bin 0 -> 16976 bytes archives/21/src/main.c | 50 ++++++++++++++++++ archives/21/src/utils.c | 72 ++++++++++++++++++++++++++ archives/21/src/utils.h | 11 ++++ current | Bin 17016 -> 16976 bytes src/main.c | 109 +++++++++++++--------------------------- 6 files changed, 168 insertions(+), 74 deletions(-) create mode 100755 archives/21/current create mode 100644 archives/21/src/main.c create mode 100644 archives/21/src/utils.c create mode 100644 archives/21/src/utils.h diff --git a/archives/21/current b/archives/21/current new file mode 100755 index 0000000000000000000000000000000000000000..c9ba7d89fbcbb566943d2552e21bfce9040749ca GIT binary patch literal 16976 zcmeHOdvH|M89$rl5fC>)K@lI>T2U-!2^NvZM6)3mZk(u860udhEZK!*n(U^#cPl8d z$g0D2iPEVv;?!x=Kdf}xncC4hI2GLh66&BXt>e(qj%cw>l-fu`jnD1xJNJB>yEhwk zs(B9ug(J@zQQ`2#Kjs?I690#8727 zeSR`Ag<#73e0_e&7Q#(c`vg-*edJ1SwXN4%TS&W<{3e$k6-n=LrT4hfV>(0*Au;86 zQcUQ#SjE##{oqmZ%YPxSenb3?yQK%Vovn z7u7*yYUOn;)cqO4R2XGn%ur?GpL%lI$7{}e`HrjJeD;nHA56^~dZuh1+n_p0h7#%X zkf1WL>LAs8VNHLH;v9vdsM7!YOG&wTpqYQaD^}$o3Ay(k$7Zdd%}#wo3CBo5sOBe zL+d+8b7N;Lsx%E-w5T9lrCuv5`1ha(JwSO}CTF*!Tg${Xs$sl7@VxAuZZmeP`Oo+| zg_qaae8#za^lBTYu|i&OI_AK6P7!awfy?z#DGWJqu7g-34xGj%r#%X%Wt7^N~19#5rtOHj|GMg&VQUpp7C`F(Yfl>rY5hz8V6oIcH0{^bK;3GYCqFhf;{L6eH z^m{U9SuU%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Z{_YRA@G>!- z#vZH94PJuDwC8M_o}@%pQheGQQu?V)1bu%>X_igIOhuU}HPNfS`=b|$l-9}r(S0F*3#ghUbX76q+m&PN zcSh;sF~3Y){{^bda(JI3+lP2c2=8KLxlP%_`!D88O>7Hgxmoe?nn0Gh9m@RIM)`T__)e}DPf@lPm7ghiT`815E5Du;;%AFu}1%EZb{RN0! z*dg(;u(yiQgCB<3X|&SOj|7f=gk#3Wj@bH8hY>bo@q`gd zZW67r&aRG#83_j#*DP94T!;>xv>Ty#Jha(}M9uhSu^}Gnj2Pi$XXj?9I7$X2%>q$6 zngW-SW_w2h)G$`u5WH41wCfrSoINR&4-2E=yVnJ;ZCqZ+k%wFW;cSti>B@rMaDy;b zHeFvIY%;E2v0}B>Y%~Y!n>4a2kH)knlG1ZNS5sH_WlzY2!tf*#4w)f!2FIo9K6>M3 zlcs&X2EG&?wlTtqn9&xBhUp+qY?yBOM`9P`R!SQv_rj1IPw8#!#e8BGM`XW@HnJG^`;VlN}w1 zw5fsI7KSx0**5GEZEJ8IRfX`T3C__t2_W7gfZ5cE8NyTYt5CWFz|w zxBeR7c*PcD|M~uyDc8^YHn;yF=+mB!_4z)U>5!_Ie55$DKJTyEfl-rLpYOMs^1cuv zGLa2u`T+{G=VE=nFK0^c^C+?ZEXVXt@MsUmWxjuB>L+C+xBoUOL=Q3)Q`YDEe5M&C z$o0G1|B%wJS8}{hWxCFxPcd`r{{k4rgze*!XeUM8cew8Uf5fHlS9(lWDRWF*=EY+! zecp#KW%=>+A9v|*RSHb&SW!{7$Mk8Jenv5vp2`QtHo$spmOk2b#*gEq@Khdw_S+FcD0iRJ9lXqoX(!JsbU`gy;{=h=sp|1|$7u^#v1 zuYr*W>+`;_SKU~y1J9XQpXnqhJM~4KlCH5S*TXhgkIU1bOc>YC_m`DQ-z`sdIn#7i zzY@>0Sbts~u`{giq&#+ +#include "utils.h" + +/* + Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). + If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers. + + For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. + + Evaluate the sum of all the amicable numbers under 10000. + + https://projecteuler.net/problem=21 +*/ + +int main(int argc,char**argv) { + int counter=1; + long totalSum=0; + while (counter<10000) { + //printf("Factor sum of %d: 1,",counter); + int factorSum=1; + int max=counter/2; + for (int i=2;i +#include + +struct String add(struct String numb1, struct String numb2){ + byte carryover=0; + int digitCount=0; + char*str = malloc(0); + if (numb1.length>=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]; + } + } + } 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]; + } + } + } + if (carryover>0) { + str = realloc(str,++digitCount); + str[digitCount-1]='1'; + } + for (int i=0;i6ttj7g#7({gZ5k^}J= zo2O_c#aKply!9JCVl1I@VKy&ch%VY`{7Ob<3o(`ykp0t#{M2$VDaYTP4OE9&lCnge z+RT!}rhNX8MQsSHu(FLUj7DQ@ES0lQJZhiT?CZiTf%a+5zB0_xl%?|2!%VYGqh(sP z{1NZlSZdgftq}uuMEN^uvi8v@_o6Bx-J#o_xG-HuDWUy{4{$0 zYm?fwa1}~yp|Sc0W$&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main.c @@ -2,88 +2,49 @@ #include "utils.h" /* - You are given the following information, but you may prefer to do some research for yourself. + Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). + If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers. - 1 Jan 1900 was a Monday. - Thirty days has September, - April, June and November. - All the rest have thirty-one, - Saving February alone, - Which has twenty-eight, rain or shine. - And on leap years, twenty-nine. - A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400. - How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)? + For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. - https://projecteuler.net/problem=19 -*/ - -enum Month {JANUARY=1,FEBRUARY,MARCH,APRIL,MAY,JUNE,JULY,AUGUST,SEPTEMBER,OCTOBER,NOVEMBER,DECEMBER}; + Evaluate the sum of all the amicable numbers under 10000. -int DaysInMonth(enum Month month,int year) { - switch (month) { - case JANUARY: - case MARCH: - case MAY: - case JULY: - case AUGUST: - case OCTOBER: - case DECEMBER:{ - return 31; - }break; - case APRIL: - case JUNE: - case SEPTEMBER: - case NOVEMBER:{ - return 30; - }break; - case FEBRUARY:{ - return ((year%100==0)&&(year%400!=0))?28:(year%4==0)?29:28; - }break; - } -} + https://projecteuler.net/problem=21 +*/ int main(int argc,char**argv) { - int day=1; - enum Month month=1; - int year=1900; - enum Weekday{ - SUNDAY, - MONDAY, - TUESDAY, - WEDNESDAY, - THURSDAY, - FRIDAY, - SATURDAY, - } weekday=MONDAY; - - int sundayCount=0; - - while((day!=31)||(month!=12)||(year!=2000)) { - printf("Date: %d/%d/%d\n",month,day,year); - if (year>=1901) { - //Start counting Sundays. - if (weekday==SUNDAY&&day==1) { - sundayCount++; + int counter=1; + long totalSum=0; + while (counter<10000) { + //printf("Factor sum of %d: 1,",counter); + int factorSum=1; + int max=counter/2; + for (int i=2;i