From 7be570c4a6e86fb7060f0bc06910ca57003dfe90 Mon Sep 17 00:00:00 2001 From: Orfeas <38209077+0xfea5@users.noreply.github.com> Date: Sat, 8 Jun 2024 13:50:47 +0300 Subject: Update file names and init.sh --- LICENSE | 698 ++++++++++++++- day01/example.txt | 14 + day01/input.txt | 2238 ++++++++++++++++++++++++++++++++++++++++++++++ day01/solution.nim | 20 + day02/example.txt | 3 + day02/input.txt | 2500 ++++++++++++++++++++++++++++++++++++++++++++++++++++ day02/solution.nim | 51 ++ day03/example.txt | 6 + day03/input.txt | 300 +++++++ day03/solution.nim | 47 + day04/example.txt | 6 + day04/input.txt | 1000 +++++++++++++++++++++ day04/solution.nim | 42 + day05/example.txt | 9 + day05/input.txt | 512 +++++++++++ day05/solution.nim | 87 ++ day06/example.txt | 1 + day06/input.txt | 1 + day06/solution.nim | 39 + day07/example.txt | 23 + day07/input.txt | 1096 +++++++++++++++++++++++ day07/solution.nim | 97 ++ day08/example.txt | 5 + day08/input.txt | 99 +++ day08/solution.nim | 85 ++ day09/example.txt | 8 + day09/input.txt | 2000 +++++++++++++++++++++++++++++++++++++++++ day09/solution.nim | 61 ++ day1/example.txt | 14 - day1/input.txt | 2238 ---------------------------------------------- day1/solution.nim | 20 - day2/example.txt | 3 - day2/input.txt | 2500 ---------------------------------------------------- day2/solution.nim | 51 -- day3/example.txt | 6 - day3/input.txt | 300 ------- day3/solution.nim | 47 - day4/example.txt | 6 - day4/input.txt | 1000 --------------------- day4/solution.nim | 42 - day5/example.txt | 9 - day5/input.txt | 512 ----------- day5/solution.nim | 87 -- day6/example.txt | 1 - day6/input.txt | 1 - day6/solution.nim | 39 - day7/example.txt | 23 - day7/input.txt | 1096 ----------------------- day7/solution.nim | 97 -- day8/example.txt | 5 - day8/input.txt | 99 --- day8/solution.nim | 85 -- day9/example.txt | 8 - day9/input.txt | 2000 ----------------------------------------- day9/solution.nim | 61 -- init.sh | 24 +- 56 files changed, 11039 insertions(+), 10383 deletions(-) create mode 100644 day01/example.txt create mode 100644 day01/input.txt create mode 100644 day01/solution.nim create mode 100644 day02/example.txt create mode 100644 day02/input.txt create mode 100644 day02/solution.nim create mode 100644 day03/example.txt create mode 100644 day03/input.txt create mode 100644 day03/solution.nim create mode 100644 day04/example.txt create mode 100644 day04/input.txt create mode 100644 day04/solution.nim create mode 100644 day05/example.txt create mode 100644 day05/input.txt create mode 100644 day05/solution.nim create mode 100644 day06/example.txt create mode 100644 day06/input.txt create mode 100644 day06/solution.nim create mode 100644 day07/example.txt create mode 100644 day07/input.txt create mode 100644 day07/solution.nim create mode 100644 day08/example.txt create mode 100644 day08/input.txt create mode 100644 day08/solution.nim create mode 100644 day09/example.txt create mode 100644 day09/input.txt create mode 100644 day09/solution.nim delete mode 100644 day1/example.txt delete mode 100644 day1/input.txt delete mode 100644 day1/solution.nim delete mode 100644 day2/example.txt delete mode 100644 day2/input.txt delete mode 100644 day2/solution.nim delete mode 100644 day3/example.txt delete mode 100644 day3/input.txt delete mode 100644 day3/solution.nim delete mode 100644 day4/example.txt delete mode 100644 day4/input.txt delete mode 100644 day4/solution.nim delete mode 100644 day5/example.txt delete mode 100644 day5/input.txt delete mode 100644 day5/solution.nim delete mode 100644 day6/example.txt delete mode 100644 day6/input.txt delete mode 100644 day6/solution.nim delete mode 100644 day7/example.txt delete mode 100644 day7/input.txt delete mode 100644 day7/solution.nim delete mode 100644 day8/example.txt delete mode 100644 day8/input.txt delete mode 100644 day8/solution.nim delete mode 100644 day9/example.txt delete mode 100644 day9/input.txt delete mode 100644 day9/solution.nim diff --git a/LICENSE b/LICENSE index fdddb29..f288702 100644 --- a/LICENSE +++ b/LICENSE @@ -1,24 +1,674 @@ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/day01/example.txt b/day01/example.txt new file mode 100644 index 0000000..2094f91 --- /dev/null +++ b/day01/example.txt @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 diff --git a/day01/input.txt b/day01/input.txt new file mode 100644 index 0000000..723d26d --- /dev/null +++ b/day01/input.txt @@ -0,0 +1,2238 @@ +5118 +5554 +4186 +4729 +1242 +4360 +1427 +5312 +6012 +1017 +5581 +5203 +3811 +4945 +3960 + +3812 +7757 +4448 +2205 +15715 + +4164 +6482 +4479 +3061 +4082 +2474 +1175 +1918 +4755 + +4056 +5122 +11426 +5529 +3659 +9592 +10257 + +3435 +3106 +4933 +2695 +3107 +6567 +5579 +1463 +5734 +4547 +4532 +2152 +5132 + +6074 +11600 +4337 +3444 +7637 +6725 +1189 + +5637 +1226 +7068 +6290 +4411 +3858 +6677 +1858 +2840 +1175 +5056 +6569 + +32887 +19643 + +4951 +2276 +4300 +4473 +1895 +5251 +1770 +4623 +4602 +4925 +1769 + +68012 + +5760 +2687 +3192 +2730 +4867 +4723 +2591 +1677 +4458 +4388 +6038 +3127 +6416 +3048 + +2485 +1630 +1595 +2864 +2125 +3852 +2216 +3883 +4293 +4165 +2762 +4016 +2508 +1396 +4541 + +5918 +6874 +6644 +4024 +3229 +1318 +1851 +1566 +1035 + +7625 +1369 + +3894 +18802 +1362 +12368 + +10251 +6249 +2784 +9394 +5932 +5610 +7201 +9922 + +10994 +10092 +4121 +2966 +1178 +2235 +9379 + +2592 +1895 +1740 +4357 +5314 +1068 +2228 +3775 +3949 +7162 +3078 +1450 + +9484 +1796 +8055 +7901 +9323 +1982 +2517 +8358 +2614 + +18536 +23454 +12107 + +6703 +6966 +1086 +7022 +3487 +3871 +2568 +6441 +1216 +2105 +5100 +2945 + +3268 +4866 +3569 +4374 +3666 +2477 +3263 +1312 +5121 +6592 +5337 +1417 + +17864 +11775 +1345 +11675 + +6636 +1678 +3982 +4552 +2719 +2736 +1342 +6375 +2671 +1541 +1093 +5538 + +21177 +36871 + +4608 +5474 +5004 +3229 +2744 +1577 +2182 +4518 +4930 +1986 +5776 +5023 +2070 +5342 +1952 + +13940 +15506 +13799 + +3672 +3303 +4866 +5507 +5282 +5768 +2847 +2214 +1688 +2255 +4302 +4962 +4585 +4285 +3602 + +4766 +4358 +4532 +10741 +13311 +2271 + +3073 +5990 +8256 +3692 +4658 +4561 +6347 +3260 +6938 +8643 + +5261 +1524 +1671 +3277 +2326 +5603 +5837 +1638 +5104 +3696 +1910 +2319 +2305 +1373 +4801 + +2593 +3527 +1517 +4626 +2003 +4414 +4677 +2282 +3000 +1457 +3530 +5344 +1890 +1703 +1268 + +9002 +7173 +3848 +6891 +1741 +5303 +1670 +1342 +1865 + +10319 +10539 +2972 +4667 + +4318 +1366 +1430 +5003 +2691 +7117 +3015 +6516 +6895 +1618 +3189 +6739 + +2494 +7140 +2905 +8784 +8727 +4711 +2284 +6894 +7030 +1688 + +1853 +7351 +7815 +3222 +8276 +1461 +5028 +8048 +5534 + +12546 +6236 +20372 + +2778 +5745 +2783 +5774 +4508 +3691 +6097 +4637 +5643 +5902 +1166 +1208 +3983 +5030 + +3767 +2558 +3988 +1056 +6570 +5437 +1920 +2822 +9126 + +3173 +3242 +5762 +4311 +5206 +3892 +4978 +5065 +1319 +2577 +1347 +3232 +1915 +5986 +3536 + +2308 +2812 +1119 +3845 +4589 +4779 +1503 +3613 +1576 +3827 +1468 +1533 +5896 +4981 + +9740 +16395 +19471 +12882 + +4779 +7293 +12593 +15897 + +36970 + +2386 +1094 +2957 +4452 +4005 +2723 +1124 +3533 +2671 +1701 +2508 +3075 +4741 +1471 +3416 + +37202 + +5272 +2736 +4756 +2235 +4679 +4093 +1773 +4088 +2419 +3192 +4429 +3959 +5230 +4342 + +8514 +11430 +5023 +9565 +3726 +11026 +6334 + +6563 +2638 +12569 +3458 +5449 +1216 + +1320 +4708 +1627 +4189 +3962 +1463 +2628 +5667 +5494 +6105 +4925 +3540 +1613 +2288 + +5974 +7710 +5200 +4859 +2346 +5619 +1337 +4814 +1359 +3020 +1798 + +2744 +1957 +10669 +4877 +3507 +7657 +7748 + +1021 +4297 +1689 +6925 +16175 + +7147 +11617 +5654 +11861 +6065 +3090 +1744 + +3782 +6658 +2389 +4339 +2312 +7245 +2039 +3411 +6251 +1778 +2345 +5814 + +13113 +10123 +18700 +6991 + +16138 +11645 +18610 + +9586 +6653 +1001 +4547 +2891 +2726 +7618 +5679 +1567 + +2380 +1858 +1059 +1160 +5115 +2588 +1969 +2629 +5525 +5831 +2139 +5469 +2783 + +10606 +4518 +9057 +5905 +4187 +4693 +4396 +2191 + +4374 +4407 +1083 +7787 +7716 +7505 +10096 +10650 + +5809 +4387 +3426 +3730 +3699 +4944 +4176 +2681 +5197 +1325 +5920 +4957 +5876 +5345 + +20155 + +1243 +11423 +13133 +4539 +4880 +4276 + +1073 +1316 +1841 +5102 +1196 +4847 +1293 +2424 +2345 +2298 +4214 +4215 +5760 +5775 + +4542 +1152 +5164 +5642 +2069 +1419 +5614 +7343 +1507 + +2840 +3922 +3563 +1856 +5216 +4886 +3794 +4637 +1826 +3520 +5582 +4602 +2442 +3631 +4946 + +7956 +3248 +7897 +7846 +2054 +5576 +3753 +3378 +1899 +3490 +6142 + +9837 +10901 +15019 +1735 +5306 + +3246 +2485 +5573 + +2722 +2084 +18774 + +7940 +10855 +8498 +5547 +13550 +4239 + +1857 +7355 +4374 +6798 +2341 +13128 + +14215 +9770 +2447 +1035 + +8426 +1873 +4518 +2812 +7611 +2465 +4770 + +8166 +19955 +6472 + +10884 +11212 +1463 +2716 +1796 +12003 +1240 + +2802 +2639 +3268 +2492 +6676 +8851 +4054 +9603 +5354 + +1483 +3080 +6696 +8713 +6856 +4796 +7728 +4600 +3616 +8565 + +26580 +15329 + +6074 +15758 +5707 +13583 +2595 + +4957 +9125 +6534 +8684 +1728 +3690 +7983 +4131 +8907 + +12147 +15776 +14765 +17316 + +27492 +12173 + +5967 +1170 +7896 +7865 +7945 +2261 +2026 +1751 +3988 +3759 +5258 + +20764 + +7020 +7441 +8780 +6111 +3483 +8606 +4547 +8153 +3543 +6791 + +5397 +4408 +1572 +2315 +3376 +2021 +1140 +2876 +5045 +6034 +4404 +5705 +3814 +3981 +3814 + +6836 +3601 +7452 +8519 +2302 +2382 +8481 +1455 +7154 +6565 + +2077 +5139 +5462 +1508 +2094 +4850 +1688 +4382 +1991 +2297 +1930 +4720 +4995 +2891 +1967 + +2201 +3673 +9817 +7417 +1283 + +4988 +3052 +2258 +6022 +3678 +2938 +7073 +6437 +2402 +5973 + +2492 +4592 +1501 +4818 +3141 +3470 +2821 +4367 +4952 +2779 +2237 +4283 +5625 +2935 + +2422 +5273 +4053 +4471 +1343 +1128 +4538 +4328 +2974 +3674 +4155 +5472 +3520 +2427 +4145 + +19383 +13539 +9822 +2453 + +2244 +3506 +2573 +3837 +1725 +5081 +4668 +4438 +2414 +1446 +1862 +2453 +2049 +4867 +5438 + +16970 +5265 + +7417 +8051 +7490 +1175 +11316 +4219 + +1065 + +6974 +1232 +6746 +3660 +3883 +5403 +3793 +4956 +4253 +2237 +5815 + +6537 +4906 +11084 +7541 +10019 +5164 +11601 + +4215 +4216 +1160 +2096 +1453 +6271 +5534 +4353 +6423 +4060 +6811 +4701 +3383 + +2138 +12998 +19743 + +8678 +6328 +6426 +7184 +8008 +7896 +5365 +9506 +1955 + +1498 +19856 +7833 + +17023 +7023 +21278 + +2110 +5542 +7191 +6509 +8813 +5236 +7771 +9593 +1262 + +11625 +19032 +17458 + +5266 +4751 +7950 +2185 +7837 +5710 +2053 +7332 +7422 +6356 + +5781 +1330 +2974 +2628 +7407 +7339 +3767 +5411 +3400 + +5330 +3441 +6203 +5272 +5867 +6034 +3167 +2187 +6006 +6614 +1089 +2485 + +3792 +4129 +1207 +1121 +3599 +6143 +4394 +5550 +1488 +2675 +6064 +1527 +4429 + +1606 +1129 +5426 +5260 +3827 +5595 +2286 +1974 +7525 +1290 +4569 + +2181 +5045 +7730 +5502 +5467 +7720 +1780 +4553 +1188 +4213 + +2565 +10635 +12032 +3283 + +9902 +2896 +9653 +6296 +2656 +11583 +5835 + +4932 +4548 +3832 +2377 +3371 +2612 +1907 +3494 +4567 +3130 +3375 +2750 + +7757 +1033 +8201 +13544 +13481 + +3382 +12952 +9450 +4982 +13966 + +4691 +3678 +1026 +7359 +1885 +1245 +5281 +8602 +6744 + +13041 +9202 + +3621 +3558 +2279 +2854 +6415 +5368 + +1102 +5319 +5768 +1990 +2526 +1900 +6294 +4744 +3655 +5011 +3092 +2697 +3864 + +12013 + +27776 +14644 + +5434 +1501 +1439 +4972 +1365 +6076 +1428 +6291 +6020 +5509 +3835 +2571 +6308 +1483 + +3972 +9357 +8383 +11037 +9557 +10966 + +8344 +1761 +10183 +4200 +3936 +5778 +9722 +1298 + +3962 +2611 +7361 +1156 +2522 +2462 +4249 +5127 +1443 +5989 +2942 + +5384 +7053 +2194 +11964 +5937 +7708 + +3052 +3192 +3224 +5708 +2120 +5756 +6107 +1198 +5519 +3803 +1169 +2903 +5942 +4376 +3675 + +11517 +9051 +2084 +4508 +4197 +7219 +9902 + +4566 +5562 +4263 +1970 +1965 +1333 +1601 +2665 +3443 +5463 +4981 +3792 +2588 +3282 + +1243 +3604 +4947 +1044 +6962 +2276 +2828 +6334 +2508 + +1339 +3050 +10158 +2095 +7779 +5165 +9420 +6101 + +4512 + +3273 +2248 +2082 +12415 +13944 + +5638 +5204 +3327 +1361 +3775 +3421 +7597 +1917 +1802 +3896 +4058 + +1901 +1813 +7388 +3861 +6838 +6154 +5500 +3086 +6403 +3654 +7471 +6904 + +1932 +1303 +1930 +1720 +5505 +1595 +2260 +5629 + +38957 + +4629 +3672 +3629 +5011 +5182 +3952 +2295 +4943 +2644 +2851 +5894 +4654 +5257 +3972 + +48469 + +3481 +1398 +3837 +2611 +3330 +3229 +7619 +4106 +6816 +3486 +2763 + +6591 +2522 +6262 +5458 +3025 +2804 +6403 +1390 +2964 +3081 +3449 + +6408 +3223 +4302 +1079 +5836 +5580 +1538 +2616 +3850 +5272 +3688 +2381 +5775 +5497 + +1891 +1448 +4283 +5965 +2726 +1425 +5399 +2795 +1583 +2489 +5171 +3133 +2547 +5117 +3092 + +11463 +11581 +6972 +5410 +3675 +8578 +4283 + +1398 +1747 +1341 +5365 +5086 +2268 +4544 +5286 +5910 +1393 +4580 +4726 +1123 +3949 +1223 + +7526 +3223 +5495 +7184 +10259 +7681 +4795 + +7168 +6278 +7939 +3829 +3670 +7969 +4917 +7406 +9035 + +5687 +4872 +2967 +10772 +9196 +6207 +6244 +2801 + +3500 +1786 +1517 +1585 +4536 +2645 +5249 +4808 +5681 +4591 +5595 +2751 +3336 +1615 +2200 + +6894 +4752 +1794 +6507 +2184 +5589 +3016 +4532 +2321 +6843 +2909 +2104 +4065 + +24126 + +3293 +8274 +1297 +4841 +4653 +1817 +1972 +6169 +1001 +7070 + +6969 +5331 +4779 +5316 +5249 +3315 +4355 +3596 +3868 +5647 +1110 + +5235 +5846 +5619 +6259 +4372 +2600 +7526 +3962 +3840 + +4260 +4484 +6361 +4276 +6344 +4776 +1173 +1884 +4572 +1411 +5230 +3976 +1800 +2426 + +19185 +15235 +19905 +8664 + +3346 +7532 +8840 +2182 +10048 +4181 +5030 +8078 + +2080 +2279 +6250 +3388 +6097 +4607 +6262 +4259 +3261 +4653 +3338 +7025 + +1138 +2851 +5912 +8592 +7341 +3596 +7669 +1030 +7624 + +6551 +6753 +7807 +4296 +3515 +6873 +5010 +8497 +1742 +5767 + +8921 +7840 +9067 +3809 +4347 +2876 +3886 +9982 + +11455 +10295 +15198 + +1574 +4240 +4052 +1739 +5701 +8449 +5055 +3893 +2700 + +3864 +4306 +4190 +1165 +1708 +5705 +5654 +6753 +3840 +4139 +2121 +5735 + +1662 +3541 +2480 +6124 +3355 +5737 +5537 +6806 +7953 +1109 + +14180 +15876 +25965 + +7732 +33422 + +5918 +5146 +6768 +9366 +1687 +1440 +3115 +1065 +6514 + +2316 +4905 +2945 +5351 +6196 +6207 +5751 +3811 +4765 +1419 +5253 +1616 +2274 +6363 + +5125 +2491 +5057 +2749 +1586 +4997 +5249 +3944 +3964 +3845 +2457 +5972 +5313 +6453 + +30602 +6865 + +4413 +1651 +6256 +6524 +3466 +1160 +4599 +6477 +2681 +1855 +4785 + +6435 +5377 +6008 +1744 +5182 +4469 +3999 +2913 +3367 +3233 +2369 +1712 +5408 +4622 + +4201 +5475 +1117 +2679 +2649 +1446 +4043 +1136 +3750 +4523 +3800 +3245 +3179 +6183 + +7682 +7213 +5144 +1557 +5579 +5005 +6307 +5906 +7244 +6230 + +1205 +2764 +3576 +5212 +1723 +4138 +1801 +1772 +4809 +1429 +2010 +3093 +4435 +2268 +4904 + +4386 +6822 +1865 +3688 +6771 +5433 +1430 +4870 +6745 +5758 +4456 +6549 +6203 + +2413 +3287 +3376 +5780 +1190 +1177 +1577 +4375 +5558 +5117 +6773 +2483 +4436 + +5870 +4195 +5932 +1117 +5072 +4581 +6922 +2695 +3134 +2021 +3327 +5538 +2324 + +2609 +4270 +5809 +1096 +6794 +3530 +3222 +4881 +3806 +2887 +7158 + +2989 +5279 +6821 +2474 +3144 +8621 +3854 +5012 +1144 +1354 + +9033 +7624 +5535 +2433 +1433 +5568 +8161 + +5691 +5394 +3445 +4619 +1703 +6197 +2113 +4277 +2506 +3380 +6039 +6423 +6429 + +23751 +4571 +7508 + +9674 +3084 +3612 +3841 +3555 +8146 +6263 +7746 +3586 + +7907 +6263 +2320 +4430 +15429 + +2825 +2248 +7184 +3650 +1008 +5219 +5600 +2610 +7357 +5113 +1039 +2019 + +2167 +4159 +6290 +3757 +10133 +1345 +7250 +10590 + +6712 +5361 +3243 +6239 +1667 +2699 +5389 +1400 +1334 +2382 +1604 +3256 +2439 + +6520 +1478 +3049 +6452 +6899 +1850 +2466 +3485 +3020 +6683 +8000 + +7715 +6597 +5588 +2062 +6732 +3811 +10470 + +4793 +1206 +6481 +11715 +8827 +3174 + +3492 +1535 +2603 +5877 +4937 +6805 +1620 +9488 +1593 + +2182 +8258 +3319 +5499 +6257 +1466 +6435 +8334 +1140 +6764 + +15599 +28121 + +5804 +6653 +1670 +7337 +4711 +8303 +10073 +6327 + +2754 +2040 +2295 +8503 +2231 +11685 +6556 + +16325 +4057 +11110 + +6482 +2035 +5189 +6641 +4232 +1100 +1088 +2779 +2220 +3078 +2847 +6009 +1981 + +8655 +8687 +7225 +4133 +4449 +7193 +4009 +7455 + +2014 +2691 +1207 +1140 +6736 +4780 +2781 +2855 +5056 +3590 +2372 +6188 + +6779 +4130 +5169 +5726 +1503 +1520 +8302 +3054 +3037 +6190 + +6862 +7039 +1305 +4226 +5769 +5068 +8362 +7612 +6856 + +17695 +18988 +3757 +15137 + +5268 +3234 +2073 +1529 +1190 +5659 +7316 +3075 +4191 +6111 +2582 +7122 + +9316 +2087 +2980 +12121 +1703 +6661 +4286 + +20694 +6712 +15401 + +4342 +3838 +3208 +2372 +1410 +1648 +2342 +6113 +5573 +6091 +2624 +1749 +5643 +4258 + +2303 +2178 +3449 +3150 +3825 +3673 +1326 +6377 + +10398 +3801 +11714 +7455 +3382 +6182 + +27882 + +6667 +3268 +11915 +7045 +10478 +10538 +2287 + +5694 +5516 +6094 +4909 +5685 +4931 +5949 +6361 +6476 +6439 +1667 +5691 +3883 +3307 + +9977 +7477 +6533 +9766 +4576 +2051 +1376 + +5966 +7654 +5784 +2727 +7568 +4600 +2150 +1333 +6583 +4119 +2648 + +11274 +8674 +4155 +2163 +1897 +6579 +11099 + +2751 +4530 +5488 +1491 +2456 +2752 +1767 +6113 +7730 +7127 + +8657 +6947 +4803 +5103 +4373 +9501 +1486 +5689 + +4382 +5176 +2533 +6017 +6100 +4935 +1841 +4530 +6120 +4735 +3438 +3305 +5324 +2814 + +41401 + +20975 +30628 + +2099 +5390 +4829 +5845 +2674 +1029 +3312 +3412 +3402 +5544 +4773 +5274 +2458 +4309 +2741 + +4345 +7095 +7361 +2171 +6003 +5069 +1941 +2473 +2116 +6508 +6491 +7227 + +8137 +8052 +5372 +1086 +2369 +5763 +8937 +9055 +1208 + +4359 +3906 +5012 +2086 +4937 +4239 +3390 +3280 +4948 +3906 +6387 + +6430 +11071 +1179 +6918 +12028 +1855 + +11059 +14754 +15751 +15821 +9411 + +8722 +1104 +7422 +9229 +7919 +6200 +2274 +2980 +5686 + +3277 +4325 +9477 +9651 +4798 +8742 +4308 +6656 +6746 + +5777 +6805 +4337 +4847 +4966 +3525 +2729 +6611 +3070 +3734 +1957 +1360 +1678 + diff --git a/day01/solution.nim b/day01/solution.nim new file mode 100644 index 0000000..b17411a --- /dev/null +++ b/day01/solution.nim @@ -0,0 +1,20 @@ +import std/strutils +import std/algorithm + +let content = readFile("./input.txt").splitLines() + +var + sum = 0 + sums = newSeq[int]() + +for line in content: + if line.isEmptyOrWhitespace(): + sums.add(sum) + sum = 0 + continue + sum += parseInt(line) + +sort(sums, system.cmp[int], Descending) + +echo sums[0] +echo sums[0]+sums[1]+sums[2] diff --git a/day02/example.txt b/day02/example.txt new file mode 100644 index 0000000..db60e36 --- /dev/null +++ b/day02/example.txt @@ -0,0 +1,3 @@ +A Y +B X +C Z diff --git a/day02/input.txt b/day02/input.txt new file mode 100644 index 0000000..b94766c --- /dev/null +++ b/day02/input.txt @@ -0,0 +1,2500 @@ +C Y +A Z +B Y +A Z +A X +A Z +B Y +A Z +B Y +C Z +B Y +C Z +A Z +C Y +B Y +B Y +B Y +C Y +B Y +B Y +A X +B Y +A Y +B Y +B Y +B X +A Y +C Z +C X +A Z +B Y +A X +C Y +C X +C Z +C X +B Y +B Y +B X +A Z +A X +C Y +A Z +C Z +B X +C X +B Y +C X +C Z +C Y +C Z +A Y +A Z +C Z +A Z +A Z +A Z +A Z +B Y +A Z +B Y +B Y +B Y +B X +A Z +B X +C Z +C Z +A Z +A Z +B Y +C Y +A X +C Y +C Y +B Z +B Y +C X +A X +A Z +C Z +C X +B Y +A X +C X +B Y +C X +B Y +C X +B Y +C Y +A Z +C Z +B X +C Y +B Y +A Z +B X +C Z +C Z +B Y +C Z +C X +A X +A Z +A Z +A Y +C Z +C Y +A X +C Z +C Y +A Z +C X +B X +A Z +B Y +A Z +B X +C X +A Z +C Y +C Z +B Y +C Y +C X +A Z +C X +C X +B Y +B Z +A X +B X +C Y +A Z +B Y +C Z +B Y +C Z +B X +B Y +B X +B Y +B Y +B Y +C Y +A Z +A Y +A Z +C Z +B Y +C Z +B Y +C Y +A Z +B X +B Y +C Z +A X +A Y +C X +B X +A Z +C X +A Y +A X +A Z +A Z +A Z +B Y +B Y +B Z +B Y +C Y +B Y +A Z +C X +A Z +A X +B Y +A X +C X +C X +A X +B X +C X +C Z +B Y +B Y +C Y +B X +C X +A Z +B Y +B Y +C Z +A Z +B Y +B X +C Z +A Y +B Y +A Y +C Y +C X +A X +B Y +C X +B Z +B Y +B Y +A Z +C Y +B Y +B Y +A Y +B Z +B Z +A Y +B Y +C Y +A Z +B Y +C Z +A Z +B Y +A Z +C Y +A X +B Z +C X +C Y +B Y +C Y +A Z +A Z +B Y +B Y +C Y +A Y +A Y +C Y +A Z +C Y +B X +C X +A X +A Y +A Z +A Y +A Z +B Y +B Y +B Y +A Z +C Y +C Z +A Y +C Y +A Z +A Z +C Z +B Y +A Z +C Z +B Y +C Y +C Z +C X +B Y +A Z +B Y +B Y +A Z +C X +B Y +A Z +B Y +C Y +A Y +A Z +C X +A Z +A Y +C Y +A Z +C Y +C Y +B X +A Z +B Y +A Z +C Y +B Y +B Y +B Y +A Z +C Z +C Y +B Y +C Z +C Y +C Y +C Y +A X +B X +C X +B Y +B Y +B X +B Y +B Y +C Z +B Y +B Z +C X +B Y +C Y +C Y +B X +A Z +B Y +B Y +A Z +B Y +C Z +B Y +B Y +A Z +C Z +C Z +A Z +C Y +B Y +B Y +C Y +B Z +A Y +C X +A Z +B X +C Y +A Z +C Z +B Y +B X +B Y +B Y +B Y +C Z +A Z +B Y +B X +B Y +B X +B X +C Z +A Z +B Y +C Z +A Z +C Y +C Y +A Z +A Z +A Y +B Y +C X +A Z +B Y +A Z +A Z +A Z +A Y +A Z +A Z +A Y +A X +A Z +C Z +C Y +C Y +C X +A Z +A Y +B Y +A Z +A Z +B Y +B X +B Y +A Z +A X +B Y +C Y +C Y +A Z +C Y +C X +B Y +A X +A X +C Y +A X +C Z +C X +C Y +B Y +A Z +C Y +A Z +A Z +C Z +B Y +A Z +A Y +A X +C X +C X +B Y +C X +B Y +C Z +A Y +B Y +C Y +C X +B Y +C Y +A Z +B Y +A X +C Y +A Y +A Z +A Z +B Y +A Z +A Z +C X +B Y +B Y +A Z +B Y +C Y +C Z +A Z +C Z +C Z +B Y +A Z +B Y +A Z +B Z +C Z +A Y +B Y +B Y +B Y +C Y +A X +A X +B X +B Y +C Z +C Y +C Y +C Y +A X +B Y +B Y +C Z +C X +B Y +A X +A Z +C Y +C Y +A Z +A Z +C Z +A Z +C Y +B Y +A X +B Y +C Z +A Z +A Y +B Y +B Z +C Y +C Y +C X +B Y +C Y +C Y +C Y +C Z +B Y +A Y +A Y +A Z +B Y +C X +B X +B X +B X +A Z +B Y +C Z +C Z +C X +B Y +B Y +B Y +A X +A Z +A Z +B Y +C Y +B Y +C Y +B X +A Z +B Y +B Y +B Y +B Y +B Y +B Y +C X +A Y +B Y +B Y +C Y +A Z +B Y +C X +B X +C Z +C X +A X +C X +B Y +B Y +C X +B Y +C Y +A Z +B Y +A X +C Y +A X +C Y +C Y +B Y +A Y +A Z +B Y +C Z +C Z +B Y +C Z +A Z +A Y +A Z +C Y +C Z +B Y +C Z +A Z +C X +A Y +C Z +A Z +B Y +C Z +C Y +B Y +A Z +B X +A Z +B X +C Z +B Y +A X +C Y +A Z +C Y +B Y +B Y +B Y +C Y +B Y +B Y +C X +A Z +A Z +B Y +C Y +C Z +C X +A Z +C Y +B X +B Y +A X +B Y +A Z +A Z +B Y +B X +C Z +C X +B Z +A Y +B Y +B Z +C Y +A Z +B X +C Y +B Y +C Z +B Z +A Y +A X +C X +B Y +C Y +A X +A Z +B Y +A Y +B Z +C X +B Y +C Y +C X +A Z +A Y +A Z +B Y +C Z +B X +A X +B Y +B Z +A Z +C Y +C X +A Z +C Y +C Z +B X +A Z +B X +A Z +A Z +C Y +B Z +C Y +C Y +B Y +C X +B X +A X +A Z +C Z +B X +B X +B X +B Z +B Y +B Z +C Y +B Y +C Y +C Z +A Z +A X +B Y +B Y +B Y +B Y +C X +B Y +B Y +A X +C X +B Y +C Z +C Y +A Z +A Y +B Y +C Y +B Y +C X +C X +B Y +B Y +B Y +C Y +A Z +A Y +C X +A Z +A Z +B Y +C X +C Y +B Y +B Y +C Y +C X +B X +C Y +B X +A Z +B Y +C X +B X +C Y +C Y +A Z +B Y +A Z +C Y +A Z +A Z +C Z +C X +C Y +A Z +C Z +A Z +B Y +A X +B Y +B Y +A Z +C X +B Z +B Y +C X +A Y +B Y +A Z +C Z +A Z +A Z +A Z +B Y +B Y +B X +B Y +B Y +B Y +C Z +B Y +A Z +C X +C Z +A Z +C Z +C Y +B Y +C Y +B X +C Y +B Y +A Z +B Y +C X +B Y +A Z +C Y +B Y +C Y +C Z +A X +B X +C X +B X +A X +B Y +A X +C Z +B Y +C Z +B Y +B Y +C Z +B Y +A Y +C Z +B Z +A Z +C X +A Z +A Z +B Y +B Y +C Y +C Z +C X +A Y +B Y +B Y +A X +A Y +B X +C Z +C Z +B Y +C Y +B Y +C X +B Z +A Z +A Z +B Y +A Y +A Y +A X +A Z +B Y +A X +B Z +C Z +B X +C Z +B X +B Y +A Y +B X +A Z +A Z +C Z +A X +C Z +B Y +A Y +C Z +C X +B Y +B Y +A X +C Y +C X +C Y +C X +A X +B Y +B X +B Y +C Y +C Y +C X +A Y +A Z +C Y +C Y +B Y +B X +B Y +B X +A Z +A Z +C Z +B Y +B Y +B Y +B X +C Z +A Y +A Z +B Y +B Y +B Y +B X +A X +B Y +C Z +A Z +A Z +C Y +C Y +B Y +B Y +A Z +B Y +A X +A Z +C Z +A Z +B Y +C X +B Y +A X +B Y +B X +B Y +B X +C X +A Z +C Z +C Z +B X +A Z +B Y +A Z +B X +B Y +A Z +C Y +B Y +A Z +A X +B Y +A Z +B Y +B Y +C Y +A Z +B Y +B Y +C Y +A Z +C Z +A Z +C Z +B Y +A Z +B Y +A Z +C Y +B Y +A X +A Z +B Y +B Y +C Z +C Z +C Z +B Y +C Y +A X +C X +A X +C Y +A Y +B X +B Y +C Z +B Y +B Y +B X +C Z +B Y +C X +A Z +C X +B Y +A X +C X +C Y +A Z +A X +C Z +C Z +B Y +C Y +A Y +A Z +A Y +C X +C X +B Y +C Y +B Y +A Z +C X +B Y +C Y +A X +A Z +C Y +B Y +B Y +A Y +C X +B Y +C Y +B Y +B X +A Z +C Y +C Y +A X +C X +A Z +C X +B Y +A X +C Z +B Y +C X +B Y +A Z +A Y +B Y +B X +B Y +C Y +C Z +B Y +A Z +A X +B X +C X +C Z +B Y +B Y +C X +C Z +A Z +C Y +C Z +B Y +A Z +B Y +B Y +C Z +C Z +B Y +C Y +B Y +A Z +B X +B Y +B Y +C X +A Z +A Z +B Y +C Y +B Y +A Z +A Y +A X +C Z +C Y +C Z +C Z +C Z +A Z +B Y +C Z +A Z +C Y +A Z +B Y +B Y +B Y +A Z +B Y +B X +B Y +B Y +B Y +B Y +B Y +B Y +A X +C Z +B X +B Y +C X +A Z +B Y +B X +C Y +B Y +C Y +B Y +A Z +B Y +C Y +A X +B Y +C X +B X +B Y +C Z +B X +C X +C Y +C X +C Y +C X +A Z +C X +B Y +A Z +B X +A Z +B X +B X +A Z +C Z +A Z +B X +B Z +C X +C Y +A X +A Z +B X +C Y +A Z +C Z +B Y +B Y +C Y +B Z +B Y +B Y +C Y +C Z +B Y +A Z +A X +B X +B X +C X +A Z +C Y +B Y +B Y +A Z +B Y +A Z +A Z +B Y +B Y +B Y +B Y +C X +B Y +B X +C Z +B X +C X +B X +B Y +B Y +B Y +A Z +B Y +A X +A Y +C X +B X +B Y +B Y +C Z +A Y +C Z +C Y +A Z +C Z +C Z +B X +B Y +A Z +B Y +C X +C Y +C Y +B X +B Y +B Z +A Y +A Z +C X +A X +B X +C X +B Y +B Y +B Y +B X +C X +B Y +A Z +A Z +A Y +B X +C Y +C Z +A Z +A Z +B X +A Z +C Y +B Y +A X +B X +A Z +B Y +B Y +B Y +B Y +C Z +C Z +A Y +B Y +C Z +C Z +B Y +B X +A Z +C Y +C X +A Z +A Z +C Y +C X +C Y +A Y +B Y +C X +B Y +B X +C Z +C X +C Y +B Y +B Y +A Z +B Y +C Z +C Y +B X +B Y +A Z +A Z +B X +B Y +A X +A Z +B Y +B Y +B Y +B Y +B Y +C Y +B Y +B Y +C Y +B Y +B Y +C Z +B Y +A X +C Y +B Y +A Z +B Y +C Z +C Z +C Y +A Y +B Y +A Z +A X +C Y +C Z +C Y +C Z +C Z +C Y +B X +B Y +B Y +C Z +C X +A Y +C Y +B Y +B Y +A Y +A Y +C X +C Y +A Z +A Z +A X +B Z +B X +A X +A Y +A Z +B Y +C Y +B X +B Y +B Y +C Z +C X +B Y +B Y +B Y +B Y +C Y +B Y +B X +C X +C Y +B Y +A Z +A Y +A Z +C Z +C Y +A Z +A Z +B Y +B Y +C Y +A X +B Y +A Z +B Y +A Z +B Y +B X +C X +C Y +A Z +A Y +B Y +C X +A Z +B Y +A Z +C Y +B X +B Y +B X +C Z +C X +B Y +A Z +B Y +B X +A X +C Z +C X +A Z +A Y +A X +A Z +A Z +A Z +C Y +A Z +B Y +A Z +A Z +C Z +B X +B Y +B Y +B Y +B Y +A Z +B Y +C Y +A Z +A Y +B Y +B Y +C Y +C Y +A Z +C Z +A Z +B Y +B Y +A Z +A X +A Z +A Z +C Y +C Z +A Z +C X +A X +B Y +C Y +C X +C Z +B Y +C Y +A Z +A Z +C Z +A Z +A Z +A X +B Y +C Y +A Z +C X +C Y +B Y +C X +B X +B Y +C Y +A Z +A Z +A X +B Y +A Z +B Y +B Y +C Z +C Z +A X +A Y +B Y +C Z +B Y +B Y +C X +A Z +C Z +A X +B Y +A Y +B Y +C Z +B Y +C X +B Y +B X +B Y +B Y +C Y +B X +B Y +A Z +A Z +B Z +A Z +B Y +B Y +A Y +A Z +C Z +C Y +B X +B Y +C Y +B X +C X +B Y +C X +A Z +B Y +B Y +B Y +C Y +B Y +B Z +A Z +B Y +A Z +C Y +B Y +B Y +B Y +B Y +C Z +B Y +B Y +B Y +A Z +C Z +B Y +B X +A Z +C X +C Y +C Z +B Y +A Z +C Y +A Y +A X +C Y +A X +A Z +A Z +B X +B Y +B Y +C Y +B X +B Y +A Z +B X +B Y +C Y +B Y +C X +A Z +A Z +A Z +A Z +C Z +A Y +C Z +C Z +C Z +B X +B Y +B X +A Z +A Y +B Y +A X +C X +C X +B Y +B Y +B Y +A X +A X +B Y +C Z +B Y +A Z +C Y +B Y +B Y +A Z +C Y +C Z +A Y +A Z +B Y +C X +C X +A Z +B Y +C Y +A Z +A Z +C Z +C X +B Y +C Z +C Z +B Y +A Z +A Z +B X +C X +B Y +C Y +B Y +C Y +B Y +B Y +A Z +A Y +B X +C Y +B Y +C X +C X +C Y +A Z +B Y +C Y +B Y +C Y +B Y +A Y +B Y +A Z +C X +C Z +C Z +C Y +B Y +C Y +B X +B X +A X +B Y +A X +B Y +A Z +C X +B Y +A Z +B X +B Z +B Y +B Y +C Y +B Y +A Z +B Y +C Y +C Z +A Z +C Z +B Y +B Y +B Z +A Z +B Y +C Z +B X +A Z +A X +B X +B Y +A X +B Y +C Y +A Z +A Y +B Y +A Z +B Y +A Y +B Y +C Z +C Z +C Y +C Z +B Y +A Z +B X +B Y +C Y +B Y +C Y +C Y +A Z +A Z +C X +A Y +C Z +B Y +B Y +B Y +C Y +B X +C Y +B Y +A Z +A Y +B Y +B Y +B Y +C X +B Y +C Z +A Y +B X +A Z +A Z +C X +B Y +B Y +A Z +A Y +A Y +C Z +A Z +A Y +B Y +C X +A X +A Y +B Y +A X +B Y +B X +C Y +C Z +C X +B Y +C Y +A Z +B X +A Z +B Y +B Y +B Y +C Y +B Z +C Z +C Y +B Y +C Y +B X +A X +B Y +B Y +A X +C Y +C Y +C Z +B X +A Z +C X +A Z +A Z +C Z +C Y +B Y +C Y +C X +A Z +C Z +B Y +A Z +A Z +C Z +A X +B Y +B Y +C Y +A Z +B X +B X +B X +B Y +B Y +B Y +B Y +A X +B Y +B Y +B X +C X +A Z +A Z +A Z +A Z +B Y +A Z +A Z +B X +A Z +C Y +B Y +B Y +B Y +B X +C Z +A Z +B Y +C X +A X +C Z +B Y +C Y +C Z +A Y +C Z +C X +C Y +B Z +B Y +B Y +B Y +A Z +C Z +A Z +A Z +C Z +B X +C Z +C Y +B X +B Y +C Y +B Y +B X +A Y +B Y +A Z +A Z +B Y +B Y +B X +B X +B X +B Y +A Y +C X +C Y +B Y +C X +B X +A Z +B Y +C X +B Y +B Y +B Y +B Y +A Z +B Y +C Z +B Y +C Z +A X +A Z +C Y +B Y +C Z +B Y +A Y +C X +C X +C Y +A Z +B Y +C X +B Y +B Y +A X +C X +A Z +C X +A Z +B Y +C Y +B Y +B Y +C Y +A Z +A X +C X +B X +B Y +B Y +A Y +B Y +B Y +C X +A Z +B Y +A Y +B Y +B Y +B Y +C Y +B Y +C X +B X +B X +C X +A Z +C X +C X +C Z +B Y +B Y +B Y +B Y +C Z +B X +B Y +B Y +A Z +A X +A Y +A Z +C Y +B Y +B Y +C X +B Y +B Y +B X +A Y +C Y +B Y +B Y +B Y +A Z +A Z +B X +C Y +B Y +A X +B Y +B Y +B X +B Y +A Y +C X +B Y +C Y +C Z +A Z +A Z +C Z +C Y +A Z +B Y +B X +B Y +B Y +C Z +B Y +A Z +C X +B Y +A Z +B Y +B Y +B Y +C X +A Z +A X +C Z +B Y +A Z +C Y +A Y +B Y +A Y +B Y +C Y +C Z +B Y +A Z +A Z +B Y +A X +C X +C Z +C X +B X +C Z +B Z +B Y +B X +C Z +B Y +C Y +C Y +A Z +B Y +B Y +B Y +B Y +C Y +A Z +B Y +A Z +C Z +A X +A Z +B Z +A Z +C Y +B Y +C Z +B Y +C Z +A Z +C Z +B Y +B Y +B Y +A Z +B Y +B X +B X +B X +A Z +C Z +C Y +B X +C Z +A X +B Y +C Y +B Y +B X +B Y +A Z +A X +A X +B Y +C Y +C Y +B Y +B Y +A Z +C Y +A X +A Z +C Y +A Z +C Z +C Y +A Z +C Y +C X +A Z +B X +B Y +A X +C Z +C Z +B X +C X +B Y +A Z +C Z +C Y +C Z +C X +C Z +A X +C Z +B X +C Y +C Z +B Y +C X +A Z +A Y +B Y +A Z +B Y +B Y +B X +C Z +B Y +B Y +B X +B Y +C Y +C Z +B X +B Y +C Z +B Y +B Y +B Y +B Y +A Z +C Z +C Y +B X +B X +B Y +B X +C Y +C Y +A Z +A Z +B X +B Y +B Y +C Z +C Z +B Y +A Z +C X +C Y +C X +B Y +B Y +C Z +C X +B Y +C Y +C Z +C Y +C X +C Y +B X +B X +B Y +B Y +B Y +C Z +B X +B Y +C X +C Y +C Y +C X +A Z +B Y +C Y +C Z +B Y +C Y +B Y +A Y +A Z +C Z +C Z +C Y +A X +C X +C Z +C Y +C Z +B X +C Z +B Y +C X +C Y +C Y +A Z +B Y +A Z +B Y +A X +C Z +A Z +C Z +B Y +B Y +B Y +A Z +A X +B Y +B Z +B Y +B Y +A Z +B Y +B Y +C Z +B Z +A Z +C X +B Y +A Y +B Y +C Y +C Y +C X +B Y +B Z +C Y +B Y +A Y +C X +A Z +A Z +B X +C Y +B Y +B Z +A Z +A Z +B Y +A Z +A Z +A Z +C Y +A Z +A Y +A Z +C Z +C Y +B Y +A Z +B X +B Y +A Z +A Y +B X +B Y +C Y +C Z +C Y +B X +C Y +B Y +B Y +A Z +A Z +B Y +C X +A X +A Z +A X +A X +C Y +B Y +C Z +A Z +B Z +B Y +B Y +B Y +C X +B Y +C Z +B Y +B Y +C Z +C Z +A Z +A Z +A Z +A Z +C Y +A Z +A Z +B Y +B Y +A Z +A Z +C X +C Y +A Z +B Z +B Y +C X +C X +B Y +C X +B Y +C Y +C X +B Y +C Z +A X +B Y +B X +B Y +C Y +B Y +A X +C X +B Y +B Y +B X +B Y +A Z +A Z +A Z +A Z +B Z +B Y +B Y +C X +A Z +C Y +B Z +A X +B Y +B X +B Y +A X +C X +B Y +B Y +A Z +B Y +C Z +A Y +B X +C X +B Y +B Y +A Z +C X +C Y +B Y +C Y +C Z +A Y +A Z +B Y +B Y +A Z +C Y +B Y +C Y +C X +C X +C Y +C Z +A Z +C X +B Y +A Z +B Y +C X +B Y +B Y +A Z +A Z +C X +B Y +A Z +B Y +A Y +B X +B Y +B X +A Y +B Y +B X +B Y +A Z +B Y +C Z +B Y +B Y +B Y +A Y +B Y +C Z +B X +B Y +A X +A Z +B Y +A Z +B X +C Y +B Y +B Z +C Y +B Y +C Y +C X +C X +C Z +B Y +B Y +B Y +A Z +B X +A Z +C Z +B Y +A Y +B Y +C Y +A Z +B Y +A Y +B X +B Y +C Y +C Y +A Z +A Z +B Y +C Y +C Z +A Z +A X +B Y +B Y +B Y +B Y +A Z +C Y +A Z +B Y +B Y +C Z +A Z +A X +C Y +B Y +B Y +A Z +B X +C Z +C Y +C Z +C Y +B Y +A Z +A Z +B Y +A Z +A Z +B Z +C X +C X +B Y +C Z +A Z +B X +A X +A Y +C Y +C Y +A Z +C Y +B Y +A Z +A Z +C Y +B Y +A Y +B X +C Z +B Y +B Y +A Z +B Z +C Z +B Y +B Y +B Y +A Y +C Y +A Z +A X +B Y +B Y +B Y +C Z +A X +B Y +B Y +C Y +B X +B Y +A Z +B Y +A Z +A Y +C Y +B Y +B Y +A Z +B X +A Z +A Z +A Z +B Y +A Y +C Z +B Y +B X +B Y +B Y +B Y +B Y +B Y +A X +C Z +B Y +B Y +B Y +C Z +B X +A Y +B X +C Z +B Y +C X +C X +A Z +B Y +B Y +A Z +C X +C X +A Z +B X +B Y +C X +C Z +A X +B X +B Y diff --git a/day02/solution.nim b/day02/solution.nim new file mode 100644 index 0000000..8a794d3 --- /dev/null +++ b/day02/solution.nim @@ -0,0 +1,51 @@ +import std/strutils +import std/sequtils + +let content = readFile("./input.txt").strip().split("\n") +let rounds = map( + content, + # Split line into pair of characters + proc(round: string): tuple[other: char, self: char] = + var splitted = round.split(" ") + (splitted[0][0], splitted[1][0])) + +# example: rounds = [('A', 'Z'), ('C', 'Y')] +# echo rounds + +proc solve(dScore: array[3, array[3, int]]): int = + var score = 0 + for round in rounds: + let + i = ord(round.other) - ord('A') + j = ord(round.self) - ord('X') + score += dScore[i][j] + + return score + +let pt1 = [ + # A = Rock + # X Y Z + [1 + 3, 2 + 6, 3 + 0], + # B = Paper + # X Y Z + [1 + 0, 2 + 3, 3 + 6], + # C = Scissors + # X Y Z + [1 + 6, 2 + 0, 3 + 3], +] + +echo solve(pt1) + +let pt2 = [ + # A = Rock + # X Y Z + [3 + 0, 1 + 3, 2 + 6], + # B = Paper + # X Y Z + [1 + 0, 2 + 3, 3 + 6], + # C = Scissors + # X Y Z + [2 + 0, 3 + 3, 1 + 6], +] + +echo solve(pt2) diff --git a/day03/example.txt b/day03/example.txt new file mode 100644 index 0000000..f17e726 --- /dev/null +++ b/day03/example.txt @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw diff --git a/day03/input.txt b/day03/input.txt new file mode 100644 index 0000000..a30889c --- /dev/null +++ b/day03/input.txt @@ -0,0 +1,300 @@ +hqBqJsqHhHvhHHqlBvlfpHQQwLVzVwtVzjzttjQVSjMjwL +gRTRnCRsFNGbTzLjwcSTMmSz +dGgsRWPGdWgZJqBBqhfpPq +HNCNJHCWJRRLqNJWlfrrrwsmlwGmmf +dddvLdLjdDvjvswlmGwlZQtjrt +dvcpbLVcvNJJHNPHSp +QDprSpLQRLQrQDmQcQFZjbbhZwdRsRFbbBss +gWGGPgNvJlgJzDlNGHCGPNZZgFBbsjbFFBwZwfhdZbZB +lHTlGMHlGCPNvClzGzJHvGcrMcVtLqMLcrrQVcVDrqrm +SrBpJFfldlFNslFJBZwsmwgVGGsCCVmZZD +jLtjvzLQMtWjbbQvDZZwGRJGgwggGZgv +MzqqjznQPqnnjznnctnFlSddPfHflhfBJFNdHd +mPNNGVCRngnSbgNw +WqsqlTssgvqvZWZzhsTzWhScdHtfJJnfbtSJwfczdtSS +sqTvhpqQvWZQLmDpDGMDGrgL +DQRcLQVLbbcbrFPcRtTBBBJnTZrrnmZTrMgJ +slGjjjdlhMfvdMQTvg +jlzNhWHhhWjHlwwwGLDSDtPQVtRzR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JhnnfrfsJrCNffvspRrPPFMbPMRRPPMZgZHR +FnJZnssHvMdJWJpW +mlDlllGrSGmttwlGvZgrzZNWgggzTzdT +bCltZCthtRcbcFbjFL +JGmHrJwGzzpllRZdzZLRcW +htbPSbVtFbbgjhffgPSfTVSDcHDDDLWscRdsZjdZcRssWc +vhfFbFvVHbtTVgFPhmJBCvBNrqBBrGCqQB +BcNQcvcBchSQNccLLvhTqbJZTrHrrrzzqTZMZMFZ +tpHDsnDRslllCCHtwnpsfjRgrJrVMfMmMrFrzVJFzrVZbZrr +tnDpjCwPLNSPdhPH +qnjvvBwBhSSFPgDQLVVDqgLr +WbszTbHTbsbHJWHLLMVZmJPQDrvmZL +ctlRbtCWWtvlSfjljjhBnBNB +TsnvssDDQlRbzMzjDMqHwq +tSGjZCfFZtCFLtVGWGZFbcqwHbhWdbzbwHbdwbdw +ZGBFJFZVBLjStZPBBZLRvlmsPTvsgrrnrTllvs +PgQdNsQFsdNwWqQBsQrTrTLpbrnTpGngnbTG +hCzzMJVDmfzmBDMCfSfhTMGcnpnTcjGrpjbMGjbL +CVVfvCflSHNHvPdBHW +DwlMjMNjStgmthMghg +PTlpHnJJTcZvTTbHZWZTvpqdHhmLgrgdfrhLLsmshmsLts +vncqTbPqcpCnbCPvccZbDBCGzzNBwjDlVVGFjjVR +QsdGGCztZVRddPgndf +DrNNBbwNHNwlbjFbbCNjNwDWWDPPVfDMgfmVMfnMWmmP +rvJBbbBNcLCtJZQL +NfLlqLhbNPddLPqLhpgHwFFwFHHTwRHWwPFTrT +MSMSCnjBnBjCscjVDVljTvHmmWnrwTrwFTrvTWTT +JCMMBzDMJcZZCjDzSBDNJgdfdQlqlLNdhgGLhp diff --git a/day03/solution.nim b/day03/solution.nim new file mode 100644 index 0000000..6df88f2 --- /dev/null +++ b/day03/solution.nim @@ -0,0 +1,47 @@ +import std/strutils +import std/sequtils +import std/sets + +proc Points(c: char): int = + if c.isLowerAscii(): + return ord(c) - ord('a') + 1 + else: + return ord(c) - ord('A') + 27 + +proc part1(content: seq[string]): int = + let ruckshacks = map( content, + proc(line: string): tuple[first: string, second: string] = + let pivot = int(line.len()/2) + (line[0 .. pivot-1], line[pivot .. ^1]) + ) + + var score = 0 + for ruckshack in ruckshacks: + let + uniqFirst = toHashSet(ruckshack.first) + uniqSecond = toHashSet(ruckshack.second) + + var c = toSeq(uniqFirst * uniqSecond)[0] + score += Points(c) + + return score + +proc part2(content: seq[string]): int = + assert(content.len() mod 3 == 0) + + let ruckshacks = content + var score = 0 + for i in countup(0, ruckshacks.len()-1, 3): + let + uniqFirst = toHashSet(ruckshacks[i]) + uniqSecond = toHashSet(ruckshacks[i+1]) + uniqThird = toHashSet(ruckshacks[i+2]) + + var c = toSeq(uniqFirst * uniqSecond * uniqThird)[0] + score += Points(c) + + return score + +let content = readFile("./input.txt").strip().split("\n") +echo part1(content) +echo part2(content) diff --git a/day04/example.txt b/day04/example.txt new file mode 100644 index 0000000..9f9e9cf --- /dev/null +++ b/day04/example.txt @@ -0,0 +1,6 @@ +2-4,6-8 +2-3,4-5 +5-7,7-9 +2-8,3-7 +6-6,4-6 +2-6,4-8 diff --git a/day04/input.txt b/day04/input.txt new file mode 100644 index 0000000..5304059 --- /dev/null +++ b/day04/input.txt @@ -0,0 +1,1000 @@ +36-92,35-78 +26-31,25-27 +17-72,16-71 +3-77,76-90 +20-22,21-87 +5-75,6-75 +42-44,43-95 +51-73,50-52 +81-89,80-81 +7-58,47-58 +72-91,20-92 +27-64,51-64 +5-94,94-95 +88-93,88-89 +7-45,46-91 +30-40,29-29 +81-90,80-90 +4-71,4-71 +68-83,65-84 +1-4,3-79 +94-95,35-82 +30-84,31-97 +6-82,81-86 +88-88,4-89 +41-97,40-89 +95-99,34-94 +18-56,18-56 +53-64,22-53 +5-9,9-71 +18-41,40-66 +38-39,38-78 +23-99,22-94 +34-54,34-53 +33-76,85-94 +72-91,63-79 +33-94,93-94 +56-82,20-56 +60-85,60-86 +31-76,31-33 +29-79,78-80 +9-9,66-69 +6-97,6-75 +40-78,39-77 +14-30,14-15 +91-94,88-98 +1-23,10-23 +9-84,7-9 +75-76,75-98 +45-87,45-46 +11-11,11-11 +16-64,64-65 +60-60,20-61 +48-81,93-94 +5-48,32-47 +37-75,74-75 +13-76,13-13 +15-93,92-96 +41-86,86-96 +48-92,64-91 +1-9,2-97 +43-56,55-55 +7-99,98-99 +98-99,1-99 +15-97,7-99 +76-76,32-77 +71-76,76-77 +13-28,13-29 +38-69,42-50 +49-49,50-77 +68-84,71-83 +26-51,32-51 +12-40,39-63 +21-92,9-88 +7-65,65-69 +56-76,56-77 +40-62,62-62 +35-96,92-95 +37-99,12-86 +94-98,4-81 +32-38,34-39 +11-94,24-93 +1-97,1-60 +7-77,7-59 +62-81,80-96 +38-83,82-82 +44-44,43-98 +22-23,22-62 +28-97,16-97 +53-88,67-88 +2-2,56-97 +41-72,71-72 +78-80,47-79 +1-1,2-41 +23-99,33-98 +33-98,61-97 +80-95,80-80 +8-90,8-91 +4-90,50-89 +94-94,3-95 +3-83,2-99 +45-52,12-44 +22-65,66-71 +9-72,72-73 +2-62,2-82 +40-61,30-60 +57-87,25-56 +76-78,77-77 +16-88,87-88 +14-77,73-77 +37-90,36-38 +10-75,11-11 +37-99,3-97 +47-48,45-47 +6-92,7-91 +60-74,60-61 +20-29,8-21 +95-96,47-95 +63-70,31-63 +6-97,6-76 +19-91,19-92 +50-92,49-50 +17-96,18-97 +3-4,3-93 +13-51,1-13 +34-87,23-33 +2-99,98-98 +4-6,7-76 +46-60,36-45 +50-80,25-51 +60-61,24-61 +97-98,3-98 +33-34,83-99 +30-76,22-77 +27-72,72-94 +47-96,31-47 +26-90,11-27 +47-87,3-72 +86-91,9-87 +32-79,78-79 +72-95,94-94 +88-96,8-89 +11-84,12-98 +5-8,8-29 +6-38,86-86 +14-33,5-33 +20-95,39-94 +6-99,12-93 +52-91,52-90 +3-99,2-72 +72-96,56-90 +7-84,7-8 +20-37,14-37 +26-74,74-75 +40-54,4-71 +42-42,93-94 +53-69,23-52 +20-96,95-96 +1-18,18-83 +2-3,2-69 +36-87,87-87 +8-94,8-94 +59-99,59-60 +15-35,11-35 +6-26,5-26 +7-12,11-80 +79-79,79-79 +2-47,46-47 +76-96,96-97 +12-79,11-77 +45-71,46-94 +62-63,62-94 +30-84,84-85 +9-35,9-13 +18-60,18-61 +13-90,13-85 +2-38,1-2 +76-81,24-54 +48-49,48-95 +59-92,58-69 +72-72,15-73 +15-16,15-99 +79-85,60-86 +58-58,46-59 +55-60,3-54 +22-26,26-58 +6-86,7-85 +66-76,47-66 +52-73,52-53 +21-76,20-77 +44-73,16-77 +29-80,30-30 +15-47,14-16 +3-75,1-3 +55-61,9-56 +37-55,36-82 +64-83,83-84 +9-91,41-89 +22-86,33-85 +6-19,5-34 +80-92,93-93 +99-99,85-98 +96-99,14-97 +2-72,5-59 +93-94,56-94 +34-83,34-86 +33-34,34-73 +17-84,18-44 +82-83,26-83 +3-85,18-84 +88-88,9-88 +93-93,27-94 +12-13,12-14 +8-90,8-42 +78-86,41-77 +63-79,80-81 +15-66,14-16 +77-77,28-76 +9-96,8-10 +19-78,77-79 +13-95,72-93 +13-49,14-14 +84-85,84-95 +25-37,25-37 +49-93,49-91 +24-78,5-38 +2-92,2-92 +17-90,16-90 +8-50,8-50 +76-99,76-98 +71-86,77-86 +70-71,54-70 +8-84,39-84 +40-58,55-58 +8-87,1-9 +5-7,6-85 +25-97,24-25 +9-97,14-96 +17-48,10-47 +81-87,30-80 +3-83,83-84 +2-7,6-42 +20-70,70-93 +67-85,17-61 +7-18,6-20 +21-73,20-22 +80-81,18-79 +43-95,44-96 +38-45,44-44 +15-91,90-91 +32-44,34-43 +24-93,24-25 +10-16,11-12 +22-92,61-92 +3-7,6-73 +72-79,71-74 +34-47,34-46 +56-96,75-82 +31-48,48-81 +54-81,53-82 +2-91,93-97 +41-74,10-40 +51-63,52-86 +80-90,75-90 +86-87,10-87 +80-94,84-94 +46-47,9-47 +20-77,78-92 +38-38,17-37 +30-76,5-30 +6-58,58-77 +10-73,74-85 +1-96,2-31 +64-73,4-74 +60-79,59-77 +4-98,8-89 +7-9,8-78 +4-6,5-95 +29-93,53-90 +32-94,20-33 +78-91,38-79 +10-95,96-99 +5-97,86-96 +6-65,5-64 +28-71,7-72 +15-54,45-53 +3-87,46-99 +1-90,40-90 +44-86,19-86 +3-94,93-94 +92-93,1-93 +93-93,42-94 +90-97,21-91 +16-94,16-62 +20-27,79-86 +28-28,29-39 +30-94,29-30 +28-68,76-79 +54-73,54-55 +35-36,35-87 +5-42,43-47 +10-90,8-91 +15-74,23-49 +16-97,1-98 +2-82,82-89 +1-3,2-86 +16-87,15-86 +9-10,9-60 +14-90,10-14 +36-85,5-85 +36-41,37-89 +50-50,15-50 +82-86,85-86 +28-66,28-32 +15-84,14-14 +32-69,31-33 +31-95,30-96 +60-85,61-92 +10-87,86-87 +96-99,5-97 +97-97,39-96 +34-35,3-35 +51-88,33-88 +14-49,48-90 +4-51,52-56 +7-76,31-75 +3-99,3-87 +29-86,29-75 +61-64,61-65 +85-97,13-86 +59-67,6-58 +51-97,44-50 +21-64,64-93 +9-56,10-81 +20-51,50-51 +33-87,32-87 +18-79,5-90 +51-51,22-52 +24-83,21-25 +79-93,24-94 +14-14,13-83 +43-49,44-50 +72-72,10-73 +14-57,35-57 +4-63,3-4 +4-93,26-91 +26-93,25-26 +33-35,33-43 +36-87,87-92 +27-69,6-70 +38-60,30-39 +96-96,1-95 +2-96,99-99 +16-87,88-88 +41-52,41-51 +61-77,76-82 +9-77,3-10 +39-50,38-51 +12-63,12-62 +17-30,18-76 +22-86,22-23 +3-43,2-44 +21-66,66-66 +3-64,2-2 +60-65,60-65 +7-42,74-96 +81-98,38-98 +16-24,17-23 +95-97,32-96 +23-38,23-37 +42-54,40-46 +16-18,13-17 +1-81,3-63 +16-17,17-50 +82-87,88-97 +6-47,5-48 +8-81,92-94 +95-97,11-96 +23-94,22-86 +6-35,3-56 +7-93,90-92 +6-49,3-6 +24-86,86-86 +67-78,67-78 +11-98,10-96 +87-88,17-88 +8-98,99-99 +15-73,72-73 +1-60,60-60 +39-45,33-45 +77-95,41-76 +5-23,24-99 +96-98,97-97 +18-55,55-56 +97-98,60-90 +33-34,13-34 +7-96,8-96 +7-32,46-61 +75-93,20-96 +30-99,29-31 +4-99,3-97 +3-30,29-30 +40-40,39-63 +48-49,48-60 +22-24,6-22 +28-28,3-28 +64-64,37-63 +29-48,5-48 +20-37,19-36 +77-77,19-77 +18-85,2-19 +99-99,30-80 +35-36,31-35 +28-79,75-98 +26-94,26-95 +22-97,73-96 +42-42,5-41 +6-8,7-99 +10-14,13-14 +39-72,39-73 +12-90,89-90 +93-94,12-94 +50-88,89-93 +47-88,88-89 +39-64,38-38 +15-79,78-79 +28-32,32-33 +50-65,51-51 +7-79,6-64 +33-49,32-34 +82-95,75-96 +6-14,4-9 +95-95,10-96 +14-51,3-15 +97-98,21-98 +39-61,53-61 +68-69,37-68 +15-73,73-95 +42-70,43-83 +1-60,60-61 +6-11,11-94 +10-79,87-93 +36-40,41-41 +3-17,3-43 +4-81,4-82 +90-91,6-90 +2-3,5-68 +20-98,74-97 +4-86,3-85 +47-49,23-48 +26-89,26-90 +31-42,42-47 +57-81,39-58 +17-87,18-96 +9-77,9-78 +79-88,80-84 +30-84,83-83 +15-89,15-88 +11-11,10-94 +59-82,27-59 +8-78,14-33 +46-95,85-94 +93-97,92-94 +4-34,2-3 +34-80,30-82 +48-83,27-49 +47-99,47-48 +27-51,51-56 +48-49,35-48 +31-51,42-51 +96-97,19-96 +43-44,20-44 +76-76,13-75 +5-90,27-90 +26-27,27-51 +47-54,49-95 +69-72,4-73 +94-98,68-95 +1-2,3-86 +25-90,24-26 +28-90,89-89 +91-91,74-91 +56-95,40-57 +55-92,28-54 +28-34,27-35 +85-87,28-86 +8-10,10-98 +45-45,44-44 +31-83,27-59 +67-84,2-68 +17-69,51-69 +49-52,34-53 +22-81,2-23 +95-96,2-96 +82-99,17-82 +40-57,40-58 +9-40,40-40 +1-2,3-68 +1-97,90-97 +2-20,21-34 +2-2,1-92 +84-86,2-86 +7-92,97-99 +2-6,5-42 +1-52,1-52 +98-99,1-98 +38-80,29-43 +39-69,39-39 +97-99,3-98 +70-71,8-71 +26-52,25-38 +8-92,91-92 +12-49,13-27 +7-95,94-95 +91-99,15-92 +19-45,18-19 +75-76,76-97 +59-74,13-86 +3-3,2-3 +41-60,53-59 +75-99,29-96 +66-68,18-67 +3-91,3-95 +33-98,32-34 +5-78,10-77 +55-95,54-59 +6-81,6-81 +78-94,52-75 +20-93,10-94 +12-37,83-99 +46-93,92-99 +17-79,8-94 +45-99,46-46 +73-90,68-73 +82-83,58-83 +15-88,90-94 +66-96,18-65 +12-87,61-86 +35-85,36-84 +96-96,28-95 +82-95,2-83 +1-2,2-99 +59-88,59-60 +54-90,53-74 +35-48,57-57 +16-28,16-29 +35-45,36-36 +25-39,24-58 +19-74,27-75 +35-73,31-36 +16-76,6-87 +8-99,7-97 +1-1,1-89 +9-74,10-75 +12-74,11-56 +80-81,2-80 +13-97,19-92 +43-83,82-89 +55-59,60-60 +20-79,98-98 +61-62,61-86 +35-82,93-97 +21-42,43-43 +49-94,43-50 +5-81,98-99 +5-95,1-95 +6-80,91-97 +26-85,11-25 +34-68,19-48 +3-99,3-87 +81-81,19-81 +8-47,8-48 +46-70,46-71 +13-73,46-73 +13-83,14-82 +6-97,96-99 +19-33,18-34 +30-99,2-99 +50-84,1-84 +6-97,6-96 +96-96,6-96 +10-96,9-94 +38-39,38-43 +18-94,19-97 +86-86,87-91 +8-98,8-97 +84-86,78-85 +23-71,72-72 +5-99,98-98 +26-75,26-75 +87-87,20-88 +11-85,7-8 +52-61,45-62 +42-97,42-97 +25-89,21-24 +95-96,4-93 +66-69,67-68 +2-93,94-96 +8-9,9-81 +72-97,21-98 +59-75,58-60 +14-16,15-96 +71-71,70-71 +10-79,3-10 +54-54,53-98 +2-4,3-69 +14-66,14-67 +16-17,16-65 +27-99,76-99 +19-94,95-97 +3-83,83-84 +36-57,31-56 +34-83,33-83 +56-67,66-88 +30-70,17-31 +24-80,79-80 +43-52,42-43 +10-65,66-68 +50-69,1-70 +10-10,10-33 +10-99,9-98 +86-96,85-85 +30-65,31-60 +18-81,17-19 +12-84,49-71 +19-98,18-18 +3-67,4-68 +88-99,69-99 +11-87,10-11 +98-98,37-85 +8-90,47-89 +2-43,67-79 +5-5,4-97 +31-94,93-96 +13-83,14-14 +72-85,71-84 +51-53,26-52 +3-58,57-62 +41-58,41-58 +29-84,30-56 +89-98,21-90 +51-97,50-94 +8-96,8-95 +1-4,4-81 +23-51,52-95 +29-61,8-60 +11-15,1-5 +2-75,7-75 +42-66,46-66 +53-93,53-94 +5-99,3-6 +2-5,6-13 +65-97,46-99 +51-72,50-90 +36-65,64-66 +1-4,4-94 +7-8,7-86 +4-89,3-90 +61-98,60-62 +40-81,19-81 +28-73,27-73 +4-98,6-97 +63-73,63-89 +13-97,96-98 +5-13,13-88 +24-92,7-92 +15-31,14-28 +2-88,97-97 +11-45,11-45 +40-82,82-82 +51-51,50-60 +84-91,21-83 +71-98,71-97 +21-95,31-94 +1-97,1-41 +2-3,2-84 +3-4,4-91 +98-98,17-97 +15-15,16-84 +43-48,11-37 +13-83,11-15 +88-96,3-96 +55-91,24-55 +4-96,96-99 +66-82,80-80 +3-61,62-93 +99-99,11-70 +56-56,57-59 +40-40,39-99 +57-58,35-58 +36-95,94-94 +2-63,64-81 +18-24,24-62 +63-98,12-63 +81-81,18-80 +19-61,19-20 +11-18,11-22 +9-14,9-11 +6-7,6-85 +41-51,41-41 +18-43,17-19 +8-70,71-84 +76-76,11-75 +87-88,9-88 +55-73,54-56 +56-57,57-68 +4-11,11-88 +8-81,11-80 +25-70,71-71 +22-45,23-48 +14-84,5-95 +58-68,47-58 +17-66,38-66 +58-89,88-89 +7-28,14-27 +31-87,22-63 +92-96,39-91 +14-41,14-14 +62-65,3-61 +48-66,48-66 +4-95,2-96 +7-7,8-77 +17-50,18-51 +80-89,14-79 +28-50,28-89 +32-40,7-40 +19-77,18-19 +34-60,1-6 +33-50,51-91 +16-17,16-54 +29-45,19-32 +36-42,37-37 +1-95,3-87 +70-93,92-98 +4-11,46-79 +20-82,1-19 +40-41,2-42 +75-77,31-76 +8-14,14-78 +69-91,68-69 +9-63,77-89 +47-70,39-47 +3-98,97-98 +84-84,30-84 +9-9,10-95 +24-24,23-92 +27-95,21-95 +2-99,2-99 +38-59,54-59 +20-81,15-82 +6-73,13-73 +98-98,99-99 +18-92,17-19 +93-94,5-93 +13-99,13-14 +34-34,34-79 +12-88,87-96 +55-67,83-89 +6-30,1-31 +24-80,24-80 +5-90,16-91 +49-68,10-49 +11-14,13-92 +23-85,24-92 +67-81,67-68 +32-99,32-89 +85-86,35-84 +21-21,20-60 +25-85,25-84 +20-56,21-21 +6-9,9-71 +82-98,26-81 +37-37,15-38 +5-97,3-5 +11-18,19-26 +14-69,6-83 +51-73,50-75 +29-85,19-28 +8-59,5-60 +92-92,46-93 +8-57,7-9 +16-16,16-84 +10-32,10-11 +1-86,1-86 +26-98,19-91 +7-97,6-94 +41-81,42-80 +3-97,13-98 +24-25,24-87 +54-54,18-55 +49-49,33-50 +6-80,79-80 +38-95,38-95 +52-84,52-77 +6-92,1-6 +1-3,3-88 +6-71,2-5 +16-46,2-17 +79-86,15-80 +6-6,5-54 +8-41,11-40 +53-98,52-54 +2-79,1-3 +51-70,50-52 +55-55,56-69 +4-61,10-97 +75-92,12-76 +27-79,92-94 +6-55,5-7 +19-25,20-22 +79-92,65-93 +95-99,27-94 +23-88,23-88 +82-83,83-96 +2-94,2-74 +14-71,6-14 +6-14,5-7 +3-89,1-2 +48-82,13-26 +48-80,26-48 +43-93,92-92 +32-51,85-91 +3-5,5-90 +99-99,95-97 +38-39,38-88 +93-95,75-94 +15-64,14-16 +84-94,67-90 +22-47,48-80 +41-56,5-57 +2-80,7-79 +22-71,21-23 +21-49,20-22 +95-95,61-95 +56-57,57-58 +25-27,26-62 +52-76,41-61 +28-98,71-98 +74-93,4-93 +35-74,73-98 +4-57,3-57 +4-99,32-98 +8-75,7-75 +23-67,23-68 +15-15,15-56 +3-97,1-98 +10-90,91-91 +18-30,17-19 +10-38,1-90 +50-73,37-73 +40-91,92-95 +39-39,40-91 +86-87,7-87 +12-37,37-94 +78-87,14-50 +89-95,11-90 +60-98,4-94 +41-82,81-98 +66-92,67-67 +88-92,5-89 +86-91,85-86 +6-98,97-97 +34-87,95-95 +44-46,45-78 +7-87,17-87 +7-96,95-97 +15-75,76-85 +1-98,2-93 +3-55,50-54 +87-94,72-86 +19-70,19-63 +7-51,50-79 +3-73,3-73 +32-38,31-34 +2-99,98-98 +3-4,5-88 +16-37,38-38 +39-48,40-42 +65-77,65-77 +5-94,3-96 +28-89,97-98 +34-77,53-77 +24-54,25-28 +6-48,7-7 +6-38,3-6 +10-83,9-11 +26-65,64-84 +50-85,84-86 +36-91,37-92 +2-2,2-84 +4-6,5-83 +18-71,35-70 +5-85,5-64 +94-99,13-95 +1-32,2-9 +11-71,53-98 +99-99,18-97 +26-46,22-27 +39-78,91-93 +38-43,38-44 +14-76,15-54 +91-95,23-90 +7-55,3-55 +91-95,29-92 +10-23,9-59 +21-67,20-66 +17-27,20-26 +2-94,1-94 +16-97,13-97 +67-68,67-94 +81-83,27-82 +51-69,81-96 +79-81,57-80 +55-55,55-68 +34-96,34-95 +83-85,19-84 +4-81,3-80 +16-23,23-97 +45-74,46-74 +2-98,98-99 +37-59,35-59 +72-74,70-74 +16-91,91-92 +43-68,44-75 +4-77,7-92 +93-94,6-94 +18-92,93-94 +51-76,76-76 +17-42,41-79 +61-62,49-61 +19-77,9-9 +11-70,43-69 +21-62,53-61 +40-77,78-89 +10-55,10-46 +5-70,98-99 +19-21,20-86 +7-68,10-67 +2-24,3-3 +65-70,46-66 +1-78,2-77 +71-95,17-72 +25-88,88-89 +13-98,14-14 +7-81,7-8 +8-99,8-98 +13-97,14-97 +3-56,3-4 +89-99,29-73 +41-50,28-51 +76-88,76-87 +82-96,25-31 +30-41,8-42 +27-39,38-38 +46-71,46-71 +23-88,10-88 +28-83,28-84 +82-94,81-86 +99-99,1-99 +4-46,4-63 +7-68,67-99 +5-92,93-97 +91-95,3-89 +57-76,3-70 +1-89,53-88 +4-32,6-31 +75-76,2-76 +17-17,18-37 +43-90,89-94 +4-65,1-66 +88-91,90-91 +43-57,44-84 +2-95,2-94 +3-31,1-32 +12-94,30-93 +12-94,5-94 +35-54,34-54 +30-81,30-30 +51-53,52-98 +68-97,41-69 +32-94,19-31 +14-70,7-15 +1-99,41-98 +41-63,41-63 +88-88,27-87 +54-56,53-55 +26-26,27-71 +29-64,1-62 +4-54,1-92 +88-89,22-89 +15-88,15-16 +21-95,43-96 +12-13,12-27 +10-96,23-96 +82-83,22-83 +13-85,13-86 +77-83,4-65 +3-91,3-63 +73-98,73-98 +49-49,8-50 +3-96,4-4 diff --git a/day04/solution.nim b/day04/solution.nim new file mode 100644 index 0000000..8085445 --- /dev/null +++ b/day04/solution.nim @@ -0,0 +1,42 @@ +import std/strutils +import std/sequtils +import std/sugar + +type + # We use begin and length for Range representation to simplify calculations later + Range = tuple[begin: int, length: int] + Entry = tuple[first: Range, second: Range] + +proc solve(entries: seq[Entry], part2 = false): int = + var score = 0 + for e in entries: + var r: Entry + # Let first become the leftmost range. In case both ranges start at the same index, we consider the longest one to be first + if e.first.begin < e.second.begin or (e.first.begin == e.second.begin and e.first.length >= e.second.length): + r.first = e.first + r.second = e.second + else: + r.first = e.second + r.second = e.first + + if not part2: + if r.first.length >= r.second.length + r.second.begin - r.first.begin: + score += 1 + else: + if r.first.begin + r.first.length - 1 >= r.second.begin: + score += 1 + + return score + +func entryFromLine(line: string): Entry = + # Get tokens and parse them as integers + let tokens = map(line.split({',', '-'}), token => token.parseInt()) + # Init Entry + ((tokens[0], tokens[1] - tokens[0]+1), (tokens[2], tokens[3] - tokens[2]+1)) + +let + content = readFile("./input.txt").strip().splitLines() + entries = map(content, entryFromLine) + +echo solve(entries) +echo solve(entries, true) diff --git a/day05/example.txt b/day05/example.txt new file mode 100644 index 0000000..84933bb --- /dev/null +++ b/day05/example.txt @@ -0,0 +1,9 @@ + [D] +[N] [C] +[Z] [M] [P] + 1 2 3 + +move 1 from 2 to 1 +move 3 from 1 to 3 +move 2 from 2 to 1 +move 1 from 1 to 2 diff --git a/day05/input.txt b/day05/input.txt new file mode 100644 index 0000000..988dbdd --- /dev/null +++ b/day05/input.txt @@ -0,0 +1,512 @@ + [V] [C] [M] +[V] [J] [N] [H] [V] +[R] [F] [N] [W] [Z] [N] +[H] [R] [D] [Q] [M] [L] [B] +[B] [C] [H] [V] [R] [C] [G] [R] +[G] [G] [F] [S] [D] [H] [B] [R] [S] +[D] [N] [S] [D] [H] [G] [J] [J] [G] +[W] [J] [L] [J] [S] [P] [F] [S] [L] + 1 2 3 4 5 6 7 8 9 + +move 2 from 2 to 7 +move 8 from 5 to 6 +move 2 from 4 to 5 +move 1 from 4 to 5 +move 1 from 5 to 8 +move 5 from 9 to 2 +move 7 from 1 to 6 +move 7 from 3 to 8 +move 1 from 4 to 6 +move 2 from 5 to 6 +move 6 from 7 to 5 +move 2 from 2 to 4 +move 4 from 5 to 2 +move 10 from 8 to 1 +move 2 from 7 to 4 +move 4 from 2 to 8 +move 2 from 9 to 8 +move 1 from 8 to 4 +move 2 from 4 to 9 +move 5 from 8 to 2 +move 1 from 4 to 6 +move 1 from 8 to 9 +move 1 from 7 to 2 +move 2 from 4 to 2 +move 1 from 7 to 3 +move 13 from 2 to 1 +move 1 from 2 to 4 +move 1 from 2 to 3 +move 2 from 5 to 4 +move 17 from 6 to 4 +move 3 from 4 to 9 +move 14 from 1 to 4 +move 4 from 6 to 8 +move 1 from 9 to 8 +move 23 from 4 to 8 +move 6 from 1 to 7 +move 3 from 1 to 5 +move 1 from 3 to 8 +move 5 from 7 to 8 +move 1 from 3 to 4 +move 1 from 5 to 3 +move 1 from 5 to 1 +move 1 from 3 to 2 +move 1 from 9 to 4 +move 9 from 4 to 9 +move 1 from 1 to 2 +move 11 from 8 to 2 +move 1 from 4 to 5 +move 13 from 2 to 3 +move 7 from 9 to 6 +move 1 from 5 to 6 +move 1 from 5 to 2 +move 1 from 9 to 4 +move 1 from 4 to 9 +move 2 from 8 to 9 +move 1 from 7 to 8 +move 8 from 9 to 1 +move 8 from 1 to 4 +move 4 from 6 to 7 +move 1 from 9 to 4 +move 2 from 3 to 9 +move 1 from 9 to 1 +move 6 from 4 to 1 +move 2 from 1 to 3 +move 22 from 8 to 6 +move 1 from 2 to 5 +move 3 from 7 to 8 +move 15 from 6 to 4 +move 7 from 3 to 7 +move 4 from 6 to 9 +move 2 from 9 to 2 +move 6 from 3 to 5 +move 3 from 9 to 5 +move 5 from 5 to 8 +move 1 from 2 to 1 +move 6 from 8 to 2 +move 1 from 1 to 2 +move 3 from 5 to 3 +move 1 from 7 to 2 +move 4 from 7 to 8 +move 4 from 6 to 1 +move 1 from 5 to 1 +move 4 from 8 to 7 +move 2 from 3 to 2 +move 1 from 1 to 3 +move 15 from 4 to 2 +move 3 from 7 to 3 +move 4 from 7 to 2 +move 1 from 4 to 9 +move 5 from 3 to 8 +move 29 from 2 to 1 +move 1 from 9 to 5 +move 1 from 2 to 1 +move 11 from 1 to 5 +move 1 from 4 to 5 +move 2 from 6 to 3 +move 1 from 3 to 4 +move 16 from 1 to 9 +move 4 from 8 to 4 +move 3 from 6 to 9 +move 1 from 3 to 7 +move 1 from 7 to 3 +move 6 from 1 to 6 +move 3 from 4 to 3 +move 3 from 8 to 5 +move 3 from 1 to 8 +move 3 from 1 to 4 +move 2 from 4 to 9 +move 3 from 6 to 3 +move 15 from 5 to 2 +move 3 from 2 to 3 +move 4 from 2 to 7 +move 2 from 5 to 9 +move 10 from 3 to 6 +move 11 from 9 to 5 +move 2 from 4 to 9 +move 8 from 9 to 4 +move 1 from 9 to 6 +move 7 from 4 to 6 +move 3 from 5 to 8 +move 22 from 6 to 9 +move 4 from 7 to 8 +move 8 from 5 to 8 +move 2 from 4 to 3 +move 1 from 8 to 1 +move 17 from 8 to 3 +move 3 from 3 to 4 +move 13 from 3 to 9 +move 20 from 9 to 7 +move 2 from 2 to 9 +move 19 from 9 to 5 +move 1 from 1 to 4 +move 3 from 2 to 7 +move 4 from 4 to 3 +move 1 from 9 to 8 +move 18 from 5 to 1 +move 1 from 9 to 4 +move 1 from 9 to 7 +move 2 from 4 to 8 +move 1 from 5 to 4 +move 3 from 2 to 7 +move 3 from 3 to 1 +move 2 from 1 to 3 +move 3 from 3 to 8 +move 1 from 4 to 8 +move 6 from 8 to 2 +move 1 from 3 to 9 +move 1 from 3 to 9 +move 10 from 1 to 9 +move 7 from 1 to 7 +move 4 from 7 to 4 +move 29 from 7 to 3 +move 6 from 2 to 9 +move 25 from 3 to 6 +move 5 from 3 to 9 +move 13 from 6 to 9 +move 12 from 6 to 2 +move 1 from 8 to 9 +move 10 from 2 to 6 +move 7 from 6 to 5 +move 20 from 9 to 3 +move 11 from 3 to 6 +move 1 from 7 to 9 +move 2 from 2 to 9 +move 19 from 9 to 2 +move 14 from 6 to 8 +move 4 from 5 to 2 +move 2 from 4 to 6 +move 3 from 5 to 1 +move 13 from 8 to 5 +move 1 from 6 to 1 +move 2 from 4 to 2 +move 8 from 2 to 4 +move 6 from 4 to 7 +move 1 from 9 to 8 +move 2 from 4 to 7 +move 5 from 2 to 4 +move 4 from 4 to 2 +move 10 from 5 to 6 +move 1 from 1 to 7 +move 1 from 5 to 4 +move 1 from 4 to 9 +move 4 from 7 to 8 +move 5 from 1 to 7 +move 1 from 9 to 7 +move 7 from 3 to 2 +move 2 from 5 to 2 +move 8 from 6 to 9 +move 1 from 4 to 6 +move 3 from 7 to 4 +move 5 from 9 to 7 +move 2 from 4 to 3 +move 20 from 2 to 4 +move 2 from 4 to 8 +move 14 from 4 to 2 +move 12 from 7 to 4 +move 8 from 2 to 1 +move 10 from 2 to 4 +move 6 from 8 to 5 +move 1 from 7 to 8 +move 4 from 4 to 3 +move 1 from 3 to 9 +move 1 from 2 to 7 +move 1 from 6 to 8 +move 5 from 3 to 5 +move 1 from 3 to 2 +move 7 from 4 to 5 +move 6 from 1 to 7 +move 5 from 7 to 6 +move 1 from 6 to 5 +move 2 from 7 to 8 +move 1 from 2 to 6 +move 2 from 8 to 2 +move 5 from 5 to 7 +move 6 from 6 to 8 +move 16 from 4 to 9 +move 16 from 9 to 4 +move 11 from 5 to 4 +move 5 from 8 to 3 +move 2 from 5 to 2 +move 14 from 4 to 2 +move 1 from 6 to 3 +move 1 from 6 to 9 +move 1 from 5 to 3 +move 3 from 8 to 2 +move 10 from 4 to 7 +move 5 from 9 to 2 +move 3 from 4 to 7 +move 1 from 1 to 4 +move 3 from 2 to 5 +move 2 from 3 to 7 +move 1 from 4 to 2 +move 18 from 2 to 8 +move 3 from 8 to 4 +move 5 from 3 to 1 +move 1 from 3 to 9 +move 1 from 9 to 3 +move 8 from 8 to 7 +move 2 from 5 to 4 +move 1 from 5 to 6 +move 1 from 2 to 5 +move 1 from 5 to 8 +move 1 from 6 to 9 +move 3 from 2 to 7 +move 27 from 7 to 4 +move 2 from 2 to 4 +move 4 from 8 to 4 +move 1 from 9 to 8 +move 3 from 1 to 6 +move 1 from 3 to 5 +move 3 from 8 to 3 +move 1 from 1 to 4 +move 1 from 8 to 1 +move 3 from 1 to 4 +move 2 from 8 to 2 +move 2 from 6 to 2 +move 8 from 4 to 9 +move 1 from 7 to 1 +move 1 from 5 to 4 +move 1 from 7 to 3 +move 4 from 2 to 7 +move 1 from 8 to 6 +move 8 from 9 to 7 +move 1 from 6 to 3 +move 3 from 3 to 4 +move 37 from 4 to 1 +move 1 from 4 to 5 +move 13 from 7 to 8 +move 6 from 8 to 4 +move 5 from 8 to 3 +move 1 from 7 to 6 +move 4 from 1 to 5 +move 1 from 6 to 5 +move 2 from 8 to 4 +move 32 from 1 to 5 +move 1 from 1 to 4 +move 5 from 3 to 5 +move 1 from 3 to 2 +move 1 from 2 to 9 +move 19 from 5 to 2 +move 1 from 9 to 1 +move 16 from 5 to 1 +move 7 from 5 to 6 +move 1 from 3 to 1 +move 11 from 1 to 2 +move 18 from 2 to 4 +move 1 from 5 to 9 +move 8 from 6 to 1 +move 10 from 2 to 6 +move 7 from 4 to 9 +move 2 from 2 to 1 +move 7 from 4 to 2 +move 5 from 4 to 5 +move 2 from 9 to 6 +move 9 from 6 to 3 +move 5 from 5 to 3 +move 8 from 4 to 9 +move 7 from 9 to 8 +move 4 from 2 to 9 +move 10 from 3 to 1 +move 6 from 8 to 1 +move 2 from 6 to 3 +move 5 from 3 to 8 +move 3 from 2 to 7 +move 1 from 9 to 5 +move 1 from 3 to 5 +move 2 from 7 to 8 +move 1 from 8 to 9 +move 1 from 6 to 1 +move 23 from 1 to 4 +move 2 from 5 to 3 +move 1 from 8 to 2 +move 2 from 8 to 5 +move 2 from 5 to 6 +move 1 from 2 to 7 +move 1 from 7 to 5 +move 4 from 9 to 7 +move 1 from 7 to 5 +move 1 from 3 to 6 +move 3 from 7 to 4 +move 1 from 3 to 8 +move 1 from 4 to 6 +move 6 from 1 to 8 +move 4 from 6 to 4 +move 2 from 9 to 1 +move 1 from 5 to 1 +move 19 from 4 to 2 +move 2 from 9 to 3 +move 1 from 9 to 3 +move 9 from 1 to 8 +move 1 from 5 to 8 +move 1 from 9 to 3 +move 2 from 3 to 9 +move 3 from 8 to 4 +move 1 from 4 to 9 +move 1 from 9 to 5 +move 2 from 3 to 4 +move 6 from 4 to 7 +move 3 from 9 to 5 +move 4 from 4 to 7 +move 1 from 5 to 6 +move 18 from 2 to 7 +move 13 from 7 to 9 +move 3 from 5 to 1 +move 1 from 2 to 1 +move 1 from 6 to 5 +move 3 from 1 to 7 +move 1 from 1 to 5 +move 7 from 9 to 6 +move 8 from 7 to 4 +move 11 from 7 to 6 +move 5 from 9 to 2 +move 17 from 6 to 1 +move 2 from 5 to 1 +move 11 from 8 to 1 +move 20 from 1 to 2 +move 3 from 8 to 1 +move 1 from 9 to 8 +move 1 from 6 to 1 +move 11 from 1 to 7 +move 18 from 2 to 3 +move 12 from 4 to 8 +move 11 from 7 to 3 +move 7 from 2 to 3 +move 2 from 1 to 5 +move 1 from 1 to 3 +move 1 from 8 to 1 +move 1 from 5 to 9 +move 1 from 9 to 6 +move 1 from 8 to 7 +move 1 from 5 to 3 +move 1 from 6 to 7 +move 2 from 8 to 1 +move 8 from 3 to 2 +move 7 from 2 to 9 +move 6 from 8 to 6 +move 1 from 9 to 3 +move 2 from 6 to 4 +move 5 from 9 to 6 +move 7 from 6 to 2 +move 8 from 2 to 9 +move 2 from 1 to 9 +move 2 from 7 to 2 +move 2 from 4 to 8 +move 1 from 2 to 7 +move 25 from 3 to 7 +move 7 from 9 to 7 +move 1 from 2 to 5 +move 1 from 1 to 4 +move 3 from 8 to 1 +move 3 from 1 to 8 +move 3 from 7 to 8 +move 15 from 7 to 3 +move 10 from 8 to 3 +move 1 from 5 to 7 +move 1 from 8 to 5 +move 3 from 9 to 2 +move 1 from 6 to 4 +move 2 from 2 to 7 +move 1 from 2 to 5 +move 14 from 7 to 9 +move 1 from 6 to 2 +move 1 from 7 to 1 +move 1 from 5 to 4 +move 3 from 4 to 3 +move 1 from 7 to 6 +move 1 from 2 to 7 +move 1 from 1 to 2 +move 3 from 9 to 1 +move 1 from 6 to 2 +move 2 from 2 to 6 +move 17 from 3 to 6 +move 1 from 8 to 3 +move 1 from 5 to 4 +move 2 from 7 to 2 +move 9 from 9 to 8 +move 1 from 9 to 3 +move 16 from 3 to 2 +move 1 from 7 to 5 +move 5 from 6 to 5 +move 1 from 1 to 6 +move 1 from 4 to 1 +move 1 from 9 to 3 +move 9 from 8 to 6 +move 3 from 1 to 5 +move 1 from 9 to 1 +move 16 from 2 to 1 +move 2 from 2 to 7 +move 2 from 3 to 9 +move 2 from 7 to 4 +move 2 from 9 to 3 +move 3 from 3 to 5 +move 1 from 4 to 5 +move 1 from 4 to 2 +move 1 from 1 to 7 +move 1 from 7 to 1 +move 1 from 3 to 6 +move 2 from 5 to 1 +move 3 from 6 to 2 +move 2 from 5 to 8 +move 8 from 5 to 4 +move 1 from 5 to 3 +move 1 from 3 to 2 +move 1 from 8 to 3 +move 1 from 3 to 8 +move 4 from 1 to 7 +move 9 from 1 to 7 +move 6 from 1 to 8 +move 3 from 7 to 4 +move 7 from 6 to 7 +move 11 from 4 to 3 +move 2 from 3 to 8 +move 8 from 3 to 8 +move 4 from 6 to 1 +move 1 from 7 to 4 +move 2 from 1 to 2 +move 8 from 7 to 2 +move 1 from 4 to 8 +move 10 from 8 to 2 +move 2 from 6 to 1 +move 1 from 1 to 4 +move 1 from 4 to 8 +move 2 from 1 to 4 +move 6 from 6 to 5 +move 1 from 1 to 9 +move 2 from 6 to 8 +move 1 from 4 to 5 +move 1 from 6 to 9 +move 4 from 8 to 9 +move 1 from 7 to 1 +move 6 from 8 to 6 +move 1 from 6 to 1 +move 1 from 4 to 9 +move 2 from 9 to 5 +move 5 from 5 to 9 +move 8 from 9 to 5 +move 2 from 8 to 5 +move 3 from 6 to 9 +move 8 from 5 to 7 +move 5 from 5 to 6 +move 1 from 9 to 2 +move 1 from 3 to 1 +move 1 from 6 to 7 +move 1 from 5 to 6 +move 24 from 2 to 4 +move 3 from 9 to 7 +move 16 from 4 to 5 +move 2 from 1 to 3 +move 12 from 5 to 6 +move 1 from 9 to 5 +move 4 from 5 to 9 +move 1 from 1 to 6 +move 1 from 5 to 2 +move 2 from 9 to 8 +move 1 from 8 to 1 +move 5 from 4 to 5 +move 2 from 3 to 5 +move 1 from 8 to 3 +move 1 from 1 to 6 +move 3 from 5 to 7 +move 1 from 9 to 1 +move 1 from 2 to 8 diff --git a/day05/solution.nim b/day05/solution.nim new file mode 100644 index 0000000..2bf41aa --- /dev/null +++ b/day05/solution.nim @@ -0,0 +1,87 @@ +import std/strutils +import std/sequtils +import std/enumerate +import std/algorithm +import std/re + +type + Move = tuple + Amount: int + From: int + To: int + + Stack = seq[char] + + Input = tuple + Stacks: seq[Stack] + Moves: seq[Move] + +proc parseContent(content: string): Input = + # Parse stacks + let tokens = content.split("\n\n") + var strStacks = map( + # All lines containing characters of the stacks + # Exclude last line since it contain's each stack's id + tokens[0].splitLines()[0 .. ^2], + proc(line: string): string = + var retval = "" + # keep only the relevant characters (spaces/letters) + for i in countup(1, line.len(), 4): + retval.add(line[i]) + retval + ) + + var Stacks = newSeq[Stack](10) + + for layer in strStacks: + for i, c in enumerate(layer): + if c != ' ': + Stacks[i+1].add(c) + + var strMoves = map( + # All moves described in the input + tokens[1].strip().splitLines(), + proc(line: string): seq[int] = + # Remove words and split on spaces + let tokens = line.replace(re"[a-z]+ ").split(" ") + # Parse them as integers + map(tokens, proc (num: string): int = num.parseInt()) + ) + + var Moves: seq[Move] + for move in strMoves: + Moves.add((move[0], move[1], move[2])) + + return (Stacks, Moves) + +proc makeMove(stacks: var seq[Stack], move: Move, inPlace = false): void = + # copy top of the stack + var yoink = stacks[move.From][0 ..< move.Amount] + # moving in place preserves the order of the moved crates (part2) + if not inPlace: + yoink.reverse() + # remove it from origin + stacks[move.From].delete(0 ..< move.Amount) + # concat it in front of destination + stacks[move.To] = concat(yoink, stacks[move.To]) + +proc getAnswer(stacks: seq[Stack]): string = + var answer = "" + for stack in stacks: + if stack.len() > 0: + answer.add(stack[0]) + answer + +let content = readFile("./input.txt") +var input = parseContent(content) + +let moves = input.Moves +var stacksPart1 = input.Stacks +var stacksPart2 = input.Stacks + +for move in moves: + makeMove(stacksPart1, move) + makeMove(stacksPart2, move, true) + +echo getAnswer(stacksPart1) +echo getAnswer(stacksPart2) diff --git a/day06/example.txt b/day06/example.txt new file mode 100644 index 0000000..7980a82 --- /dev/null +++ b/day06/example.txt @@ -0,0 +1 @@ +mjqjpqmgbljsphdztnvjfqwrcgsmlb diff --git a/day06/input.txt b/day06/input.txt new file mode 100644 index 0000000..26e0f4a --- /dev/null +++ b/day06/input.txt @@ -0,0 +1 @@ +rhghwwsmsgmgsmmmlzljllrddvsvhvhhnvvrcccwhhvgghchwhvwvcvrrrgtgrgdggfdgffshsllvvslsppglgvgwgswwcbcwbwrrbjbwjjtgjjdzdfdhfddrmmhqhpqhhqghhzssqzqccbwwffzvzffvtftddrbrtrrcjrrmmbmrrrlrppplmplmppfzpfpvpqvpqqdndpndnmnwmwjmwmwbbrhhmzmffwfqwfqwffppvfpvffnwwwwcbwbhbccvmmplmplmmlmplpprbpbllmhlhzhffngfnntrrsrprrvlllvjvmjvvppsrrfnrfnrfrfwrffrsfrflfltfllpfprrthhhnhqnnfwwcttvzzddqsddwpddnrnttvjttjjdjvdjvjnvnrvvchhschhlffjggtqgqnnvrnrsnrsnsvspsnncppvwvvtmmcqmcmscmsmwmvmpvvlqqmbqqlwwtgtztgttpjjbfjjzhzthhzssffwqqdmdcdlclrclrccbmmqjqmqcmmnnsvnntpphhdpdhhtbtdtffhzfhhpwhppwbppfspphdhggzqgzzffdsdfsszcscpscsqcssffhjhnhhlqqdbqqdmdsmddrfddndldgglvglvlggqlggjngjnnbffthhjbjpjnjmnmgmqqbjqjzjqzzzjffwttcnnzffmllcncmnnthnncttpgpnnjdjfftmmvqmqsqggfrfjjqbjbvvshvhphfhhljlfjjvcclzclctcmmfwfvwfvwwjvwvjjplpbpqqdvqqbhbdbnnsndssgffgsglssmfmjjfrjfrfttljldjdffjjdnjjlbbnrntrtfrttmhhndnsdsffgqqrpplvvfwvfvsfszzfzhfzzlttlctllrzrggvwvhhgnnlmnlmlpppdldqqdpdlplrpppjspspzzhphccgjjpmmwvwbwssnpssrzrwrhhmzhmhsmhmttrqrvqvcclggptpjpzpccltctppflfjffrtrjrhjhffhjfjbfjfqfqzffdtthwwjwzjzggsgzgqqjdqjddvgvsvnnqwqgwgtttfvfrfwrfwfwmwmqwmmmbzmzvzfvfrfvvgvtvptpbpwbwrbwrwffzzfgzfgfcfzcffjdjjvrvnnfmmtztffsggjcjzcjcssscnscnssmmwgwbbljlnjndnrrqwqjjjbnnmbmcmbcmbbvvmtvmmfcmcjcdcnnzfzfzqfzfvvmbvmmndnbnsnnlddqvvsnngvnnrttfbtbqqnwqqzfzfzccfmmgrrsbbhvvgjjhfhssjmmsjjzzbqblqlfqllwhlwwvvstvtfvttnncjjzcjcjrrsvrssmfsfczbrzrvscvmcmrjpzwhcqfrrzbljnmqlzbzqtmhrshlrjjpvhnsvtlhqggqwppsjpszmqwfqmlwbqzwcrggrvfbvztnflwvbrqcrqbcllswvsvhwjzpldgphwptfdnlgdlnbttjfzrdcfvpdhlssfsljvdjmwddbnrpqnnqlfdfdspbnjwqjwrgtnrftsqcfjpmqwgwhttggjwzvgbwlhmtmmjlwhssrgshzpbcnstzlqdshdhjfgqlsmqqhpwbscsjhfbhprvhmftqngjgdbcvfldqgqsjqjfdmcvsflwzflsjfssnjpbwffnsfcnrdsphbjpgghmcthgnzmpgppqjdvbztvhnwqzndntcpjdtwwhvsmgdcthpssszrqcbntgsznpghmbqddpqscntjprlwzhbzhjtwzbwwcldwdgsttzmtnstjnngzrgvhncdbgqnllfzbthldztsdwsngjzprbvrnbzrsghlgssbqfnbvhnhzwmmmtncvsdngdtwcbjlnnzbnlrnmrvnvsjnvzdqnggmsvljlvjznwdszcmblhrsjvczpnlhsmqjsmwhbjbplbtqsgqjdllhncwdgbvzwnmqvndcbfhnvtjnzmvjhwzvdldhgfwbqqzcnbflfnwntlhmqgdhmrgwqcpmsvfbmwhbtsbdlhcnbcbswvdfffgjvddrbpzpcwsrsjnfvmzhlvbdnwttnqrmzbnnntbfvptrlhjhwjcsbnhvtwtwzvgfnzjplthqjbsjjwzdtqqvblnbvgcmvrmnvmwfrhcqgvrcjlfzdlpbfvncbtfgvnsflbjzqqhczcmtbwqmrppmptfgzvfbmcslwlfrfpvvnvvnwfvvmmdzmmtjsgqdfhngtphtlfjqrtljgnthgnbbqfrnpfmpwhpzdvzmtswwdvcnpsdcqwjdwlvbsbmlwdsjbcbgcrfljshlvpngfmsrzlfhtfqgwbcctnzzhnqhdmqzdwthftwtmpbcmqvdcdtgvltbzmszzwwmhzlfvbdqnhjqgdmstsnhftcwzvvbmnhwvgqzscwcdjbdgfmvpjdzctwqwltbwjlgcblnnhpnmggbmvqpqtgqjzspgqzvcvsdbvjgjfzdzhfpbzjqljjcgldzgnlmtjcmfgdbqgglvjqrppwmhccvqzvsrjjvfhjprwdsqsnszfprznljtcsrtqhcrpljfrccflmbpvqtzgmzhjrlbnrmmsmmjbtzwpglqgdvvvjvnfzmplsmvlvcnjshvjwntclwgpznnzwhjssgdcjbzrmsgnfgcgphrhfvrfhzwdcvsplhbmqwhpmjvqlmschznbqblvhtqfgtdggmncndhhplnzjphccjmlmtdqnmnlnpnfqdstljqnsqbrjrtspvrwvdmwzlgdmsfvctzgtmgqhqqrzpbgplzcfdqnzhsqrbcvhsccshnnpvvrpvqzqsgzgmpzfvvrrcvhdtntnsqnjrbzlbzmpgwdqzbhtlrrhbwdqjlsfgdhmvgmgbqhwvljmmqfllqvvrznrlftgzjdcgtstjffqmgvffpvtctzpdqjfnmlcdzscntctmqhrtmhrlhbjzttrcvcnlhsrvtpbmdchhntnnpnzlvqqnsrjcmblcvphqgwshnjmplgvnbsmmdzgqcpqztjhhgjvtlbpdpdwlwmmfrdgcvzfbgvbgpbjnwsssvhszwplcgvpgjwdrwngbcdjwvlsfhqlrqzgrzpfgjstqfdbrpqdvrlgdwqcsrgvhctznjjlzsmzctsqtfnhhlpjgnltssglmlwshfbrgmjqbvsmqwvszdfsvhmtrfjgwjctpsmgzzjbpwsztnnvzrhwvvmhdpgdmwzsjprhlgzcdvhznlfgjqvcwqrplcfvzmthsdsnrtfvnlrmvwplmbdvdggmlvpgdgzhvzmvzwmptzsnfrcrjspccmqjpjmhjqgrjbdcdjbzjmphmcdvjqtmdshhjrqgjgsnpzfbfgpjpczwzvmclgzgztlvzmdbwgncnndjwhhhjnhtjdmcnrmnqbmjdrdcmtvcsmftqcfhsvhsfjmtzjpnwffggpfqlqmzlbhnnhbtgzfgnjvdzmvthqjrhzbwvhcjzcsmsvsctrqbltpcrpjjnsbjdbfjqfcbpcgcwtqsflmlwprjcwlmcjjgsfdpwcqvhjpsgvdgsfnscnbzsrmrbbvdrlltzplbvgqsdnplcvbhddbtmwnfmvqhqdlrtrmrmzmhlccgwgmbdppjqdjtwmvdzfsbsggrfstjwjpjnljffwffmqncfnthnhglwvsgvzmgbzhtdfpfmdwmcldthvsnqnptpmhqctblgfsszhcfbvcrggjdhthqvvvlldshvqwmvdtfslrhzvgdfwztrczdjgcfcgtmwnphqthlgpfnrqwcgpzwnlgdvsnvzftlnlfflfsmjzhrhqjctsbvtccwbfsdrnbhszzjhqndvwcsmffnstnfdfwpbgfztjmjngdczzlgpscjtshpmmmzlnqndsttbdgfjqcvbqlphwhlhgcvjbhjmtrfzlgpwdnvzrllndbhvhlngvhlszzdcrdgvrmjwcvhhtbhnjmdzgctqnpdlrnqjzbchjtcsggsczlgmvtqvzmsqvtrhtvdmzlcdddfnbvbsnrzvgzfqjtbhjqhdznrhbfbqwtnwvrfqsznbqfzfzfgmhvjjsgbbdbdtzswwlnfrq diff --git a/day06/solution.nim b/day06/solution.nim new file mode 100644 index 0000000..ce3ccd0 --- /dev/null +++ b/day06/solution.nim @@ -0,0 +1,39 @@ +import std/strutils +import std/sequtils +import std/tables + +proc solve(message: string, nUniq: int): int = + var cntUniq = initCountTable[char]() + + # init found + var uniq = 0 + for c in message[0 ..< nUniq]: + cntUniq.inc(c) + if cntUniq[c] == 1: + uniq += 1 + + let pairs = zip( + message[0 ..< message.len()-nUniq], + message[nUniq ..< message.len()]) + + for i, pair in pairs: + if uniq == nUniq: + return i+nUniq + + cntUniq.inc(pair[0], -1) + if cntUniq[pair[0]] == 0: + # we lost one uniq number in sequence + uniq -= 1 + + cntUniq.inc(pair[1]) + if cntUniq[pair[1]] == 1: + # we found new uniq number in sequence + uniq += 1 + + assert(false) + return -1 + +let content = readFile("./input.txt").strip() + +echo solve(content, 4) +echo solve(content, 14) diff --git a/day07/example.txt b/day07/example.txt new file mode 100644 index 0000000..09a921e --- /dev/null +++ b/day07/example.txt @@ -0,0 +1,23 @@ +$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k diff --git a/day07/input.txt b/day07/input.txt new file mode 100644 index 0000000..036d66d --- /dev/null +++ b/day07/input.txt @@ -0,0 +1,1096 @@ +$ cd / +$ ls +dir brdsppd +dir dnjqmzgg +126880 fmftdzrp.fwt +173625 hhfqgzfj.qvt +dir lbbcfjl +dir mzdqcb +dir npppw +dir plmb +6337 rfgtcj.tdn +dir szfw +230140 vmc.cdf +$ cd brdsppd +$ ls +dir gjc +dir lcz +218543 ndqmcv +dir qnj +dir rrdd +dir zppsglq +$ cd gjc +$ ls +dir bvctghh +262132 cbczvmdf +111855 dnltsq.fwv +22416 fnrwscz.vwb +dir gwd +dir lsprzlbf +$ cd bvctghh +$ ls +dir lsprzlbf +dir lwfgnzz +dir tjslbpb +$ cd lsprzlbf +$ ls +182522 hhfqgzfj.qvt +dir hts +229288 jtpdh +dir lwfgnzz +284594 szfw +89639 tgdsjl +$ cd hts +$ ls +11158 dnltsq.fwv +52582 tchv +$ cd .. +$ cd lwfgnzz +$ ls +dir tjslbpb +$ cd tjslbpb +$ ls +58586 jtzmjgw.bql +$ cd .. +$ cd .. +$ cd .. +$ cd lwfgnzz +$ ls +199598 rlhz.pbs +$ cd .. +$ cd tjslbpb +$ ls +119666 fmzfs.glg +$ cd .. +$ cd .. +$ cd gwd +$ ls +dir bcfqd +1631 hhfqgzfj.qvt +$ cd bcfqd +$ ls +197168 cqvwnslp.ltw +$ cd .. +$ cd .. +$ cd lsprzlbf +$ ls +dir jwznh +$ cd jwznh +$ ls +dir lpm +dir ncs +dir vqprn +$ cd lpm +$ ls +15172 bnw.rqm +215818 flpbspn.stt +$ cd .. +$ cd ncs +$ ls +dir rzdbw +$ cd rzdbw +$ ls +15150 cvjldjt.gdc +$ cd .. +$ cd .. +$ cd vqprn +$ ls +23882 njjjh +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd lcz +$ ls +37587 gwcvttb.dhc +195583 lsprzlbf.vng +152648 tchv +$ cd .. +$ cd qnj +$ ls +dir bpvl +275640 cfvznj.bqc +dir lwfgnzz +213007 nwbt.mct +135231 twpf.pft +165501 vmc.cdf +88097 vmvs.hnr +dir znbdpp +$ cd bpvl +$ ls +dir nmzbpb +$ cd nmzbpb +$ ls +129477 pjlvs.zcp +$ cd .. +$ cd .. +$ cd lwfgnzz +$ ls +dir lwfgnzz +dir rsbdcwjr +dir sgh +dir wvwmf +$ cd lwfgnzz +$ ls +33186 ftcrfnmd +$ cd .. +$ cd rsbdcwjr +$ ls +dir lsprzlbf +$ cd lsprzlbf +$ ls +dir jvcgnbs +288445 pjmqm +111585 szfw.drf +dir vnftvqf +$ cd jvcgnbs +$ ls +dir ctlwjnjz +dir lwfgnzz +dir tjslbpb +$ cd ctlwjnjz +$ ls +72087 zmhnsmmf +$ cd .. +$ cd lwfgnzz +$ ls +151358 sqs +$ cd .. +$ cd tjslbpb +$ ls +112471 mftdzhwj.zvt +$ cd .. +$ cd .. +$ cd vnftvqf +$ ls +120421 lsprzlbf.tqc +$ cd .. +$ cd .. +$ cd .. +$ cd sgh +$ ls +228239 szfw.dzv +$ cd .. +$ cd wvwmf +$ ls +dir bcjfz +$ cd bcjfz +$ ls +26284 bzhqwdjq.nzn +$ cd .. +$ cd .. +$ cd .. +$ cd znbdpp +$ ls +dir szfw +$ cd szfw +$ ls +dir nthzqpws +dir snfmt +$ cd nthzqpws +$ ls +96382 twhdbvtw.lbj +$ cd .. +$ cd snfmt +$ ls +133360 bjmgtpgh +134215 vmc.cdf +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd rrdd +$ ls +185903 cpgpgntt.tfn +$ cd .. +$ cd zppsglq +$ ls +41689 jvcgnbs.hrt +169754 wgnpq +$ cd .. +$ cd .. +$ cd dnjqmzgg +$ ls +dir lsprzlbf +dir lwfgnzz +dir nmvj +dir sfpg +$ cd lsprzlbf +$ ls +dir lbw +141416 sqs +$ cd lbw +$ ls +48758 cjv +235522 dnltsq.fwv +$ cd .. +$ cd .. +$ cd lwfgnzz +$ ls +36709 bcmtmwcz +$ cd .. +$ cd nmvj +$ ls +dir dqpw +dir tjslbpb +$ cd dqpw +$ ls +10608 hhfqgzfj.qvt +$ cd .. +$ cd tjslbpb +$ ls +261140 qfzb +$ cd .. +$ cd .. +$ cd sfpg +$ ls +8543 szfw +69248 tjslbpb +$ cd .. +$ cd .. +$ cd lbbcfjl +$ ls +dir csnjp +dir drwpfn +301956 hhfqgzfj.qvt +dir jvcgnbs +dir lsprzlbf +dir pdzlnm +161886 tchv +153858 vmc.cdf +87849 wghtg +dir zhgchnld +$ cd csnjp +$ ls +dir ffgfmcm +dir gtd +dir lbjvqv +dir lwfgnzz +11312 sqs +$ cd ffgfmcm +$ ls +dir bcnvw +dir lcf +dir lsprzlbf +$ cd bcnvw +$ ls +111692 ftcvs.tcz +173665 jpfh.hrs +120561 lwfgnzz.zvd +dir ngtbzz +29479 tchv +dir tjslbpb +$ cd ngtbzz +$ ls +dir czrqmh +dir jrhpnpw +dir lsprzlbf +$ cd czrqmh +$ ls +225055 hhfqgzfj.qvt +$ cd .. +$ cd jrhpnpw +$ ls +206497 tjslbpb.zbv +$ cd .. +$ cd lsprzlbf +$ ls +66627 szfw.wtd +$ cd .. +$ cd .. +$ cd tjslbpb +$ ls +dir cgzlp +116060 lsprzlbf +dir szfw +128885 zht.ptf +$ cd cgzlp +$ ls +18201 sqs +$ cd .. +$ cd szfw +$ ls +104128 tchv +$ cd .. +$ cd .. +$ cd .. +$ cd lcf +$ ls +137662 lwfgnzz +$ cd .. +$ cd lsprzlbf +$ ls +151745 fmcgs.tvh +37707 gszw.jlm +dir lsprzlbf +178133 rjw.wrq +dir szw +267875 tchv +198852 vmc.cdf +$ cd lsprzlbf +$ ls +54734 lsprzlbf.hcq +81537 lwfgnzz +120990 qppfdrf +$ cd .. +$ cd szw +$ ls +dir jtvschrd +dir zcnpls +$ cd jtvschrd +$ ls +dir gtz +$ cd gtz +$ ls +dir rdzzlm +$ cd rdzzlm +$ ls +55063 tchv +8813 zfwvvpvz.zzb +$ cd .. +$ cd .. +$ cd .. +$ cd zcnpls +$ ls +282808 dpmd +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd gtd +$ ls +148653 cmchsg.zdr +66537 hhfqgzfj.qvt +125493 mdtmqbml.gnt +dir rwjdjqcs +dir tjslbpb +$ cd rwjdjqcs +$ ls +77026 zpt.gfp +$ cd .. +$ cd tjslbpb +$ ls +dir dfl +$ cd dfl +$ ls +203731 qpsmsjgh.gvs +dir tjslbpb +84386 vmc.cdf +dir zgh +$ cd tjslbpb +$ ls +dir lwfgnzz +140021 qnp +312305 svh.vqt +$ cd lwfgnzz +$ ls +49701 lgffdn.gmr +$ cd .. +$ cd .. +$ cd zgh +$ ls +138627 tchv +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd lbjvqv +$ ls +dir bnl +$ cd bnl +$ ls +dir gbv +dir lwfgnzz +$ cd gbv +$ ls +dir lsprzlbf +36406 lsprzlbf.cfd +$ cd lsprzlbf +$ ls +168615 hlhp.rvp +$ cd .. +$ cd .. +$ cd lwfgnzz +$ ls +149511 cdpwjbpd +$ cd .. +$ cd .. +$ cd .. +$ cd lwfgnzz +$ ls +232898 dnltsq.fwv +181665 hhfqgzfj.qvt +62529 qfmhhvvq.prh +57822 sqs +$ cd .. +$ cd .. +$ cd drwpfn +$ ls +dir fvgw +dir lsprzlbf +dir lwfgnzz +104745 nqvlqd.mdb +203189 qqpmz +159549 tchv +dir tjslbpb +dir wnrns +$ cd fvgw +$ ls +dir tlzmplfl +$ cd tlzmplfl +$ ls +29740 vmc.cdf +30062 wgrm.dst +181738 zqr +$ cd .. +$ cd .. +$ cd lsprzlbf +$ ls +dir lcqhctjl +dir ldr +dir tjslbpb +$ cd lcqhctjl +$ ls +209114 bcfr.gpf +$ cd .. +$ cd ldr +$ ls +148649 fzh.pqm +$ cd .. +$ cd tjslbpb +$ ls +241013 dnltsq.fwv +$ cd .. +$ cd .. +$ cd lwfgnzz +$ ls +288335 cdctnn +67277 tchv +$ cd .. +$ cd tjslbpb +$ ls +dir pblzrspg +dir qqgddb +86103 sqs +183539 tjslbpb.wrs +$ cd pblzrspg +$ ls +dir pgl +$ cd pgl +$ ls +305421 lwfgnzz.jdz +114244 tjslbpb +dir vzff +$ cd vzff +$ ls +80591 rlww.htq +86968 sqs +$ cd .. +$ cd .. +$ cd .. +$ cd qqgddb +$ ls +dir szfw +$ cd szfw +$ ls +dir jtw +$ cd jtw +$ ls +263 szfw.lzp +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd wnrns +$ ls +203725 dnltsq.fwv +77752 qrg.fnt +$ cd .. +$ cd .. +$ cd jvcgnbs +$ ls +296356 lwfgnzz.svf +294928 ptvdsngf +$ cd .. +$ cd lsprzlbf +$ ls +dir lwfgnzz +dir tjslbpb +$ cd lwfgnzz +$ ls +105095 tchv +$ cd .. +$ cd tjslbpb +$ ls +53558 hhfqgzfj.qvt +189180 szfw +$ cd .. +$ cd .. +$ cd pdzlnm +$ ls +76426 jwttcp.rjj +dir lsprzlbf +dir qldhzf +dir rtdsjf +dir sfdtljj +69033 slhl.jst +$ cd lsprzlbf +$ ls +71362 vgdr +$ cd .. +$ cd qldhzf +$ ls +303106 lsprzlbf.rbq +$ cd .. +$ cd rtdsjf +$ ls +45781 pzbgwrdm.lwt +dir rzc +$ cd rzc +$ ls +297081 qqvlp +86015 zthlr +$ cd .. +$ cd .. +$ cd sfdtljj +$ ls +254377 ftw.fwg +dir jvcgnbs +153393 lwfgnzz.dws +dir pnphc +220821 wslttcn +$ cd jvcgnbs +$ ls +92642 bzpvvlsn.gvt +$ cd .. +$ cd pnphc +$ ls +288388 lwfgnzz +$ cd .. +$ cd .. +$ cd .. +$ cd zhgchnld +$ ls +16588 ftgrpj.srl +112044 vmc.cdf +$ cd .. +$ cd .. +$ cd mzdqcb +$ ls +dir bfphcs +dir cgjmj +dir jgcqqsh +dir jvcgnbs +dir lccjbtqs +dir lwfgnzz +dir pprvjm +dir szfw +dir tjslbpb +dir ztc +$ cd bfphcs +$ ls +124148 wzt.qtr +$ cd .. +$ cd cgjmj +$ ls +28095 ddjdbdf +dir jvcgnbs +169536 sqs +dir svbsrj +159511 vmc.cdf +$ cd jvcgnbs +$ ls +dir crmsnch +dir jvcgnbs +$ cd crmsnch +$ ls +195745 lsprzlbf.prh +271424 tjslbpb +227054 vmc.cdf +$ cd .. +$ cd jvcgnbs +$ ls +294249 vmc.cdf +$ cd .. +$ cd .. +$ cd svbsrj +$ ls +49038 cspzcpqs +dir czltsqrg +98084 ljhljcw +dir ntdjg +202570 szfw.lpj +$ cd czltsqrg +$ ls +207690 dnltsq.fwv +208745 lnns.hsv +40703 rgmjszf.vtd +$ cd .. +$ cd ntdjg +$ ls +dir szfw +$ cd szfw +$ ls +284994 qzwptr.ggb +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd jgcqqsh +$ ls +2462 djfwggvp +$ cd .. +$ cd jvcgnbs +$ ls +dir ftjprdj +289965 zhlrstpt +$ cd ftjprdj +$ ls +dir wnmhs +$ cd wnmhs +$ ls +dir tjslbpb +$ cd tjslbpb +$ ls +dir jvcgnbs +$ cd jvcgnbs +$ ls +160761 dnltsq.fwv +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd lccjbtqs +$ ls +dir jjrdbgtg +77186 sqs +116398 szfw.qjt +182665 vmc.cdf +248366 vqdjwsh +$ cd jjrdbgtg +$ ls +237358 bdvbjs.sjp +$ cd .. +$ cd .. +$ cd lwfgnzz +$ ls +dir ggptdvr +dir jnb +dir lcpmzpr +222506 lsprzlbf +293605 qbjfqh +dir smvwg +291643 tchv +247095 vwdstb.pdw +dir wghpmnm +dir wtrbfrj +$ cd ggptdvr +$ ls +184198 vmc.cdf +$ cd .. +$ cd jnb +$ ls +296536 dnltsq.fwv +91419 jvcgnbs.cvq +279635 rwt.wth +$ cd .. +$ cd lcpmzpr +$ ls +184769 hhfqgzfj.qvt +dir qwqcbdms +236533 tjslbpb.bnc +162397 vmvctfnw +dir wcc +$ cd qwqcbdms +$ ls +232132 jgm.tfm +dir jnfmcnfh +173727 mwrbndt +dir qshphcb +dir tjslbpb +$ cd jnfmcnfh +$ ls +dir rngnt +$ cd rngnt +$ ls +236114 hhfqgzfj.qvt +$ cd .. +$ cd .. +$ cd qshphcb +$ ls +78407 lsprzlbf.hpd +$ cd .. +$ cd tjslbpb +$ ls +30200 brbz +171368 jvcgnbs.vwl +236158 sqs +285872 srfwnmb +dir znr +$ cd znr +$ ls +108194 hhfqgzfj.qvt +$ cd .. +$ cd .. +$ cd .. +$ cd wcc +$ ls +167768 jvcgnbs +289640 lgthn.cjn +28517 lwfgnzz.chf +dir nvgfwn +43738 rrg +81011 sqs +$ cd nvgfwn +$ ls +270370 hgnv.ssj +98235 lwfgnzz.nfv +$ cd .. +$ cd .. +$ cd .. +$ cd smvwg +$ ls +dir jvcgnbs +77510 tchv +dir tgrm +$ cd jvcgnbs +$ ls +287955 bqcnj.zzv +119021 bsrtmzd +3391 cnngp.mbf +68540 qjmb.vjz +149062 tchv +$ cd .. +$ cd tgrm +$ ls +112315 qzth +277566 scqp +$ cd .. +$ cd .. +$ cd wghpmnm +$ ls +dir hpm +$ cd hpm +$ ls +113354 hhfqgzfj.qvt +$ cd .. +$ cd .. +$ cd wtrbfrj +$ ls +dir ggrsgzvv +dir mvzzsl +dir szfw +dir vsqjb +$ cd ggrsgzvv +$ ls +dir dpv +dir gqtsmnr +dir lsprzlbf +dir pcjcm +137203 tchv +84711 tns.sdh +$ cd dpv +$ ls +233264 dmd +dir fzlchpb +293097 gwmspnm.qtp +100283 jbbnssc.nnv +$ cd fzlchpb +$ ls +150431 pdmzrs.rll +$ cd .. +$ cd .. +$ cd gqtsmnr +$ ls +dir jdml +dir jfqtjt +dir lwfgnzz +dir tjslbpb +$ cd jdml +$ ls +148333 bwm.dnt +dir lsprzlbf +$ cd lsprzlbf +$ ls +dir cslvm +dir lwfgnzz +dir rllt +265856 sqs +dir szfw +56452 tchv +$ cd cslvm +$ ls +266380 vmc.cdf +$ cd .. +$ cd lwfgnzz +$ ls +dir tzghdrd +$ cd tzghdrd +$ ls +dir tjslbpb +dir vhv +$ cd tjslbpb +$ ls +dir jvcgnbs +$ cd jvcgnbs +$ ls +18188 sqs +$ cd .. +$ cd .. +$ cd vhv +$ ls +95547 jhhblnn.vzt +dir srgh +$ cd srgh +$ ls +299624 lsprzlbf.dnr +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd rllt +$ ls +dir crpcbl +308185 dnltsq.fwv +dir szfw +$ cd crpcbl +$ ls +209445 dfds.mzh +$ cd .. +$ cd szfw +$ ls +dir lsprzlbf +159720 vmc.cdf +$ cd lsprzlbf +$ ls +291090 tzrvpv +$ cd .. +$ cd .. +$ cd .. +$ cd szfw +$ ls +113605 fbrtbfjm +$ cd .. +$ cd .. +$ cd .. +$ cd jfqtjt +$ ls +119124 hhfqgzfj.qvt +251412 jvcgnbs.zfm +dir rbv +dir tjslbpb +142371 tjslbpb.czt +65455 vmc.cdf +47786 zjmtjsv +$ cd rbv +$ ls +300632 dzssgm.pqn +$ cd .. +$ cd tjslbpb +$ ls +221545 pswrb.bsw +$ cd .. +$ cd .. +$ cd lwfgnzz +$ ls +34086 wshbr.spm +$ cd .. +$ cd tjslbpb +$ ls +118394 djfwjd.fvl +65377 qmgcpdr.qjz +146317 tchv +$ cd .. +$ cd .. +$ cd lsprzlbf +$ ls +195086 clqmgmq.gbw +dir cpgjgbdf +109787 jmwshtg.snl +305108 lsprzlbf +dir szfw +174614 szfw.qjq +105247 vmcf.rsm +$ cd cpgjgbdf +$ ls +dir vzddwsr +$ cd vzddwsr +$ ls +91787 nwgfs +$ cd .. +$ cd .. +$ cd szfw +$ ls +193316 tjslbpb +$ cd .. +$ cd .. +$ cd pcjcm +$ ls +dir lsprzlbf +$ cd lsprzlbf +$ ls +210834 hvrpj.cdc +29497 wcnf +$ cd .. +$ cd .. +$ cd .. +$ cd mvzzsl +$ ls +dir rnrtf +$ cd rnrtf +$ ls +221025 btwgwrp.ctj +$ cd .. +$ cd .. +$ cd szfw +$ ls +dir jvcgnbs +dir szfw +31365 tjslbpb +$ cd jvcgnbs +$ ls +250409 lwfgnzz.nvf +66638 tchv +dir tlms +$ cd tlms +$ ls +84192 lsprzlbf.pcm +107549 nwqzqcmw.rls +97234 svdqvwcz +$ cd .. +$ cd .. +$ cd szfw +$ ls +45362 zsflqrtc +$ cd .. +$ cd .. +$ cd vsqjb +$ ls +dir vvnzdcbb +$ cd vvnzdcbb +$ ls +144027 tchv +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd pprvjm +$ ls +dir hvst +137237 lwfgnzz.qfp +dir szfw +$ cd hvst +$ ls +100531 svmvncf +$ cd .. +$ cd szfw +$ ls +233868 hhfqgzfj.qvt +$ cd .. +$ cd .. +$ cd szfw +$ ls +14971 tchv +$ cd .. +$ cd tjslbpb +$ ls +283684 lwfgnzz.wzv +$ cd .. +$ cd ztc +$ ls +dir bwhfncdm +161420 jvcgnbs +135102 tchv +$ cd bwhfncdm +$ ls +108615 lwfgnzz.msn +$ cd .. +$ cd .. +$ cd .. +$ cd npppw +$ ls +94593 cwdz.tlb +258598 jsswljc +245674 nmmfzscz +$ cd .. +$ cd plmb +$ ls +dir dwnpl +dir lwfgnzz +$ cd dwnpl +$ ls +15993 hhfqgzfj.qvt +264944 vmc.cdf +$ cd .. +$ cd lwfgnzz +$ ls +154801 cnbmh.hsh +$ cd .. +$ cd .. +$ cd szfw +$ ls +173334 lsprzlbf +dir lwfgnzz +70693 szfw +$ cd lwfgnzz +$ ls +dir jgwzcgd +dir qgdcjq +dir spwcmrl +$ cd jgwzcgd +$ ls +dir jvcgnbs +dir nvtvcf +$ cd jvcgnbs +$ ls +131852 cntlhf.mqq +217305 dnltsq.fwv +174110 jvcgnbs.njb +179602 lwfgnzz.mth +dir pzcssdhv +dir qcmqmnpn +227361 szfw +dir wmhhl +$ cd pzcssdhv +$ ls +187518 gjfwbwnv +115671 lsprzlbf +$ cd .. +$ cd qcmqmnpn +$ ls +197002 dlns +40030 mmpp.ggt +198158 tchv +$ cd .. +$ cd wmhhl +$ ls +168011 hhfqgzfj.qvt +$ cd .. +$ cd .. +$ cd nvtvcf +$ ls +dir rrzjjjhc +$ cd rrzjjjhc +$ ls +33548 sqs +$ cd .. +$ cd .. +$ cd .. +$ cd qgdcjq +$ ls +252274 prshd.qdj +$ cd .. +$ cd spwcmrl +$ ls +dir lslmr +dir szfw +135076 tchv +265608 vmc.cdf +$ cd lslmr +$ ls +172247 rrvwsbl +$ cd .. +$ cd szfw +$ ls +192729 rnq diff --git a/day07/solution.nim b/day07/solution.nim new file mode 100644 index 0000000..e6f4643 --- /dev/null +++ b/day07/solution.nim @@ -0,0 +1,97 @@ +import std/strutils + +type + Command = string + # using LeFile for name because File already exists + LeFile = ref object + Size: int + Name: string + +type + Directory = ref object + Name: string + Files: seq[LeFile] + Parent: Directory + Subdirectories: seq[Directory] + +# Directory methods +method cd(self: Directory, path: string): Directory = + if path == "..": + return self.Parent + + for subdir in self.Subdirectories: + if subdir.Name == path: + return subdir + +method add(self: Directory, file: LeFile): void = + self.Files.add(file) + +method add(self: Directory, dir: Directory): void = + self.Subdirectories.add(dir) + +let total = 70_000_000 +var part1 = 0 +var minRemoved = total + +method size(self: Directory, freeThreshold = total): int = + var size = 0 + for file in self.Files: + size += file.Size + + for subdir in self.Subdirectories: + size += subdir.size(freeThreshold) + + if size <= 100_000: + part1 += size + + if size >= freeThreshold: + minRemoved = min(minRemoved, size) + + return size + +proc run(root: Directory, input: seq[Command]): void = + # start pc from 1 to ignore "cd /" command thats coming first + var pc = 1 + var current = root + + let endpc = input.len() + while pc < endpc: + let command = input[pc] + assert(command[0] == '$') + + let tokens = command.splitWhitespace() + + case tokens[1]: + of "cd": + current = current.cd(tokens[2]) + pc += 1 + of "ls": + pc += 1 + while pc < endpc: + let file = input[pc] + # end of file list + if file[0] == '$': + break + + let fileInfo = file.splitWhitespace() + if fileInfo[0] == "dir": + current.add(Directory(Name: fileInfo[1], Files: @[], Parent: current, Subdirectories: @[])) + else: + current.add(LeFile(Size: fileInfo[0].parseInt(), Name: fileInfo[1])) + pc += 1 + else: + assert(false) + + return + +let content = readFile("./input.txt").strip().splitLines() + +var root = Directory(Name: "/", Files: @[], Parent: nil, Subdirectories: @[]) +run(root, content) + +let totalUsed = root.size() +let totalFree = total - totalUsed +discard root.size(30_000_000 - totalFree) + +echo part1 +echo minRemoved diff --git a/day08/example.txt b/day08/example.txt new file mode 100644 index 0000000..16d6fbd --- /dev/null +++ b/day08/example.txt @@ -0,0 +1,5 @@ +30373 +25512 +65332 +33549 +35390 diff --git a/day08/input.txt b/day08/input.txt new file mode 100644 index 0000000..15fbc4e --- /dev/null +++ b/day08/input.txt @@ -0,0 +1,99 @@ +200200221023111313131033314121142013103432145142351212334232423210101340410243413011333312111010010 +021002023301222221234134021422342024344555521535143232341414552024224120114233210330203002020100112 +120000123021210023111321143114331115334535223455511513445233523154411102203411040133312002213001021 +110211312303200204232110124204135453554533435152342542252215415141133330323032234114310011301232202 +112002122201001100330432244432552555524445123151222142521452233321152332132412434434431321322021220 +000131233030332102140440124221314455255431113413445553414144524134315351524134030112312012102102122 +011002120310213142402320144522121125454423123245535451115134412543215113433312403430132101003202030 +001221312201314442411333454131552331253553254425236334643151355314514413411344034432330410221101023 +133033302114012204213054544541124453214232545523665466356466451514332142121512400041213432211332332 +122103100320433433403313515121232352332442555253656542336644235234542522322522414400320014312110331 +220032121143103434234531224315451255225362634256634623342624242245654341134514413144333113211200033 +320112113344013332224131114231235263526556625325625352254643224563365551253353323542200003301120011 +130332114433413215333445212514445445656665256554333534422554442522234433415533124353022320300112030 +122220320003402342433443415465352622564252264442264334335624365224645544545412124352220434440211220 +012123032311134245212342233263346563632453535355553473445564362634252543555515242444423232000444220 +210332422344222154315435122245243633424643346345734336333746422324336263624544151122442021330341202 +122113144440445232235222443563362625543565533465377647363543377645634552632254214531354231413432430 +312340402310532324322313244522226622547366756445444754767335355365264622465662241215332253310001232 +203342203201331433144542522354633356376457563745333765735577477354743263423666625212251354244021004 +023132211325442531332565334564256663665357767653737436565453774766335532544656254552332354313323032 +104344140125552254523443534436547653753334746356364664565677777637444474643245425325454224440231203 +030303323422144551254256535247737377634445575474654433333453643564664344462332353234553115322142242 +043342223454513255464263333566337576377476354884845654658465735544446646436232534263314313142020101 +340311214411551345423466343646644336367654787858788857666654635337366537645634644263323112331404131 +040141315333331565455545334767475747755574585547567756844746644445646736447635456236413253453410130 +211021153443415666656253646443465373878486485664464485545486846643475567536535465634262415153200040 +434443334231526223353563373464374574547886487867474546748668788886554566336675234542522151345414431 +342100553111533623655466757467553555676668887764575574556755884875687334634675256256443425223423211 +421145141552463255552236436455476686566587654558577848647854485587448337355756554555544211113112433 +401034232152434624233754647737667758845867866675595798957488447876578774367337742646625521543244120 +201414142512656264345465456536564477766677986565767776589758477664747866666435364642236343442335143 +422042442525465325256445643735574646548578959977866889666586787677748745536646677524242544332243420 +101531424154626224664754337344565457557999965875599965977796778866568855445766577565632633451545144 +111515354125252635577747557658555488765757696767797558565755699985844788764347763523465333315513212 +222334234142233522754645544788567846579566995878775676667979868685866578655574543564453254615121150 +121552233464445256557546467767485865866888757989977669966767877786686475874646454752632664243132511 +412242332564644335747746348878865677677797755798669796798699855757865564547645373677564252625352445 +104135225262634344357677645645458796767865979969889676688676788669777674757634454746666526341145313 +021542323626266573437334685574765967759968767697666876767887775889896866845887736736426556541522241 +321245255565266675757675486554868969567677786789686889669988776968557656488476534636744443443445532 +424153123565322534465577464547665888797687899787966868666667897595997786576655333657432563645515114 +151513345354454444763668544475487669995769769878776696968966788666679588686556634737544644543232332 +315411214333624753546345646876778875556666766899787967667988799866697798768788653774352466325322155 +411515135354235576553778556478657685968679689776697889878966888788686556488744645555636235464132151 +521535123365535747465567756884789758877668899777979788877786896957896655744848765333672323354342345 +511122245466262643344764588545559786677866787999989789989769786875585659588677463454335226643415231 +234355522634365636744684556586586576767676868898988888987788888877768767654646777776645642226512141 +113123464223654555566666486667798785887896678897787899778677766996769787745467865757755656543512345 +513251343243554753654655574645569758987667887877878998789898989677659987488676836733553556554225344 +514313564242345475335768454478576556889868687997999987778988866675979779845785867656464634654245123 +114315542426623675675378664848688856798777688977789877988898769769667968885864643357435456442515251 +342223563236537773664686558445968779787887987788777777899877867865678669767686535536743642245412355 +125543254543547353647388564555887588899766978788778797797796898997787999888766547554567344424443422 +235522554554262346774664445787579599869688998989778778978989968998575857577865454747575353226552114 +222421136654623646474466478475666768686777899887878779887688896658596779765485853765563356364225314 +521231534444644737467764858748655998796879877877788879799986898965697856444748453437553352232525543 +451421316463534654736364878868555996777987969978898798976796968858967778666788533743354325346223354 +353521254635223475773456867765596786879787787769889887896999898885688596454456655466765442452131244 +112452332645434776643548885574558878789797669769989989886877966757566586444578445673434665652431423 +125112515242255354574555588568695879785886989867778677698879979576678878668587547744623644323213555 +222335123454333544773645644774469985799577787667779799699876685666756857858446357667422332624342332 +342124352633564466565447655564575889567797869876686996679999868665879886844677564455723264641334552 +211531121363532576364535865484865759689798698998996686966767965765789787447464533667726322444223531 +003112555432534436636776465475555776887557956877687879969697585659596546865447775565562326263355343 +433244413454525566563634447454784577659787856568996976596789778896764874668454673456462646455545115 +315114535444536635475346535567864558579958679557799758766667597987857466754537555645552424625323424 +041544243435426366744535764674465545875655656695956899997569789788477547755346553676234364525135211 +110125213453624243247556736654454474595787967599557857997699578855767558775435554762633446551353134 +230513132216566245267463366654684755868756978975659588575959655686655788733345435522656542222543322 +042134352115436525535436657767864645756586865777685969969787676584458468744346376522324323225232212 +113011555414226244554676353335845564485568555689599656977797776777868787473376444245355443123441231 +141222553351554636564756467565656675455484874698998587887767666457458846465776554544333612224555323 +410201213345143434422573347343756574748746464486554485756685477655667634334766422236535313341542224 +400013155121116452255553534765374544884448574876457458645878446585657476536357256436654223345343132 +142320132432156443246333547553474375466866456765867768748787675644755677446563663223424341524352200 +130310433221343524424456477364543647448885475465487864674454548867635637545422424333245424354220221 +104443025533452125362252625375463664447488646447874885476567646456653665465543643663511122334514003 +302020415314212533664642446555554345445458887778858887685645576353536647674424342553325334543032421 +241431045353353251642363462546445336355737566757557674865573447644353353564422462552323432524142311 +123213233322144323666345645436644754537635574357377674465747755476333656624223243445125521412332331 +012331042212144212425325652566536457633744775665435737646677453634637335562564643341411132411032042 +312330023343231454516256365325363757435647543374644573757667446466553456424326532235455225410011222 +330440423204155515131264636336326536353437335474474464535536754457526344465446535213522513202431334 +111010303340451214252454445262262654354536464545434674354557674362552463364322545323344220103312142 +011012340310414525221212256242445654336566374374366636534765356655652454533664444453134140113204011 +230024312112245355233251252646423364546365646735756334573543653656365434363633141223321213032042131 +031001023032240425233144214253446244556226622634747362226456645266342264223215113131540112130410110 +322123043034044225552242443355356433432465646225242242422346453346634325254325435535313321413201023 +022331002231110112224233354325624225342363424426633436565344545533465463152555421312331102120410200 +013020314334233240543141441351342432435423252532545655664253435662546145412112135314414140233322202 +023101011114024240134343343214355543453244325544366633232356362353335431215322232434231302030012200 +121203223241323132430512521115213312263253263242264335335446352453314333354413113210133333212120303 +102030123234100043232214342352345452215246465634534464364425653323345231332311444434220444330131120 +000331303323044244144032522114521112125142214553424464423124453113211413324230342333130021200000221 +121203123313224230334312325441234431451535345453515132125413445443323514321330302200100022013232311 +000221331111234212331404233225332533323225131525322111443344452254442544201223424140243032213101301 +010202021330012103042021024434411545123253214353525251521434235541535344240243403200122322133122101 +121102231211003113342040440404003344542241345133131133414435235243325441120032344431223311313111221 +011210032333020312123124101444102341443212553521355222414135533333310320012002223342012031112321112 diff --git a/day08/solution.nim b/day08/solution.nim new file mode 100644 index 0000000..f2c4f23 --- /dev/null +++ b/day08/solution.nim @@ -0,0 +1,85 @@ +import std/strutils +import std/strformat +import std/sequtils +import std/algorithm +import std/sugar + +type + Tree = tuple + height: int + found: bool + +proc scanTree(tree: Tree, answer: var int, maxHeight: var int): Tree = + result = tree + if tree.height > maxHeight: + maxHeight = tree.height + if not tree.found: + answer += 1 + result = (tree.height, true) + +proc calculate(row: var seq[Tree], reved = false): int = + var + answer = 0 + maxHeight = -1 + newRow: seq[Tree] + + if reved: + newRow = row.reversed() + else: + newRow = row + + for i, r in newRow: + newRow[i] = scanTree(r, answer, maxHeight) + row = newRow + + return answer + +func part1(content: seq[string]): int = + var grid = map( + content, + (row) => zip(map(row, (c) => ord(c) - ord('0')), newSeq[bool](row.len())) + ) + var answer = 0 + + for row in grid.mitems(): + answer += calculate(row) + answer += calculate(row, true) + + for i in 0 ..< grid.len(): + var col = map(grid, (row) => row[i]) + answer += calculate(col) + answer += calculate(col, true) + + return answer + +func checkVisibility(line: seq[int], height: int): int = + result = 0 + for h in line: + result += 1 + if h >= height: + return result + + return result + +proc part2(content: seq[string]): int = + let grid = map(content, (row) => map(row, (c) => ord(c) - ord('0'))) + result = 0 + + for i, row in grid: + for j, h in row: + var col = map(grid, (row) => row[j]) + var count = + checkVisibility(row[j+1 .. ^1], h) * + checkVisibility(row[0 .. j-1].reversed(), h) * + checkVisibility(col[i+1 .. ^1], h) * + checkVisibility(col[0 .. i-1].reversed(), h) + + # echo fmt"{i}, {j} = {count}" + result = max(result, count) + + return result + +let content = readFile("./input.txt").strip().splitLines() + +echo part1(content) +echo part2(content) diff --git a/day09/example.txt b/day09/example.txt new file mode 100644 index 0000000..60bd43b --- /dev/null +++ b/day09/example.txt @@ -0,0 +1,8 @@ +R 5 +U 8 +L 8 +D 3 +R 17 +D 10 +L 25 +U 20 diff --git a/day09/input.txt b/day09/input.txt new file mode 100644 index 0000000..06c4a9b --- /dev/null +++ b/day09/input.txt @@ -0,0 +1,2000 @@ +L 2 +R 2 +U 1 +R 2 +U 2 +D 2 +U 1 +L 1 +U 1 +L 1 +D 1 +U 1 +L 1 +R 1 +L 2 +D 2 +R 1 +L 2 +D 2 +L 2 +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 5 +U 9 +R 11 +D 18 +R 16 +L 4 +D 8 +R 18 +L 14 +R 11 +D 14 +R 2 +D 6 +L 12 +D 3 +U 3 +L 4 +D 7 +L 4 +D 6 +L 12 +D 9 +L 2 +R 16 +L 12 +U 4 +L 12 +U 4 +R 17 +L 8 +U 8 +R 11 +U 14 +D 15 +L 19 +R 1 +L 16 +R 3 +U 15 +R 5 +L 1 +D 17 +L 13 +U 14 +D 9 +U 3 +L 7 +R 11 +D 7 +R 15 +L 6 +U 17 +R 17 +D 17 +U 18 +L 1 +R 8 +L 7 +D 9 +L 5 +D 1 +R 2 +D 16 +U 18 +D 7 +U 13 +L 10 +U 15 +R 18 +U 7 +L 9 +R 6 +U 18 +R 9 +D 8 +L 6 +R 7 +L 11 +U 12 +R 7 +D 4 +U 8 +R 16 +U 17 +D 4 +U 10 +L 19 +D 14 +L 12 +R 18 +D 4 +R 9 +U 12 +R 14 +U 9 +L 16 +D 14 +U 7 +R 14 +L 19 +U 16 +L 18 +U 1 +R 19 +D 7 +R 6 +U 12 +L 16 +R 16 +U 16 +L 6 +R 18 +L 19 +U 10 +D 15 +U 7 +D 1 +U 7 +L 12 +U 4 +R 5 +U 12 +R 18 +D 15 +U 4 +L 8 +U 18 +D 18 +L 3 +R 19 +L 15 +R 11 +U 1 +R 6 +L 8 +R 1 +L 3 diff --git a/day09/solution.nim b/day09/solution.nim new file mode 100644 index 0000000..ef25492 --- /dev/null +++ b/day09/solution.nim @@ -0,0 +1,61 @@ +import strutils +import sequtils +import sets + +type Move = tuple[Direction: char, Distance: int] +type Position = tuple[r: int, c: int] + +proc parse(content: seq[string]): seq[Move] = + let moves = map(content, + proc (line: string): Move = + let temp = line.split(" ") + (temp[0][0], temp[1].parseInt()) + ) + return moves + +proc move(rope: var seq[Position], uniqPositions: var HashSet[Position]): void = + for i in 1 ..< rope.len(): + # rope[i-1] = leader + # rope[i] = follower + let roffset = rope[i-1].r - rope[i].r + let coffset = rope[i-1].c - rope[i].c + + if roffset in [2, -2]: + rope[i].r += int(roffset/2) + if coffset in [-1, 1]: + rope[i].c = rope[i-1].c + + if coffset in [2, -2]: + rope[i].c += int(coffset/2) + if roffset in [-1, 1]: + rope[i].r = rope[i-1].r + + uniqPositions.incl(rope[rope.len()-1]) + +proc emulate(moves: seq[Move], len = 2): int = + var rope = newSeq[Position](len) + var uniqPositions: HashSet[Position] + init(uniqPositions) + echo rope + for move in moves: + for i in 1 .. move.Distance: + case move.Direction: + of 'U': + rope[0].r -= 1 + of 'R': + rope[0].c += 1 + of 'D': + rope[0].r += 1 + of 'L': + rope[0].c -= 1 + else: + assert(false) + move(rope, uniqPositions) + + return len(uniqPositions) + +let content = readFile("./input.txt").strip().splitLines() +let moves = parse(content) + +echo emulate(moves) +echo emulate(moves, 10) diff --git a/day1/example.txt b/day1/example.txt deleted file mode 100644 index 2094f91..0000000 --- a/day1/example.txt +++ /dev/null @@ -1,14 +0,0 @@ -1000 -2000 -3000 - -4000 - -5000 -6000 - -7000 -8000 -9000 - -10000 diff --git a/day1/input.txt b/day1/input.txt deleted file mode 100644 index 723d26d..0000000 --- a/day1/input.txt +++ /dev/null @@ -1,2238 +0,0 @@ -5118 -5554 -4186 -4729 -1242 -4360 -1427 -5312 -6012 -1017 -5581 -5203 -3811 -4945 -3960 - -3812 -7757 -4448 -2205 -15715 - -4164 -6482 -4479 -3061 -4082 -2474 -1175 -1918 -4755 - -4056 -5122 -11426 -5529 -3659 -9592 -10257 - -3435 -3106 -4933 -2695 -3107 -6567 -5579 -1463 -5734 -4547 -4532 -2152 -5132 - -6074 -11600 -4337 -3444 -7637 -6725 -1189 - -5637 -1226 -7068 -6290 -4411 -3858 -6677 -1858 -2840 -1175 -5056 -6569 - -32887 -19643 - -4951 -2276 -4300 -4473 -1895 -5251 -1770 -4623 -4602 -4925 -1769 - -68012 - -5760 -2687 -3192 -2730 -4867 -4723 -2591 -1677 -4458 -4388 -6038 -3127 -6416 -3048 - -2485 -1630 -1595 -2864 -2125 -3852 -2216 -3883 -4293 -4165 -2762 -4016 -2508 -1396 -4541 - -5918 -6874 -6644 -4024 -3229 -1318 -1851 -1566 -1035 - -7625 -1369 - -3894 -18802 -1362 -12368 - -10251 -6249 -2784 -9394 -5932 -5610 -7201 -9922 - -10994 -10092 -4121 -2966 -1178 -2235 -9379 - -2592 -1895 -1740 -4357 -5314 -1068 -2228 -3775 -3949 -7162 -3078 -1450 - -9484 -1796 -8055 -7901 -9323 -1982 -2517 -8358 -2614 - -18536 -23454 -12107 - -6703 -6966 -1086 -7022 -3487 -3871 -2568 -6441 -1216 -2105 -5100 -2945 - -3268 -4866 -3569 -4374 -3666 -2477 -3263 -1312 -5121 -6592 -5337 -1417 - -17864 -11775 -1345 -11675 - -6636 -1678 -3982 -4552 -2719 -2736 -1342 -6375 -2671 -1541 -1093 -5538 - -21177 -36871 - -4608 -5474 -5004 -3229 -2744 -1577 -2182 -4518 -4930 -1986 -5776 -5023 -2070 -5342 -1952 - -13940 -15506 -13799 - -3672 -3303 -4866 -5507 -5282 -5768 -2847 -2214 -1688 -2255 -4302 -4962 -4585 -4285 -3602 - -4766 -4358 -4532 -10741 -13311 -2271 - -3073 -5990 -8256 -3692 -4658 -4561 -6347 -3260 -6938 -8643 - -5261 -1524 -1671 -3277 -2326 -5603 -5837 -1638 -5104 -3696 -1910 -2319 -2305 -1373 -4801 - -2593 -3527 -1517 -4626 -2003 -4414 -4677 -2282 -3000 -1457 -3530 -5344 -1890 -1703 -1268 - -9002 -7173 -3848 -6891 -1741 -5303 -1670 -1342 -1865 - -10319 -10539 -2972 -4667 - -4318 -1366 -1430 -5003 -2691 -7117 -3015 -6516 -6895 -1618 -3189 -6739 - -2494 -7140 -2905 -8784 -8727 -4711 -2284 -6894 -7030 -1688 - -1853 -7351 -7815 -3222 -8276 -1461 -5028 -8048 -5534 - -12546 -6236 -20372 - -2778 -5745 -2783 -5774 -4508 -3691 -6097 -4637 -5643 -5902 -1166 -1208 -3983 -5030 - -3767 -2558 -3988 -1056 -6570 -5437 -1920 -2822 -9126 - -3173 -3242 -5762 -4311 -5206 -3892 -4978 -5065 -1319 -2577 -1347 -3232 -1915 -5986 -3536 - -2308 -2812 -1119 -3845 -4589 -4779 -1503 -3613 -1576 -3827 -1468 -1533 -5896 -4981 - -9740 -16395 -19471 -12882 - -4779 -7293 -12593 -15897 - -36970 - -2386 -1094 -2957 -4452 -4005 -2723 -1124 -3533 -2671 -1701 -2508 -3075 -4741 -1471 -3416 - -37202 - -5272 -2736 -4756 -2235 -4679 -4093 -1773 -4088 -2419 -3192 -4429 -3959 -5230 -4342 - -8514 -11430 -5023 -9565 -3726 -11026 -6334 - -6563 -2638 -12569 -3458 -5449 -1216 - -1320 -4708 -1627 -4189 -3962 -1463 -2628 -5667 -5494 -6105 -4925 -3540 -1613 -2288 - -5974 -7710 -5200 -4859 -2346 -5619 -1337 -4814 -1359 -3020 -1798 - -2744 -1957 -10669 -4877 -3507 -7657 -7748 - -1021 -4297 -1689 -6925 -16175 - -7147 -11617 -5654 -11861 -6065 -3090 -1744 - -3782 -6658 -2389 -4339 -2312 -7245 -2039 -3411 -6251 -1778 -2345 -5814 - -13113 -10123 -18700 -6991 - -16138 -11645 -18610 - -9586 -6653 -1001 -4547 -2891 -2726 -7618 -5679 -1567 - -2380 -1858 -1059 -1160 -5115 -2588 -1969 -2629 -5525 -5831 -2139 -5469 -2783 - -10606 -4518 -9057 -5905 -4187 -4693 -4396 -2191 - -4374 -4407 -1083 -7787 -7716 -7505 -10096 -10650 - -5809 -4387 -3426 -3730 -3699 -4944 -4176 -2681 -5197 -1325 -5920 -4957 -5876 -5345 - -20155 - -1243 -11423 -13133 -4539 -4880 -4276 - -1073 -1316 -1841 -5102 -1196 -4847 -1293 -2424 -2345 -2298 -4214 -4215 -5760 -5775 - -4542 -1152 -5164 -5642 -2069 -1419 -5614 -7343 -1507 - -2840 -3922 -3563 -1856 -5216 -4886 -3794 -4637 -1826 -3520 -5582 -4602 -2442 -3631 -4946 - -7956 -3248 -7897 -7846 -2054 -5576 -3753 -3378 -1899 -3490 -6142 - -9837 -10901 -15019 -1735 -5306 - -3246 -2485 -5573 - -2722 -2084 -18774 - -7940 -10855 -8498 -5547 -13550 -4239 - -1857 -7355 -4374 -6798 -2341 -13128 - -14215 -9770 -2447 -1035 - -8426 -1873 -4518 -2812 -7611 -2465 -4770 - -8166 -19955 -6472 - -10884 -11212 -1463 -2716 -1796 -12003 -1240 - -2802 -2639 -3268 -2492 -6676 -8851 -4054 -9603 -5354 - -1483 -3080 -6696 -8713 -6856 -4796 -7728 -4600 -3616 -8565 - -26580 -15329 - -6074 -15758 -5707 -13583 -2595 - -4957 -9125 -6534 -8684 -1728 -3690 -7983 -4131 -8907 - -12147 -15776 -14765 -17316 - -27492 -12173 - -5967 -1170 -7896 -7865 -7945 -2261 -2026 -1751 -3988 -3759 -5258 - -20764 - -7020 -7441 -8780 -6111 -3483 -8606 -4547 -8153 -3543 -6791 - -5397 -4408 -1572 -2315 -3376 -2021 -1140 -2876 -5045 -6034 -4404 -5705 -3814 -3981 -3814 - -6836 -3601 -7452 -8519 -2302 -2382 -8481 -1455 -7154 -6565 - -2077 -5139 -5462 -1508 -2094 -4850 -1688 -4382 -1991 -2297 -1930 -4720 -4995 -2891 -1967 - -2201 -3673 -9817 -7417 -1283 - -4988 -3052 -2258 -6022 -3678 -2938 -7073 -6437 -2402 -5973 - -2492 -4592 -1501 -4818 -3141 -3470 -2821 -4367 -4952 -2779 -2237 -4283 -5625 -2935 - -2422 -5273 -4053 -4471 -1343 -1128 -4538 -4328 -2974 -3674 -4155 -5472 -3520 -2427 -4145 - -19383 -13539 -9822 -2453 - -2244 -3506 -2573 -3837 -1725 -5081 -4668 -4438 -2414 -1446 -1862 -2453 -2049 -4867 -5438 - -16970 -5265 - -7417 -8051 -7490 -1175 -11316 -4219 - -1065 - -6974 -1232 -6746 -3660 -3883 -5403 -3793 -4956 -4253 -2237 -5815 - -6537 -4906 -11084 -7541 -10019 -5164 -11601 - -4215 -4216 -1160 -2096 -1453 -6271 -5534 -4353 -6423 -4060 -6811 -4701 -3383 - -2138 -12998 -19743 - -8678 -6328 -6426 -7184 -8008 -7896 -5365 -9506 -1955 - -1498 -19856 -7833 - -17023 -7023 -21278 - -2110 -5542 -7191 -6509 -8813 -5236 -7771 -9593 -1262 - -11625 -19032 -17458 - -5266 -4751 -7950 -2185 -7837 -5710 -2053 -7332 -7422 -6356 - -5781 -1330 -2974 -2628 -7407 -7339 -3767 -5411 -3400 - -5330 -3441 -6203 -5272 -5867 -6034 -3167 -2187 -6006 -6614 -1089 -2485 - -3792 -4129 -1207 -1121 -3599 -6143 -4394 -5550 -1488 -2675 -6064 -1527 -4429 - -1606 -1129 -5426 -5260 -3827 -5595 -2286 -1974 -7525 -1290 -4569 - -2181 -5045 -7730 -5502 -5467 -7720 -1780 -4553 -1188 -4213 - -2565 -10635 -12032 -3283 - -9902 -2896 -9653 -6296 -2656 -11583 -5835 - -4932 -4548 -3832 -2377 -3371 -2612 -1907 -3494 -4567 -3130 -3375 -2750 - -7757 -1033 -8201 -13544 -13481 - -3382 -12952 -9450 -4982 -13966 - -4691 -3678 -1026 -7359 -1885 -1245 -5281 -8602 -6744 - -13041 -9202 - -3621 -3558 -2279 -2854 -6415 -5368 - -1102 -5319 -5768 -1990 -2526 -1900 -6294 -4744 -3655 -5011 -3092 -2697 -3864 - -12013 - -27776 -14644 - -5434 -1501 -1439 -4972 -1365 -6076 -1428 -6291 -6020 -5509 -3835 -2571 -6308 -1483 - -3972 -9357 -8383 -11037 -9557 -10966 - -8344 -1761 -10183 -4200 -3936 -5778 -9722 -1298 - -3962 -2611 -7361 -1156 -2522 -2462 -4249 -5127 -1443 -5989 -2942 - -5384 -7053 -2194 -11964 -5937 -7708 - -3052 -3192 -3224 -5708 -2120 -5756 -6107 -1198 -5519 -3803 -1169 -2903 -5942 -4376 -3675 - -11517 -9051 -2084 -4508 -4197 -7219 -9902 - -4566 -5562 -4263 -1970 -1965 -1333 -1601 -2665 -3443 -5463 -4981 -3792 -2588 -3282 - -1243 -3604 -4947 -1044 -6962 -2276 -2828 -6334 -2508 - -1339 -3050 -10158 -2095 -7779 -5165 -9420 -6101 - -4512 - -3273 -2248 -2082 -12415 -13944 - -5638 -5204 -3327 -1361 -3775 -3421 -7597 -1917 -1802 -3896 -4058 - -1901 -1813 -7388 -3861 -6838 -6154 -5500 -3086 -6403 -3654 -7471 -6904 - -1932 -1303 -1930 -1720 -5505 -1595 -2260 -5629 - -38957 - -4629 -3672 -3629 -5011 -5182 -3952 -2295 -4943 -2644 -2851 -5894 -4654 -5257 -3972 - -48469 - -3481 -1398 -3837 -2611 -3330 -3229 -7619 -4106 -6816 -3486 -2763 - -6591 -2522 -6262 -5458 -3025 -2804 -6403 -1390 -2964 -3081 -3449 - -6408 -3223 -4302 -1079 -5836 -5580 -1538 -2616 -3850 -5272 -3688 -2381 -5775 -5497 - -1891 -1448 -4283 -5965 -2726 -1425 -5399 -2795 -1583 -2489 -5171 -3133 -2547 -5117 -3092 - -11463 -11581 -6972 -5410 -3675 -8578 -4283 - -1398 -1747 -1341 -5365 -5086 -2268 -4544 -5286 -5910 -1393 -4580 -4726 -1123 -3949 -1223 - -7526 -3223 -5495 -7184 -10259 -7681 -4795 - -7168 -6278 -7939 -3829 -3670 -7969 -4917 -7406 -9035 - -5687 -4872 -2967 -10772 -9196 -6207 -6244 -2801 - -3500 -1786 -1517 -1585 -4536 -2645 -5249 -4808 -5681 -4591 -5595 -2751 -3336 -1615 -2200 - -6894 -4752 -1794 -6507 -2184 -5589 -3016 -4532 -2321 -6843 -2909 -2104 -4065 - -24126 - -3293 -8274 -1297 -4841 -4653 -1817 -1972 -6169 -1001 -7070 - -6969 -5331 -4779 -5316 -5249 -3315 -4355 -3596 -3868 -5647 -1110 - -5235 -5846 -5619 -6259 -4372 -2600 -7526 -3962 -3840 - -4260 -4484 -6361 -4276 -6344 -4776 -1173 -1884 -4572 -1411 -5230 -3976 -1800 -2426 - -19185 -15235 -19905 -8664 - -3346 -7532 -8840 -2182 -10048 -4181 -5030 -8078 - -2080 -2279 -6250 -3388 -6097 -4607 -6262 -4259 -3261 -4653 -3338 -7025 - -1138 -2851 -5912 -8592 -7341 -3596 -7669 -1030 -7624 - -6551 -6753 -7807 -4296 -3515 -6873 -5010 -8497 -1742 -5767 - -8921 -7840 -9067 -3809 -4347 -2876 -3886 -9982 - -11455 -10295 -15198 - -1574 -4240 -4052 -1739 -5701 -8449 -5055 -3893 -2700 - -3864 -4306 -4190 -1165 -1708 -5705 -5654 -6753 -3840 -4139 -2121 -5735 - -1662 -3541 -2480 -6124 -3355 -5737 -5537 -6806 -7953 -1109 - -14180 -15876 -25965 - -7732 -33422 - -5918 -5146 -6768 -9366 -1687 -1440 -3115 -1065 -6514 - -2316 -4905 -2945 -5351 -6196 -6207 -5751 -3811 -4765 -1419 -5253 -1616 -2274 -6363 - -5125 -2491 -5057 -2749 -1586 -4997 -5249 -3944 -3964 -3845 -2457 -5972 -5313 -6453 - -30602 -6865 - -4413 -1651 -6256 -6524 -3466 -1160 -4599 -6477 -2681 -1855 -4785 - -6435 -5377 -6008 -1744 -5182 -4469 -3999 -2913 -3367 -3233 -2369 -1712 -5408 -4622 - -4201 -5475 -1117 -2679 -2649 -1446 -4043 -1136 -3750 -4523 -3800 -3245 -3179 -6183 - -7682 -7213 -5144 -1557 -5579 -5005 -6307 -5906 -7244 -6230 - -1205 -2764 -3576 -5212 -1723 -4138 -1801 -1772 -4809 -1429 -2010 -3093 -4435 -2268 -4904 - -4386 -6822 -1865 -3688 -6771 -5433 -1430 -4870 -6745 -5758 -4456 -6549 -6203 - -2413 -3287 -3376 -5780 -1190 -1177 -1577 -4375 -5558 -5117 -6773 -2483 -4436 - -5870 -4195 -5932 -1117 -5072 -4581 -6922 -2695 -3134 -2021 -3327 -5538 -2324 - -2609 -4270 -5809 -1096 -6794 -3530 -3222 -4881 -3806 -2887 -7158 - -2989 -5279 -6821 -2474 -3144 -8621 -3854 -5012 -1144 -1354 - -9033 -7624 -5535 -2433 -1433 -5568 -8161 - -5691 -5394 -3445 -4619 -1703 -6197 -2113 -4277 -2506 -3380 -6039 -6423 -6429 - -23751 -4571 -7508 - -9674 -3084 -3612 -3841 -3555 -8146 -6263 -7746 -3586 - -7907 -6263 -2320 -4430 -15429 - -2825 -2248 -7184 -3650 -1008 -5219 -5600 -2610 -7357 -5113 -1039 -2019 - -2167 -4159 -6290 -3757 -10133 -1345 -7250 -10590 - -6712 -5361 -3243 -6239 -1667 -2699 -5389 -1400 -1334 -2382 -1604 -3256 -2439 - -6520 -1478 -3049 -6452 -6899 -1850 -2466 -3485 -3020 -6683 -8000 - -7715 -6597 -5588 -2062 -6732 -3811 -10470 - -4793 -1206 -6481 -11715 -8827 -3174 - -3492 -1535 -2603 -5877 -4937 -6805 -1620 -9488 -1593 - -2182 -8258 -3319 -5499 -6257 -1466 -6435 -8334 -1140 -6764 - -15599 -28121 - -5804 -6653 -1670 -7337 -4711 -8303 -10073 -6327 - -2754 -2040 -2295 -8503 -2231 -11685 -6556 - -16325 -4057 -11110 - -6482 -2035 -5189 -6641 -4232 -1100 -1088 -2779 -2220 -3078 -2847 -6009 -1981 - -8655 -8687 -7225 -4133 -4449 -7193 -4009 -7455 - -2014 -2691 -1207 -1140 -6736 -4780 -2781 -2855 -5056 -3590 -2372 -6188 - -6779 -4130 -5169 -5726 -1503 -1520 -8302 -3054 -3037 -6190 - -6862 -7039 -1305 -4226 -5769 -5068 -8362 -7612 -6856 - -17695 -18988 -3757 -15137 - -5268 -3234 -2073 -1529 -1190 -5659 -7316 -3075 -4191 -6111 -2582 -7122 - -9316 -2087 -2980 -12121 -1703 -6661 -4286 - -20694 -6712 -15401 - -4342 -3838 -3208 -2372 -1410 -1648 -2342 -6113 -5573 -6091 -2624 -1749 -5643 -4258 - -2303 -2178 -3449 -3150 -3825 -3673 -1326 -6377 - -10398 -3801 -11714 -7455 -3382 -6182 - -27882 - -6667 -3268 -11915 -7045 -10478 -10538 -2287 - -5694 -5516 -6094 -4909 -5685 -4931 -5949 -6361 -6476 -6439 -1667 -5691 -3883 -3307 - -9977 -7477 -6533 -9766 -4576 -2051 -1376 - -5966 -7654 -5784 -2727 -7568 -4600 -2150 -1333 -6583 -4119 -2648 - -11274 -8674 -4155 -2163 -1897 -6579 -11099 - -2751 -4530 -5488 -1491 -2456 -2752 -1767 -6113 -7730 -7127 - -8657 -6947 -4803 -5103 -4373 -9501 -1486 -5689 - -4382 -5176 -2533 -6017 -6100 -4935 -1841 -4530 -6120 -4735 -3438 -3305 -5324 -2814 - -41401 - -20975 -30628 - -2099 -5390 -4829 -5845 -2674 -1029 -3312 -3412 -3402 -5544 -4773 -5274 -2458 -4309 -2741 - -4345 -7095 -7361 -2171 -6003 -5069 -1941 -2473 -2116 -6508 -6491 -7227 - -8137 -8052 -5372 -1086 -2369 -5763 -8937 -9055 -1208 - -4359 -3906 -5012 -2086 -4937 -4239 -3390 -3280 -4948 -3906 -6387 - -6430 -11071 -1179 -6918 -12028 -1855 - -11059 -14754 -15751 -15821 -9411 - -8722 -1104 -7422 -9229 -7919 -6200 -2274 -2980 -5686 - -3277 -4325 -9477 -9651 -4798 -8742 -4308 -6656 -6746 - -5777 -6805 -4337 -4847 -4966 -3525 -2729 -6611 -3070 -3734 -1957 -1360 -1678 - diff --git a/day1/solution.nim b/day1/solution.nim deleted file mode 100644 index b17411a..0000000 --- a/day1/solution.nim +++ /dev/null @@ -1,20 +0,0 @@ -import std/strutils -import std/algorithm - -let content = readFile("./input.txt").splitLines() - -var - sum = 0 - sums = newSeq[int]() - -for line in content: - if line.isEmptyOrWhitespace(): - sums.add(sum) - sum = 0 - continue - sum += parseInt(line) - -sort(sums, system.cmp[int], Descending) - -echo sums[0] -echo sums[0]+sums[1]+sums[2] diff --git a/day2/example.txt b/day2/example.txt deleted file mode 100644 index db60e36..0000000 --- a/day2/example.txt +++ /dev/null @@ -1,3 +0,0 @@ -A Y -B X -C Z diff --git a/day2/input.txt b/day2/input.txt deleted file mode 100644 index b94766c..0000000 --- a/day2/input.txt +++ /dev/null @@ -1,2500 +0,0 @@ -C Y -A Z -B Y -A Z -A X -A Z -B Y -A Z -B Y -C Z -B Y -C Z -A Z -C Y -B Y -B Y -B Y -C Y -B Y -B Y -A X -B Y -A Y -B Y -B Y -B X -A Y -C Z -C X -A Z -B Y -A X -C Y -C X -C Z -C X -B Y -B Y -B X -A Z -A X -C Y -A Z -C Z -B X -C X -B Y -C X -C Z -C Y -C Z -A Y -A Z -C Z -A Z -A Z -A Z -A Z -B Y -A Z -B Y -B Y -B Y -B X -A Z -B X -C Z -C Z -A Z -A Z -B Y -C Y -A X -C Y -C Y -B Z -B Y -C X -A X -A Z -C Z -C X -B Y -A X -C X -B Y -C X -B Y -C X -B Y -C Y -A Z -C Z -B X -C Y -B Y -A Z -B X -C Z -C Z -B Y -C Z -C X -A X -A Z -A Z -A Y -C Z -C Y -A X -C Z -C Y -A Z -C X -B X -A Z -B Y -A Z -B X -C X -A Z -C Y -C Z -B Y -C Y -C X -A Z -C X -C X -B Y -B Z -A X -B X -C Y -A Z -B Y -C Z -B Y -C Z -B X -B Y -B X -B Y -B Y -B Y -C Y -A Z -A Y -A Z -C Z -B Y -C Z -B Y -C Y -A Z -B X -B Y -C Z -A X -A Y -C X -B X -A Z -C X -A Y -A X -A Z -A Z -A Z -B Y -B Y -B Z -B Y -C Y -B Y -A Z -C X -A Z -A X -B Y -A X -C X -C X -A X -B X -C X -C Z -B Y -B Y -C Y -B X -C X -A Z -B Y -B Y -C Z -A Z -B Y -B X -C Z -A Y -B Y -A Y -C Y -C X -A X -B Y -C X -B Z -B Y -B Y -A Z -C Y -B Y -B Y -A Y -B Z -B Z -A Y -B Y -C Y -A Z -B Y -C Z -A Z -B Y -A Z -C Y -A X -B Z -C X -C Y -B Y -C Y -A Z -A Z -B Y -B Y -C Y -A Y -A Y -C Y -A Z -C Y -B X -C X -A X -A Y -A Z -A Y -A Z -B Y -B Y -B Y -A Z -C Y -C Z -A Y -C Y -A Z -A Z -C Z -B Y -A Z -C Z -B Y -C Y -C Z -C X -B Y -A Z -B Y -B Y -A Z -C X -B Y -A Z -B Y -C Y -A Y -A Z -C X -A Z -A Y -C Y -A Z -C Y -C Y -B X -A Z -B Y -A Z -C Y -B Y -B Y -B Y -A Z -C Z -C Y -B Y -C Z -C Y -C Y -C Y -A X -B X -C X -B Y -B Y -B X -B Y -B Y -C Z -B Y -B Z -C X -B Y -C Y -C Y -B X -A Z -B Y -B Y -A Z -B Y -C Z -B Y -B Y -A Z -C Z -C Z -A Z -C Y -B Y -B Y -C Y -B Z -A Y -C X -A Z -B X -C Y -A Z -C Z -B Y -B X -B Y -B Y -B Y -C Z -A Z -B Y -B X -B Y -B X -B X -C Z -A Z -B Y -C Z -A Z -C Y -C Y -A Z -A Z -A Y -B Y -C X -A Z -B Y -A Z -A Z -A Z -A Y -A Z -A Z -A Y -A X -A Z -C Z -C Y -C Y -C X -A Z -A Y -B Y -A Z -A Z -B Y -B X -B Y -A Z -A X -B Y -C Y -C Y -A Z -C Y -C X -B Y -A X -A X -C Y -A X -C Z -C X -C Y -B Y -A Z -C Y -A Z -A Z -C Z -B Y -A Z -A Y -A X -C X -C X -B Y -C X -B Y -C Z -A Y -B Y -C Y -C X -B Y -C Y -A Z -B Y -A X -C Y -A Y -A Z -A Z -B Y -A Z -A Z -C X -B Y -B Y -A Z -B Y -C Y -C Z -A Z -C Z -C Z -B Y -A Z -B Y -A Z -B Z -C Z -A Y -B Y -B Y -B Y -C Y -A X -A X -B X -B Y -C Z -C Y -C Y -C Y -A X -B Y -B Y -C Z -C X -B Y -A X -A Z -C Y -C Y -A Z -A Z -C Z -A Z -C Y -B Y -A X -B Y -C Z -A Z -A Y -B Y -B Z -C Y -C Y -C X -B Y -C Y -C Y -C Y -C Z -B Y -A Y -A Y -A Z -B Y -C X -B X -B X -B X -A Z -B Y -C Z -C Z -C X -B Y -B Y -B Y -A X -A Z -A Z -B Y -C Y -B Y -C Y -B X -A Z -B Y -B Y -B Y -B Y -B Y -B Y -C X -A Y -B Y -B Y -C Y -A Z -B Y -C X -B X -C Z -C X -A X -C X -B Y -B Y -C X -B Y -C Y -A Z -B Y -A X -C Y -A X -C Y -C Y -B Y -A Y -A Z -B Y -C Z -C Z -B Y -C Z -A Z -A Y -A Z -C Y -C Z -B Y -C Z -A Z -C X -A Y -C Z -A Z -B Y -C Z -C Y -B Y -A Z -B X -A Z -B X -C Z -B Y -A X -C Y -A Z -C Y -B Y -B Y -B Y -C Y -B Y -B Y -C X -A Z -A Z -B Y -C Y -C Z -C X -A Z -C Y -B X -B Y -A X -B Y -A Z -A Z -B Y -B X -C Z -C X -B Z -A Y -B Y -B Z -C Y -A Z -B X -C Y -B Y -C Z -B Z -A Y -A X -C X -B Y -C Y -A X -A Z -B Y -A Y -B Z -C X -B Y -C Y -C X -A Z -A Y -A Z -B Y -C Z -B X -A X -B Y -B Z -A Z -C Y -C X -A Z -C Y -C Z -B X -A Z -B X -A Z -A Z -C Y -B Z -C Y -C Y -B Y -C X -B X -A X -A Z -C Z -B X -B X -B X -B Z -B Y -B Z -C Y -B Y -C Y -C Z -A Z -A X -B Y -B Y -B Y -B Y -C X -B Y -B Y -A X -C X -B Y -C Z -C Y -A Z -A Y -B Y -C Y -B Y -C X -C X -B Y -B Y -B Y -C Y -A Z -A Y -C X -A Z -A Z -B Y -C X -C Y -B Y -B Y -C Y -C X -B X -C Y -B X -A Z -B Y -C X -B X -C Y -C Y -A Z -B Y -A Z -C Y -A Z -A Z -C Z -C X -C Y -A Z -C Z -A Z -B Y -A X -B Y -B Y -A Z -C X -B Z -B Y -C X -A Y -B Y -A Z -C Z -A Z -A Z -A Z -B Y -B Y -B X -B Y -B Y -B Y -C Z -B Y -A Z -C X -C Z -A Z -C Z -C Y -B Y -C Y -B X -C Y -B Y -A Z -B Y -C X -B Y -A Z -C Y -B Y -C Y -C Z -A X -B X -C X -B X -A X -B Y -A X -C Z -B Y -C Z -B Y -B Y -C Z -B Y -A Y -C Z -B Z -A Z -C X -A Z -A Z -B Y -B Y -C Y -C Z -C X -A Y -B Y -B Y -A X -A Y -B X -C Z -C Z -B Y -C Y -B Y -C X -B Z -A Z -A Z -B Y -A Y -A Y -A X -A Z -B Y -A X -B Z -C Z -B X -C Z -B X -B Y -A Y -B X -A Z -A Z -C Z -A X -C Z -B Y -A Y -C Z -C X -B Y -B Y -A X -C Y -C X -C Y -C X -A X -B Y -B X -B Y -C Y -C Y -C X -A Y -A Z -C Y -C Y -B Y -B X -B Y -B X -A Z -A Z -C Z -B Y -B Y -B Y -B X -C Z -A Y -A Z -B Y -B Y -B Y -B X -A X -B Y -C Z -A Z -A Z -C Y -C Y -B Y -B Y -A Z -B Y -A X -A Z -C Z -A Z -B Y -C X -B Y -A X -B Y -B X -B Y -B X -C X -A Z -C Z -C Z -B X -A Z -B Y -A Z -B X -B Y -A Z -C Y -B Y -A Z -A X -B Y -A Z -B Y -B Y -C Y -A Z -B Y -B Y -C Y -A Z -C Z -A Z -C Z -B Y -A Z -B Y -A Z -C Y -B Y -A X -A Z -B Y -B Y -C Z -C Z -C Z -B Y -C Y -A X -C X -A X -C Y -A Y -B X -B Y -C Z -B Y -B Y -B X -C Z -B Y -C X -A Z -C X -B Y -A X -C X -C Y -A Z -A X -C Z -C Z -B Y -C Y -A Y -A Z -A Y -C X -C X -B Y -C Y -B Y -A Z -C X -B Y -C Y -A X -A Z -C Y -B Y -B Y -A Y -C X -B Y -C Y -B Y -B X -A Z -C Y -C Y -A X -C X -A Z -C X -B Y -A X -C Z -B Y -C X -B Y -A Z -A Y -B Y -B X -B Y -C Y -C Z -B Y -A Z -A X -B X -C X -C Z -B Y -B Y -C X -C Z -A Z -C Y -C Z -B Y -A Z -B Y -B Y -C Z -C Z -B Y -C Y -B Y -A Z -B X -B Y -B Y -C X -A Z -A Z -B Y -C Y -B Y -A Z -A Y -A X -C Z -C Y -C Z -C Z -C Z -A Z -B Y -C Z -A Z -C Y -A Z -B Y -B Y -B Y -A Z -B Y -B X -B Y -B Y -B Y -B Y -B Y -B Y -A X -C Z -B X -B Y -C X -A Z -B Y -B X -C Y -B Y -C Y -B Y -A Z -B Y -C Y -A X -B Y -C X -B X -B Y -C Z -B X -C X -C Y -C X -C Y -C X -A Z -C X -B Y -A Z -B X -A Z -B X -B X -A Z -C Z -A Z -B X -B Z -C X -C Y -A X -A Z -B X -C Y -A Z -C Z -B Y -B Y -C Y -B Z -B Y -B Y -C Y -C Z -B Y -A Z -A X -B X -B X -C X -A Z -C Y -B Y -B Y -A Z -B Y -A Z -A Z -B Y -B Y -B Y -B Y -C X -B Y -B X -C Z -B X -C X -B X -B Y -B Y -B Y -A Z -B Y -A X -A Y -C X -B X -B Y -B Y -C Z -A Y -C Z -C Y -A Z -C Z -C Z -B X -B Y -A Z -B Y -C X -C Y -C Y -B X -B Y -B Z -A Y -A Z -C X -A X -B X -C X -B Y -B Y -B Y -B X -C X -B Y -A Z -A Z -A Y -B X -C Y -C Z -A Z -A Z -B X -A Z -C Y -B Y -A X -B X -A Z -B Y -B Y -B Y -B Y -C Z -C Z -A Y -B Y -C Z -C Z -B Y -B X -A Z -C Y -C X -A Z -A Z -C Y -C X -C Y -A Y -B Y -C X -B Y -B X -C Z -C X -C Y -B Y -B Y -A Z -B Y -C Z -C Y -B X -B Y -A Z -A Z -B X -B Y -A X -A Z -B Y -B Y -B Y -B Y -B Y -C Y -B Y -B Y -C Y -B Y -B Y -C Z -B Y -A X -C Y -B Y -A Z -B Y -C Z -C Z -C Y -A Y -B Y -A Z -A X -C Y -C Z -C Y -C Z -C Z -C Y -B X -B Y -B Y -C Z -C X -A Y -C Y -B Y -B Y -A Y -A Y -C X -C Y -A Z -A Z -A X -B Z -B X -A X -A Y -A Z -B Y -C Y -B X -B Y -B Y -C Z -C X -B Y -B Y -B Y -B Y -C Y -B Y -B X -C X -C Y -B Y -A Z -A Y -A Z -C Z -C Y -A Z -A Z -B Y -B Y -C Y -A X -B Y -A Z -B Y -A Z -B Y -B X -C X -C Y -A Z -A Y -B Y -C X -A Z -B Y -A Z -C Y -B X -B Y -B X -C Z -C X -B Y -A Z -B Y -B X -A X -C Z -C X -A Z -A Y -A X -A Z -A Z -A Z -C Y -A Z -B Y -A Z -A Z -C Z -B X -B Y -B Y -B Y -B Y -A Z -B Y -C Y -A Z -A Y -B Y -B Y -C Y -C Y -A Z -C Z -A Z -B Y -B Y -A Z -A X -A Z -A Z -C Y -C Z -A Z -C X -A X -B Y -C Y -C X -C Z -B Y -C Y -A Z -A Z -C Z -A Z -A Z -A X -B Y -C Y -A Z -C X -C Y -B Y -C X -B X -B Y -C Y -A Z -A Z -A X -B Y -A Z -B Y -B Y -C Z -C Z -A X -A Y -B Y -C Z -B Y -B Y -C X -A Z -C Z -A X -B Y -A Y -B Y -C Z -B Y -C X -B Y -B X -B Y -B Y -C Y -B X -B Y -A Z -A Z -B Z -A Z -B Y -B Y -A Y -A Z -C Z -C Y -B X -B Y -C Y -B X -C X -B Y -C X -A Z -B Y -B Y -B Y -C Y -B Y -B Z -A Z -B Y -A Z -C Y -B Y -B Y -B Y -B Y -C Z -B Y -B Y -B Y -A Z -C Z -B Y -B X -A Z -C X -C Y -C Z -B Y -A Z -C Y -A Y -A X -C Y -A X -A Z -A Z -B X -B Y -B Y -C Y -B X -B Y -A Z -B X -B Y -C Y -B Y -C X -A Z -A Z -A Z -A Z -C Z -A Y -C Z -C Z -C Z -B X -B Y -B X -A Z -A Y -B Y -A X -C X -C X -B Y -B Y -B Y -A X -A X -B Y -C Z -B Y -A Z -C Y -B Y -B Y -A Z -C Y -C Z -A Y -A Z -B Y -C X -C X -A Z -B Y -C Y -A Z -A Z -C Z -C X -B Y -C Z -C Z -B Y -A Z -A Z -B X -C X -B Y -C Y -B Y -C Y -B Y -B Y -A Z -A Y -B X -C Y -B Y -C X -C X -C Y -A Z -B Y -C Y -B Y -C Y -B Y -A Y -B Y -A Z -C X -C Z -C Z -C Y -B Y -C Y -B X -B X -A X -B Y -A X -B Y -A Z -C X -B Y -A Z -B X -B Z -B Y -B Y -C Y -B Y -A Z -B Y -C Y -C Z -A Z -C Z -B Y -B Y -B Z -A Z -B Y -C Z -B X -A Z -A X -B X -B Y -A X -B Y -C Y -A Z -A Y -B Y -A Z -B Y -A Y -B Y -C Z -C Z -C Y -C Z -B Y -A Z -B X -B Y -C Y -B Y -C Y -C Y -A Z -A Z -C X -A Y -C Z -B Y -B Y -B Y -C Y -B X -C Y -B Y -A Z -A Y -B Y -B Y -B Y -C X -B Y -C Z -A Y -B X -A Z -A Z -C X -B Y -B Y -A Z -A Y -A Y -C Z -A Z -A Y -B Y -C X -A X -A Y -B Y -A X -B Y -B X -C Y -C Z -C X -B Y -C Y -A Z -B X -A Z -B Y -B Y -B Y -C Y -B Z -C Z -C Y -B Y -C Y -B X -A X -B Y -B Y -A X -C Y -C Y -C Z -B X -A Z -C X -A Z -A Z -C Z -C Y -B Y -C Y -C X -A Z -C Z -B Y -A Z -A Z -C Z -A X -B Y -B Y -C Y -A Z -B X -B X -B X -B Y -B Y -B Y -B Y -A X -B Y -B Y -B X -C X -A Z -A Z -A Z -A Z -B Y -A Z -A Z -B X -A Z -C Y -B Y -B Y -B Y -B X -C Z -A Z -B Y -C X -A X -C Z -B Y -C Y -C Z -A Y -C Z -C X -C Y -B Z -B Y -B Y -B Y -A Z -C Z -A Z -A Z -C Z -B X -C Z -C Y -B X -B Y -C Y -B Y -B X -A Y -B Y -A Z -A Z -B Y -B Y -B X -B X -B X -B Y -A Y -C X -C Y -B Y -C X -B X -A Z -B Y -C X -B Y -B Y -B Y -B Y -A Z -B Y -C Z -B Y -C Z -A X -A Z -C Y -B Y -C Z -B Y -A Y -C X -C X -C Y -A Z -B Y -C X -B Y -B Y -A X -C X -A Z -C X -A Z -B Y -C Y -B Y -B Y -C Y -A Z -A X -C X -B X -B Y -B Y -A Y -B Y -B Y -C X -A Z -B Y -A Y -B Y -B Y -B Y -C Y -B Y -C X -B X -B X -C X -A Z -C X -C X -C Z -B Y -B Y -B Y -B Y -C Z -B X -B Y -B Y -A Z -A X -A Y -A Z -C Y -B Y -B Y -C X -B Y -B Y -B X -A Y -C Y -B Y -B Y -B Y -A Z -A Z -B X -C Y -B Y -A X -B Y -B Y -B X -B Y -A Y -C X -B Y -C Y -C Z -A Z -A Z -C Z -C Y -A Z -B Y -B X -B Y -B Y -C Z -B Y -A Z -C X -B Y -A Z -B Y -B Y -B Y -C X -A Z -A X -C Z -B Y -A Z -C Y -A Y -B Y -A Y -B Y -C Y -C Z -B Y -A Z -A Z -B Y -A X -C X -C Z -C X -B X -C Z -B Z -B Y -B X -C Z -B Y -C Y -C Y -A Z -B Y -B Y -B Y -B Y -C Y -A Z -B Y -A Z -C Z -A X -A Z -B Z -A Z -C Y -B Y -C Z -B Y -C Z -A Z -C Z -B Y -B Y -B Y -A Z -B Y -B X -B X -B X -A Z -C Z -C Y -B X -C Z -A X -B Y -C Y -B Y -B X -B Y -A Z -A X -A X -B Y -C Y -C Y -B Y -B Y -A Z -C Y -A X -A Z -C Y -A Z -C Z -C Y -A Z -C Y -C X -A Z -B X -B Y -A X -C Z -C Z -B X -C X -B Y -A Z -C Z -C Y -C Z -C X -C Z -A X -C Z -B X -C Y -C Z -B Y -C X -A Z -A Y -B Y -A Z -B Y -B Y -B X -C Z -B Y -B Y -B X -B Y -C Y -C Z -B X -B Y -C Z -B Y -B Y -B Y -B Y -A Z -C Z -C Y -B X -B X -B Y -B X -C Y -C Y -A Z -A Z -B X -B Y -B Y -C Z -C Z -B Y -A Z -C X -C Y -C X -B Y -B Y -C Z -C X -B Y -C Y -C Z -C Y -C X -C Y -B X -B X -B Y -B Y -B Y -C Z -B X -B Y -C X -C Y -C Y -C X -A Z -B Y -C Y -C Z -B Y -C Y -B Y -A Y -A Z -C Z -C Z -C Y -A X -C X -C Z -C Y -C Z -B X -C Z -B Y -C X -C Y -C Y -A Z -B Y -A Z -B Y -A X -C Z -A Z -C Z -B Y -B Y -B Y -A Z -A X -B Y -B Z -B Y -B Y -A Z -B Y -B Y -C Z -B Z -A Z -C X -B Y -A Y -B Y -C Y -C Y -C X -B Y -B Z -C Y -B Y -A Y -C X -A Z -A Z -B X -C Y -B Y -B Z -A Z -A Z -B Y -A Z -A Z -A Z -C Y -A Z -A Y -A Z -C Z -C Y -B Y -A Z -B X -B Y -A Z -A Y -B X -B Y -C Y -C Z -C Y -B X -C Y -B Y -B Y -A Z -A Z -B Y -C X -A X -A Z -A X -A X -C Y -B Y -C Z -A Z -B Z -B Y -B Y -B Y -C X -B Y -C Z -B Y -B Y -C Z -C Z -A Z -A Z -A Z -A Z -C Y -A Z -A Z -B Y -B Y -A Z -A Z -C X -C Y -A Z -B Z -B Y -C X -C X -B Y -C X -B Y -C Y -C X -B Y -C Z -A X -B Y -B X -B Y -C Y -B Y -A X -C X -B Y -B Y -B X -B Y -A Z -A Z -A Z -A Z -B Z -B Y -B Y -C X -A Z -C Y -B Z -A X -B Y -B X -B Y -A X -C X -B Y -B Y -A Z -B Y -C Z -A Y -B X -C X -B Y -B Y -A Z -C X -C Y -B Y -C Y -C Z -A Y -A Z -B Y -B Y -A Z -C Y -B Y -C Y -C X -C X -C Y -C Z -A Z -C X -B Y -A Z -B Y -C X -B Y -B Y -A Z -A Z -C X -B Y -A Z -B Y -A Y -B X -B Y -B X -A Y -B Y -B X -B Y -A Z -B Y -C Z -B Y -B Y -B Y -A Y -B Y -C Z -B X -B Y -A X -A Z -B Y -A Z -B X -C Y -B Y -B Z -C Y -B Y -C Y -C X -C X -C Z -B Y -B Y -B Y -A Z -B X -A Z -C Z -B Y -A Y -B Y -C Y -A Z -B Y -A Y -B X -B Y -C Y -C Y -A Z -A Z -B Y -C Y -C Z -A Z -A X -B Y -B Y -B Y -B Y -A Z -C Y -A Z -B Y -B Y -C Z -A Z -A X -C Y -B Y -B Y -A Z -B X -C Z -C Y -C Z -C Y -B Y -A Z -A Z -B Y -A Z -A Z -B Z -C X -C X -B Y -C Z -A Z -B X -A X -A Y -C Y -C Y -A Z -C Y -B Y -A Z -A Z -C Y -B Y -A Y -B X -C Z -B Y -B Y -A Z -B Z -C Z -B Y -B Y -B Y -A Y -C Y -A Z -A X -B Y -B Y -B Y -C Z -A X -B Y -B Y -C Y -B X -B Y -A Z -B Y -A Z -A Y -C Y -B Y -B Y -A Z -B X -A Z -A Z -A Z -B Y -A Y -C Z -B Y -B X -B Y -B Y -B Y -B Y -B Y -A X -C Z -B Y -B Y -B Y -C Z -B X -A Y -B X -C Z -B Y -C X -C X -A Z -B Y -B Y -A Z -C X -C X -A Z -B X -B Y -C X -C Z -A X -B X -B Y diff --git a/day2/solution.nim b/day2/solution.nim deleted file mode 100644 index 8a794d3..0000000 --- a/day2/solution.nim +++ /dev/null @@ -1,51 +0,0 @@ -import std/strutils -import std/sequtils - -let content = readFile("./input.txt").strip().split("\n") -let rounds = map( - content, - # Split line into pair of characters - proc(round: string): tuple[other: char, self: char] = - var splitted = round.split(" ") - (splitted[0][0], splitted[1][0])) - -# example: rounds = [('A', 'Z'), ('C', 'Y')] -# echo rounds - -proc solve(dScore: array[3, array[3, int]]): int = - var score = 0 - for round in rounds: - let - i = ord(round.other) - ord('A') - j = ord(round.self) - ord('X') - score += dScore[i][j] - - return score - -let pt1 = [ - # A = Rock - # X Y Z - [1 + 3, 2 + 6, 3 + 0], - # B = Paper - # X Y Z - [1 + 0, 2 + 3, 3 + 6], - # C = Scissors - # X Y Z - [1 + 6, 2 + 0, 3 + 3], -] - -echo solve(pt1) - -let pt2 = [ - # A = Rock - # X Y Z - [3 + 0, 1 + 3, 2 + 6], - # B = Paper - # X Y Z - [1 + 0, 2 + 3, 3 + 6], - # C = Scissors - # X Y Z - [2 + 0, 3 + 3, 1 + 6], -] - -echo solve(pt2) diff --git a/day3/example.txt b/day3/example.txt deleted file mode 100644 index f17e726..0000000 --- a/day3/example.txt +++ /dev/null @@ -1,6 +0,0 @@ -vJrwpWtwJgWrhcsFMMfFFhFp -jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL -PmmdzqPrVvPwwTWBwg -wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn -ttgJtRGJQctTZtZT -CrZsJsPPZsGzwwsLwLmpwMDw diff --git a/day3/input.txt b/day3/input.txt deleted file mode 100644 index a30889c..0000000 --- a/day3/input.txt +++ /dev/null @@ -1,300 +0,0 @@ -hqBqJsqHhHvhHHqlBvlfpHQQwLVzVwtVzjzttjQVSjMjwL -gRTRnCRsFNGbTzLjwcSTMmSz -dGgsRWPGdWgZJqBBqhfpPq -HNCNJHCWJRRLqNJWlfrrrwsmlwGmmf -dddvLdLjdDvjvswlmGwlZQtjrt -dvcpbLVcvNJJHNPHSp -QDprSpLQRLQrQDmQcQFZjbbhZwdRsRFbbBss -gWGGPgNvJlgJzDlNGHCGPNZZgFBbsjbFFBwZwfhdZbZB -lHTlGMHlGCPNvClzGzJHvGcrMcVtLqMLcrrQVcVDrqrm -SrBpJFfldlFNslFJBZwsmwgVGGsCCVmZZD -jLtjvzLQMtWjbbQvDZZwGRJGgwggGZgv -MzqqjznQPqnnjznnctnFlSddPfHflhfBJFNdHd -mPNNGVCRngnSbgNw -WqsqlTssgvqvZWZzhsTzWhScdHtfJJnfbtSJwfczdtSS -sqTvhpqQvWZQLmDpDGMDGrgL -DQRcLQVLbbcbrFPcRtTBBBJnTZrrnmZTrMgJ -slGjjjdlhMfvdMQTvg -jlzNhWHhhWjHlwwwGLDSDtPQVtRzRbSzpp -DzDgfvzfDczfHCHSlgHLCmWG -PrpNPJtpPMBssmmVdmSVVr -PSRMwPnMpBNtNBTnnZwDqzQFfwhjZZqfhh -fzfBwhBJFbCwbwwg -strtgtrPgmPgFRsMdRnZRMFn -mrmLPDvGmmtSLDgmSqvHchhcHQzcQQJHBfBh -NsgwPPDgsPHqsTqqmLbLrDRhmrRVrbVW -lFpGFtfFlvSFplGFzptSGSSlhZbhjhfrmWbhLhmLbCZVZjWr -ccplJQSGcSSpVFvNqqsqPNqPQPTwqd -HFhPNNZGqSZrCDBVZBCB -RJTtwczTzCRVQrRHpR -mfgblfltwgwwmlJgcHNnGhSb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bsbHJWHLLMVZmJPQDrvmZL -ctlRbtCWWtvlSfjljjhBnBNB -TsnvssDDQlRbzMzjDMqHwq -tSGjZCfFZtCFLtVGWGZFbcqwHbhWdbzbwHbdwbdw -ZGBFJFZVBLjStZPBBZLRvlmsPTvsgrrnrTllvs -PgQdNsQFsdNwWqQBsQrTrTLpbrnTpGngnbTG -hCzzMJVDmfzmBDMCfSfhTMGcnpnTcjGrpjbMGjbL -CVVfvCflSHNHvPdBHW -DwlMjMNjStgmthMghg -PTlpHnJJTcZvTTbHZWZTvpqdHhmLgrgdfrhLLsmshmsLts -vncqTbPqcpCnbCPvccZbDBCGzzNBwjDlVVGFjjVR -QsdGGCztZVRddPgndf -DrNNBbwNHNwlbjFbbCNjNwDWWDPPVfDMgfmVMfnMWmmP -rvJBbbBNcLCtJZQL -NfLlqLhbNPddLPqLhpgHwFFwFHHTwRHWwPFTrT -MSMSCnjBnBjCscjVDVljTvHmmWnrwTrwFTrvTWTT -JCMMBzDMJcZZCjDzSBDNJgdfdQlqlLNdhgGLhp diff --git a/day3/solution.nim b/day3/solution.nim deleted file mode 100644 index 6df88f2..0000000 --- a/day3/solution.nim +++ /dev/null @@ -1,47 +0,0 @@ -import std/strutils -import std/sequtils -import std/sets - -proc Points(c: char): int = - if c.isLowerAscii(): - return ord(c) - ord('a') + 1 - else: - return ord(c) - ord('A') + 27 - -proc part1(content: seq[string]): int = - let ruckshacks = map( content, - proc(line: string): tuple[first: string, second: string] = - let pivot = int(line.len()/2) - (line[0 .. pivot-1], line[pivot .. ^1]) - ) - - var score = 0 - for ruckshack in ruckshacks: - let - uniqFirst = toHashSet(ruckshack.first) - uniqSecond = toHashSet(ruckshack.second) - - var c = toSeq(uniqFirst * uniqSecond)[0] - score += Points(c) - - return score - -proc part2(content: seq[string]): int = - assert(content.len() mod 3 == 0) - - let ruckshacks = content - var score = 0 - for i in countup(0, ruckshacks.len()-1, 3): - let - uniqFirst = toHashSet(ruckshacks[i]) - uniqSecond = toHashSet(ruckshacks[i+1]) - uniqThird = toHashSet(ruckshacks[i+2]) - - var c = toSeq(uniqFirst * uniqSecond * uniqThird)[0] - score += Points(c) - - return score - -let content = readFile("./input.txt").strip().split("\n") -echo part1(content) -echo part2(content) diff --git a/day4/example.txt b/day4/example.txt deleted file mode 100644 index 9f9e9cf..0000000 --- a/day4/example.txt +++ /dev/null @@ -1,6 +0,0 @@ -2-4,6-8 -2-3,4-5 -5-7,7-9 -2-8,3-7 -6-6,4-6 -2-6,4-8 diff --git a/day4/input.txt b/day4/input.txt deleted file mode 100644 index 5304059..0000000 --- a/day4/input.txt +++ /dev/null @@ -1,1000 +0,0 @@ -36-92,35-78 -26-31,25-27 -17-72,16-71 -3-77,76-90 -20-22,21-87 -5-75,6-75 -42-44,43-95 -51-73,50-52 -81-89,80-81 -7-58,47-58 -72-91,20-92 -27-64,51-64 -5-94,94-95 -88-93,88-89 -7-45,46-91 -30-40,29-29 -81-90,80-90 -4-71,4-71 -68-83,65-84 -1-4,3-79 -94-95,35-82 -30-84,31-97 -6-82,81-86 -88-88,4-89 -41-97,40-89 -95-99,34-94 -18-56,18-56 -53-64,22-53 -5-9,9-71 -18-41,40-66 -38-39,38-78 -23-99,22-94 -34-54,34-53 -33-76,85-94 -72-91,63-79 -33-94,93-94 -56-82,20-56 -60-85,60-86 -31-76,31-33 -29-79,78-80 -9-9,66-69 -6-97,6-75 -40-78,39-77 -14-30,14-15 -91-94,88-98 -1-23,10-23 -9-84,7-9 -75-76,75-98 -45-87,45-46 -11-11,11-11 -16-64,64-65 -60-60,20-61 -48-81,93-94 -5-48,32-47 -37-75,74-75 -13-76,13-13 -15-93,92-96 -41-86,86-96 -48-92,64-91 -1-9,2-97 -43-56,55-55 -7-99,98-99 -98-99,1-99 -15-97,7-99 -76-76,32-77 -71-76,76-77 -13-28,13-29 -38-69,42-50 -49-49,50-77 -68-84,71-83 -26-51,32-51 -12-40,39-63 -21-92,9-88 -7-65,65-69 -56-76,56-77 -40-62,62-62 -35-96,92-95 -37-99,12-86 -94-98,4-81 -32-38,34-39 -11-94,24-93 -1-97,1-60 -7-77,7-59 -62-81,80-96 -38-83,82-82 -44-44,43-98 -22-23,22-62 -28-97,16-97 -53-88,67-88 -2-2,56-97 -41-72,71-72 -78-80,47-79 -1-1,2-41 -23-99,33-98 -33-98,61-97 -80-95,80-80 -8-90,8-91 -4-90,50-89 -94-94,3-95 -3-83,2-99 -45-52,12-44 -22-65,66-71 -9-72,72-73 -2-62,2-82 -40-61,30-60 -57-87,25-56 -76-78,77-77 -16-88,87-88 -14-77,73-77 -37-90,36-38 -10-75,11-11 -37-99,3-97 -47-48,45-47 -6-92,7-91 -60-74,60-61 -20-29,8-21 -95-96,47-95 -63-70,31-63 -6-97,6-76 -19-91,19-92 -50-92,49-50 -17-96,18-97 -3-4,3-93 -13-51,1-13 -34-87,23-33 -2-99,98-98 -4-6,7-76 -46-60,36-45 -50-80,25-51 -60-61,24-61 -97-98,3-98 -33-34,83-99 -30-76,22-77 -27-72,72-94 -47-96,31-47 -26-90,11-27 -47-87,3-72 -86-91,9-87 -32-79,78-79 -72-95,94-94 -88-96,8-89 -11-84,12-98 -5-8,8-29 -6-38,86-86 -14-33,5-33 -20-95,39-94 -6-99,12-93 -52-91,52-90 -3-99,2-72 -72-96,56-90 -7-84,7-8 -20-37,14-37 -26-74,74-75 -40-54,4-71 -42-42,93-94 -53-69,23-52 -20-96,95-96 -1-18,18-83 -2-3,2-69 -36-87,87-87 -8-94,8-94 -59-99,59-60 -15-35,11-35 -6-26,5-26 -7-12,11-80 -79-79,79-79 -2-47,46-47 -76-96,96-97 -12-79,11-77 -45-71,46-94 -62-63,62-94 -30-84,84-85 -9-35,9-13 -18-60,18-61 -13-90,13-85 -2-38,1-2 -76-81,24-54 -48-49,48-95 -59-92,58-69 -72-72,15-73 -15-16,15-99 -79-85,60-86 -58-58,46-59 -55-60,3-54 -22-26,26-58 -6-86,7-85 -66-76,47-66 -52-73,52-53 -21-76,20-77 -44-73,16-77 -29-80,30-30 -15-47,14-16 -3-75,1-3 -55-61,9-56 -37-55,36-82 -64-83,83-84 -9-91,41-89 -22-86,33-85 -6-19,5-34 -80-92,93-93 -99-99,85-98 -96-99,14-97 -2-72,5-59 -93-94,56-94 -34-83,34-86 -33-34,34-73 -17-84,18-44 -82-83,26-83 -3-85,18-84 -88-88,9-88 -93-93,27-94 -12-13,12-14 -8-90,8-42 -78-86,41-77 -63-79,80-81 -15-66,14-16 -77-77,28-76 -9-96,8-10 -19-78,77-79 -13-95,72-93 -13-49,14-14 -84-85,84-95 -25-37,25-37 -49-93,49-91 -24-78,5-38 -2-92,2-92 -17-90,16-90 -8-50,8-50 -76-99,76-98 -71-86,77-86 -70-71,54-70 -8-84,39-84 -40-58,55-58 -8-87,1-9 -5-7,6-85 -25-97,24-25 -9-97,14-96 -17-48,10-47 -81-87,30-80 -3-83,83-84 -2-7,6-42 -20-70,70-93 -67-85,17-61 -7-18,6-20 -21-73,20-22 -80-81,18-79 -43-95,44-96 -38-45,44-44 -15-91,90-91 -32-44,34-43 -24-93,24-25 -10-16,11-12 -22-92,61-92 -3-7,6-73 -72-79,71-74 -34-47,34-46 -56-96,75-82 -31-48,48-81 -54-81,53-82 -2-91,93-97 -41-74,10-40 -51-63,52-86 -80-90,75-90 -86-87,10-87 -80-94,84-94 -46-47,9-47 -20-77,78-92 -38-38,17-37 -30-76,5-30 -6-58,58-77 -10-73,74-85 -1-96,2-31 -64-73,4-74 -60-79,59-77 -4-98,8-89 -7-9,8-78 -4-6,5-95 -29-93,53-90 -32-94,20-33 -78-91,38-79 -10-95,96-99 -5-97,86-96 -6-65,5-64 -28-71,7-72 -15-54,45-53 -3-87,46-99 -1-90,40-90 -44-86,19-86 -3-94,93-94 -92-93,1-93 -93-93,42-94 -90-97,21-91 -16-94,16-62 -20-27,79-86 -28-28,29-39 -30-94,29-30 -28-68,76-79 -54-73,54-55 -35-36,35-87 -5-42,43-47 -10-90,8-91 -15-74,23-49 -16-97,1-98 -2-82,82-89 -1-3,2-86 -16-87,15-86 -9-10,9-60 -14-90,10-14 -36-85,5-85 -36-41,37-89 -50-50,15-50 -82-86,85-86 -28-66,28-32 -15-84,14-14 -32-69,31-33 -31-95,30-96 -60-85,61-92 -10-87,86-87 -96-99,5-97 -97-97,39-96 -34-35,3-35 -51-88,33-88 -14-49,48-90 -4-51,52-56 -7-76,31-75 -3-99,3-87 -29-86,29-75 -61-64,61-65 -85-97,13-86 -59-67,6-58 -51-97,44-50 -21-64,64-93 -9-56,10-81 -20-51,50-51 -33-87,32-87 -18-79,5-90 -51-51,22-52 -24-83,21-25 -79-93,24-94 -14-14,13-83 -43-49,44-50 -72-72,10-73 -14-57,35-57 -4-63,3-4 -4-93,26-91 -26-93,25-26 -33-35,33-43 -36-87,87-92 -27-69,6-70 -38-60,30-39 -96-96,1-95 -2-96,99-99 -16-87,88-88 -41-52,41-51 -61-77,76-82 -9-77,3-10 -39-50,38-51 -12-63,12-62 -17-30,18-76 -22-86,22-23 -3-43,2-44 -21-66,66-66 -3-64,2-2 -60-65,60-65 -7-42,74-96 -81-98,38-98 -16-24,17-23 -95-97,32-96 -23-38,23-37 -42-54,40-46 -16-18,13-17 -1-81,3-63 -16-17,17-50 -82-87,88-97 -6-47,5-48 -8-81,92-94 -95-97,11-96 -23-94,22-86 -6-35,3-56 -7-93,90-92 -6-49,3-6 -24-86,86-86 -67-78,67-78 -11-98,10-96 -87-88,17-88 -8-98,99-99 -15-73,72-73 -1-60,60-60 -39-45,33-45 -77-95,41-76 -5-23,24-99 -96-98,97-97 -18-55,55-56 -97-98,60-90 -33-34,13-34 -7-96,8-96 -7-32,46-61 -75-93,20-96 -30-99,29-31 -4-99,3-97 -3-30,29-30 -40-40,39-63 -48-49,48-60 -22-24,6-22 -28-28,3-28 -64-64,37-63 -29-48,5-48 -20-37,19-36 -77-77,19-77 -18-85,2-19 -99-99,30-80 -35-36,31-35 -28-79,75-98 -26-94,26-95 -22-97,73-96 -42-42,5-41 -6-8,7-99 -10-14,13-14 -39-72,39-73 -12-90,89-90 -93-94,12-94 -50-88,89-93 -47-88,88-89 -39-64,38-38 -15-79,78-79 -28-32,32-33 -50-65,51-51 -7-79,6-64 -33-49,32-34 -82-95,75-96 -6-14,4-9 -95-95,10-96 -14-51,3-15 -97-98,21-98 -39-61,53-61 -68-69,37-68 -15-73,73-95 -42-70,43-83 -1-60,60-61 -6-11,11-94 -10-79,87-93 -36-40,41-41 -3-17,3-43 -4-81,4-82 -90-91,6-90 -2-3,5-68 -20-98,74-97 -4-86,3-85 -47-49,23-48 -26-89,26-90 -31-42,42-47 -57-81,39-58 -17-87,18-96 -9-77,9-78 -79-88,80-84 -30-84,83-83 -15-89,15-88 -11-11,10-94 -59-82,27-59 -8-78,14-33 -46-95,85-94 -93-97,92-94 -4-34,2-3 -34-80,30-82 -48-83,27-49 -47-99,47-48 -27-51,51-56 -48-49,35-48 -31-51,42-51 -96-97,19-96 -43-44,20-44 -76-76,13-75 -5-90,27-90 -26-27,27-51 -47-54,49-95 -69-72,4-73 -94-98,68-95 -1-2,3-86 -25-90,24-26 -28-90,89-89 -91-91,74-91 -56-95,40-57 -55-92,28-54 -28-34,27-35 -85-87,28-86 -8-10,10-98 -45-45,44-44 -31-83,27-59 -67-84,2-68 -17-69,51-69 -49-52,34-53 -22-81,2-23 -95-96,2-96 -82-99,17-82 -40-57,40-58 -9-40,40-40 -1-2,3-68 -1-97,90-97 -2-20,21-34 -2-2,1-92 -84-86,2-86 -7-92,97-99 -2-6,5-42 -1-52,1-52 -98-99,1-98 -38-80,29-43 -39-69,39-39 -97-99,3-98 -70-71,8-71 -26-52,25-38 -8-92,91-92 -12-49,13-27 -7-95,94-95 -91-99,15-92 -19-45,18-19 -75-76,76-97 -59-74,13-86 -3-3,2-3 -41-60,53-59 -75-99,29-96 -66-68,18-67 -3-91,3-95 -33-98,32-34 -5-78,10-77 -55-95,54-59 -6-81,6-81 -78-94,52-75 -20-93,10-94 -12-37,83-99 -46-93,92-99 -17-79,8-94 -45-99,46-46 -73-90,68-73 -82-83,58-83 -15-88,90-94 -66-96,18-65 -12-87,61-86 -35-85,36-84 -96-96,28-95 -82-95,2-83 -1-2,2-99 -59-88,59-60 -54-90,53-74 -35-48,57-57 -16-28,16-29 -35-45,36-36 -25-39,24-58 -19-74,27-75 -35-73,31-36 -16-76,6-87 -8-99,7-97 -1-1,1-89 -9-74,10-75 -12-74,11-56 -80-81,2-80 -13-97,19-92 -43-83,82-89 -55-59,60-60 -20-79,98-98 -61-62,61-86 -35-82,93-97 -21-42,43-43 -49-94,43-50 -5-81,98-99 -5-95,1-95 -6-80,91-97 -26-85,11-25 -34-68,19-48 -3-99,3-87 -81-81,19-81 -8-47,8-48 -46-70,46-71 -13-73,46-73 -13-83,14-82 -6-97,96-99 -19-33,18-34 -30-99,2-99 -50-84,1-84 -6-97,6-96 -96-96,6-96 -10-96,9-94 -38-39,38-43 -18-94,19-97 -86-86,87-91 -8-98,8-97 -84-86,78-85 -23-71,72-72 -5-99,98-98 -26-75,26-75 -87-87,20-88 -11-85,7-8 -52-61,45-62 -42-97,42-97 -25-89,21-24 -95-96,4-93 -66-69,67-68 -2-93,94-96 -8-9,9-81 -72-97,21-98 -59-75,58-60 -14-16,15-96 -71-71,70-71 -10-79,3-10 -54-54,53-98 -2-4,3-69 -14-66,14-67 -16-17,16-65 -27-99,76-99 -19-94,95-97 -3-83,83-84 -36-57,31-56 -34-83,33-83 -56-67,66-88 -30-70,17-31 -24-80,79-80 -43-52,42-43 -10-65,66-68 -50-69,1-70 -10-10,10-33 -10-99,9-98 -86-96,85-85 -30-65,31-60 -18-81,17-19 -12-84,49-71 -19-98,18-18 -3-67,4-68 -88-99,69-99 -11-87,10-11 -98-98,37-85 -8-90,47-89 -2-43,67-79 -5-5,4-97 -31-94,93-96 -13-83,14-14 -72-85,71-84 -51-53,26-52 -3-58,57-62 -41-58,41-58 -29-84,30-56 -89-98,21-90 -51-97,50-94 -8-96,8-95 -1-4,4-81 -23-51,52-95 -29-61,8-60 -11-15,1-5 -2-75,7-75 -42-66,46-66 -53-93,53-94 -5-99,3-6 -2-5,6-13 -65-97,46-99 -51-72,50-90 -36-65,64-66 -1-4,4-94 -7-8,7-86 -4-89,3-90 -61-98,60-62 -40-81,19-81 -28-73,27-73 -4-98,6-97 -63-73,63-89 -13-97,96-98 -5-13,13-88 -24-92,7-92 -15-31,14-28 -2-88,97-97 -11-45,11-45 -40-82,82-82 -51-51,50-60 -84-91,21-83 -71-98,71-97 -21-95,31-94 -1-97,1-41 -2-3,2-84 -3-4,4-91 -98-98,17-97 -15-15,16-84 -43-48,11-37 -13-83,11-15 -88-96,3-96 -55-91,24-55 -4-96,96-99 -66-82,80-80 -3-61,62-93 -99-99,11-70 -56-56,57-59 -40-40,39-99 -57-58,35-58 -36-95,94-94 -2-63,64-81 -18-24,24-62 -63-98,12-63 -81-81,18-80 -19-61,19-20 -11-18,11-22 -9-14,9-11 -6-7,6-85 -41-51,41-41 -18-43,17-19 -8-70,71-84 -76-76,11-75 -87-88,9-88 -55-73,54-56 -56-57,57-68 -4-11,11-88 -8-81,11-80 -25-70,71-71 -22-45,23-48 -14-84,5-95 -58-68,47-58 -17-66,38-66 -58-89,88-89 -7-28,14-27 -31-87,22-63 -92-96,39-91 -14-41,14-14 -62-65,3-61 -48-66,48-66 -4-95,2-96 -7-7,8-77 -17-50,18-51 -80-89,14-79 -28-50,28-89 -32-40,7-40 -19-77,18-19 -34-60,1-6 -33-50,51-91 -16-17,16-54 -29-45,19-32 -36-42,37-37 -1-95,3-87 -70-93,92-98 -4-11,46-79 -20-82,1-19 -40-41,2-42 -75-77,31-76 -8-14,14-78 -69-91,68-69 -9-63,77-89 -47-70,39-47 -3-98,97-98 -84-84,30-84 -9-9,10-95 -24-24,23-92 -27-95,21-95 -2-99,2-99 -38-59,54-59 -20-81,15-82 -6-73,13-73 -98-98,99-99 -18-92,17-19 -93-94,5-93 -13-99,13-14 -34-34,34-79 -12-88,87-96 -55-67,83-89 -6-30,1-31 -24-80,24-80 -5-90,16-91 -49-68,10-49 -11-14,13-92 -23-85,24-92 -67-81,67-68 -32-99,32-89 -85-86,35-84 -21-21,20-60 -25-85,25-84 -20-56,21-21 -6-9,9-71 -82-98,26-81 -37-37,15-38 -5-97,3-5 -11-18,19-26 -14-69,6-83 -51-73,50-75 -29-85,19-28 -8-59,5-60 -92-92,46-93 -8-57,7-9 -16-16,16-84 -10-32,10-11 -1-86,1-86 -26-98,19-91 -7-97,6-94 -41-81,42-80 -3-97,13-98 -24-25,24-87 -54-54,18-55 -49-49,33-50 -6-80,79-80 -38-95,38-95 -52-84,52-77 -6-92,1-6 -1-3,3-88 -6-71,2-5 -16-46,2-17 -79-86,15-80 -6-6,5-54 -8-41,11-40 -53-98,52-54 -2-79,1-3 -51-70,50-52 -55-55,56-69 -4-61,10-97 -75-92,12-76 -27-79,92-94 -6-55,5-7 -19-25,20-22 -79-92,65-93 -95-99,27-94 -23-88,23-88 -82-83,83-96 -2-94,2-74 -14-71,6-14 -6-14,5-7 -3-89,1-2 -48-82,13-26 -48-80,26-48 -43-93,92-92 -32-51,85-91 -3-5,5-90 -99-99,95-97 -38-39,38-88 -93-95,75-94 -15-64,14-16 -84-94,67-90 -22-47,48-80 -41-56,5-57 -2-80,7-79 -22-71,21-23 -21-49,20-22 -95-95,61-95 -56-57,57-58 -25-27,26-62 -52-76,41-61 -28-98,71-98 -74-93,4-93 -35-74,73-98 -4-57,3-57 -4-99,32-98 -8-75,7-75 -23-67,23-68 -15-15,15-56 -3-97,1-98 -10-90,91-91 -18-30,17-19 -10-38,1-90 -50-73,37-73 -40-91,92-95 -39-39,40-91 -86-87,7-87 -12-37,37-94 -78-87,14-50 -89-95,11-90 -60-98,4-94 -41-82,81-98 -66-92,67-67 -88-92,5-89 -86-91,85-86 -6-98,97-97 -34-87,95-95 -44-46,45-78 -7-87,17-87 -7-96,95-97 -15-75,76-85 -1-98,2-93 -3-55,50-54 -87-94,72-86 -19-70,19-63 -7-51,50-79 -3-73,3-73 -32-38,31-34 -2-99,98-98 -3-4,5-88 -16-37,38-38 -39-48,40-42 -65-77,65-77 -5-94,3-96 -28-89,97-98 -34-77,53-77 -24-54,25-28 -6-48,7-7 -6-38,3-6 -10-83,9-11 -26-65,64-84 -50-85,84-86 -36-91,37-92 -2-2,2-84 -4-6,5-83 -18-71,35-70 -5-85,5-64 -94-99,13-95 -1-32,2-9 -11-71,53-98 -99-99,18-97 -26-46,22-27 -39-78,91-93 -38-43,38-44 -14-76,15-54 -91-95,23-90 -7-55,3-55 -91-95,29-92 -10-23,9-59 -21-67,20-66 -17-27,20-26 -2-94,1-94 -16-97,13-97 -67-68,67-94 -81-83,27-82 -51-69,81-96 -79-81,57-80 -55-55,55-68 -34-96,34-95 -83-85,19-84 -4-81,3-80 -16-23,23-97 -45-74,46-74 -2-98,98-99 -37-59,35-59 -72-74,70-74 -16-91,91-92 -43-68,44-75 -4-77,7-92 -93-94,6-94 -18-92,93-94 -51-76,76-76 -17-42,41-79 -61-62,49-61 -19-77,9-9 -11-70,43-69 -21-62,53-61 -40-77,78-89 -10-55,10-46 -5-70,98-99 -19-21,20-86 -7-68,10-67 -2-24,3-3 -65-70,46-66 -1-78,2-77 -71-95,17-72 -25-88,88-89 -13-98,14-14 -7-81,7-8 -8-99,8-98 -13-97,14-97 -3-56,3-4 -89-99,29-73 -41-50,28-51 -76-88,76-87 -82-96,25-31 -30-41,8-42 -27-39,38-38 -46-71,46-71 -23-88,10-88 -28-83,28-84 -82-94,81-86 -99-99,1-99 -4-46,4-63 -7-68,67-99 -5-92,93-97 -91-95,3-89 -57-76,3-70 -1-89,53-88 -4-32,6-31 -75-76,2-76 -17-17,18-37 -43-90,89-94 -4-65,1-66 -88-91,90-91 -43-57,44-84 -2-95,2-94 -3-31,1-32 -12-94,30-93 -12-94,5-94 -35-54,34-54 -30-81,30-30 -51-53,52-98 -68-97,41-69 -32-94,19-31 -14-70,7-15 -1-99,41-98 -41-63,41-63 -88-88,27-87 -54-56,53-55 -26-26,27-71 -29-64,1-62 -4-54,1-92 -88-89,22-89 -15-88,15-16 -21-95,43-96 -12-13,12-27 -10-96,23-96 -82-83,22-83 -13-85,13-86 -77-83,4-65 -3-91,3-63 -73-98,73-98 -49-49,8-50 -3-96,4-4 diff --git a/day4/solution.nim b/day4/solution.nim deleted file mode 100644 index 8085445..0000000 --- a/day4/solution.nim +++ /dev/null @@ -1,42 +0,0 @@ -import std/strutils -import std/sequtils -import std/sugar - -type - # We use begin and length for Range representation to simplify calculations later - Range = tuple[begin: int, length: int] - Entry = tuple[first: Range, second: Range] - -proc solve(entries: seq[Entry], part2 = false): int = - var score = 0 - for e in entries: - var r: Entry - # Let first become the leftmost range. In case both ranges start at the same index, we consider the longest one to be first - if e.first.begin < e.second.begin or (e.first.begin == e.second.begin and e.first.length >= e.second.length): - r.first = e.first - r.second = e.second - else: - r.first = e.second - r.second = e.first - - if not part2: - if r.first.length >= r.second.length + r.second.begin - r.first.begin: - score += 1 - else: - if r.first.begin + r.first.length - 1 >= r.second.begin: - score += 1 - - return score - -func entryFromLine(line: string): Entry = - # Get tokens and parse them as integers - let tokens = map(line.split({',', '-'}), token => token.parseInt()) - # Init Entry - ((tokens[0], tokens[1] - tokens[0]+1), (tokens[2], tokens[3] - tokens[2]+1)) - -let - content = readFile("./input.txt").strip().splitLines() - entries = map(content, entryFromLine) - -echo solve(entries) -echo solve(entries, true) diff --git a/day5/example.txt b/day5/example.txt deleted file mode 100644 index 84933bb..0000000 --- a/day5/example.txt +++ /dev/null @@ -1,9 +0,0 @@ - [D] -[N] [C] -[Z] [M] [P] - 1 2 3 - -move 1 from 2 to 1 -move 3 from 1 to 3 -move 2 from 2 to 1 -move 1 from 1 to 2 diff --git a/day5/input.txt b/day5/input.txt deleted file mode 100644 index 988dbdd..0000000 --- a/day5/input.txt +++ /dev/null @@ -1,512 +0,0 @@ - [V] [C] [M] -[V] [J] [N] [H] [V] -[R] [F] [N] [W] [Z] [N] -[H] [R] [D] [Q] [M] [L] [B] -[B] [C] [H] [V] [R] [C] [G] [R] -[G] [G] [F] [S] [D] [H] [B] [R] [S] -[D] [N] [S] [D] [H] [G] [J] [J] [G] -[W] [J] [L] [J] [S] [P] [F] [S] [L] - 1 2 3 4 5 6 7 8 9 - -move 2 from 2 to 7 -move 8 from 5 to 6 -move 2 from 4 to 5 -move 1 from 4 to 5 -move 1 from 5 to 8 -move 5 from 9 to 2 -move 7 from 1 to 6 -move 7 from 3 to 8 -move 1 from 4 to 6 -move 2 from 5 to 6 -move 6 from 7 to 5 -move 2 from 2 to 4 -move 4 from 5 to 2 -move 10 from 8 to 1 -move 2 from 7 to 4 -move 4 from 2 to 8 -move 2 from 9 to 8 -move 1 from 8 to 4 -move 2 from 4 to 9 -move 5 from 8 to 2 -move 1 from 4 to 6 -move 1 from 8 to 9 -move 1 from 7 to 2 -move 2 from 4 to 2 -move 1 from 7 to 3 -move 13 from 2 to 1 -move 1 from 2 to 4 -move 1 from 2 to 3 -move 2 from 5 to 4 -move 17 from 6 to 4 -move 3 from 4 to 9 -move 14 from 1 to 4 -move 4 from 6 to 8 -move 1 from 9 to 8 -move 23 from 4 to 8 -move 6 from 1 to 7 -move 3 from 1 to 5 -move 1 from 3 to 8 -move 5 from 7 to 8 -move 1 from 3 to 4 -move 1 from 5 to 3 -move 1 from 5 to 1 -move 1 from 3 to 2 -move 1 from 9 to 4 -move 9 from 4 to 9 -move 1 from 1 to 2 -move 11 from 8 to 2 -move 1 from 4 to 5 -move 13 from 2 to 3 -move 7 from 9 to 6 -move 1 from 5 to 6 -move 1 from 5 to 2 -move 1 from 9 to 4 -move 1 from 4 to 9 -move 2 from 8 to 9 -move 1 from 7 to 8 -move 8 from 9 to 1 -move 8 from 1 to 4 -move 4 from 6 to 7 -move 1 from 9 to 4 -move 2 from 3 to 9 -move 1 from 9 to 1 -move 6 from 4 to 1 -move 2 from 1 to 3 -move 22 from 8 to 6 -move 1 from 2 to 5 -move 3 from 7 to 8 -move 15 from 6 to 4 -move 7 from 3 to 7 -move 4 from 6 to 9 -move 2 from 9 to 2 -move 6 from 3 to 5 -move 3 from 9 to 5 -move 5 from 5 to 8 -move 1 from 2 to 1 -move 6 from 8 to 2 -move 1 from 1 to 2 -move 3 from 5 to 3 -move 1 from 7 to 2 -move 4 from 7 to 8 -move 4 from 6 to 1 -move 1 from 5 to 1 -move 4 from 8 to 7 -move 2 from 3 to 2 -move 1 from 1 to 3 -move 15 from 4 to 2 -move 3 from 7 to 3 -move 4 from 7 to 2 -move 1 from 4 to 9 -move 5 from 3 to 8 -move 29 from 2 to 1 -move 1 from 9 to 5 -move 1 from 2 to 1 -move 11 from 1 to 5 -move 1 from 4 to 5 -move 2 from 6 to 3 -move 1 from 3 to 4 -move 16 from 1 to 9 -move 4 from 8 to 4 -move 3 from 6 to 9 -move 1 from 3 to 7 -move 1 from 7 to 3 -move 6 from 1 to 6 -move 3 from 4 to 3 -move 3 from 8 to 5 -move 3 from 1 to 8 -move 3 from 1 to 4 -move 2 from 4 to 9 -move 3 from 6 to 3 -move 15 from 5 to 2 -move 3 from 2 to 3 -move 4 from 2 to 7 -move 2 from 5 to 9 -move 10 from 3 to 6 -move 11 from 9 to 5 -move 2 from 4 to 9 -move 8 from 9 to 4 -move 1 from 9 to 6 -move 7 from 4 to 6 -move 3 from 5 to 8 -move 22 from 6 to 9 -move 4 from 7 to 8 -move 8 from 5 to 8 -move 2 from 4 to 3 -move 1 from 8 to 1 -move 17 from 8 to 3 -move 3 from 3 to 4 -move 13 from 3 to 9 -move 20 from 9 to 7 -move 2 from 2 to 9 -move 19 from 9 to 5 -move 1 from 1 to 4 -move 3 from 2 to 7 -move 4 from 4 to 3 -move 1 from 9 to 8 -move 18 from 5 to 1 -move 1 from 9 to 4 -move 1 from 9 to 7 -move 2 from 4 to 8 -move 1 from 5 to 4 -move 3 from 2 to 7 -move 3 from 3 to 1 -move 2 from 1 to 3 -move 3 from 3 to 8 -move 1 from 4 to 8 -move 6 from 8 to 2 -move 1 from 3 to 9 -move 1 from 3 to 9 -move 10 from 1 to 9 -move 7 from 1 to 7 -move 4 from 7 to 4 -move 29 from 7 to 3 -move 6 from 2 to 9 -move 25 from 3 to 6 -move 5 from 3 to 9 -move 13 from 6 to 9 -move 12 from 6 to 2 -move 1 from 8 to 9 -move 10 from 2 to 6 -move 7 from 6 to 5 -move 20 from 9 to 3 -move 11 from 3 to 6 -move 1 from 7 to 9 -move 2 from 2 to 9 -move 19 from 9 to 2 -move 14 from 6 to 8 -move 4 from 5 to 2 -move 2 from 4 to 6 -move 3 from 5 to 1 -move 13 from 8 to 5 -move 1 from 6 to 1 -move 2 from 4 to 2 -move 8 from 2 to 4 -move 6 from 4 to 7 -move 1 from 9 to 8 -move 2 from 4 to 7 -move 5 from 2 to 4 -move 4 from 4 to 2 -move 10 from 5 to 6 -move 1 from 1 to 7 -move 1 from 5 to 4 -move 1 from 4 to 9 -move 4 from 7 to 8 -move 5 from 1 to 7 -move 1 from 9 to 7 -move 7 from 3 to 2 -move 2 from 5 to 2 -move 8 from 6 to 9 -move 1 from 4 to 6 -move 3 from 7 to 4 -move 5 from 9 to 7 -move 2 from 4 to 3 -move 20 from 2 to 4 -move 2 from 4 to 8 -move 14 from 4 to 2 -move 12 from 7 to 4 -move 8 from 2 to 1 -move 10 from 2 to 4 -move 6 from 8 to 5 -move 1 from 7 to 8 -move 4 from 4 to 3 -move 1 from 3 to 9 -move 1 from 2 to 7 -move 1 from 6 to 8 -move 5 from 3 to 5 -move 1 from 3 to 2 -move 7 from 4 to 5 -move 6 from 1 to 7 -move 5 from 7 to 6 -move 1 from 6 to 5 -move 2 from 7 to 8 -move 1 from 2 to 6 -move 2 from 8 to 2 -move 5 from 5 to 7 -move 6 from 6 to 8 -move 16 from 4 to 9 -move 16 from 9 to 4 -move 11 from 5 to 4 -move 5 from 8 to 3 -move 2 from 5 to 2 -move 14 from 4 to 2 -move 1 from 6 to 3 -move 1 from 6 to 9 -move 1 from 5 to 3 -move 3 from 8 to 2 -move 10 from 4 to 7 -move 5 from 9 to 2 -move 3 from 4 to 7 -move 1 from 1 to 4 -move 3 from 2 to 5 -move 2 from 3 to 7 -move 1 from 4 to 2 -move 18 from 2 to 8 -move 3 from 8 to 4 -move 5 from 3 to 1 -move 1 from 3 to 9 -move 1 from 9 to 3 -move 8 from 8 to 7 -move 2 from 5 to 4 -move 1 from 5 to 6 -move 1 from 2 to 5 -move 1 from 5 to 8 -move 1 from 6 to 9 -move 3 from 2 to 7 -move 27 from 7 to 4 -move 2 from 2 to 4 -move 4 from 8 to 4 -move 1 from 9 to 8 -move 3 from 1 to 6 -move 1 from 3 to 5 -move 3 from 8 to 3 -move 1 from 1 to 4 -move 1 from 8 to 1 -move 3 from 1 to 4 -move 2 from 8 to 2 -move 2 from 6 to 2 -move 8 from 4 to 9 -move 1 from 7 to 1 -move 1 from 5 to 4 -move 1 from 7 to 3 -move 4 from 2 to 7 -move 1 from 8 to 6 -move 8 from 9 to 7 -move 1 from 6 to 3 -move 3 from 3 to 4 -move 37 from 4 to 1 -move 1 from 4 to 5 -move 13 from 7 to 8 -move 6 from 8 to 4 -move 5 from 8 to 3 -move 1 from 7 to 6 -move 4 from 1 to 5 -move 1 from 6 to 5 -move 2 from 8 to 4 -move 32 from 1 to 5 -move 1 from 1 to 4 -move 5 from 3 to 5 -move 1 from 3 to 2 -move 1 from 2 to 9 -move 19 from 5 to 2 -move 1 from 9 to 1 -move 16 from 5 to 1 -move 7 from 5 to 6 -move 1 from 3 to 1 -move 11 from 1 to 2 -move 18 from 2 to 4 -move 1 from 5 to 9 -move 8 from 6 to 1 -move 10 from 2 to 6 -move 7 from 4 to 9 -move 2 from 2 to 1 -move 7 from 4 to 2 -move 5 from 4 to 5 -move 2 from 9 to 6 -move 9 from 6 to 3 -move 5 from 5 to 3 -move 8 from 4 to 9 -move 7 from 9 to 8 -move 4 from 2 to 9 -move 10 from 3 to 1 -move 6 from 8 to 1 -move 2 from 6 to 3 -move 5 from 3 to 8 -move 3 from 2 to 7 -move 1 from 9 to 5 -move 1 from 3 to 5 -move 2 from 7 to 8 -move 1 from 8 to 9 -move 1 from 6 to 1 -move 23 from 1 to 4 -move 2 from 5 to 3 -move 1 from 8 to 2 -move 2 from 8 to 5 -move 2 from 5 to 6 -move 1 from 2 to 7 -move 1 from 7 to 5 -move 4 from 9 to 7 -move 1 from 7 to 5 -move 1 from 3 to 6 -move 3 from 7 to 4 -move 1 from 3 to 8 -move 1 from 4 to 6 -move 6 from 1 to 8 -move 4 from 6 to 4 -move 2 from 9 to 1 -move 1 from 5 to 1 -move 19 from 4 to 2 -move 2 from 9 to 3 -move 1 from 9 to 3 -move 9 from 1 to 8 -move 1 from 5 to 8 -move 1 from 9 to 3 -move 2 from 3 to 9 -move 3 from 8 to 4 -move 1 from 4 to 9 -move 1 from 9 to 5 -move 2 from 3 to 4 -move 6 from 4 to 7 -move 3 from 9 to 5 -move 4 from 4 to 7 -move 1 from 5 to 6 -move 18 from 2 to 7 -move 13 from 7 to 9 -move 3 from 5 to 1 -move 1 from 2 to 1 -move 1 from 6 to 5 -move 3 from 1 to 7 -move 1 from 1 to 5 -move 7 from 9 to 6 -move 8 from 7 to 4 -move 11 from 7 to 6 -move 5 from 9 to 2 -move 17 from 6 to 1 -move 2 from 5 to 1 -move 11 from 8 to 1 -move 20 from 1 to 2 -move 3 from 8 to 1 -move 1 from 9 to 8 -move 1 from 6 to 1 -move 11 from 1 to 7 -move 18 from 2 to 3 -move 12 from 4 to 8 -move 11 from 7 to 3 -move 7 from 2 to 3 -move 2 from 1 to 5 -move 1 from 1 to 3 -move 1 from 8 to 1 -move 1 from 5 to 9 -move 1 from 9 to 6 -move 1 from 8 to 7 -move 1 from 5 to 3 -move 1 from 6 to 7 -move 2 from 8 to 1 -move 8 from 3 to 2 -move 7 from 2 to 9 -move 6 from 8 to 6 -move 1 from 9 to 3 -move 2 from 6 to 4 -move 5 from 9 to 6 -move 7 from 6 to 2 -move 8 from 2 to 9 -move 2 from 1 to 9 -move 2 from 7 to 2 -move 2 from 4 to 8 -move 1 from 2 to 7 -move 25 from 3 to 7 -move 7 from 9 to 7 -move 1 from 2 to 5 -move 1 from 1 to 4 -move 3 from 8 to 1 -move 3 from 1 to 8 -move 3 from 7 to 8 -move 15 from 7 to 3 -move 10 from 8 to 3 -move 1 from 5 to 7 -move 1 from 8 to 5 -move 3 from 9 to 2 -move 1 from 6 to 4 -move 2 from 2 to 7 -move 1 from 2 to 5 -move 14 from 7 to 9 -move 1 from 6 to 2 -move 1 from 7 to 1 -move 1 from 5 to 4 -move 3 from 4 to 3 -move 1 from 7 to 6 -move 1 from 2 to 7 -move 1 from 1 to 2 -move 3 from 9 to 1 -move 1 from 6 to 2 -move 2 from 2 to 6 -move 17 from 3 to 6 -move 1 from 8 to 3 -move 1 from 5 to 4 -move 2 from 7 to 2 -move 9 from 9 to 8 -move 1 from 9 to 3 -move 16 from 3 to 2 -move 1 from 7 to 5 -move 5 from 6 to 5 -move 1 from 1 to 6 -move 1 from 4 to 1 -move 1 from 9 to 3 -move 9 from 8 to 6 -move 3 from 1 to 5 -move 1 from 9 to 1 -move 16 from 2 to 1 -move 2 from 2 to 7 -move 2 from 3 to 9 -move 2 from 7 to 4 -move 2 from 9 to 3 -move 3 from 3 to 5 -move 1 from 4 to 5 -move 1 from 4 to 2 -move 1 from 1 to 7 -move 1 from 7 to 1 -move 1 from 3 to 6 -move 2 from 5 to 1 -move 3 from 6 to 2 -move 2 from 5 to 8 -move 8 from 5 to 4 -move 1 from 5 to 3 -move 1 from 3 to 2 -move 1 from 8 to 3 -move 1 from 3 to 8 -move 4 from 1 to 7 -move 9 from 1 to 7 -move 6 from 1 to 8 -move 3 from 7 to 4 -move 7 from 6 to 7 -move 11 from 4 to 3 -move 2 from 3 to 8 -move 8 from 3 to 8 -move 4 from 6 to 1 -move 1 from 7 to 4 -move 2 from 1 to 2 -move 8 from 7 to 2 -move 1 from 4 to 8 -move 10 from 8 to 2 -move 2 from 6 to 1 -move 1 from 1 to 4 -move 1 from 4 to 8 -move 2 from 1 to 4 -move 6 from 6 to 5 -move 1 from 1 to 9 -move 2 from 6 to 8 -move 1 from 4 to 5 -move 1 from 6 to 9 -move 4 from 8 to 9 -move 1 from 7 to 1 -move 6 from 8 to 6 -move 1 from 6 to 1 -move 1 from 4 to 9 -move 2 from 9 to 5 -move 5 from 5 to 9 -move 8 from 9 to 5 -move 2 from 8 to 5 -move 3 from 6 to 9 -move 8 from 5 to 7 -move 5 from 5 to 6 -move 1 from 9 to 2 -move 1 from 3 to 1 -move 1 from 6 to 7 -move 1 from 5 to 6 -move 24 from 2 to 4 -move 3 from 9 to 7 -move 16 from 4 to 5 -move 2 from 1 to 3 -move 12 from 5 to 6 -move 1 from 9 to 5 -move 4 from 5 to 9 -move 1 from 1 to 6 -move 1 from 5 to 2 -move 2 from 9 to 8 -move 1 from 8 to 1 -move 5 from 4 to 5 -move 2 from 3 to 5 -move 1 from 8 to 3 -move 1 from 1 to 6 -move 3 from 5 to 7 -move 1 from 9 to 1 -move 1 from 2 to 8 diff --git a/day5/solution.nim b/day5/solution.nim deleted file mode 100644 index 2bf41aa..0000000 --- a/day5/solution.nim +++ /dev/null @@ -1,87 +0,0 @@ -import std/strutils -import std/sequtils -import std/enumerate -import std/algorithm -import std/re - -type - Move = tuple - Amount: int - From: int - To: int - - Stack = seq[char] - - Input = tuple - Stacks: seq[Stack] - Moves: seq[Move] - -proc parseContent(content: string): Input = - # Parse stacks - let tokens = content.split("\n\n") - var strStacks = map( - # All lines containing characters of the stacks - # Exclude last line since it contain's each stack's id - tokens[0].splitLines()[0 .. ^2], - proc(line: string): string = - var retval = "" - # keep only the relevant characters (spaces/letters) - for i in countup(1, line.len(), 4): - retval.add(line[i]) - retval - ) - - var Stacks = newSeq[Stack](10) - - for layer in strStacks: - for i, c in enumerate(layer): - if c != ' ': - Stacks[i+1].add(c) - - var strMoves = map( - # All moves described in the input - tokens[1].strip().splitLines(), - proc(line: string): seq[int] = - # Remove words and split on spaces - let tokens = line.replace(re"[a-z]+ ").split(" ") - # Parse them as integers - map(tokens, proc (num: string): int = num.parseInt()) - ) - - var Moves: seq[Move] - for move in strMoves: - Moves.add((move[0], move[1], move[2])) - - return (Stacks, Moves) - -proc makeMove(stacks: var seq[Stack], move: Move, inPlace = false): void = - # copy top of the stack - var yoink = stacks[move.From][0 ..< move.Amount] - # moving in place preserves the order of the moved crates (part2) - if not inPlace: - yoink.reverse() - # remove it from origin - stacks[move.From].delete(0 ..< move.Amount) - # concat it in front of destination - stacks[move.To] = concat(yoink, stacks[move.To]) - -proc getAnswer(stacks: seq[Stack]): string = - var answer = "" - for stack in stacks: - if stack.len() > 0: - answer.add(stack[0]) - answer - -let content = readFile("./input.txt") -var input = parseContent(content) - -let moves = input.Moves -var stacksPart1 = input.Stacks -var stacksPart2 = input.Stacks - -for move in moves: - makeMove(stacksPart1, move) - makeMove(stacksPart2, move, true) - -echo getAnswer(stacksPart1) -echo getAnswer(stacksPart2) diff --git a/day6/example.txt b/day6/example.txt deleted file mode 100644 index 7980a82..0000000 --- a/day6/example.txt +++ /dev/null @@ -1 +0,0 @@ -mjqjpqmgbljsphdztnvjfqwrcgsmlb diff --git a/day6/input.txt b/day6/input.txt deleted file mode 100644 index 26e0f4a..0000000 --- a/day6/input.txt +++ /dev/null @@ -1 +0,0 @@ -rhghwwsmsgmgsmmmlzljllrddvsvhvhhnvvrcccwhhvgghchwhvwvcvrrrgtgrgdggfdgffshsllvvslsppglgvgwgswwcbcwbwrrbjbwjjtgjjdzdfdhfddrmmhqhpqhhqghhzssqzqccbwwffzvzffvtftddrbrtrrcjrrmmbmrrrlrppplmplmppfzpfpvpqvpqqdndpndnmnwmwjmwmwbbrhhmzmffwfqwfqwffppvfpvffnwwwwcbwbhbccvmmplmplmmlmplpprbpbllmhlhzhffngfnntrrsrprrvlllvjvmjvvppsrrfnrfnrfrfwrffrsfrflfltfllpfprrthhhnhqnnfwwcttvzzddqsddwpddnrnttvjttjjdjvdjvjnvnrvvchhschhlffjggtqgqnnvrnrsnrsnsvspsnncppvwvvtmmcqmcmscmsmwmvmpvvlqqmbqqlwwtgtztgttpjjbfjjzhzthhzssffwqqdmdcdlclrclrccbmmqjqmqcmmnnsvnntpphhdpdhhtbtdtffhzfhhpwhppwbppfspphdhggzqgzzffdsdfsszcscpscsqcssffhjhnhhlqqdbqqdmdsmddrfddndldgglvglvlggqlggjngjnnbffthhjbjpjnjmnmgmqqbjqjzjqzzzjffwttcnnzffmllcncmnnthnncttpgpnnjdjfftmmvqmqsqggfrfjjqbjbvvshvhphfhhljlfjjvcclzclctcmmfwfvwfvwwjvwvjjplpbpqqdvqqbhbdbnnsndssgffgsglssmfmjjfrjfrfttljldjdffjjdnjjlbbnrntrtfrttmhhndnsdsffgqqrpplvvfwvfvsfszzfzhfzzlttlctllrzrggvwvhhgnnlmnlmlpppdldqqdpdlplrpppjspspzzhphccgjjpmmwvwbwssnpssrzrwrhhmzhmhsmhmttrqrvqvcclggptpjpzpccltctppflfjffrtrjrhjhffhjfjbfjfqfqzffdtthwwjwzjzggsgzgqqjdqjddvgvsvnnqwqgwgtttfvfrfwrfwfwmwmqwmmmbzmzvzfvfrfvvgvtvptpbpwbwrbwrwffzzfgzfgfcfzcffjdjjvrvnnfmmtztffsggjcjzcjcssscnscnssmmwgwbbljlnjndnrrqwqjjjbnnmbmcmbcmbbvvmtvmmfcmcjcdcnnzfzfzqfzfvvmbvmmndnbnsnnlddqvvsnngvnnrttfbtbqqnwqqzfzfzccfmmgrrsbbhvvgjjhfhssjmmsjjzzbqblqlfqllwhlwwvvstvtfvttnncjjzcjcjrrsvrssmfsfczbrzrvscvmcmrjpzwhcqfrrzbljnmqlzbzqtmhrshlrjjpvhnsvtlhqggqwppsjpszmqwfqmlwbqzwcrggrvfbvztnflwvbrqcrqbcllswvsvhwjzpldgphwptfdnlgdlnbttjfzrdcfvpdhlssfsljvdjmwddbnrpqnnqlfdfdspbnjwqjwrgtnrftsqcfjpmqwgwhttggjwzvgbwlhmtmmjlwhssrgshzpbcnstzlqdshdhjfgqlsmqqhpwbscsjhfbhprvhmftqngjgdbcvfldqgqsjqjfdmcvsflwzflsjfssnjpbwffnsfcnrdsphbjpgghmcthgnzmpgppqjdvbztvhnwqzndntcpjdtwwhvsmgdcthpssszrqcbntgsznpghmbqddpqscntjprlwzhbzhjtwzbwwcldwdgsttzmtnstjnngzrgvhncdbgqnllfzbthldztsdwsngjzprbvrnbzrsghlgssbqfnbvhnhzwmmmtncvsdngdtwcbjlnnzbnlrnmrvnvsjnvzdqnggmsvljlvjznwdszcmblhrsjvczpnlhsmqjsmwhbjbplbtqsgqjdllhncwdgbvzwnmqvndcbfhnvtjnzmvjhwzvdldhgfwbqqzcnbflfnwntlhmqgdhmrgwqcpmsvfbmwhbtsbdlhcnbcbswvdfffgjvddrbpzpcwsrsjnfvmzhlvbdnwttnqrmzbnnntbfvptrlhjhwjcsbnhvtwtwzvgfnzjplthqjbsjjwzdtqqvblnbvgcmvrmnvmwfrhcqgvrcjlfzdlpbfvncbtfgvnsflbjzqqhczcmtbwqmrppmptfgzvfbmcslwlfrfpvvnvvnwfvvmmdzmmtjsgqdfhngtphtlfjqrtljgnthgnbbqfrnpfmpwhpzdvzmtswwdvcnpsdcqwjdwlvbsbmlwdsjbcbgcrfljshlvpngfmsrzlfhtfqgwbcctnzzhnqhdmqzdwthftwtmpbcmqvdcdtgvltbzmszzwwmhzlfvbdqnhjqgdmstsnhftcwzvvbmnhwvgqzscwcdjbdgfmvpjdzctwqwltbwjlgcblnnhpnmggbmvqpqtgqjzspgqzvcvsdbvjgjfzdzhfpbzjqljjcgldzgnlmtjcmfgdbqgglvjqrppwmhccvqzvsrjjvfhjprwdsqsnszfprznljtcsrtqhcrpljfrccflmbpvqtzgmzhjrlbnrmmsmmjbtzwpglqgdvvvjvnfzmplsmvlvcnjshvjwntclwgpznnzwhjssgdcjbzrmsgnfgcgphrhfvrfhzwdcvsplhbmqwhpmjvqlmschznbqblvhtqfgtdggmncndhhplnzjphccjmlmtdqnmnlnpnfqdstljqnsqbrjrtspvrwvdmwzlgdmsfvctzgtmgqhqqrzpbgplzcfdqnzhsqrbcvhsccshnnpvvrpvqzqsgzgmpzfvvrrcvhdtntnsqnjrbzlbzmpgwdqzbhtlrrhbwdqjlsfgdhmvgmgbqhwvljmmqfllqvvrznrlftgzjdcgtstjffqmgvffpvtctzpdqjfnmlcdzscntctmqhrtmhrlhbjzttrcvcnlhsrvtpbmdchhntnnpnzlvqqnsrjcmblcvphqgwshnjmplgvnbsmmdzgqcpqztjhhgjvtlbpdpdwlwmmfrdgcvzfbgvbgpbjnwsssvhszwplcgvpgjwdrwngbcdjwvlsfhqlrqzgrzpfgjstqfdbrpqdvrlgdwqcsrgvhctznjjlzsmzctsqtfnhhlpjgnltssglmlwshfbrgmjqbvsmqwvszdfsvhmtrfjgwjctpsmgzzjbpwsztnnvzrhwvvmhdpgdmwzsjprhlgzcdvhznlfgjqvcwqrplcfvzmthsdsnrtfvnlrmvwplmbdvdggmlvpgdgzhvzmvzwmptzsnfrcrjspccmqjpjmhjqgrjbdcdjbzjmphmcdvjqtmdshhjrqgjgsnpzfbfgpjpczwzvmclgzgztlvzmdbwgncnndjwhhhjnhtjdmcnrmnqbmjdrdcmtvcsmftqcfhsvhsfjmtzjpnwffggpfqlqmzlbhnnhbtgzfgnjvdzmvthqjrhzbwvhcjzcsmsvsctrqbltpcrpjjnsbjdbfjqfcbpcgcwtqsflmlwprjcwlmcjjgsfdpwcqvhjpsgvdgsfnscnbzsrmrbbvdrlltzplbvgqsdnplcvbhddbtmwnfmvqhqdlrtrmrmzmhlccgwgmbdppjqdjtwmvdzfsbsggrfstjwjpjnljffwffmqncfnthnhglwvsgvzmgbzhtdfpfmdwmcldthvsnqnptpmhqctblgfsszhcfbvcrggjdhthqvvvlldshvqwmvdtfslrhzvgdfwztrczdjgcfcgtmwnphqthlgpfnrqwcgpzwnlgdvsnvzftlnlfflfsmjzhrhqjctsbvtccwbfsdrnbhszzjhqndvwcsmffnstnfdfwpbgfztjmjngdczzlgpscjtshpmmmzlnqndsttbdgfjqcvbqlphwhlhgcvjbhjmtrfzlgpwdnvzrllndbhvhlngvhlszzdcrdgvrmjwcvhhtbhnjmdzgctqnpdlrnqjzbchjtcsggsczlgmvtqvzmsqvtrhtvdmzlcdddfnbvbsnrzvgzfqjtbhjqhdznrhbfbqwtnwvrfqsznbqfzfzfgmhvjjsgbbdbdtzswwlnfrq diff --git a/day6/solution.nim b/day6/solution.nim deleted file mode 100644 index ce3ccd0..0000000 --- a/day6/solution.nim +++ /dev/null @@ -1,39 +0,0 @@ -import std/strutils -import std/sequtils -import std/tables - -proc solve(message: string, nUniq: int): int = - var cntUniq = initCountTable[char]() - - # init found - var uniq = 0 - for c in message[0 ..< nUniq]: - cntUniq.inc(c) - if cntUniq[c] == 1: - uniq += 1 - - let pairs = zip( - message[0 ..< message.len()-nUniq], - message[nUniq ..< message.len()]) - - for i, pair in pairs: - if uniq == nUniq: - return i+nUniq - - cntUniq.inc(pair[0], -1) - if cntUniq[pair[0]] == 0: - # we lost one uniq number in sequence - uniq -= 1 - - cntUniq.inc(pair[1]) - if cntUniq[pair[1]] == 1: - # we found new uniq number in sequence - uniq += 1 - - assert(false) - return -1 - -let content = readFile("./input.txt").strip() - -echo solve(content, 4) -echo solve(content, 14) diff --git a/day7/example.txt b/day7/example.txt deleted file mode 100644 index 09a921e..0000000 --- a/day7/example.txt +++ /dev/null @@ -1,23 +0,0 @@ -$ cd / -$ ls -dir a -14848514 b.txt -8504156 c.dat -dir d -$ cd a -$ ls -dir e -29116 f -2557 g -62596 h.lst -$ cd e -$ ls -584 i -$ cd .. -$ cd .. -$ cd d -$ ls -4060174 j -8033020 d.log -5626152 d.ext -7214296 k diff --git a/day7/input.txt b/day7/input.txt deleted file mode 100644 index 036d66d..0000000 --- a/day7/input.txt +++ /dev/null @@ -1,1096 +0,0 @@ -$ cd / -$ ls -dir brdsppd -dir dnjqmzgg -126880 fmftdzrp.fwt -173625 hhfqgzfj.qvt -dir lbbcfjl -dir mzdqcb -dir npppw -dir plmb -6337 rfgtcj.tdn -dir szfw -230140 vmc.cdf -$ cd brdsppd -$ ls -dir gjc -dir lcz -218543 ndqmcv -dir qnj -dir rrdd -dir zppsglq -$ cd gjc -$ ls -dir bvctghh -262132 cbczvmdf -111855 dnltsq.fwv -22416 fnrwscz.vwb -dir gwd -dir lsprzlbf -$ cd bvctghh -$ ls -dir lsprzlbf -dir lwfgnzz -dir tjslbpb -$ cd lsprzlbf -$ ls -182522 hhfqgzfj.qvt -dir hts -229288 jtpdh -dir lwfgnzz -284594 szfw -89639 tgdsjl -$ cd hts -$ ls -11158 dnltsq.fwv -52582 tchv -$ cd .. -$ cd lwfgnzz -$ ls -dir tjslbpb -$ cd tjslbpb -$ ls -58586 jtzmjgw.bql -$ cd .. -$ cd .. -$ cd .. -$ cd lwfgnzz -$ ls -199598 rlhz.pbs -$ cd .. -$ cd tjslbpb -$ ls -119666 fmzfs.glg -$ cd .. -$ cd .. -$ cd gwd -$ ls -dir bcfqd -1631 hhfqgzfj.qvt -$ cd bcfqd -$ ls -197168 cqvwnslp.ltw -$ cd .. -$ cd .. -$ cd lsprzlbf -$ ls -dir jwznh -$ cd jwznh -$ ls -dir lpm -dir ncs -dir vqprn -$ cd lpm -$ ls -15172 bnw.rqm -215818 flpbspn.stt -$ cd .. -$ cd ncs -$ ls -dir rzdbw -$ cd rzdbw -$ ls -15150 cvjldjt.gdc -$ cd .. -$ cd .. -$ cd vqprn -$ ls -23882 njjjh -$ cd .. -$ cd .. -$ cd .. -$ cd .. -$ cd lcz -$ ls -37587 gwcvttb.dhc -195583 lsprzlbf.vng -152648 tchv -$ cd .. -$ cd qnj -$ ls -dir bpvl -275640 cfvznj.bqc -dir lwfgnzz -213007 nwbt.mct -135231 twpf.pft -165501 vmc.cdf -88097 vmvs.hnr -dir znbdpp -$ cd bpvl -$ ls -dir nmzbpb -$ cd nmzbpb -$ ls -129477 pjlvs.zcp -$ cd .. -$ cd .. -$ cd lwfgnzz -$ ls -dir lwfgnzz -dir rsbdcwjr -dir sgh -dir wvwmf -$ cd lwfgnzz -$ ls -33186 ftcrfnmd -$ cd .. -$ cd rsbdcwjr -$ ls -dir lsprzlbf -$ cd lsprzlbf -$ ls -dir jvcgnbs -288445 pjmqm -111585 szfw.drf -dir vnftvqf -$ cd jvcgnbs -$ ls -dir ctlwjnjz -dir lwfgnzz -dir tjslbpb -$ cd ctlwjnjz -$ ls -72087 zmhnsmmf -$ cd .. -$ cd lwfgnzz -$ ls -151358 sqs -$ cd .. -$ cd tjslbpb -$ ls -112471 mftdzhwj.zvt -$ cd .. -$ cd .. -$ cd vnftvqf -$ ls -120421 lsprzlbf.tqc -$ cd .. -$ cd .. -$ cd .. -$ cd sgh -$ ls -228239 szfw.dzv -$ cd .. -$ cd wvwmf -$ ls -dir bcjfz -$ cd bcjfz -$ ls -26284 bzhqwdjq.nzn -$ cd .. -$ cd .. -$ cd .. -$ cd znbdpp -$ ls -dir szfw -$ cd szfw -$ ls -dir nthzqpws -dir snfmt -$ cd nthzqpws -$ ls -96382 twhdbvtw.lbj -$ cd .. -$ cd snfmt -$ ls -133360 bjmgtpgh -134215 vmc.cdf -$ cd .. -$ cd .. -$ cd .. -$ cd .. -$ cd rrdd -$ ls -185903 cpgpgntt.tfn -$ cd .. -$ cd zppsglq -$ ls -41689 jvcgnbs.hrt -169754 wgnpq -$ cd .. -$ cd .. -$ cd dnjqmzgg -$ ls -dir lsprzlbf -dir lwfgnzz -dir nmvj -dir sfpg -$ cd lsprzlbf -$ ls -dir lbw -141416 sqs -$ cd lbw -$ ls -48758 cjv -235522 dnltsq.fwv -$ cd .. -$ cd .. -$ cd lwfgnzz -$ ls -36709 bcmtmwcz -$ cd .. -$ cd nmvj -$ ls -dir dqpw -dir tjslbpb -$ cd dqpw -$ ls -10608 hhfqgzfj.qvt -$ cd .. -$ cd tjslbpb -$ ls -261140 qfzb -$ cd .. -$ cd .. -$ cd sfpg -$ ls -8543 szfw -69248 tjslbpb -$ cd .. -$ cd .. -$ cd lbbcfjl -$ ls -dir csnjp -dir drwpfn -301956 hhfqgzfj.qvt -dir jvcgnbs -dir lsprzlbf -dir pdzlnm -161886 tchv -153858 vmc.cdf -87849 wghtg -dir zhgchnld -$ cd csnjp -$ ls -dir ffgfmcm -dir gtd -dir lbjvqv -dir lwfgnzz -11312 sqs -$ cd ffgfmcm -$ ls -dir bcnvw -dir lcf -dir lsprzlbf -$ cd bcnvw -$ ls -111692 ftcvs.tcz -173665 jpfh.hrs -120561 lwfgnzz.zvd -dir ngtbzz -29479 tchv -dir tjslbpb -$ cd ngtbzz -$ ls -dir czrqmh -dir jrhpnpw -dir lsprzlbf -$ cd czrqmh -$ ls -225055 hhfqgzfj.qvt -$ cd .. -$ cd jrhpnpw -$ ls -206497 tjslbpb.zbv -$ cd .. -$ cd lsprzlbf -$ ls -66627 szfw.wtd -$ cd .. -$ cd .. -$ cd tjslbpb -$ ls -dir cgzlp -116060 lsprzlbf -dir szfw -128885 zht.ptf -$ cd cgzlp -$ ls -18201 sqs -$ cd .. -$ cd szfw -$ ls -104128 tchv -$ cd .. -$ cd .. -$ cd .. -$ cd lcf -$ ls -137662 lwfgnzz -$ cd .. -$ cd lsprzlbf -$ ls -151745 fmcgs.tvh -37707 gszw.jlm -dir lsprzlbf -178133 rjw.wrq -dir szw -267875 tchv -198852 vmc.cdf -$ cd lsprzlbf -$ ls -54734 lsprzlbf.hcq -81537 lwfgnzz -120990 qppfdrf -$ cd .. -$ cd szw -$ ls -dir jtvschrd -dir zcnpls -$ cd jtvschrd -$ ls -dir gtz -$ cd gtz -$ ls -dir rdzzlm -$ cd rdzzlm -$ ls -55063 tchv -8813 zfwvvpvz.zzb -$ cd .. -$ cd .. -$ cd .. -$ cd zcnpls -$ ls -282808 dpmd -$ cd .. -$ cd .. -$ cd .. -$ cd .. -$ cd gtd -$ ls -148653 cmchsg.zdr -66537 hhfqgzfj.qvt -125493 mdtmqbml.gnt -dir rwjdjqcs -dir tjslbpb -$ cd rwjdjqcs -$ ls -77026 zpt.gfp -$ cd .. -$ cd tjslbpb -$ ls -dir dfl -$ cd dfl -$ ls -203731 qpsmsjgh.gvs -dir tjslbpb -84386 vmc.cdf -dir zgh -$ cd tjslbpb -$ ls -dir lwfgnzz -140021 qnp -312305 svh.vqt -$ cd lwfgnzz -$ ls -49701 lgffdn.gmr -$ cd .. -$ cd .. -$ cd zgh -$ ls -138627 tchv -$ cd .. -$ cd .. -$ cd .. -$ cd .. -$ cd lbjvqv -$ ls -dir bnl -$ cd bnl -$ ls -dir gbv -dir lwfgnzz -$ cd gbv -$ ls -dir lsprzlbf -36406 lsprzlbf.cfd -$ cd lsprzlbf -$ ls -168615 hlhp.rvp -$ cd .. -$ cd .. -$ cd lwfgnzz -$ ls -149511 cdpwjbpd -$ cd .. -$ cd .. -$ cd .. -$ cd lwfgnzz -$ ls -232898 dnltsq.fwv -181665 hhfqgzfj.qvt -62529 qfmhhvvq.prh -57822 sqs -$ cd .. -$ cd .. -$ cd drwpfn -$ ls -dir fvgw -dir lsprzlbf -dir lwfgnzz -104745 nqvlqd.mdb -203189 qqpmz -159549 tchv -dir tjslbpb -dir wnrns -$ cd fvgw -$ ls -dir tlzmplfl -$ cd tlzmplfl -$ ls -29740 vmc.cdf -30062 wgrm.dst -181738 zqr -$ cd .. -$ cd .. -$ cd lsprzlbf -$ ls -dir lcqhctjl -dir ldr -dir tjslbpb -$ cd lcqhctjl -$ ls -209114 bcfr.gpf -$ cd .. -$ cd ldr -$ ls -148649 fzh.pqm -$ cd .. -$ cd tjslbpb -$ ls -241013 dnltsq.fwv -$ cd .. -$ cd .. -$ cd lwfgnzz -$ ls -288335 cdctnn -67277 tchv -$ cd .. -$ cd tjslbpb -$ ls -dir pblzrspg -dir qqgddb -86103 sqs -183539 tjslbpb.wrs -$ cd pblzrspg -$ ls -dir pgl -$ cd pgl -$ ls -305421 lwfgnzz.jdz -114244 tjslbpb -dir vzff -$ cd vzff -$ ls -80591 rlww.htq -86968 sqs -$ cd .. -$ cd .. -$ cd .. -$ cd qqgddb -$ ls -dir szfw -$ cd szfw -$ ls -dir jtw -$ cd jtw -$ ls -263 szfw.lzp -$ cd .. -$ cd .. -$ cd .. -$ cd .. -$ cd wnrns -$ ls -203725 dnltsq.fwv -77752 qrg.fnt -$ cd .. -$ cd .. -$ cd jvcgnbs -$ ls -296356 lwfgnzz.svf -294928 ptvdsngf -$ cd .. -$ cd lsprzlbf -$ ls -dir lwfgnzz -dir tjslbpb -$ cd lwfgnzz -$ ls -105095 tchv -$ cd .. -$ cd tjslbpb -$ ls -53558 hhfqgzfj.qvt -189180 szfw -$ cd .. -$ cd .. -$ cd pdzlnm -$ ls -76426 jwttcp.rjj -dir lsprzlbf -dir qldhzf -dir rtdsjf -dir sfdtljj -69033 slhl.jst -$ cd lsprzlbf -$ ls -71362 vgdr -$ cd .. -$ cd qldhzf -$ ls -303106 lsprzlbf.rbq -$ cd .. -$ cd rtdsjf -$ ls -45781 pzbgwrdm.lwt -dir rzc -$ cd rzc -$ ls -297081 qqvlp -86015 zthlr -$ cd .. -$ cd .. -$ cd sfdtljj -$ ls -254377 ftw.fwg -dir jvcgnbs -153393 lwfgnzz.dws -dir pnphc -220821 wslttcn -$ cd jvcgnbs -$ ls -92642 bzpvvlsn.gvt -$ cd .. -$ cd pnphc -$ ls -288388 lwfgnzz -$ cd .. -$ cd .. -$ cd .. -$ cd zhgchnld -$ ls -16588 ftgrpj.srl -112044 vmc.cdf -$ cd .. -$ cd .. -$ cd mzdqcb -$ ls -dir bfphcs -dir cgjmj -dir jgcqqsh -dir jvcgnbs -dir lccjbtqs -dir lwfgnzz -dir pprvjm -dir szfw -dir tjslbpb -dir ztc -$ cd bfphcs -$ ls -124148 wzt.qtr -$ cd .. -$ cd cgjmj -$ ls -28095 ddjdbdf -dir jvcgnbs -169536 sqs -dir svbsrj -159511 vmc.cdf -$ cd jvcgnbs -$ ls -dir crmsnch -dir jvcgnbs -$ cd crmsnch -$ ls -195745 lsprzlbf.prh -271424 tjslbpb -227054 vmc.cdf -$ cd .. -$ cd jvcgnbs -$ ls -294249 vmc.cdf -$ cd .. -$ cd .. -$ cd svbsrj -$ ls -49038 cspzcpqs -dir czltsqrg -98084 ljhljcw -dir ntdjg -202570 szfw.lpj -$ cd czltsqrg -$ ls -207690 dnltsq.fwv -208745 lnns.hsv -40703 rgmjszf.vtd -$ cd .. -$ cd ntdjg -$ ls -dir szfw -$ cd szfw -$ ls -284994 qzwptr.ggb -$ cd .. -$ cd .. -$ cd .. -$ cd .. -$ cd jgcqqsh -$ ls -2462 djfwggvp -$ cd .. -$ cd jvcgnbs -$ ls -dir ftjprdj -289965 zhlrstpt -$ cd ftjprdj -$ ls -dir wnmhs -$ cd wnmhs -$ ls -dir tjslbpb -$ cd tjslbpb -$ ls -dir jvcgnbs -$ cd jvcgnbs -$ ls -160761 dnltsq.fwv -$ cd .. -$ cd .. -$ cd .. -$ cd .. -$ cd .. -$ cd lccjbtqs -$ ls -dir jjrdbgtg -77186 sqs -116398 szfw.qjt -182665 vmc.cdf -248366 vqdjwsh -$ cd jjrdbgtg -$ ls -237358 bdvbjs.sjp -$ cd .. -$ cd .. -$ cd lwfgnzz -$ ls -dir ggptdvr -dir jnb -dir lcpmzpr -222506 lsprzlbf -293605 qbjfqh -dir smvwg -291643 tchv -247095 vwdstb.pdw -dir wghpmnm -dir wtrbfrj -$ cd ggptdvr -$ ls -184198 vmc.cdf -$ cd .. -$ cd jnb -$ ls -296536 dnltsq.fwv -91419 jvcgnbs.cvq -279635 rwt.wth -$ cd .. -$ cd lcpmzpr -$ ls -184769 hhfqgzfj.qvt -dir qwqcbdms -236533 tjslbpb.bnc -162397 vmvctfnw -dir wcc -$ cd qwqcbdms -$ ls -232132 jgm.tfm -dir jnfmcnfh -173727 mwrbndt -dir qshphcb -dir tjslbpb -$ cd jnfmcnfh -$ ls -dir rngnt -$ cd rngnt -$ ls -236114 hhfqgzfj.qvt -$ cd .. -$ cd .. -$ cd qshphcb -$ ls -78407 lsprzlbf.hpd -$ cd .. -$ cd tjslbpb -$ ls -30200 brbz -171368 jvcgnbs.vwl -236158 sqs -285872 srfwnmb -dir znr -$ cd znr -$ ls -108194 hhfqgzfj.qvt -$ cd .. -$ cd .. -$ cd .. -$ cd wcc -$ ls -167768 jvcgnbs -289640 lgthn.cjn -28517 lwfgnzz.chf -dir nvgfwn -43738 rrg -81011 sqs -$ cd nvgfwn -$ ls -270370 hgnv.ssj -98235 lwfgnzz.nfv -$ cd .. -$ cd .. -$ cd .. -$ cd smvwg -$ ls -dir jvcgnbs -77510 tchv -dir tgrm -$ cd jvcgnbs -$ ls -287955 bqcnj.zzv -119021 bsrtmzd -3391 cnngp.mbf -68540 qjmb.vjz -149062 tchv -$ cd .. -$ cd tgrm -$ ls -112315 qzth -277566 scqp -$ cd .. -$ cd .. -$ cd wghpmnm -$ ls -dir hpm -$ cd hpm -$ ls -113354 hhfqgzfj.qvt -$ cd .. -$ cd .. -$ cd wtrbfrj -$ ls -dir ggrsgzvv -dir mvzzsl -dir szfw -dir vsqjb -$ cd ggrsgzvv -$ ls -dir dpv -dir gqtsmnr -dir lsprzlbf -dir pcjcm -137203 tchv -84711 tns.sdh -$ cd dpv -$ ls -233264 dmd -dir fzlchpb -293097 gwmspnm.qtp -100283 jbbnssc.nnv -$ cd fzlchpb -$ ls -150431 pdmzrs.rll -$ cd .. -$ cd .. -$ cd gqtsmnr -$ ls -dir jdml -dir jfqtjt -dir lwfgnzz -dir tjslbpb -$ cd jdml -$ ls -148333 bwm.dnt -dir lsprzlbf -$ cd lsprzlbf -$ ls -dir cslvm -dir lwfgnzz -dir rllt -265856 sqs -dir szfw -56452 tchv -$ cd cslvm -$ ls -266380 vmc.cdf -$ cd .. -$ cd lwfgnzz -$ ls -dir tzghdrd -$ cd tzghdrd -$ ls -dir tjslbpb -dir vhv -$ cd tjslbpb -$ ls -dir jvcgnbs -$ cd jvcgnbs -$ ls -18188 sqs -$ cd .. -$ cd .. -$ cd vhv -$ ls -95547 jhhblnn.vzt -dir srgh -$ cd srgh -$ ls -299624 lsprzlbf.dnr -$ cd .. -$ cd .. -$ cd .. -$ cd .. -$ cd rllt -$ ls -dir crpcbl -308185 dnltsq.fwv -dir szfw -$ cd crpcbl -$ ls -209445 dfds.mzh -$ cd .. -$ cd szfw -$ ls -dir lsprzlbf -159720 vmc.cdf -$ cd lsprzlbf -$ ls -291090 tzrvpv -$ cd .. -$ cd .. -$ cd .. -$ cd szfw -$ ls -113605 fbrtbfjm -$ cd .. -$ cd .. -$ cd .. -$ cd jfqtjt -$ ls -119124 hhfqgzfj.qvt -251412 jvcgnbs.zfm -dir rbv -dir tjslbpb -142371 tjslbpb.czt -65455 vmc.cdf -47786 zjmtjsv -$ cd rbv -$ ls -300632 dzssgm.pqn -$ cd .. -$ cd tjslbpb -$ ls -221545 pswrb.bsw -$ cd .. -$ cd .. -$ cd lwfgnzz -$ ls -34086 wshbr.spm -$ cd .. -$ cd tjslbpb -$ ls -118394 djfwjd.fvl -65377 qmgcpdr.qjz -146317 tchv -$ cd .. -$ cd .. -$ cd lsprzlbf -$ ls -195086 clqmgmq.gbw -dir cpgjgbdf -109787 jmwshtg.snl -305108 lsprzlbf -dir szfw -174614 szfw.qjq -105247 vmcf.rsm -$ cd cpgjgbdf -$ ls -dir vzddwsr -$ cd vzddwsr -$ ls -91787 nwgfs -$ cd .. -$ cd .. -$ cd szfw -$ ls -193316 tjslbpb -$ cd .. -$ cd .. -$ cd pcjcm -$ ls -dir lsprzlbf -$ cd lsprzlbf -$ ls -210834 hvrpj.cdc -29497 wcnf -$ cd .. -$ cd .. -$ cd .. -$ cd mvzzsl -$ ls -dir rnrtf -$ cd rnrtf -$ ls -221025 btwgwrp.ctj -$ cd .. -$ cd .. -$ cd szfw -$ ls -dir jvcgnbs -dir szfw -31365 tjslbpb -$ cd jvcgnbs -$ ls -250409 lwfgnzz.nvf -66638 tchv -dir tlms -$ cd tlms -$ ls -84192 lsprzlbf.pcm -107549 nwqzqcmw.rls -97234 svdqvwcz -$ cd .. -$ cd .. -$ cd szfw -$ ls -45362 zsflqrtc -$ cd .. -$ cd .. -$ cd vsqjb -$ ls -dir vvnzdcbb -$ cd vvnzdcbb -$ ls -144027 tchv -$ cd .. -$ cd .. -$ cd .. -$ cd .. -$ cd pprvjm -$ ls -dir hvst -137237 lwfgnzz.qfp -dir szfw -$ cd hvst -$ ls -100531 svmvncf -$ cd .. -$ cd szfw -$ ls -233868 hhfqgzfj.qvt -$ cd .. -$ cd .. -$ cd szfw -$ ls -14971 tchv -$ cd .. -$ cd tjslbpb -$ ls -283684 lwfgnzz.wzv -$ cd .. -$ cd ztc -$ ls -dir bwhfncdm -161420 jvcgnbs -135102 tchv -$ cd bwhfncdm -$ ls -108615 lwfgnzz.msn -$ cd .. -$ cd .. -$ cd .. -$ cd npppw -$ ls -94593 cwdz.tlb -258598 jsswljc -245674 nmmfzscz -$ cd .. -$ cd plmb -$ ls -dir dwnpl -dir lwfgnzz -$ cd dwnpl -$ ls -15993 hhfqgzfj.qvt -264944 vmc.cdf -$ cd .. -$ cd lwfgnzz -$ ls -154801 cnbmh.hsh -$ cd .. -$ cd .. -$ cd szfw -$ ls -173334 lsprzlbf -dir lwfgnzz -70693 szfw -$ cd lwfgnzz -$ ls -dir jgwzcgd -dir qgdcjq -dir spwcmrl -$ cd jgwzcgd -$ ls -dir jvcgnbs -dir nvtvcf -$ cd jvcgnbs -$ ls -131852 cntlhf.mqq -217305 dnltsq.fwv -174110 jvcgnbs.njb -179602 lwfgnzz.mth -dir pzcssdhv -dir qcmqmnpn -227361 szfw -dir wmhhl -$ cd pzcssdhv -$ ls -187518 gjfwbwnv -115671 lsprzlbf -$ cd .. -$ cd qcmqmnpn -$ ls -197002 dlns -40030 mmpp.ggt -198158 tchv -$ cd .. -$ cd wmhhl -$ ls -168011 hhfqgzfj.qvt -$ cd .. -$ cd .. -$ cd nvtvcf -$ ls -dir rrzjjjhc -$ cd rrzjjjhc -$ ls -33548 sqs -$ cd .. -$ cd .. -$ cd .. -$ cd qgdcjq -$ ls -252274 prshd.qdj -$ cd .. -$ cd spwcmrl -$ ls -dir lslmr -dir szfw -135076 tchv -265608 vmc.cdf -$ cd lslmr -$ ls -172247 rrvwsbl -$ cd .. -$ cd szfw -$ ls -192729 rnq diff --git a/day7/solution.nim b/day7/solution.nim deleted file mode 100644 index e6f4643..0000000 --- a/day7/solution.nim +++ /dev/null @@ -1,97 +0,0 @@ -import std/strutils - -type - Command = string - # using LeFile for name because File already exists - LeFile = ref object - Size: int - Name: string - -type - Directory = ref object - Name: string - Files: seq[LeFile] - Parent: Directory - Subdirectories: seq[Directory] - -# Directory methods -method cd(self: Directory, path: string): Directory = - if path == "..": - return self.Parent - - for subdir in self.Subdirectories: - if subdir.Name == path: - return subdir - -method add(self: Directory, file: LeFile): void = - self.Files.add(file) - -method add(self: Directory, dir: Directory): void = - self.Subdirectories.add(dir) - -let total = 70_000_000 -var part1 = 0 -var minRemoved = total - -method size(self: Directory, freeThreshold = total): int = - var size = 0 - for file in self.Files: - size += file.Size - - for subdir in self.Subdirectories: - size += subdir.size(freeThreshold) - - if size <= 100_000: - part1 += size - - if size >= freeThreshold: - minRemoved = min(minRemoved, size) - - return size - -proc run(root: Directory, input: seq[Command]): void = - # start pc from 1 to ignore "cd /" command thats coming first - var pc = 1 - var current = root - - let endpc = input.len() - while pc < endpc: - let command = input[pc] - assert(command[0] == '$') - - let tokens = command.splitWhitespace() - - case tokens[1]: - of "cd": - current = current.cd(tokens[2]) - pc += 1 - of "ls": - pc += 1 - while pc < endpc: - let file = input[pc] - # end of file list - if file[0] == '$': - break - - let fileInfo = file.splitWhitespace() - if fileInfo[0] == "dir": - current.add(Directory(Name: fileInfo[1], Files: @[], Parent: current, Subdirectories: @[])) - else: - current.add(LeFile(Size: fileInfo[0].parseInt(), Name: fileInfo[1])) - pc += 1 - else: - assert(false) - - return - -let content = readFile("./input.txt").strip().splitLines() - -var root = Directory(Name: "/", Files: @[], Parent: nil, Subdirectories: @[]) -run(root, content) - -let totalUsed = root.size() -let totalFree = total - totalUsed -discard root.size(30_000_000 - totalFree) - -echo part1 -echo minRemoved diff --git a/day8/example.txt b/day8/example.txt deleted file mode 100644 index 16d6fbd..0000000 --- a/day8/example.txt +++ /dev/null @@ -1,5 +0,0 @@ -30373 -25512 -65332 -33549 -35390 diff --git a/day8/input.txt b/day8/input.txt deleted file mode 100644 index 15fbc4e..0000000 --- a/day8/input.txt +++ /dev/null @@ -1,99 +0,0 @@ -200200221023111313131033314121142013103432145142351212334232423210101340410243413011333312111010010 -021002023301222221234134021422342024344555521535143232341414552024224120114233210330203002020100112 -120000123021210023111321143114331115334535223455511513445233523154411102203411040133312002213001021 -110211312303200204232110124204135453554533435152342542252215415141133330323032234114310011301232202 -112002122201001100330432244432552555524445123151222142521452233321152332132412434434431321322021220 -000131233030332102140440124221314455255431113413445553414144524134315351524134030112312012102102122 -011002120310213142402320144522121125454423123245535451115134412543215113433312403430132101003202030 -001221312201314442411333454131552331253553254425236334643151355314514413411344034432330410221101023 -133033302114012204213054544541124453214232545523665466356466451514332142121512400041213432211332332 -122103100320433433403313515121232352332442555253656542336644235234542522322522414400320014312110331 -220032121143103434234531224315451255225362634256634623342624242245654341134514413144333113211200033 -320112113344013332224131114231235263526556625325625352254643224563365551253353323542200003301120011 -130332114433413215333445212514445445656665256554333534422554442522234433415533124353022320300112030 -122220320003402342433443415465352622564252264442264334335624365224645544545412124352220434440211220 -012123032311134245212342233263346563632453535355553473445564362634252543555515242444423232000444220 -210332422344222154315435122245243633424643346345734336333746422324336263624544151122442021330341202 -122113144440445232235222443563362625543565533465377647363543377645634552632254214531354231413432430 -312340402310532324322313244522226622547366756445444754767335355365264622465662241215332253310001232 -203342203201331433144542522354633356376457563745333765735577477354743263423666625212251354244021004 -023132211325442531332565334564256663665357767653737436565453774766335532544656254552332354313323032 -104344140125552254523443534436547653753334746356364664565677777637444474643245425325454224440231203 -030303323422144551254256535247737377634445575474654433333453643564664344462332353234553115322142242 -043342223454513255464263333566337576377476354884845654658465735544446646436232534263314313142020101 -340311214411551345423466343646644336367654787858788857666654635337366537645634644263323112331404131 -040141315333331565455545334767475747755574585547567756844746644445646736447635456236413253453410130 -211021153443415666656253646443465373878486485664464485545486846643475567536535465634262415153200040 -434443334231526223353563373464374574547886487867474546748668788886554566336675234542522151345414431 -342100553111533623655466757467553555676668887764575574556755884875687334634675256256443425223423211 -421145141552463255552236436455476686566587654558577848647854485587448337355756554555544211113112433 -401034232152434624233754647737667758845867866675595798957488447876578774367337742646625521543244120 -201414142512656264345465456536564477766677986565767776589758477664747866666435364642236343442335143 -422042442525465325256445643735574646548578959977866889666586787677748745536646677524242544332243420 -101531424154626224664754337344565457557999965875599965977796778866568855445766577565632633451545144 -111515354125252635577747557658555488765757696767797558565755699985844788764347763523465333315513212 -222334234142233522754645544788567846579566995878775676667979868685866578655574543564453254615121150 -121552233464445256557546467767485865866888757989977669966767877786686475874646454752632664243132511 -412242332564644335747746348878865677677797755798669796798699855757865564547645373677564252625352445 -104135225262634344357677645645458796767865979969889676688676788669777674757634454746666526341145313 -021542323626266573437334685574765967759968767697666876767887775889896866845887736736426556541522241 -321245255565266675757675486554868969567677786789686889669988776968557656488476534636744443443445532 -424153123565322534465577464547665888797687899787966868666667897595997786576655333657432563645515114 -151513345354454444763668544475487669995769769878776696968966788666679588686556634737544644543232332 -315411214333624753546345646876778875556666766899787967667988799866697798768788653774352466325322155 -411515135354235576553778556478657685968679689776697889878966888788686556488744645555636235464132151 -521535123365535747465567756884789758877668899777979788877786896957896655744848765333672323354342345 -511122245466262643344764588545559786677866787999989789989769786875585659588677463454335226643415231 -234355522634365636744684556586586576767676868898988888987788888877768767654646777776645642226512141 -113123464223654555566666486667798785887896678897787899778677766996769787745467865757755656543512345 -513251343243554753654655574645569758987667887877878998789898989677659987488676836733553556554225344 -514313564242345475335768454478576556889868687997999987778988866675979779845785867656464634654245123 -114315542426623675675378664848688856798777688977789877988898769769667968885864643357435456442515251 -342223563236537773664686558445968779787887987788777777899877867865678669767686535536743642245412355 -125543254543547353647388564555887588899766978788778797797796898997787999888766547554567344424443422 -235522554554262346774664445787579599869688998989778778978989968998575857577865454747575353226552114 -222421136654623646474466478475666768686777899887878779887688896658596779765485853765563356364225314 -521231534444644737467764858748655998796879877877788879799986898965697856444748453437553352232525543 -451421316463534654736364878868555996777987969978898798976796968858967778666788533743354325346223354 -353521254635223475773456867765596786879787787769889887896999898885688596454456655466765442452131244 -112452332645434776643548885574558878789797669769989989886877966757566586444578445673434665652431423 -125112515242255354574555588568695879785886989867778677698879979576678878668587547744623644323213555 -222335123454333544773645644774469985799577787667779799699876685666756857858446357667422332624342332 -342124352633564466565447655564575889567797869876686996679999868665879886844677564455723264641334552 -211531121363532576364535865484865759689798698998996686966767965765789787447464533667726322444223531 -003112555432534436636776465475555776887557956877687879969697585659596546865447775565562326263355343 -433244413454525566563634447454784577659787856568996976596789778896764874668454673456462646455545115 -315114535444536635475346535567864558579958679557799758766667597987857466754537555645552424625323424 -041544243435426366744535764674465545875655656695956899997569789788477547755346553676234364525135211 -110125213453624243247556736654454474595787967599557857997699578855767558775435554762633446551353134 -230513132216566245267463366654684755868756978975659588575959655686655788733345435522656542222543322 -042134352115436525535436657767864645756586865777685969969787676584458468744346376522324323225232212 -113011555414226244554676353335845564485568555689599656977797776777868787473376444245355443123441231 -141222553351554636564756467565656675455484874698998587887767666457458846465776554544333612224555323 -410201213345143434422573347343756574748746464486554485756685477655667634334766422236535313341542224 -400013155121116452255553534765374544884448574876457458645878446585657476536357256436654223345343132 -142320132432156443246333547553474375466866456765867768748787675644755677446563663223424341524352200 -130310433221343524424456477364543647448885475465487864674454548867635637545422424333245424354220221 -104443025533452125362252625375463664447488646447874885476567646456653665465543643663511122334514003 -302020415314212533664642446555554345445458887778858887685645576353536647674424342553325334543032421 -241431045353353251642363462546445336355737566757557674865573447644353353564422462552323432524142311 -123213233322144323666345645436644754537635574357377674465747755476333656624223243445125521412332331 -012331042212144212425325652566536457633744775665435737646677453634637335562564643341411132411032042 -312330023343231454516256365325363757435647543374644573757667446466553456424326532235455225410011222 -330440423204155515131264636336326536353437335474474464535536754457526344465446535213522513202431334 -111010303340451214252454445262262654354536464545434674354557674362552463364322545323344220103312142 -011012340310414525221212256242445654336566374374366636534765356655652454533664444453134140113204011 -230024312112245355233251252646423364546365646735756334573543653656365434363633141223321213032042131 -031001023032240425233144214253446244556226622634747362226456645266342264223215113131540112130410110 -322123043034044225552242443355356433432465646225242242422346453346634325254325435535313321413201023 -022331002231110112224233354325624225342363424426633436565344545533465463152555421312331102120410200 -013020314334233240543141441351342432435423252532545655664253435662546145412112135314414140233322202 -023101011114024240134343343214355543453244325544366633232356362353335431215322232434231302030012200 -121203223241323132430512521115213312263253263242264335335446352453314333354413113210133333212120303 -102030123234100043232214342352345452215246465634534464364425653323345231332311444434220444330131120 -000331303323044244144032522114521112125142214553424464423124453113211413324230342333130021200000221 -121203123313224230334312325441234431451535345453515132125413445443323514321330302200100022013232311 -000221331111234212331404233225332533323225131525322111443344452254442544201223424140243032213101301 -010202021330012103042021024434411545123253214353525251521434235541535344240243403200122322133122101 -121102231211003113342040440404003344542241345133131133414435235243325441120032344431223311313111221 -011210032333020312123124101444102341443212553521355222414135533333310320012002223342012031112321112 diff --git a/day8/solution.nim b/day8/solution.nim deleted file mode 100644 index f2c4f23..0000000 --- a/day8/solution.nim +++ /dev/null @@ -1,85 +0,0 @@ -import std/strutils -import std/strformat -import std/sequtils -import std/algorithm -import std/sugar - -type - Tree = tuple - height: int - found: bool - -proc scanTree(tree: Tree, answer: var int, maxHeight: var int): Tree = - result = tree - if tree.height > maxHeight: - maxHeight = tree.height - if not tree.found: - answer += 1 - result = (tree.height, true) - -proc calculate(row: var seq[Tree], reved = false): int = - var - answer = 0 - maxHeight = -1 - newRow: seq[Tree] - - if reved: - newRow = row.reversed() - else: - newRow = row - - for i, r in newRow: - newRow[i] = scanTree(r, answer, maxHeight) - row = newRow - - return answer - -func part1(content: seq[string]): int = - var grid = map( - content, - (row) => zip(map(row, (c) => ord(c) - ord('0')), newSeq[bool](row.len())) - ) - var answer = 0 - - for row in grid.mitems(): - answer += calculate(row) - answer += calculate(row, true) - - for i in 0 ..< grid.len(): - var col = map(grid, (row) => row[i]) - answer += calculate(col) - answer += calculate(col, true) - - return answer - -func checkVisibility(line: seq[int], height: int): int = - result = 0 - for h in line: - result += 1 - if h >= height: - return result - - return result - -proc part2(content: seq[string]): int = - let grid = map(content, (row) => map(row, (c) => ord(c) - ord('0'))) - result = 0 - - for i, row in grid: - for j, h in row: - var col = map(grid, (row) => row[j]) - var count = - checkVisibility(row[j+1 .. ^1], h) * - checkVisibility(row[0 .. j-1].reversed(), h) * - checkVisibility(col[i+1 .. ^1], h) * - checkVisibility(col[0 .. i-1].reversed(), h) - - # echo fmt"{i}, {j} = {count}" - result = max(result, count) - - return result - -let content = readFile("./input.txt").strip().splitLines() - -echo part1(content) -echo part2(content) diff --git a/day9/example.txt b/day9/example.txt deleted file mode 100644 index 60bd43b..0000000 --- a/day9/example.txt +++ /dev/null @@ -1,8 +0,0 @@ -R 5 -U 8 -L 8 -D 3 -R 17 -D 10 -L 25 -U 20 diff --git a/day9/input.txt b/day9/input.txt deleted file mode 100644 index 06c4a9b..0000000 --- a/day9/input.txt +++ /dev/null @@ -1,2000 +0,0 @@ -L 2 -R 2 -U 1 -R 2 -U 2 -D 2 -U 1 -L 1 -U 1 -L 1 -D 1 -U 1 -L 1 -R 1 -L 2 -D 2 -R 1 -L 2 -D 2 -L 2 -U 1 -D 2 -R 1 -D 1 -U 1 -D 1 -U 2 -L 1 -U 2 -R 1 -D 2 -L 1 -D 1 -U 1 -L 1 -R 1 -L 1 -U 2 -L 1 -U 1 -L 2 -R 2 -D 2 -U 2 -R 1 -U 1 -D 2 -L 1 -U 1 -D 2 -U 1 -L 2 -U 1 -D 2 -U 2 -L 1 -D 2 -L 1 -U 1 -D 1 -U 1 -D 2 -R 2 -U 1 -L 1 -R 2 -D 2 -R 1 -L 1 -R 1 -D 1 -U 1 -L 2 -U 1 -L 1 -R 1 -D 2 -U 1 -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 9 -L 5 -D 1 -R 2 -D 16 -U 18 -D 7 -U 13 -L 10 -U 15 -R 18 -U 7 -L 9 -R 6 -U 18 -R 9 -D 8 -L 6 -R 7 -L 11 -U 12 -R 7 -D 4 -U 8 -R 16 -U 17 -D 4 -U 10 -L 19 -D 14 -L 12 -R 18 -D 4 -R 9 -U 12 -R 14 -U 9 -L 16 -D 14 -U 7 -R 14 -L 19 -U 16 -L 18 -U 1 -R 19 -D 7 -R 6 -U 12 -L 16 -R 16 -U 16 -L 6 -R 18 -L 19 -U 10 -D 15 -U 7 -D 1 -U 7 -L 12 -U 4 -R 5 -U 12 -R 18 -D 15 -U 4 -L 8 -U 18 -D 18 -L 3 -R 19 -L 15 -R 11 -U 1 -R 6 -L 8 -R 1 -L 3 diff --git a/day9/solution.nim b/day9/solution.nim deleted file mode 100644 index ef25492..0000000 --- a/day9/solution.nim +++ /dev/null @@ -1,61 +0,0 @@ -import strutils -import sequtils -import sets - -type Move = tuple[Direction: char, Distance: int] -type Position = tuple[r: int, c: int] - -proc parse(content: seq[string]): seq[Move] = - let moves = map(content, - proc (line: string): Move = - let temp = line.split(" ") - (temp[0][0], temp[1].parseInt()) - ) - return moves - -proc move(rope: var seq[Position], uniqPositions: var HashSet[Position]): void = - for i in 1 ..< rope.len(): - # rope[i-1] = leader - # rope[i] = follower - let roffset = rope[i-1].r - rope[i].r - let coffset = rope[i-1].c - rope[i].c - - if roffset in [2, -2]: - rope[i].r += int(roffset/2) - if coffset in [-1, 1]: - rope[i].c = rope[i-1].c - - if coffset in [2, -2]: - rope[i].c += int(coffset/2) - if roffset in [-1, 1]: - rope[i].r = rope[i-1].r - - uniqPositions.incl(rope[rope.len()-1]) - -proc emulate(moves: seq[Move], len = 2): int = - var rope = newSeq[Position](len) - var uniqPositions: HashSet[Position] - init(uniqPositions) - echo rope - for move in moves: - for i in 1 .. move.Distance: - case move.Direction: - of 'U': - rope[0].r -= 1 - of 'R': - rope[0].c += 1 - of 'D': - rope[0].r += 1 - of 'L': - rope[0].c -= 1 - else: - assert(false) - move(rope, uniqPositions) - - return len(uniqPositions) - -let content = readFile("./input.txt").strip().splitLines() -let moves = parse(content) - -echo emulate(moves) -echo emulate(moves, 10) diff --git a/init.sh b/init.sh index 86273e5..f9d5d9a 100755 --- a/init.sh +++ b/init.sh @@ -1,15 +1,21 @@ #!/bin/sh -source ../cookie.sh -if [ $# -eq 0 ] +if [ ! $# -eq 2 ] then - echo "No arguments provided." - exit 1 + echo "Usage: $0 [cookiefile]" + exit 1 fi -DAY=$1 -DIR="day$DAY" -echo "Initializing day $DAY in directory $DIR" +year=$1 +day=$2 +cookiefile=${3:-'../cookie'} +dir=$(printf "day%02d" $day) -mkdir -p $DIR && curl "https://adventofcode.com/2022/day/$DAY/input" -H "Cookie: session=$ADVENT_SESSION" > $DIR/input.txt -touch $DIR/solution.nim +echo "Initializing directory $dir/" +mkdir -p $dir + +advent_session=$(cat $cookiefile 2> /dev/null) && + echo "Downloading input ..." && + curl "https://adventofcode.com/$year/day/$day/input" -H "Cookie: session=$advent_session" > $dir/input.txt + +exit 0 -- cgit v1.2.3