From 52206219dd876affeecbc1f9edc9ccef544fea77 Mon Sep 17 00:00:00 2001 From: kirreen Date: Sun, 8 Dec 2024 16:11:17 +0100 Subject: [PATCH] day 5 a --- 5/a.out | Bin 0 -> 20480 bytes 5/input | 1351 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5/inputDemo | 28 ++ 5/main.c | 139 ++++++ 4 files changed, 1518 insertions(+) create mode 100755 5/a.out create mode 100644 5/input create mode 100644 5/inputDemo create mode 100644 5/main.c diff --git a/5/a.out b/5/a.out new file mode 100755 index 0000000000000000000000000000000000000000..64e90b1b119017ceb7d1359f310f7a2440fc25e5 GIT binary patch literal 20480 zcmeHPe{@t=oxktR+?fgaG5Nud1ZXpbLTM`#LLr3$GW?kE0-<0FnzppVWM-0#OlIQz zpiqG#0hie^JxSNPY^9c3T|HX0uG+12Pn%M=0j(}-Rn+|vmDWUXr7gNqS!O@q`|cfP zrips|W6#+=xjFN`_xt;MzxTfT?)!1`ptrSI*EFVzg}svzHdtv=Jc_YFRT%TIWvm>> z>)Bjp1KEn7N3x6IS>0qP=#X+2K+>zF$~bVgNoESF2nmwjM8zW=D9B_xNRN|}#EaoP zsi&ag=lr=y8O0@zIrt$GKv6JXk8*QnpDyM!553|mbyQ&9PP z7xXAEe{NCTe24TmQ9mq_`BzY;l{G}d?M+J>BEf}`a5S}N;htqp3!9d>6EXK<5dy`v z2tOKA8*bmu^n+}WXi8sWS^=(093rBS>{R?H?WBLx<`XsFZ|?ms%fiziZ5Uqu)}guC zFOv+lgKUxv6{68k72>I%qWw9LhFA4Cf}aA-H4c3>XyeJ-C!mKWpi`{l*|~25`b(g@ z@GCC!K^V_YWCHrN6VPiXpnn&17k9^Cgo0z%E~)YnQLXAC9n& zSWhU*;vs(|5(}_y6Zm`>T>%n}Cw<-ia1?ssL@cm;xvwJ;@JBm<2ln`V9pR`y5`G}W z0;XP1JRD7Su#QA1w2P4m8jnqELuJiibMG ziDW3gZS%TFEE?M8Z;yoFv$H!El~MUj(QySC!)V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B=`29C-dn{klbAqd@7LiQSS*X7>=0`+e=ZIu+U}7%HGJ1ComozmvUUz zrm^DZ5LLoJRc;@+vUk0ZpOJgcqv&*(D;HskB;b2+bQMrcWK7U&nc*p9CV-A-rw{Z> z+o;KP=BpZE6lzCX5s zzHoPcfoUI7oMgVeV)w8FF_MN(xi^p0o(khX zSA>I-v}SF~!lb{G3Gps}qKmnMd!uk+LadwwXE(0;;aIc)@qrf)Mf{{7Ydw)9bBi$D zNm?ek#jtS4V`7lFLtR*`_`5^Ct{`+3W@`BS@wgv>l7_0ou)jMTfY%so;oueyOk?O6 z<_^TVyJ=P74u;xOozU|~X+0;=aI_<)>i+h2tWOjs7Ew|P*~=%Rx8sH9+h2&$`w^VN z^i)ceTHMr8QIMW<$rnbQuA}*-2}r*F9;vS&T}Shan%@eX6gvySrx+=B zN}rw_PzmElD$2il&!pf563Q#Z`KPC&^bSYqtM@hvUMqD~{7OzidbCIHgcPpc3n{o& z>KDf^$&A(;lvAaz-b*PsC${|$f+t8Quc*tMf}a8}Uw=?C6x>dU%PUGxkv@k?zP?(YDOj!q zB`hAlUy}MN|I8%?CHzzE|5}m$Y^kSUt2C!TvH#OW`dw0AL3($SUsV4q+V@bw<3Di@ z5KX=>b>xY)ZdxYG%HF^K^@BZ`f5FGEHdR) zoXU*S%i&Nanu=eo2iv56u{`<8FXhs|6wk4gKF#m>Md>RzUFzq{Q2ilku-LBBQ}XjB z(0^Vk{vtOqm>R|UjT7j9@>Wy+2So}+C|f;&{`;4k`b{daGT>tUO;W$OonKsODh%gN zY!g@d3exK{su$}ItTyGecu?1`63~j8C=`#a b6M$V&j!ZP?SE9Ig8(;q;UQ?puPw4*-eETa{ literal 0 HcmV?d00001 diff --git a/5/input b/5/input new file mode 100644 index 0000000..d65050d --- /dev/null +++ b/5/input @@ -0,0 +1,1351 @@ +12|91 +25|68 +25|41 +41|34 +41|45 +41|24 +55|32 +55|19 +55|12 +55|85 +32|89 +32|96 +32|19 +32|12 +32|81 +19|81 +19|89 +19|76 +19|38 +19|68 +19|23 +87|73 +87|91 +87|38 +87|37 +87|82 +87|89 +87|29 +89|62 +89|15 +89|76 +89|95 +89|73 +89|68 +89|35 +89|23 +35|22 +35|71 +35|55 +35|85 +35|76 +35|73 +35|94 +35|97 +35|83 +18|22 +18|55 +18|32 +18|68 +18|41 +18|93 +18|37 +18|53 +18|85 +18|83 +37|32 +37|83 +37|85 +37|22 +37|53 +37|16 +37|23 +37|97 +37|55 +37|93 +37|24 +52|58 +52|25 +52|96 +52|42 +52|28 +52|49 +52|91 +52|12 +52|31 +52|45 +52|38 +52|19 +85|91 +85|52 +85|24 +85|14 +85|13 +85|32 +85|28 +85|12 +85|31 +85|42 +85|58 +85|81 +85|49 +84|87 +84|45 +84|15 +84|52 +84|42 +84|58 +84|12 +84|71 +84|19 +84|85 +84|53 +84|81 +84|91 +84|96 +58|82 +58|57 +58|25 +58|91 +58|49 +58|15 +58|89 +58|38 +58|73 +58|42 +58|45 +58|28 +58|14 +58|19 +58|81 +16|32 +16|13 +16|29 +16|87 +16|85 +16|42 +16|89 +16|19 +16|97 +16|71 +16|12 +16|24 +16|28 +16|54 +16|52 +16|31 +81|95 +81|15 +81|49 +81|25 +81|14 +81|78 +81|35 +81|83 +81|23 +81|37 +81|38 +81|93 +81|62 +81|22 +81|68 +81|41 +81|82 +96|19 +96|54 +96|12 +96|73 +96|35 +96|57 +96|49 +96|82 +96|89 +96|31 +96|45 +96|87 +96|81 +96|15 +96|58 +96|42 +96|38 +96|91 +76|96 +76|52 +76|83 +76|87 +76|22 +76|78 +76|71 +76|53 +76|62 +76|85 +76|58 +76|94 +76|34 +76|16 +76|57 +76|68 +76|32 +76|13 +76|84 +34|24 +34|96 +34|57 +34|87 +34|19 +34|13 +34|32 +34|54 +34|29 +34|81 +34|84 +34|58 +34|52 +34|45 +34|42 +34|85 +34|89 +34|31 +34|91 +34|12 +23|16 +23|29 +23|96 +23|52 +23|94 +23|87 +23|97 +23|34 +23|24 +23|57 +23|42 +23|55 +23|28 +23|31 +23|84 +23|71 +23|13 +23|85 +23|58 +23|41 +23|45 +42|76 +42|93 +42|89 +42|27 +42|95 +42|38 +42|73 +42|12 +42|45 +42|29 +42|18 +42|82 +42|91 +42|28 +42|25 +42|37 +42|81 +42|14 +42|35 +42|19 +42|31 +42|15 +91|16 +91|15 +91|73 +91|78 +91|35 +91|97 +91|55 +91|49 +91|93 +91|27 +91|62 +91|41 +91|82 +91|68 +91|14 +91|95 +91|38 +91|83 +91|22 +91|18 +91|25 +91|23 +91|76 +57|82 +57|93 +57|31 +57|38 +57|27 +57|35 +57|29 +57|81 +57|49 +57|89 +57|95 +57|42 +57|28 +57|91 +57|15 +57|37 +57|12 +57|14 +57|54 +57|45 +57|19 +57|73 +57|18 +57|25 +68|84 +68|55 +68|58 +68|57 +68|41 +68|85 +68|32 +68|31 +68|16 +68|87 +68|23 +68|24 +68|28 +68|13 +68|53 +68|97 +68|42 +68|54 +68|96 +68|52 +68|94 +68|34 +68|29 +68|71 +14|93 +14|34 +14|38 +14|55 +14|41 +14|78 +14|83 +14|97 +14|94 +14|68 +14|82 +14|16 +14|76 +14|23 +14|27 +14|18 +14|62 +14|22 +14|84 +14|95 +14|73 +14|37 +14|25 +14|35 +93|53 +93|76 +93|96 +93|68 +93|78 +93|85 +93|94 +93|97 +93|52 +93|22 +93|62 +93|24 +93|13 +93|83 +93|41 +93|32 +93|84 +93|71 +93|23 +93|34 +93|58 +93|55 +93|16 +93|27 +31|81 +31|38 +31|78 +31|95 +31|83 +31|93 +31|62 +31|12 +31|76 +31|49 +31|73 +31|37 +31|45 +31|19 +31|91 +31|15 +31|25 +31|18 +31|22 +31|14 +31|82 +31|89 +31|27 +31|35 +13|29 +13|25 +13|57 +13|35 +13|31 +13|81 +13|73 +13|42 +13|14 +13|19 +13|91 +13|89 +13|15 +13|96 +13|54 +13|82 +13|12 +13|87 +13|95 +13|45 +13|38 +13|58 +13|28 +13|49 +97|24 +97|96 +97|32 +97|12 +97|57 +97|45 +97|34 +97|84 +97|81 +97|19 +97|31 +97|52 +97|54 +97|71 +97|85 +97|89 +97|58 +97|87 +97|94 +97|13 +97|53 +97|29 +97|28 +97|42 +83|41 +83|94 +83|84 +83|68 +83|34 +83|71 +83|54 +83|57 +83|78 +83|55 +83|53 +83|97 +83|52 +83|16 +83|24 +83|28 +83|13 +83|23 +83|32 +83|87 +83|42 +83|85 +83|96 +83|58 +53|87 +53|91 +53|28 +53|57 +53|54 +53|14 +53|31 +53|19 +53|58 +53|32 +53|13 +53|12 +53|24 +53|96 +53|81 +53|15 +53|45 +53|29 +53|71 +53|89 +53|49 +53|85 +53|52 +53|42 +62|55 +62|24 +62|34 +62|78 +62|83 +62|87 +62|23 +62|57 +62|85 +62|42 +62|41 +62|52 +62|96 +62|32 +62|68 +62|58 +62|97 +62|22 +62|13 +62|71 +62|94 +62|84 +62|53 +62|16 +49|18 +49|25 +49|93 +49|55 +49|68 +49|23 +49|37 +49|97 +49|35 +49|16 +49|73 +49|82 +49|14 +49|62 +49|22 +49|27 +49|41 +49|95 +49|34 +49|83 +49|38 +49|84 +49|78 +49|76 +95|18 +95|41 +95|78 +95|83 +95|27 +95|23 +95|82 +95|16 +95|68 +95|34 +95|84 +95|76 +95|22 +95|93 +95|73 +95|55 +95|94 +95|53 +95|71 +95|97 +95|35 +95|37 +95|38 +95|62 +38|82 +38|84 +38|35 +38|53 +38|16 +38|55 +38|34 +38|18 +38|37 +38|73 +38|22 +38|41 +38|62 +38|71 +38|76 +38|78 +38|94 +38|93 +38|83 +38|85 +38|23 +38|97 +38|68 +38|27 +27|71 +27|55 +27|13 +27|58 +27|22 +27|41 +27|62 +27|83 +27|23 +27|76 +27|87 +27|85 +27|94 +27|16 +27|34 +27|24 +27|96 +27|84 +27|78 +27|52 +27|97 +27|32 +27|68 +27|53 +94|32 +94|54 +94|19 +94|24 +94|15 +94|85 +94|52 +94|96 +94|91 +94|87 +94|12 +94|57 +94|71 +94|89 +94|53 +94|49 +94|28 +94|81 +94|42 +94|29 +94|58 +94|13 +94|45 +94|31 +82|68 +82|78 +82|84 +82|37 +82|22 +82|76 +82|35 +82|62 +82|52 +82|27 +82|16 +82|85 +82|94 +82|83 +82|53 +82|34 +82|41 +82|73 +82|55 +82|23 +82|18 +82|97 +82|71 +82|93 +22|52 +22|57 +22|94 +22|23 +22|16 +22|34 +22|87 +22|78 +22|96 +22|85 +22|28 +22|24 +22|32 +22|83 +22|68 +22|53 +22|97 +22|41 +22|58 +22|13 +22|84 +22|55 +22|42 +22|71 +29|82 +29|35 +29|83 +29|15 +29|22 +29|81 +29|95 +29|76 +29|62 +29|73 +29|18 +29|27 +29|89 +29|49 +29|19 +29|31 +29|45 +29|93 +29|38 +29|25 +29|91 +29|37 +29|12 +29|14 +73|68 +73|18 +73|83 +73|27 +73|34 +73|16 +73|85 +73|94 +73|24 +73|76 +73|71 +73|41 +73|32 +73|23 +73|55 +73|37 +73|62 +73|84 +73|52 +73|53 +73|78 +73|93 +73|97 +73|22 +45|68 +45|73 +45|12 +45|25 +45|49 +45|22 +45|38 +45|93 +45|76 +45|81 +45|37 +45|15 +45|14 +45|82 +45|35 +45|19 +45|83 +45|18 +45|95 +45|91 +45|27 +45|89 +45|78 +45|62 +78|96 +78|53 +78|42 +78|84 +78|24 +78|34 +78|97 +78|29 +78|54 +78|28 +78|41 +78|87 +78|94 +78|13 +78|52 +78|23 +78|85 +78|55 +78|58 +78|57 +78|32 +78|71 +78|68 +78|16 +28|76 +28|54 +28|25 +28|81 +28|35 +28|82 +28|89 +28|73 +28|14 +28|45 +28|49 +28|19 +28|12 +28|31 +28|38 +28|18 +28|62 +28|27 +28|15 +28|29 +28|37 +28|93 +28|95 +28|91 +71|12 +71|19 +71|96 +71|89 +71|25 +71|91 +71|14 +71|52 +71|85 +71|45 +71|57 +71|42 +71|32 +71|49 +71|31 +71|87 +71|28 +71|81 +71|24 +71|54 +71|15 +71|13 +71|58 +71|29 +54|14 +54|81 +54|35 +54|49 +54|18 +54|95 +54|38 +54|19 +54|29 +54|45 +54|76 +54|62 +54|12 +54|25 +54|91 +54|15 +54|93 +54|89 +54|73 +54|27 +54|31 +54|22 +54|37 +54|82 +24|95 +24|28 +24|45 +24|57 +24|31 +24|81 +24|96 +24|25 +24|14 +24|54 +24|19 +24|89 +24|82 +24|91 +24|42 +24|49 +24|29 +24|12 +24|13 +24|35 +24|15 +24|58 +24|38 +24|87 +15|37 +15|35 +15|41 +15|76 +15|62 +15|95 +15|83 +15|55 +15|68 +15|34 +15|73 +15|22 +15|18 +15|16 +15|82 +15|78 +15|27 +15|49 +15|97 +15|93 +15|14 +15|25 +15|38 +15|23 +12|38 +12|15 +12|22 +12|81 +12|89 +12|68 +12|41 +12|82 +12|76 +12|14 +12|62 +12|83 +12|35 +12|93 +12|95 +12|49 +12|78 +12|25 +12|73 +12|27 +12|18 +12|37 +12|23 +25|53 +25|83 +25|62 +25|38 +25|78 +25|93 +25|27 +25|76 +25|34 +25|37 +25|95 +25|22 +25|94 +25|84 +25|16 +25|55 +25|97 +25|23 +25|82 +25|35 +25|18 +25|73 +41|16 +41|84 +41|52 +41|31 +41|97 +41|71 +41|55 +41|87 +41|29 +41|94 +41|57 +41|28 +41|53 +41|96 +41|32 +41|58 +41|42 +41|85 +41|19 +41|54 +41|13 +55|28 +55|13 +55|42 +55|97 +55|29 +55|24 +55|34 +55|16 +55|53 +55|52 +55|58 +55|57 +55|96 +55|87 +55|45 +55|71 +55|84 +55|94 +55|54 +55|31 +32|38 +32|95 +32|24 +32|25 +32|29 +32|13 +32|45 +32|58 +32|42 +32|14 +32|57 +32|15 +32|82 +32|87 +32|28 +32|49 +32|31 +32|54 +32|91 +19|25 +19|78 +19|82 +19|22 +19|12 +19|93 +19|73 +19|18 +19|37 +19|91 +19|95 +19|14 +19|62 +19|49 +19|15 +19|83 +19|35 +19|27 +87|19 +87|95 +87|45 +87|54 +87|49 +87|42 +87|31 +87|35 +87|57 +87|18 +87|25 +87|28 +87|12 +87|15 +87|14 +87|81 +87|93 +89|27 +89|49 +89|91 +89|22 +89|83 +89|25 +89|18 +89|78 +89|41 +89|37 +89|55 +89|93 +89|14 +89|82 +89|81 +89|38 +35|34 +35|41 +35|18 +35|53 +35|84 +35|27 +35|23 +35|37 +35|16 +35|52 +35|93 +35|68 +35|32 +35|62 +35|78 +18|84 +18|94 +18|76 +18|16 +18|52 +18|24 +18|97 +18|62 +18|13 +18|23 +18|78 +18|34 +18|27 +18|71 +37|84 +37|41 +37|62 +37|27 +37|76 +37|78 +37|94 +37|13 +37|96 +37|68 +37|34 +37|71 +37|52 +52|57 +52|29 +52|95 +52|15 +52|32 +52|13 +52|89 +52|14 +52|87 +52|24 +52|81 +52|54 +85|19 +85|95 +85|89 +85|15 +85|25 +85|87 +85|54 +85|57 +85|45 +85|96 +85|29 +84|89 +84|94 +84|57 +84|13 +84|28 +84|24 +84|29 +84|54 +84|31 +84|32 +58|95 +58|12 +58|18 +58|29 +58|54 +58|31 +58|87 +58|35 +58|37 +16|45 +16|84 +16|34 +16|58 +16|57 +16|53 +16|96 +16|94 +81|76 +81|55 +81|91 +81|27 +81|16 +81|73 +81|18 +96|25 +96|29 +96|18 +96|95 +96|14 +96|28 +76|97 +76|55 +76|23 +76|41 +76|24 +34|94 +34|28 +34|53 +34|71 +23|53 +23|54 +23|32 +42|49 +42|54 +91|37 + +94,53,85,52,32,24,13,96,87,57,28,54,29,45,12,89,81,91,15 +71,52,34,31,94,16,24,58,53,55,87,41,23,28,96,84,13,32,85,29,42,97,57 +62,22,83,78,68,23,41,55,16,97,34,84,94,53,71,52,32,24,13,96,58,87,57 +93,27,76,22,83,78,68,23,55,16,97,34,84,94,71,85,52,32,24,13,96 +37,16,84,22,73,27,85,97,18,53,94,78,32,55,62,41,52 +95,82,35,73,37,93,55,84,53 +19,95,14,57,29,54,81,82,13,45,28,91,58,87,25,12,35,49,96 +85,52,32,24,13,96,58,87,57,42,28,54,29,31,45,19,91,15,49,14,25 +49,89,37,31,18,12,62,38,45,29,91,22,15,95,81 +53,91,31,15,29,49,87,45,24,12,71 +28,42,57,58,84,94,85,16,19,31,52,96,87,34,55 +28,29,31,89,81,15,76 +28,45,81,31,76,54,19,38,25 +53,54,84,57,19,42,28,94,96,55,32 +22,38,23,82,84,78,16,62,68,95,83,18,34,53,55,27,37,94,73,93,76 +53,54,84,91,87,12,96,57,94 +84,71,41,34,55,78,54,32,28 +62,41,97,34,84,53,71,85,52,32,24,58,57 +27,76,78,84,97,53,55,94,37,93,34,52,32,16,23,71,24,41,85 +45,38,91,14,42,73,89,82,58,49,28,18,12 +96,84,54,24,87,13,89,32,53,12,81,71,34 +84,19,24,53,94,32,71,87,89,58,52,81,42,29,13 +15,95,73,18,27,78,23,41,55,16,97 +76,41,94,27,84,62,16,22,37,71,35,68,78 +96,55,28,58,53,94,68,13,34,54,24 +87,54,58,28,52,55,94,71,23,24,84,16,42,34,85,57,31 +12,49,54,35,19,62,18 +73,12,42,31,89,19,15,81,28,35,54,18,57,91,93,49,45,95,25 +76,62,22,83,68,55,16,34,84,94,53,24,13,96,58 +29,31,45,19,12,89,81,91,15,49,14,25,95,38,82,35,73,18,37,93,27,62,22 +25,38,73,76,22,78,41,84,94 +97,53,71,85,32,13,96,58,57,28,29,19,89 +37,27,22,83,68,23,55,16,97,94,32,24,13 +87,42,29,19,89,91,14,25,82,35,37 +97,84,94,71,85,52,32,24,13,96,58,87,57,28,54,29,31,45,89 +38,58,31,91,19,54,42,95,29,49,18,25,15 +13,58,54,31,45,19,15,49,25,95,35 +22,83,78,23,41,55,34,85,52,24,58,87,42 +41,84,52,78,68,96,83,22,24,23,13,34,62,53,55,58,87,32,76 +76,93,38,18,89,54,73,19,91,14,31,37,28 +37,93,27,76,22,83,78,41,16,97,84,94,53,85,32,24,13 +76,78,23,41,55,16,97,52,32,58,87 +49,25,62,37,73,95,93,41,82,35,78,15,18 +78,16,97,84,53,71,32,13,58,87,57,42,54 +23,83,62,93,82,85,76,97,27,84,78,37,16,18,41,22,73 +71,32,62,27,52,34,41,24,23,97,22,78,84,55,68,83,16 +35,73,18,37,93,27,76,62,22,83,78,68,23,41,55,16,97,84,94,53,71,85,52 +16,41,52,97,24,54,87,42,23,28,71,96,53,34,55,32,84,31,58,13,29,57,85 +49,14,25,95,38,73,18,37,93,27,22,83,34 +57,15,28,19,45,18,38,31,87,49,73,91,35,42,25,14,58,89,95,81,29 +12,45,81,19,25,31,14,57,54,96,32,91,15,38,87,29,49,28,58 +22,83,23,41,55,53,13,96,42 +15,19,85,12,91,28,13,87,31,81,53,42,32,96,89,49,58,52,29,57,54,24,71 +29,25,38,73,18,37,76 +84,83,35,62,22,71,34,52,27,53,76,18,55,97,78,41,93,16,68 +25,95,38,73,27,62,68,23,55,16,34,84,94 +91,82,35,37,22,68,23,41,16 +82,53,41,27,18,94,55,23,97,38,73,93,35,22,76,95,78 +71,57,45,87,14,13,42,52,29,89,24,96,31,15,12 +83,78,68,55,84,53,52,32,13,58,28 +19,16,97,24,29,31,42,28,84,96,13,12,57 +94,71,85,52,32,24,96,58,87,57,42,54,29,45,19,12,89,81,15 +87,45,97,19,32,53,94,57,71,13,16,24,28,52,84,29,12,34,31,85,96 +12,15,32,91,89,52,14,96,45,19,95,29,57,25,49,54,81 +24,83,96,16,62,27,94,85,78,23,84,93,32,34,22,13,97,41,68 +45,73,89,42,54,28,29 +95,49,25,38,37,18,27,73,82,93,89,91,76,22,62,68,15,81,14,83,35,23,78 +41,73,94,76,22,93,34,32,97 +24,13,87,29,89,94,96,19,85,71,42,31,52,81,34,45,28,58,54 +19,91,49,37,27,76,83 +58,52,84,57,24,68,78,16,55,28,83,87,23,71,42,13,94,32,96 +91,93,95,16,23,55,78,68,37,82,27,22,14,25,18,38,15 +62,18,45,27,76,89,15,22,73,93,35,83,81,12,14,95,91,78,25,37,82,38,19 +22,16,38,18,37,84,62,35,82,68,53,73,76,55,97,27,71,41,83,94,23 +32,96,58,57,42,28,54,31,12,81,91,15,14,95,38 +19,31,96,13,52,12,84,97,16,87,24,34,54 +38,18,37,27,22,78,55,16,97,84,71 +29,12,15,25,93,76,22 +91,27,18,62,81,35,45,38,14,82,25,49,29,93,19,12,54,76,73 +55,94,52,58,54,45,19 +31,45,15,62,83 +96,42,57,91,25,58,54,87,28 +54,29,31,45,19,12,89,91,49,14,25,95,38,82,35,73,18,93,27,76,62 +45,19,12,89,38,82,35,73,37,93,27,76,78 +38,82,35,73,18,37,27,76,62,22,83,78,68,23,55,34,84,53,71 +78,68,23,97,94,85,52,32,24,96,87,42,54 +23,41,55,84,53,52,32,58,87,57,54,29,31 +19,12,89,81,15,14,25,95,38,35,73,18,37,76,62,22,83,78,68 +96,58,87,57,42,28,54,29,31,19,89,81,91,15,49,25,95,38,82,35,73 +31,89,91,49,14,25,18,27,76,62,83 +94,93,37,68,97,32,23,78,22 +32,76,13,58,34,55,53,24,68,84,27,83,78,62,52 +58,87,91,53,84,29,31,96,12 +62,22,83,78,23,41,55,16,97,84,94,53,71,85,52,32,24,96,58,87,57 +24,57,81,89,52,49,42,14,95,96,15 +41,55,76,27,78,15,14,95,97,38,18 +41,57,22,68,16,23,55,62,58,24,97,84,13 +49,18,31,73,89,29,27,45,81,95,35,82,54,14,93 +53,52,24,13,96,57,42,28,54,31,45,19,89,81,15 +53,24,89,12,57,54,71,58,52,94,45,42,13,85,34,87,29 +71,32,23,84,16,22,78,94,73,85,76 +22,78,68,23,41,55,97,34,84,94,53,71,52,32,24,13,96,57,42 +22,83,41,27,73,62,16,18,82,95,35,55,97 +49,95,18,93,23,12,62,37,73,38,25,89,68 +49,14,25,95,38,82,35,73,18,37,93,27,76,62,22,83,78,68,23,41,16,97,34 +41,55,16,84,53,85,52,32,24,13,57,54,29,31,45 +82,73,18,22,83,78,68,23,41,55,16,94,53,71,85 +96,12,24,81,49,71,28,52,29 +38,82,73,18,93,27,76,83,55,34,84,94,71 +54,29,45,19,12,81,91,25,38,73,37,93,62 +53,57,28,87,54,52,42,91,45,32,58,29,89,49,24,13,15,81,31 +19,49,25,68,38,27,18 +25,19,14,52,15,31,13,96,12,81,49,32,95,28,45 +41,34,27,73,83,18,97,62,95,37,82 +28,54,29,45,19,12,89,81,91,15,49,14,25,95,38,82,35,73,18,37,93,27,76 +62,34,68,87,83,84,55,76,22,96,53,41,78,97,13,32,24,58,85,71,23,16,52 +94,28,68,55,34,54,29 +57,29,19,87,13,96,16,94,97,34,52,32,71,28,84,24,45 +38,15,14,12,57,49,91,89,18,25,31,54,45,87,28 +28,85,32,24,81,45,13,58,19,71,31,96,52,94,91,29,84,54,57,53,42,12,89 +13,94,96,29,32,45,31,58,84,91,19,57,42 +38,82,35,73,18,37,93,27,76,62,22,78,23,41,16,97,34,84,94,53,71 +78,91,76,45,49,18,73,22,62 +91,29,87,13,35,31,38,96,45,28,15,82,12 +82,35,14,18,15 +58,54,31,45,12,49,95,38,35 +49,68,78,35,14,16,55,22,18,62,23,83,95,91,15,37,93,73,41,82,27 +82,35,73,18,23,41,34,84,94,53,85 +97,78,87,62,16,85,13,71,76,94,34,84,83,55,22,32,53,96,68 +82,55,97,41,93,34,38,62,84,37,35,83,14,16,22,68,76,25,27 +24,49,87,38,28,96,42,82,45,95,29 +84,22,96,87,76,34,62,23,71,58,24,16,85 +83,94,68,18,97,73,35 +12,14,19,54,87,29,57,95,81,24,45,49,42,15,31,96,91,25,28,38,89 +58,24,91,89,31,52,42,85,28 +96,58,87,57,42,28,54,45,19,12,89,81,91,49,14,25,95,38,82,35,73 +95,82,73,18,37,93,27,76,62,22,83,68,23,41,55,16,97,34,94 +27,85,78,55,52,83,34,16,96,58,23 +91,49,57,87,95,31,25 +28,31,12,35,73 +32,96,87,42,31,12,89,95,38 +45,12,15,14,95,38,73,18,76,83,78 +25,49,22,68,23 +18,62,97,73,34,55,84,16,78,52,94,22,93,27,35,76,68,23,71,53,83 +91,24,49,42,28,54,81,82,87,95,14,12,38,58,15,29,19,57,25,13,96,45,31 +97,45,28,87,71,34,32,31,89,52,85,24,19,53,42,84,29 +62,81,14,78,22,23,49,37,91 +14,31,45,73,82,19,29,91,89,87,42,12,54,81,35,28,38,15,58,18,25,95,49 +35,37,83,15,82,76,62,38,25,55,18,91,23,95,49,14,73 +76,84,41,37,16,32,18 +76,62,83,78,68,23,41,55,16,97,34,84,53,71,85,52,32,24,13,58,87 +55,16,97,34,84,71,85,52,32,24,13,58,87,57,31,45,19 +52,42,45,32,49,58,13,87,28,31,91,24,12,15,85,25,29,54,57 +94,71,85,52,32,24,96,58,87,42,28,54,29,31,45,19,81,91,15 +12,18,81,62,25,35,31,91,54,14,49,19,89,76,27,93,82 +85,58,42,54,19,12,91,15,49 +15,49,14,25,95,38,82,35,73,18,37,93,27,76,62,22,83,78,68,23,55,16,97 +25,35,73,22,78 +34,68,83,78,25,94,27,38,41,35,22,16,93,37,55,95,18,97,62,76,82,73,23 +19,91,49,31,25,73,54,35,82,95,42,28,12,37,18,93,27,89,15 +41,16,94,53,52,24,96,58,29,31,45 +28,85,84,58,87 +22,71,41,27,53,68,52,93,18,83,94,55,16,84,76 +71,85,52,24,13,96,87,42,28,29,19,81,14 +12,91,49,38,82,73,93,27,23 +95,38,35,73,18,37,76,62,22,83,78,68,23,55,16,97,84,94,53 +73,27,14,23,97,38,93,15,41,37,49,22,35,68,55,78,16,95,76,18,82,62,83 +96,58,87,28,31,12,81,91,14,25,38,82,73 +97,83,85,94,71,27,76,22,37,24,18,53,55 +89,81,14,25,95,38,35,37,93,27,76,83,78,23,41 +55,34,84,94,53,71,85,52,24,13,58,87,42,28,54,29,31,45,19 +35,73,93,62,22,78,68,23,55,16,97,34,84,53,71,85,52 +84,53,71,52,24,13,96,57,42,28,54,31,45,19,91 +49,76,62,16,22,25,27,41,34,35,95,78,14 diff --git a/5/inputDemo b/5/inputDemo new file mode 100644 index 0000000..9d146d6 --- /dev/null +++ b/5/inputDemo @@ -0,0 +1,28 @@ +47|53 +97|13 +97|61 +97|47 +75|29 +61|13 +75|53 +29|13 +97|29 +53|29 +61|53 +97|53 +61|29 +47|13 +75|47 +97|75 +47|61 +75|61 +47|29 +75|13 +53|13 + +75,47,61,53,29 +97,61,53,29,13 +75,29,13 +75,97,47,61,53 +61,13,29 +97,13,75,29,47 diff --git a/5/main.c b/5/main.c new file mode 100644 index 0000000..72075f9 --- /dev/null +++ b/5/main.c @@ -0,0 +1,139 @@ +#include +#include +#include +#include + +#define LINES 1000 + +struct page { + int page; + int *illegalPrec; + int ruleLen; + struct page *next; +}; + +void add_page(struct page *head, int page) +{ + // traverse list until last member + while(head->next) head = head->next; + + // allocate and store ptr + head->next = malloc(sizeof(struct page)); + + // allocate illegalArray + head->next->illegalPrec = calloc(16, sizeof(int)); + head->next->ruleLen = 16; + + // store page number in new item + head->next->page = page; + head->next->next = 0; +} +void add_rule (struct page *page, int illegal) +{ + // make sure you wont go oob + int i = 0; + for (i = 0; i < page->ruleLen && page->illegalPrec[i] != 0; i++); + // if oob, realloc illegalPrec and change ruleLen-size + if (i >= page->ruleLen - 1) { + page->illegalPrec = realloc(page->illegalPrec, + page->ruleLen * 2 * sizeof(int)); + page->ruleLen *= 2; + } + // store illegal page + page->illegalPrec[i] = illegal; +} + +// power! x to the y! +int pow(int x, int y) +{ + int ans = 1; + for (int i = 0; i < y; i++) ans *= x; + return ans; +} +// parse string into array of numbers +int parse_numbers(char *str_row, int *row, int n) +{ + int i = 0; + for (; str_row[i] != '\n'; i++); + for (; i >= 0; i--) { + int pos = 0; + for (; str_row[i] >= '0' && str_row[i] <= '9' && i >= 0; i--) { + row[n] += (str_row[i] - '0') * pow(10, pos); + pos++; + } + n--; + } + + return 1; +} + +bool check_report (int *updates, int len, struct page *rules) +{ + for (int i = len - 1; i >= 0; i--) { + struct page *current = rules; + // for each array member, try to find it in rules + while (current->page != updates[i] && current->next) + current = current->next; + if (current->page != updates[i]) + continue; + // if found, for each lower array member, + // iterate through current->illegalPrec + // if match, illegal report + for (int j = i - 1; j >= 0; j--) { + for (int k = 0; k < current->ruleLen; k++) { + if (updates[j] == current->illegalPrec[k]) + return 0; + } + } + } + return 1; +} + +int main () +{ + FILE *input = fopen("input", "r"); + // create list of pages, each with arrays of pages that must be BEFORE them + struct page *pages = malloc(sizeof(struct page)); + struct page *current = pages; + // find pair. + int left = 0; + int right = 0; + // init head + fscanf(input, "%d|%d", &left, &right); + current->page = left; + current->ruleLen = 16; + current->illegalPrec = calloc(16, sizeof(int)); + add_rule(current, right); + while (fscanf(input, "%d|%d", &left, &right) == 2) { + // check if left exists in list + while (current->next && current->page != left) + current = current->next; + if (current->page == left) { + add_rule(current, right); + } + else { + add_page(pages, left); + add_rule(current->next, right); + } + current = pages; + } + fseek(input, -2, SEEK_CUR); + // take in line. Parse numbers until newline. + char line[100]; + int sum_reports = 0; + while (fgets(line, 100, input)) { + int numbers = 1; + for (int c = 0; line[c]; c++) numbers += (line[c] == ','); + int *updates = (int *)calloc(numbers, sizeof(int)); + parse_numbers(line, updates, numbers); + + if (check_report(updates, numbers, pages)) { + sum_reports += updates[numbers / 2]; + } + } + // Remember how many numbers you got this line, we'll iterate backwards! + // for each number in update, iterate through page-rules til you find it + // if found, make sure it isnt preceded by any page in its list? + // probably best to work completely backwards? rules can only ban pages from being before others + printf("sum: %d\n", sum_reports); +}