Compare commits

..

No commits in common. "59f7b57dfa982ddc781082eb1e77dac148c6f7f4" and "72e6d95933dfe692fcba5973336aed21a85a9695" have entirely different histories.

25 changed files with 0 additions and 3398 deletions

View File

@ -1,31 +0,0 @@
name: Build and run challenges
defaults:
run:
shell: sh
on:
push:
jobs:
build-and-run:
name: "Build and run challenge for day {{ matrix.day_number }}"
strategy:
fail-fast: true
matrix:
day_number: [1, 2, 3]
#day_number: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
defaults:
run:
working-directory: day${{ matrix.day_number }}
runs-on: debian-12
steps:
- name: Install dependencies
run: |
apt update
apt install git
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Run challenge for day ${{ matrix.day_number }}
run: cargo run --release ./input

View File

@ -93,38 +93,3 @@ day-18:
stage: build
script:
- cd day18; cargo run --release ./input
day-19:
stage: build
script:
- cd day19; cargo run --release ./input
day-20:
stage: build
script:
- cd day20; cargo run --release ./input
day-21:
stage: build
script:
- cd day21; cargo run --release ./input
day-22:
stage: build
script:
- cd day22; cargo run --release ./input
day-23:
stage: build
script:
- cd day23; cargo run --release ./input
day-24:
stage: build
script:
- cd day24; cargo run --release ./input
day-25:
stage: build
script:
- cd day25; cargo run --release ./input

674
LICENSE
View File

@ -1,674 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
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.
Advent of Code 2021
Copyright (C) 2022 Louis Vallat
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 <https://www.gnu.org/licenses/>.
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:
<program> Copyright (C) 2022 Louis Vallat
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
<https://www.gnu.org/licenses/>.
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
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@ -1,34 +0,0 @@
# Advent Of Code 2021
> Find the sleigh key to save Santa, using your smol submarine!
## What
This repository hosts the code that I produced to solve the different puzzles
provided for the Advent of Code 2021, that you can find [here](https://adventofcode.com/2021).
## How
In order to solve the different puzzles, I used the **Rust** programming language,
as I wanted a way to experiment and practice this new language.
There are no dependencies and no external crate.
To execute it, just open the specific day you want to run, and use `cargo run --release -- ./input`.
Replacing the `input` file **should** work without any code modification.
## Why
Because puzzles are fun! And Rust is fun too!
## Yikes
The code produced may not be optimal nor the fastest. And that's normal, I tried
to spend less than a day (and to do it in my spare time after school).
The code is also very ugly for a reason: usually I use single letters for the
variable names. Usually it's fine. For me. For other people re reading me, it's
less fun. So I forced myself to use mainly single characters as variable names,
just to make me want to stop doing it.

View File

@ -1,8 +0,0 @@
[package]
name = "day19"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -1,857 +0,0 @@
--- scanner 0 ---
-594,397,693
-451,-583,331
-597,843,-847
-661,524,591
730,571,661
651,-549,-489
41,0,24
630,563,701
696,-602,543
-553,706,-847
-838,-658,-361
354,874,-727
125,167,100
-525,-540,451
-848,-529,-478
349,917,-644
-576,447,702
656,-361,-480
-403,-575,353
686,-447,-369
625,-510,651
-421,729,-852
-856,-616,-408
666,-425,576
703,540,868
385,731,-682
--- scanner 1 ---
560,474,-555
479,629,-526
-426,444,-864
325,-544,-582
365,-495,-573
672,-474,608
-439,442,-612
-887,-506,499
-431,-816,-652
-560,-824,-525
568,-500,758
-786,-558,418
804,739,574
-804,411,560
-654,460,580
494,408,-481
797,614,447
455,-566,-686
-464,-715,-596
825,740,572
547,-506,737
-327,440,-725
-776,422,551
-19,-173,-3
-856,-449,417
--- scanner 2 ---
479,583,-260
565,-830,543
-784,411,557
436,645,-355
397,414,625
723,-724,570
-625,478,-617
-902,-751,-590
-919,-899,-626
-523,-598,625
-2,-63,44
-192,-138,91
302,-614,-449
-916,-786,-624
-549,395,-481
327,450,569
316,-700,-320
-566,-674,492
585,-808,629
-744,377,527
-700,488,513
-525,399,-657
-670,-689,594
257,-546,-310
593,589,-352
447,469,651
--- scanner 3 ---
710,-694,815
903,381,694
657,478,-524
-518,-827,-571
553,493,-422
-270,621,380
-736,443,-500
522,-699,-738
-329,467,390
611,-753,887
-498,-654,336
-578,337,-473
-630,-769,-453
-598,359,-559
906,268,696
595,-812,-722
-495,-556,454
510,569,-555
496,-735,-673
889,416,660
516,-708,800
-525,-828,-499
-315,553,519
125,-167,93
16,-15,13
-370,-655,495
--- scanner 4 ---
561,-530,-578
518,836,898
-765,-682,897
738,-500,-611
84,74,9
810,681,-732
461,642,874
-620,444,957
380,-730,787
-427,-566,-453
422,-564,848
-404,-493,-286
646,-571,-503
-613,773,-672
476,645,904
681,556,-764
-452,398,888
-713,-797,796
-435,-466,-493
831,660,-738
-500,863,-743
-509,903,-694
-830,-722,811
-537,495,906
408,-627,767
--- scanner 5 ---
-749,-404,454
600,598,580
-764,-722,-519
-875,-376,579
-540,572,619
-874,-397,581
-609,-641,-548
431,-746,-679
365,-633,765
339,-529,615
-420,537,517
610,493,-501
371,-654,744
650,593,-493
492,527,672
-24,-64,49
-695,874,-847
-127,84,-93
-531,567,431
-543,-707,-474
-778,869,-804
-733,838,-661
525,557,495
409,-876,-575
360,-836,-566
817,520,-470
--- scanner 6 ---
713,-860,-483
-565,-584,-526
100,-153,47
-482,692,399
-286,-557,524
822,486,680
611,-926,794
-663,-602,-640
-588,385,-667
914,492,566
557,597,-538
-600,596,-670
619,-807,-494
-655,774,415
-515,-597,533
819,430,523
-551,-666,-726
693,680,-462
-598,750,484
598,-862,-374
-608,455,-544
517,676,-438
-330,-610,594
577,-849,775
-5,-41,-71
547,-951,862
--- scanner 7 ---
347,-463,316
37,47,-20
-409,-753,-482
487,-380,-338
-866,443,-723
417,442,795
-638,-290,735
339,-411,364
295,-397,-338
-546,-740,-576
313,-463,-352
279,553,-771
-814,544,-838
375,436,604
-621,-276,818
-131,93,71
360,466,601
-427,-818,-485
-647,-495,786
-638,434,454
-721,383,403
321,492,-605
381,-538,307
-553,452,357
307,573,-668
-931,529,-763
--- scanner 8 ---
-851,737,-565
468,-753,-432
644,-742,574
-826,811,-521
470,612,765
603,790,-395
-397,-456,784
469,768,-379
387,442,803
-760,789,-468
-811,-501,-674
48,-160,0
699,-792,548
663,-862,492
530,-710,-337
354,794,-363
-125,-20,-33
-752,315,722
-888,-482,-640
-813,431,779
-913,-414,-704
-465,-607,847
524,-596,-429
299,529,760
-377,-643,805
-749,371,855
--- scanner 9 ---
-809,-724,-432
592,728,-735
-510,726,361
-872,-608,-395
-481,864,341
-639,727,-781
561,620,361
597,650,379
747,616,345
514,-386,-686
712,-382,-620
501,-755,571
438,641,-767
405,-768,421
-858,-603,-430
-70,109,-125
-435,860,415
-771,-746,729
-555,804,-737
522,656,-585
-831,-620,822
-81,-15,69
-595,838,-767
625,-261,-632
-886,-729,828
479,-683,438
--- scanner 10 ---
881,663,713
-677,-726,-668
538,-558,-909
404,-483,-855
813,-747,329
-753,-461,502
-762,-650,-629
-854,-740,-677
648,699,-925
-873,498,-874
-693,-539,543
644,513,-909
-752,692,432
-573,-457,481
20,-167,-56
614,549,-891
801,-728,320
802,-904,423
-758,544,524
400,-529,-929
-783,387,-810
825,660,670
-897,489,-883
840,642,633
-785,624,530
-90,-17,-180
--- scanner 11 ---
-55,84,120
383,423,-460
348,-628,-638
-734,-705,-302
569,-829,498
-634,422,900
-143,-36,27
-768,-740,-288
383,620,573
-770,-853,-285
-584,-636,606
415,533,727
565,605,657
-702,382,927
492,-856,638
-750,388,887
413,457,-420
-566,-546,639
-801,445,-679
-761,524,-579
481,-552,-681
-668,-630,636
369,534,-504
-625,441,-655
450,-643,-534
576,-774,631
--- scanner 12 ---
-965,-651,-291
675,621,-532
341,345,727
701,436,-619
-523,483,917
-925,-701,-381
423,-662,-330
-97,-57,82
-626,522,926
-617,-714,416
623,-582,490
375,489,727
763,601,-604
380,-631,-342
-598,-603,550
-872,-648,-484
-595,-557,449
585,-564,593
-882,368,-270
-925,420,-460
-911,390,-258
556,-524,395
468,-691,-253
-703,542,962
351,473,678
--- scanner 13 ---
-600,-593,480
-388,-344,-865
-711,624,322
719,-602,-590
-804,740,-434
832,427,-610
-65,77,-30
-644,-690,357
565,-704,548
-544,-298,-850
-780,797,-628
-497,-310,-793
-810,782,-625
-649,549,390
109,-60,58
515,-735,488
826,448,-589
455,-671,399
883,768,814
826,686,845
779,-568,-700
-553,-771,482
858,577,-714
835,-690,-669
-656,754,352
774,767,744
--- scanner 14 ---
752,-458,532
-612,-635,-844
383,-370,-637
-641,-643,368
18,72,-67
621,-442,593
680,-645,557
-778,702,603
-703,-712,366
350,579,624
-585,644,-791
321,-320,-693
-746,548,516
-550,-539,-840
385,594,-893
-378,-637,-814
-592,777,-846
334,393,628
-596,618,588
449,705,-803
376,603,-917
-669,637,-873
366,-445,-773
368,543,594
-720,-840,359
--- scanner 15 ---
-765,498,475
612,-411,653
-12,130,-66
-569,-479,650
309,-718,-754
-128,16,-175
-905,-715,-446
295,-753,-759
-651,406,481
289,722,-873
-879,709,-937
572,-381,687
353,803,665
377,627,669
-608,501,419
-499,-423,614
-619,-505,595
358,-716,-875
453,763,586
409,701,-818
-947,773,-962
-860,743,-860
-754,-778,-514
528,-367,576
-718,-736,-426
398,607,-871
--- scanner 16 ---
-624,-579,-747
700,461,-545
516,593,232
595,648,288
-367,-350,437
-450,-388,607
417,-369,-461
-279,-393,524
-698,649,683
-643,-661,-867
-634,828,-826
-42,-55,-43
485,-306,-612
-463,754,-776
397,-348,-648
-679,-605,-797
96,84,-153
772,588,-461
451,711,296
774,543,-518
833,-374,426
-823,583,641
-676,614,537
772,-431,310
-364,800,-825
769,-298,366
--- scanner 17 ---
-535,-668,-567
-643,495,929
719,-570,605
572,-601,696
-634,486,953
-593,-475,827
384,440,-344
-689,-636,-480
-694,478,-558
-619,-486,-552
338,514,-348
-460,-482,882
498,-668,-370
-600,-559,909
595,692,910
-658,460,-588
505,740,818
16,143,132
413,460,-482
581,701,733
542,-682,-481
458,-638,-404
-844,444,-592
-532,559,839
-105,25,44
676,-703,681
--- scanner 18 ---
-646,448,-358
421,-453,552
611,592,834
-668,-586,773
-794,510,-405
-550,432,452
-618,472,479
648,561,653
384,630,-628
338,-471,611
-584,-580,743
-711,659,-371
673,546,767
-590,-476,-272
596,-648,-389
433,457,-559
456,-496,563
656,-736,-522
-468,-470,-245
498,676,-566
-502,438,492
640,-637,-412
13,78,59
-686,-496,740
-428,-603,-267
--- scanner 19 ---
-535,718,531
759,469,-617
49,6,-150
-647,632,595
873,-717,-496
-291,693,-778
-549,518,613
-405,771,-809
-270,-532,640
635,486,390
-349,811,-862
729,475,337
795,-867,-501
-586,-492,-476
-729,-621,-473
593,-783,348
-499,-541,600
614,366,335
-38,-71,17
563,-870,246
-708,-633,-457
837,-715,-605
627,-802,271
657,401,-631
-314,-602,587
744,319,-742
--- scanner 20 ---
118,-4,-45
-313,-645,461
-371,-761,376
492,433,672
725,-694,306
842,470,-625
-593,271,-452
852,342,-674
-597,410,-353
-563,580,534
-595,523,-465
813,-634,395
518,618,585
-629,654,468
-608,-635,-567
-1,-181,-107
570,-585,-437
637,-527,-342
608,-567,-540
-408,609,453
-678,-655,-690
430,598,657
-289,-588,392
818,486,-674
770,-665,383
-467,-643,-693
--- scanner 21 ---
-814,-466,669
425,811,436
-460,911,-535
-500,884,-603
558,590,-653
662,-304,-469
434,-719,739
-602,-595,-476
468,800,471
468,623,-671
-519,-671,-612
-574,596,688
-589,710,663
-523,-695,-436
501,-814,797
443,752,353
-603,-463,681
-744,-589,689
472,-616,757
-75,109,56
-620,529,626
627,-318,-503
-466,871,-487
552,620,-569
775,-301,-467
--- scanner 22 ---
913,595,571
80,66,-93
-752,-661,-816
-504,563,-357
703,696,-638
-480,486,-489
-543,504,-522
-562,-609,-859
-384,650,330
948,-550,562
831,666,546
851,-578,416
897,-559,-689
-490,-408,741
-418,-428,829
-477,572,302
-764,-639,-845
846,593,-665
986,-684,-672
36,185,57
-403,-593,767
-416,607,354
884,584,439
732,-583,568
703,652,-622
880,-756,-726
--- scanner 23 ---
-602,652,-708
-729,781,-700
-942,-759,-577
434,-593,570
422,325,-390
483,408,527
-424,-783,440
340,356,-333
-77,37,73
474,436,538
440,-799,-469
341,426,-442
-673,748,-599
445,-797,-552
503,558,576
-565,-858,471
-689,773,558
428,-800,646
-818,-808,-561
416,-776,-520
-941,786,560
512,-688,549
-802,885,556
-870,-728,-568
-613,-726,424
--- scanner 24 ---
616,666,-720
559,-451,438
653,780,380
-725,733,-842
-686,657,-757
718,562,-705
-820,-373,698
585,-401,383
667,-569,-861
-425,854,320
-445,825,458
-848,-372,428
683,740,346
-744,-322,-718
581,-589,-839
-686,-382,-817
-499,900,324
641,-331,419
-694,-315,-874
585,519,-629
640,-727,-755
-774,-422,599
-63,69,-70
-677,643,-934
697,696,457
--- scanner 25 ---
674,721,-553
-334,789,662
602,-473,579
-695,-823,616
6,6,-9
-682,-410,-584
841,401,569
-680,-885,451
814,723,-484
-618,433,-463
801,-846,-654
824,660,-585
-714,-386,-627
651,-463,707
651,-497,563
850,504,530
-536,803,632
-346,760,684
-621,-358,-549
-555,466,-481
-594,301,-540
847,-905,-646
-608,-797,431
818,-945,-832
886,581,510
--- scanner 26 ---
-509,460,-504
596,-943,651
-393,-890,-842
-353,-804,-907
782,570,-465
705,-460,-568
-345,-780,303
524,808,634
644,-782,676
542,-754,603
52,-106,-94
646,710,599
-504,510,569
-582,293,-481
190,-89,58
697,459,-388
-545,585,484
659,-667,-613
645,-493,-541
715,468,-338
-511,-841,345
-278,-789,-790
-609,500,-512
-575,618,661
572,830,642
-448,-760,331
--- scanner 27 ---
655,601,-428
-587,941,-352
-727,-430,-470
581,667,-494
484,-623,497
554,-351,-259
-642,763,733
-760,859,-336
563,-302,-299
450,-373,-389
524,635,505
-634,622,607
-677,-417,589
-912,-443,-531
610,822,-413
-579,-435,703
-109,111,68
272,637,492
411,633,393
611,-631,626
-691,-499,789
-644,917,-421
-654,552,730
540,-522,530
-956,-390,-461
--- scanner 28 ---
549,558,-705
-358,771,-570
-599,-543,-592
987,-345,-830
-399,672,-445
-704,619,441
-575,-405,-631
769,592,421
-553,-568,794
818,515,520
595,499,-600
834,628,447
749,-476,817
-791,574,536
667,500,-593
46,-19,65
761,-356,681
744,-569,703
-628,-726,803
171,27,-72
921,-320,-745
-541,-437,-576
833,-393,-860
-240,673,-573
-536,-553,833
-719,633,635
--- scanner 29 ---
453,-648,732
357,421,614
-572,366,-732
275,437,787
619,545,-687
-651,-297,848
594,-522,740
369,-440,-561
-640,411,-593
-784,428,710
-584,-392,790
-777,-793,-452
-726,425,-722
-622,-495,808
-925,-810,-416
452,-516,-425
-827,440,741
-164,106,178
299,506,730
-812,-807,-418
563,702,-690
15,-56,45
557,588,-782
373,-416,-385
664,-645,720
-739,351,681
--- scanner 30 ---
415,780,-484
570,-850,-776
609,756,-427
853,770,486
478,-790,647
695,-882,-647
-864,-850,-538
-441,-641,557
71,24,16
606,786,-442
-416,728,429
-833,-907,-456
756,788,571
348,-812,543
388,-861,534
807,839,654
-341,687,-600
-763,-798,-457
-408,-540,613
591,-856,-797
-530,710,493
12,-115,-109
-400,768,600
-371,632,-470
-537,-532,486
-409,625,-675

View File

@ -1,175 +0,0 @@
use std::{fs, env, collections::{HashMap, HashSet}};
#[derive(Debug)]
struct Scanner {
pub x: i32,
pub y: i32,
pub z: i32,
pub b: Vec<(i32, i32, i32)>,
pub c: HashMap<((i32, i32, i32), (i32, i32, i32)), ((i32, i32, i32), (i32, i32, i32))>
}
fn read_input(path: &str) -> String {
return fs::read_to_string(path).expect("Cannot read file.");
}
fn parse_input(s: &str) -> Vec<Scanner> {
let mut v: Vec<Scanner> = vec![];
for l in s.lines() {
if l.starts_with("--- scanner ") {
v.push(Scanner {x: 0, y: 0, z: 0, b: vec![], c: HashMap::new()});
} else if !l.is_empty() {
let t = l.split(",").filter_map(|e| e.parse().ok())
.collect::<Vec<i32>>();
v.last_mut().unwrap().b.push((t[0], t[1], t[2]));
}
}
for s in v.iter_mut() {
populate_distances_tuples(s);
}
return v;
}
fn populate_distances_tuples(s: &mut Scanner) {
s.c.clear();
for e in s.b.clone() {
for f in s.b.clone() {
if e != f && !s.c.contains_key(&(f, e)) {
let mut d = vec![(e.0 - f.0).abs(), (e.1 - f.1).abs(), (e.2 - f.2).abs()];
let u = vec![(e.0 - f.0), (e.1 - f.1), (e.2 - f.2)];
d.sort();
s.c.insert((e, f), ((d[0], d[1], d[2]), (u[0], u[1], u[2])));
}
}
}
}
fn rotate(c: &(i32, i32, i32), r: u8) -> (i32, i32, i32) {
let (x, y, z) = *c;
return match r {
1 => { (x, z, -y) }
2 => { (x, -y, -z) }
3 => { (x, -z, -y) }
4 => { (x, -z, y) }
5 => { (-x, -y, z) }
6 => { (-x, z, y) }
7 => { (-x, y, -z) }
8 => { (-x, -z, -y) }
9 => { (y, z, x) }
10 => { (y, x, -z) }
11 => { (y, -z, -x) }
12 => { (y, -x, z) }
13 => { (-y, -z, x) }
14 => { (-y, x, z) }
15 => { (-y, z, -x) }
16 => { (-y, -x, -z) }
17 => { (z, x, y) }
18 => { (z, y, -x) }
19 => { (z, -x, -y) }
20 => { (z, -y, x) }
21 => { (-z, -x, y) }
22 => { (-z, y, x) }
23 => { (-z, x, -y) }
24 => { (-z, -y, -x) }
_ => { (x, y, z) }
}
}
fn find_rotation(d1: &(i32, i32, i32), d2: &(i32, i32, i32)) -> u8 {
for r in 0..=24 {
if *d1 == rotate(d2, r) { return r; }
}
return u8::MAX;
}
fn find_corres(s1: &Scanner, s2: &Scanner, t: usize) -> Option<(HashMap<(i32, i32, i32), (i32, i32, i32)>, u8)> {
let mut a = 0;
let mut r = u8::MAX;
let mut c = HashMap::new();
let mut p: HashMap<(i32, i32, i32), HashSet<(i32, i32, i32)>> = HashMap::new();
for d1 in s1.c.clone().into_iter() {
for d2 in s2.c.clone().into_iter() {
if d1.1.0 == d2.1.0 {
a += 1;
if !c.contains_key(&d1.0.0) {
if !p.contains_key(&d1.0.0) { p.insert(d1.0.0, HashSet::new()); }
if p.get(&d1.0.0).unwrap().contains(&d2.0.0) && !p.get(&d1.0.0).unwrap().contains(&d2.0.1) {
r = find_rotation(&d1.1.1, &d2.1.1);
c.insert(d1.0.0, d2.0.0);
} else {
p.get_mut(&d1.0.0).unwrap().insert(d2.0.0);
p.get_mut(&d1.0.0).unwrap().insert(d2.0.1);
}
}
}
}
}
return if a >= (t * (t - 1) / 2) { Some((c, r)) } else { None };
}
fn compute_absolute(v: &mut Vec<Scanner>, f: usize, a: &mut Vec<bool>) {
a[f] = true;
for i in 0..v.len() {
if i != f && !a[i] {
let c = find_corres(&v[f], &v[i], 12);
if c.is_some() {
let (h, r) = c.unwrap();
if r == u8::MAX { panic!(); }
let (g, x) = h.into_iter().last().unwrap();
let t = rotate(&x, r);
v[i].x = g.0 - t.0;
v[i].y = g.1 - t.1;
v[i].z = g.2 - t.2;
for (j, b) in v[i].b.clone().iter().enumerate() {
v[i].b[j] = rotate(&b, r);
v[i].b[j].0 += v[i].x;
v[i].b[j].1 += v[i].y;
v[i].b[j].2 += v[i].z;
}
populate_distances_tuples(&mut v[i]);
compute_absolute(v, i, a);
}
}
}
}
fn count_unique_coordinates(v: &Vec<Scanner>) -> usize {
let mut c = HashSet::new();
for s in v.iter() {
for b in s.b.iter() {
c.insert(b);
}
}
return c.len();
}
fn get_max_manhattan_distance(v: &Vec<Scanner>) -> i32 {
let mut i = i32::MIN;
for s1 in v.iter() {
for s2 in v.iter() {
i = std::cmp::max(i, (s1.x - s2.x).abs() +
(s1.y - s2.y).abs() +
(s1.z - s2.z).abs());
}
}
return i;
}
fn main() {
let args: Vec<String> = env::args().collect();
for arg in args.iter().skip(1) {
let input = read_input(&arg);
let mut vec_in = parse_input(&input);
let nb_scanner = vec_in.len();
populate_distances_tuples(&mut vec_in[0]);
compute_absolute(&mut vec_in, 0, &mut vec![false; nb_scanner]);
println!("[{}]", &arg);
println!("\t[Part 1] => Answer is '{}'.", count_unique_coordinates(&vec_in));
println!("\t[Part 2] => Answer is '{}'.", get_max_manhattan_distance(&vec_in));
}
}

View File

@ -1,8 +0,0 @@
[package]
name = "day20"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -1,102 +0,0 @@
##......##.###.#...#.#..##...##.#......##........#.#...#...####..###.#...###.....#...###..#...#.......##.#.#.#.##..##.##..#..#....##....##.####...##.#..###......##.#..####....##..#.....#......###.#...##...#.....#.######..#.###..####.#.#....###...#..#.#.##.##.###.####.##.#.###......#..##...#..###.....#..##.#.#.#..##.#.....##......#.###.#..#...######.#...#.#.#....####...##.#.#.#..#..##..###.###..###.##...#.#.##....#..##..##...####..#.##..####...#...#####.####...#......##..#...##.###..#..##...##.###..####.###.
###.###.#.#....##...#.####.##..#.######..#...####.#####..#....#....#.##.#.##.....#....#.####.#..####
#...#.....#..#.###..######..#..#...##.##.#..#...##..#####.###########.#..#....#####.......###.##.##.
.#...###...#.##..###.###..#.#.#.#####.#.#.####.#.#.###...##.#.##########.##.#.#..####.##.####.##.##.
#.##......#.#.###...#...###.#..#..##.........##..#.#..####.#.####..#.#.#.##.#....###..#..##.##.##.##
....#..##.#.##.##...##.#....###.......#.#.##..##.#.####.#...#.#..##.##..#.....##.#####.####....#.#..
.#.##..#..#.........#..##..##.##.#......#..#...####..#.#.##......#.##.#....######.#...#.###..#....##
########..#.#..#.#.##..#.#...#.##.#...#....#..##..####.#######.#.##..##..#..###.##.#####.#.###.##..#
.#.#..#...##.#.#.#...#.#..##.#######.##..#..####.##..###.#..###...#.#.#.##.##..###.#..##...#.#.###..
###.##..#.....#.####....##..#...#.#.#...#####..###.#..##.#.#.#####.##########...######.#.#.####.##..
..#.#..#.#......#..#..#.#..#.....#..#..#..###.#####.#..##..####.##.#.#.#.###..#.#..#####.#....###.##
.##..#....#...###..#...#....#.##....#.........####..######...#.#####..#....#..#..#######....####.#..
#...##...#.........##.##..###..##.##.#########....######.#.##...##..#.#.#...##..#.#.....##.####....#
.##..##.#..#####.#.###..####....#..#.#####..####....##..#..####.#..#..#..#....#......#...##..##..##.
...##.#.###.#.#.#.#####..#...###.###..#######..#....##..#..###.###.##.#.#.#.#..#...###.#.#.##.#..#.#
....##.#..#.....#.#.#...#.#..###.#....#.###..#..#.#.#...#....#.###..#...##..#....###...#######....#.
##..##..........#..#..#....###....#...##...#..###.#..#...#.###........#...........#..#....###.###.##
.##.#####.##.###..###..#.#.....#.###..##.##.######...#.###..#.####.......##..#.#....###.###...######
##.##..#.####..#..#.#.###.#.#.#.##..#.####.###.#...#.#...#...#..#....#.#...##..########.##...#####.#
.##..#.##.#..#..#...#.......##....##..#....#..##..#.##..#.#.##..##.#.######.#..##..#..#......##.#.##
.#.#....#.#.##.##.....#..#####.##.#.###..#.#.....##....#..##.#####......#....##.##.####.#...#.##.#.#
.##.......###..##.###.#.#......#...##.####.....#.##..#.###..##.#.#.###...####.#..#...##..####..#...#
.#.#...####.#...#.#..##.######....###.#.##.#...#...##....#...#.#..#..##..#.#.#..##..##..###.#.######
......#.....######.#.##..###.#.....#...#..#..#..####..##.##.#..####..##..#.#.##.#.....####.##...##.#
...#..##...#.#..#####.#.#..#...####.#.#.#..###.#..##.#.##......####.##..##.#..##.#...#..##..#.###.#.
..###....#...#...#..###.....#.#####..##......#######.##.#.#.##.#.#.#.####.###..#......#..####.#.##..
#..#...#####.#..#..##..#######.#...###..#.##.####.#######.###.....#.#....###.####.##..#..#.#.#.##...
#..####..#.###..##...###.##.#####.###.#..##.....#...###.##.#....#.##...##..#..#..#.#.#..#.###.#....#
.##.#.#.###...#...#...##...#..#.#.#......#.#.##.#.#.#.#...#########...#.####.#####.##.#.#.#...##..##
#.#..###....#######..###.##....####..#####..#.##...#.#.#.#.####..#..#..#..#..##..#.###..#.##..###.#.
..#.#...####.##.#.####....#####...#...#...#....###.#...##.##.####...#..#..#.####.##.##...##.#.#..###
#####.#.#.#.#.#..##.#....#..##.##..###.##..##...#.#.#.###.##.#....#...#..#...#...#.###....#.##.#####
..#.#.#..####..##...####..#.#.#.##.##..#..#####.##.######....##.....#.##.....####......#..###..##...
##.##....######.#.####...#.###...#.#..#..#.####.#.#...##...##..#.###...#..#..#.#..##....##....##....
.#.#.######.#.#....##.#.#.##....###.#...#.###.#..##.#....##.#..##.###.#.#.##.#..#...##.####.#.##....
.###...###.#.##...###.#.##.#.###.###.##.#.######..#.###...#######...##.##..##..###....#...###....#..
#.....#.####...#..#..#...##.#.##.#...#####....#..#.###.#.##..######.#.##..###...#.#.####.##.#.#.....
....#.#.####..#..###...###..##.##..#.....##.##..###.#..#.###.#..###..####.##...##...#..#..#.##.#..##
##....#.#.##.#.#.#.#.#.#.##.#.#..#...##.#.#.##....##.#.#..##....#######..###.####...#####.#.#..###..
.#..####.##.###.#.##.#..######..##.####..##..#.#....#.##.##.#..#.#.##..#.....#....#.###..###...#.#..
.##.#......###.###.####.#.###.##.###.##.#.#..#####..#.###..#.#..###...#.....##.###.#..##.#..###...#.
##.##.######.##..#..#..#...##.###.##.####.#.#.#####.....###...##.#..###.##..###....#..####.......###
.######.....##..#.##.##.#.#####....###.#.###.#.#...#.####...#...##.##.##....#.#.###.......#..###.#.#
##.##.#.#.##.###.##.##..##.##..##..#...#..###...#.....##.#.#.####.###...#.#..#...#.#..#...#.##..#..#
.###.###.#..##..#.###.#.###....#..#.##.##.#######..#....######..#..#####....###..#...##..#..#####...
.###.####.##.####.##.###.##..#..###.###...###.######.##.#.####.#.#...##....#...##.##.#.##.#.#.#.#..#
.##....##................#..#.#...#....#.#..###..#..#.#####.#####....####..####.####...#.#####.###.#
..###.######.#.##....#.#..##..#...##..#.####.#.###.......#...#....#.#.#..#...#######...####...####..
##.##..###..#.#..###..####....#..#.#.#..###...####.##..##.......###...##.#.###.#....##.##..#.#...###
..#..#.######.###.....#..####.##.....#....#..##.###.##..#.##.#......###....######.#.#.##.##.#.#...##
####.##...#.##.###.#.#..#.#...######.#...#...####.####..#.#..#..#.#.#.####.#..#.#..##.#..#......##..
...#..#.##.#......#..#.##.###.#.#.##..#.##.#####.#...##.##..#.#...##.#...###....#...##..#...#.####..
..###..##...#.##.#..#.#..#.#.##.#..#.#..##.#.#..#.#.....########..##..#.#..#..##.#.###....#.####.#.#
.#.##...###..#.#..###.#...#.###...###.####.#.##.#..#...#..#.##..####.#.....####..#..##.##.#...##....
.#....#.#.##.#....#..#.#.##.#.###.###..##..##.###.#.##...##.####...#..###..######.##..#.#...###.##.#
#.#.#.##..#..###.....#.###.##.###.#..######....##.##.###......###.####.##....#...#..#.###....#..####
.#.###.#.#...#..###....##.#.####..#..#..#.###..###.#.#.....#.#####......####.#.....##...#.####......
..####.#....#......##..###.....####.#..#.....##..#.......##.#.#.....#.##..#.#.#.#....###.##..##.....
######.#.##.#.#.####.#.###.##.##.##..##....#####..#####...####.##...####.##..##.#.##...##.#..##.####
.##.#...##.....##.#..#.##.#.#....##..##.###..#..####.....#.##...#.#.##...##.#.##....#.####..##.##.##
.###...#.......#.#####..##..##.####..#####.####.#####.....##...###.###....#.......##...#.#....#.#..#
#.#..####..##.##...###..##......##.#..###..#####.####.###.#####.##...#..#.#.###..###.#....#.##.#####
##...#..##...#..#.#..###.#.##.#......#.##...#.....#.#......##...##..#####..#..##.##.##...#..##.##.#.
##.##...###..##.#.#......##.###..#...###..##.#.....##..#.#......#.#####.#...#.#....#...##..#.#...#..
##..#.#####.##.#.#.#...#..#...########..##.#...###.#.....#.###.###.##.##.#.#..#.###.###...#.###..##.
.#.#####..#..###.###..##..#........#.##....#.#..####...#..##.###..##...#..######....##.#...##.#####.
.....#..#...####..##..#....#..#.#..#.....###..###.##.##.##...##....####..######.#....#....#...###.##
.#####.......###...###.###..##....#.########..##.....###.#.#.#........#.###...###.......##..###..#.#
..##.#.#..###...#....#...#.####.#.#####...###.####.....######..##.##...####....###..##.##.######.##.
#.#.#..#...#..########.##.###.###.##...#..####.#########.#...#..##.##.###.......#.#.###...#.#..#.#.#
..####..#.##.#.###....##.##.#......####.##.##..#.#.###......##.######..##........#...#....#####..###
.###.#..#....##..#..#..#.#.#.#..##..#.#..#...#.#....#......#..#.#####.#.##....###.###..#....#####...
..##..##.#..###.#....###..##.####.##...#..#.##..#....#.#....#..##.#.###.#.....###..####.####.#....#.
#.####.....#..##..#.##..##.###.#.#..###.....#.##.##..#..###..#.##.#...#.##..#....###.###.#####.###.#
.##.#####.##..###.####.##.#.##.###.#..#...##.#..#.##..#..##..##.#.#######.#...#...##.#..####.##.#.#.
..##.##.#.#.###..#.#.###...##..##..#...#..#..####.#.#.####.##.#......#.#...#.#...#.....##..#..#..#.#
.#.###..##..#.......##.#..#.##.#..#....##.#...###.###.###.##..#.#.#.#.#.#########...##.###..#.#..#..
#.###..#.##.#.#..####.###..#.#.####...#...####.#.#####..####.####.#..###...###.##.##.#...#..#.#....#
...##.#.#.#.......####.####....###.#.............###..#..#.#..#....####..##.#.######....##..##.#.##.
..#####....#..####....##..####...###...#.#...##...#..###...#..#..#..#..######..####.##.###.##.#..###
##..#.###.#..#.###.##.#.###...#.#.###..####.####.##....#..##.#..#.#.##.#.#.#.##......#...##.........
..##.##..#.##.####...#...#...###..##.#.###...###..##.#.##.##..#.##.#..#....##.#....#.##...###...##..
..#.#.#.#.#..#.##.#.#.#.##..##.......#..#.##.##.####..#####...####.#..##..#####.##.#..#.....#.#####.
#....###..###.######.###.###..###.##...#.#...##.##..#.###..####...#.##..#.#..##.#.###.##.###.......#
....##.#.#...##...#.#......#.#.####.#..#...##...##..#.###.###.#..#..#####.#.#.##..#.#.##.##.#...#..#
##..#.###.#.#.#.##.....#.#.#.#..#..#.#..####.##..######.#######...#.#.......##.#..##.##.##...##.#..#
#.#.#..######.#.##.....#####....#..#....###..#...########..#..##...##..#.#..##.####..##..##..#.#.#.#
.##...#.#.#.#.##.####..###.......####...#.......######...#.##.####..##....###......###.###.##.#.#.#.
###.#.#..####..#.#..#..##.#....######..#.###.##..#.##..##.....##.##....#.###.........###...##.##....
.#.#..######.#########.#..##.###..#...#.#.#.#.##..##.###..#..#....###..##.#....###.#.##..####...#..#
#..#.###.#.##....####..##.#...####...##.#######...#......##.......#..##..##...###.##.###....#..#.#..
#.#..#...##.#.####....#....#.##.#.#...#.#....#..##..#.#.####.#.###....###..#..##.##.###....#.##.....
.###..##...##....###...#####.#...#.##.#.#.###.###.##..##.##....#.##.#####..#.#####..#####.##.....#.#
#..###..###.###..#.##.###.##..##...#..##.##.#...###..#.##...##...#....#..#.###..#....#...#.#.....###
#.#..##.####.###..##.####.##..########..##.#...###..#####..#.###..##.......##.#..###.##.#...#...##..
.#...#.#..#.##.......#.....##.#####.#.#.###..###.#.......###.#..####.#.#.#.#.###..#.#...#.#..#.#.#.#
###.#####....#.##...######.###...#.#..#.#......##.#.#.##.#..##..#.#....#....##.##..####...#.#.###.##
##.#.##.##...###..##.#.#..###.#.##...###..#.#.#.#..##..#.##..####..#.###.#.##..#.#..##...###...####.
###..#..#..#..###..##..###.#.#.##.#.###.#..#...##.#.#.#.#.#######.#...##..##.#...##.......#.#.##.#..
.#####.....###...##..##...#.#.##..#####.#.#.##.#.#.#.##.#..##..#.#.##.#.##.....###...###...###.###.#
.#.#..##.##.##.#....##.#..#..######..#.##.###.##..#.##.#....#....#.##.##.#.##.######..####.#.#.#.##.

View File

@ -1,94 +0,0 @@
use std::{fs, env, collections::HashSet};
#[derive(Debug)]
struct Image {
pub h: usize,
pub w: usize,
pub i: HashSet<(usize, usize)>
}
fn read_input(path: &str) -> String {
return fs::read_to_string(path).expect("Cannot read file.");
}
fn parse_input(s: &str) -> (HashSet<usize>, Image) {
let mut e = HashSet::new();
let mut p = HashSet::new();
let mut r = 0;
for l in s.lines() {
if e.is_empty() {
for (i, c) in l.chars().enumerate() {
if c == '#' { e.insert(i); }
}
} else if !l.is_empty() {
for (i, c) in l.chars().enumerate() {
if c == '#' { p.insert((r, i)); }
}
r += 1;
}
}
let c = get_min_max_coord(&p);
return (e, Image { h: c.0.1, w: c.1.1, i: p });
}
fn get_min_max_coord(p: &HashSet<(usize, usize)>) -> ((usize, usize), (usize, usize)) {
let (mut lh, mut uh, mut lw, mut uw) = (usize::MAX, usize::MIN, usize::MAX, usize::MIN);
for i in p.iter() {
lh = std::cmp::min(lh, i.0);
uh = std::cmp::max(uh, i.0);
lw = std::cmp::min(lw, i.1);
uw = std::cmp::max(uw, i.1);
}
return ((lh, uh), (lw, uw));
}
fn shift_image_for_safety(i: &mut Image, s: usize) {
let mut h = HashSet::new();
for e in i.i.clone() {
h.insert((e.0 + s, e.1 + s));
}
i.h += s * 2;
i.w += s * 2;
i.i = h;
}
fn enhance_image(i: &mut Image, a: &HashSet<usize>) {
let mut e = HashSet::new();
for r in 1..i.h {
for c in 1..i.w {
let mut z = 0;
for y in (r - 1) as i32..=(r + 1) as i32 {
for x in (c - 1) as i32..=(c + 1) as i32 {
z <<= 1;
if i.i.contains(&(y as usize, x as usize)) { z += 1; }
}
}
if a.contains(&z) { e.insert((r, c)); }
}
}
i.i = e;
i.h -= 1;
i.w -= 1;
}
fn main() {
let args: Vec<String> = env::args().collect();
for arg in args.iter().skip(1) {
let input = read_input(&arg);
let mut vec_in = parse_input(&input);
shift_image_for_safety(&mut vec_in.1, 100);
let mut p1 = 0;
for i in 0..50 {
if i == 2 { p1 = vec_in.1.i.len(); }
enhance_image(&mut vec_in.1, &vec_in.0);
}
println!("[{}]", &arg);
println!("\t[Part 1] => Answer is '{}'.", p1);
println!("\t[Part 2] => Answer is '{}'.", vec_in.1.i.len());
}
}

View File

@ -1,8 +0,0 @@
[package]
name = "day21"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -1,2 +0,0 @@
Player 1 starting position: 1
Player 2 starting position: 2

View File

@ -1,100 +0,0 @@
use std::{fs, env, collections::HashMap};
struct Dice {
n: u32,
i: u32
}
impl Dice {
fn new() -> Dice { Dice { n: 0, i: 0 } }
fn get_nb_draw(&self) -> u32 { return self.n; }
fn get_next(&mut self) -> u32 {
self.n += 1;
self.i = (self.i + 1) % 100;
if self.i == 0 { self.i = 100; }
return self.i;
}
}
fn read_input(path: &str) -> String {
return fs::read_to_string(path).expect("Cannot read file.");
}
fn parse_input(s: &str) -> (u8, u8) {
let p = s.lines()
.map(|l| l.split_once(": ").unwrap().1.parse::<u8>().unwrap())
.collect::<Vec<u8>>();
return (p[0], p[1]);
}
fn play_classic(mut v: (u8, u8)) -> (u32, u32) {
let mut d = Dice::new();
let mut s = (0, 0);
let mut p = true;
while s.0 < 1000 && s.1 < 1000 {
let a = d.get_next() + d.get_next() + d.get_next();
let mut x = (if p { v.0 } else { v.1 } as u32 + a) % 10;
if x == 0 { x = 10; }
if p {
v.0 = x as u8;
s.0 += x;
if s.0 >= 1000 { return (d.get_nb_draw(), s.1); }
} else {
v.1 = x as u8;
s.1 += x;
if s.1 >= 1000 { return (d.get_nb_draw(), s.0); }
}
p = !p;
}
return (d.get_nb_draw(), std::cmp::min(s.0, s.1));
}
fn play_quantum(v: (u8, u8), s: (u8, u8), p: bool, c: &mut HashMap<((u8, u8), (u8, u8), bool), (u128, u128)>) {
if s.0 >= 21 {
c.insert((v, s, p), (1, 0));
return;
}
if s.1 >= 21 {
c.insert((v, s, p), (0, 1));
return;
}
for i in 1..=3 {
for j in 1..=3 {
for k in 1..=3 {
let mut a = v;
let mut b = s;
if p {
a.0 = (a.0 + i + j + k) % 10;
if a.0 == 0 { a.0 = 10; }
b.0 += a.0;
} else {
a.1 = (a.1 + i + j + k) % 10;
if a.1 == 0 { a.1 = 10; }
b.1 += a.1;
}
if !c.contains_key(&(a, b, !p)) { play_quantum(a, b, !p, c); }
let r = *c.get(&(a, b, !p)).unwrap();
let x = *c.get(&(v, s, p)).unwrap_or(&(0, 0));
c.insert((v, s, p), (r.0 + x.0, r.1 + x.1));
}
}
}
}
fn main() {
let args: Vec<String> = env::args().collect();
for arg in args.iter().skip(1) {
let input = read_input(&arg);
let vec_in = parse_input(&input);
let c = play_classic(vec_in);
let mut w = HashMap::new();
play_quantum(vec_in, (0, 0), true, &mut w);
let w = w.get(&(vec_in, (0, 0), true)).unwrap();
println!("[{}]", &arg);
println!("\t[Part 1] => Answer is '{}'.", c.0 * c.1);
println!("\t[Part 2] => Answer is '{}'.", std::cmp::max(w.0, w.1));
}
}

View File

@ -1,8 +0,0 @@
[package]
name = "day22"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -1,420 +0,0 @@
on x=-3..43,y=-22..22,z=-15..34
on x=-9..42,y=-40..12,z=-30..19
on x=-5..46,y=-9..38,z=-31..21
on x=-27..25,y=-30..22,z=-9..42
on x=-25..27,y=-43..3,z=-22..31
on x=-39..9,y=-45..8,z=-17..29
on x=-10..36,y=-2..44,z=-9..35
on x=-45..4,y=-41..5,z=-3..49
on x=-24..26,y=-34..12,z=-6..44
on x=-35..17,y=-36..11,z=-42..10
off x=5..19,y=6..21,z=-21..-3
on x=-45..1,y=-40..11,z=-31..20
off x=16..30,y=-16..-4,z=21..33
on x=-38..7,y=-30..15,z=-46..3
off x=36..48,y=-39..-22,z=-47..-34
on x=-23..22,y=-22..29,z=-27..24
off x=-39..-29,y=-47..-34,z=-13..-1
on x=-18..28,y=-3..44,z=-8..38
off x=-38..-24,y=-48..-39,z=14..28
on x=-32..21,y=-36..9,z=-38..16
on x=-40114..-18236,y=44675..56621,z=-62989..-35133
on x=-47063..-26565,y=34232..54684,z=-70517..-34320
on x=-56151..-43929,y=48563..58124,z=36908..41850
on x=-77794..-42408,y=-69580..-49841,z=1311..11416
on x=-55821..-38492,y=49499..69556,z=17469..29122
on x=63143..77824,y=-46210..-33353,z=9878..30392
on x=39342..53117,y=-50110..-40820,z=-62170..-40938
on x=-73484..-48152,y=-65736..-42700,z=-18262..-13156
on x=37366..54383,y=19405..43152,z=47195..68515
on x=-58204..-27378,y=-43155..-25521,z=-62841..-54391
on x=-74420..-47151,y=37359..62719,z=-25475..-3046
on x=-45598..-17555,y=-26089..-5704,z=-70074..-64019
on x=-60861..-28014,y=-73554..-54991,z=-31524..-9823
on x=-24856..-677,y=-30123..-15884,z=63853..91090
on x=-70612..-48898,y=-58794..-27838,z=31988..51431
on x=-39272..-20927,y=-20393..-13252,z=-85528..-72953
on x=-25668..-4103,y=-18215..-1734,z=-91736..-74972
on x=-58040..-34891,y=-68034..-41896,z=22484..48325
on x=-83077..-63382,y=17005..35646,z=-28949..3129
on x=-75533..-63223,y=-47132..-32953,z=18181..35552
on x=-12005..9792,y=19338..25243,z=-92843..-67825
on x=56387..84965,y=-35767..-23866,z=-7517..29845
on x=41294..42717,y=62107..77449,z=-6076..18165
on x=68909..88527,y=12129..33752,z=-14973..1514
on x=70106..89265,y=-44616..-27968,z=-11036..-1697
on x=23822..38056,y=40195..55684,z=-65662..-33478
on x=57501..81938,y=-18907..-5701,z=5821..28274
on x=-25260..-17668,y=-48592..-46210,z=-69961..-51155
on x=-40924..-23866,y=59810..71028,z=1641..21630
on x=34547..43160,y=-74622..-56131,z=-36907..-17782
on x=-21350..276,y=14485..29856,z=-77890..-58230
on x=-75736..-39641,y=-2847..32980,z=-57010..-42061
on x=-25041..-10364,y=-77922..-57550,z=18525..31966
on x=-11867..7378,y=17836..49462,z=-90609..-54269
on x=-73484..-39680,y=-39303..-21793,z=31847..54382
on x=-16778..-10708,y=-66044..-52096,z=-44957..-39847
on x=-6352..5197,y=-48264..-42773,z=-69346..-65566
on x=-70366..-51952,y=-45555..-37939,z=-60527..-28534
on x=21301..42400,y=-20291..4389,z=66067..89444
on x=45669..82341,y=-56204..-41535,z=-21028..-14812
on x=-12687..6121,y=-75650..-50731,z=40334..49677
on x=62454..72648,y=-56206..-23070,z=-36904..-4173
on x=-14045..15260,y=74607..78556,z=3616..39536
on x=3027..21243,y=58402..67345,z=32845..51345
on x=36180..53611,y=3808..31420,z=-75144..-41742
on x=62333..81915,y=22152..45857,z=-19764..3026
on x=16840..31474,y=51862..63491,z=41052..56975
on x=34291..46927,y=-64612..-48527,z=-43496..-32299
on x=-15540..7128,y=28606..58975,z=61419..80612
on x=-41973..-18320,y=-77313..-61240,z=15692..47003
on x=-53801..-30362,y=39541..57030,z=-60083..-35312
on x=68377..77233,y=20169..50880,z=-27441..-20458
on x=-48517..-32670,y=27681..29643,z=43402..61515
on x=-27916..-4199,y=26661..49908,z=52384..82183
on x=49989..60432,y=-53633..-30668,z=-41268..-22103
on x=27313..55472,y=56100..75902,z=19430..45734
on x=-6356..15818,y=-68706..-57263,z=36276..50109
on x=-86603..-47010,y=-10414..18891,z=-47053..-29175
on x=-55452..-23629,y=-70516..-54860,z=1793..24906
on x=50625..72911,y=-12487..-2707,z=-71603..-40651
on x=39137..55253,y=19930..23696,z=45922..65211
on x=-9884..16104,y=-37553..-13090,z=-80288..-61586
on x=15247..32364,y=58299..77121,z=12794..38315
on x=-66919..-64795,y=27710..52508,z=-5853..20204
on x=55575..68137,y=-44413..-25743,z=-53783..-25185
on x=-28440..950,y=-58170..-37455,z=42708..66553
on x=-62883..-47411,y=41864..58827,z=-14578..6700
on x=-77452..-58620,y=-27879..-12335,z=28389..50389
on x=16287..41670,y=-20720..-3731,z=58921..81851
on x=-39948..-11682,y=62858..90995,z=-33475..-6506
on x=-56395..-35664,y=27367..43557,z=-61199..-44459
on x=-52933..-35603,y=-11996..5380,z=-73054..-57610
on x=-13683..-926,y=-79150..-68241,z=13231..23670
on x=-2283..11495,y=-47635..-35881,z=65101..72052
on x=68775..80912,y=-16331..4168,z=9807..29318
on x=-82722..-62858,y=28101..48460,z=-20008..-10603
on x=2241..10548,y=76361..96934,z=-22674..-2056
on x=54720..67218,y=-55890..-27903,z=-24408..-4708
on x=-29992..1612,y=7330..30747,z=-89965..-57543
on x=-26063..-23251,y=-14766..-5848,z=56200..88720
on x=25688..45780,y=48319..64535,z=29487..42809
on x=-10623..723,y=21921..25266,z=59433..79964
on x=9630..28513,y=-55849..-40790,z=59817..71724
on x=11397..35361,y=-80067..-68146,z=-50677..-32416
on x=50224..86037,y=-20267..-15219,z=-58574..-37744
on x=-46674..-23145,y=25112..36216,z=62513..76632
on x=-57137..-35534,y=26364..30930,z=47504..77090
on x=-41608..-18461,y=-42765..-18900,z=59370..81028
on x=-79954..-65176,y=-48791..-24716,z=-18848..6604
on x=-34241..-17350,y=-56143..-45006,z=44227..58857
on x=-5530..18391,y=42342..80378,z=44220..64341
on x=30538..43170,y=-48953..-12974,z=-64060..-46708
on x=18461..24438,y=-27505..-8539,z=-92027..-61631
on x=7320..30402,y=2065..30085,z=63426..78441
on x=-83260..-52652,y=-51533..-38598,z=-14357..16445
on x=-62617..-42138,y=42994..61052,z=-44270..-29008
on x=41132..55256,y=17301..44161,z=47335..72698
on x=-38586..-28967,y=15440..46541,z=54083..79262
on x=4995..13584,y=-83385..-58047,z=8179..45684
on x=-9417..16240,y=-364..29729,z=63018..79305
on x=-12093..-408,y=69909..76313,z=17279..43292
on x=22311..54594,y=-61374..-47340,z=38721..58551
on x=17514..41718,y=19397..55401,z=52361..75918
on x=-50215..-25999,y=-31832..-5898,z=-76682..-69666
on x=-88531..-51323,y=20056..51515,z=-25044..3011
on x=31693..42788,y=58122..73210,z=10170..25065
on x=-53730..-34736,y=-81115..-51623,z=-18858..-15751
on x=-8074..19450,y=56979..82537,z=21384..34758
on x=-9034..12679,y=-88632..-76023,z=-5255..10049
on x=-86158..-60722,y=-29277..-10774,z=-8108..5698
on x=51152..71206,y=-60178..-30734,z=-35299..-26419
on x=-53802..-21439,y=-81913..-62752,z=-48874..-14789
on x=-73416..-53624,y=-34880..-13729,z=-53059..-31384
on x=56542..90289,y=-39884..-24348,z=-33572..-10907
on x=6068..14850,y=-24184..-14322,z=60362..84796
on x=-65456..-62775,y=-39784..-18820,z=29946..43097
on x=-20508..-10931,y=21416..42909,z=-92770..-64543
on x=-78252..-45498,y=-42625..-36372,z=-37489..-22616
on x=-57749..-32551,y=33364..54148,z=39122..59239
on x=42486..64700,y=53697..67728,z=6295..16867
on x=-49857..-32057,y=8944..15961,z=66948..80602
on x=5331..24738,y=60035..81743,z=-9594..14754
on x=-37717..-27443,y=-26773..4070,z=-92232..-59205
on x=65813..86768,y=-40687..-15775,z=-29939..-15873
on x=3652..16387,y=-11856..10121,z=74824..93756
on x=-79835..-45711,y=-53126..-25959,z=-44777..-15785
on x=29228..52342,y=-42363..-18344,z=-83369..-51120
on x=-77918..-47225,y=-64364..-34769,z=-23149..-14421
on x=53783..76513,y=-54253..-24629,z=-1497..25601
on x=-4117..22514,y=-68600..-43788,z=39330..61783
on x=56356..73410,y=29059..61247,z=23522..30743
on x=-53663..-19354,y=9252..18430,z=55428..81436
on x=-77447..-54826,y=-13321..11273,z=37758..54142
on x=-33225..-11181,y=-88722..-71114,z=-17425..-1981
on x=34224..64644,y=-2807..21051,z=-76498..-56029
on x=-84451..-58720,y=-8709..7250,z=28349..41147
on x=32736..58563,y=-56724..-25395,z=38575..66087
on x=-70967..-60938,y=-14558..-1120,z=31180..57527
on x=57978..73770,y=37063..64257,z=-6069..-220
on x=20034..21990,y=-73943..-62810,z=16616..34791
on x=-86125..-62182,y=-46075..-37645,z=-22559..-16252
on x=64441..79235,y=44123..53922,z=-15543..5734
on x=58533..82768,y=-2754..6990,z=26452..35254
on x=34809..61230,y=-73095..-41773,z=16468..37593
on x=27000..39601,y=-35268..-18100,z=-72724..-54029
on x=-84967..-77387,y=-19101..-328,z=-9397..13132
on x=-19461..8572,y=13497..45738,z=-86131..-73254
on x=-86433..-60998,y=-56901..-29700,z=-18913..-2693
on x=-18094..5939,y=-84753..-47530,z=33605..55713
on x=-52752..-32887,y=-76293..-43540,z=20582..47775
on x=38804..57591,y=28533..48342,z=23227..52409
on x=-33372..-19183,y=60151..91114,z=-5895..13014
on x=8399..15500,y=-46061..-19393,z=-88136..-58963
on x=-70207..-50729,y=-27195..3250,z=49944..64484
on x=-83322..-60694,y=-4859..1403,z=-55073..-24265
on x=51507..67511,y=22011..37789,z=27870..58092
on x=2315..14851,y=70777..97981,z=-4391..22434
on x=63322..90550,y=13247..36385,z=-20220..2069
on x=-7013..25559,y=40439..56120,z=-72584..-61716
on x=-40699..-27549,y=4164..28551,z=53800..74409
on x=-51494..-24862,y=-80402..-64283,z=5411..14489
on x=-72139..-55806,y=7820..29650,z=25222..38356
on x=12742..29953,y=56665..75761,z=-11802..13027
on x=44039..72762,y=26530..56028,z=-42832..-10426
on x=-37796..-27142,y=-30810..-8406,z=-70974..-66926
on x=43717..56286,y=-26329..-1604,z=43116..72171
on x=19995..45643,y=-81477..-55528,z=-50320..-32192
on x=-49680..-28498,y=62214..65820,z=4605..27403
on x=59518..86037,y=25183..54580,z=-18246..17254
on x=-47268..-30247,y=57888..82990,z=-12900..3592
on x=-37656..-27114,y=-74361..-62506,z=-7732..28378
on x=5240..14690,y=72411..91552,z=-4756..19683
on x=-13372..17477,y=34586..56772,z=-82117..-63141
on x=-73452..-63296,y=-30094..-10448,z=22254..41160
on x=20735..26850,y=8049..29008,z=-87764..-67519
on x=-76309..-65638,y=1432..22127,z=24850..31614
on x=-56517..-42480,y=-29032..-8499,z=-76299..-46050
on x=-36653..-19363,y=11175..28415,z=66897..87189
on x=62824..67201,y=13766..38734,z=35946..42497
on x=-19952..-10429,y=74606..80317,z=-5904..9244
on x=63120..89695,y=-7158..10597,z=20219..31044
on x=-19027..-2451,y=60517..68949,z=33513..50296
on x=-26923..178,y=60741..97131,z=-20073..-10265
on x=-34849..-16047,y=-51895..-35335,z=-70945..-60177
on x=-41721..-28645,y=55366..79906,z=27747..32753
on x=-80144..-52339,y=-59029..-24157,z=-22364..-4544
on x=-4504..10906,y=32503..70662,z=46415..77796
on x=17183..29538,y=-18225..5416,z=66301..94405
on x=75285..86468,y=-9980..8717,z=20674..33762
on x=4311..28111,y=-83354..-62962,z=25674..42363
on x=-71564..-37032,y=-3279..4967,z=45245..76671
on x=-72811..-43922,y=36116..54013,z=-9748..23400
on x=-1220..17639,y=21306..41079,z=63317..81228
on x=37556..60204,y=-62343..-41856,z=10087..40031
on x=14130..31680,y=30041..49421,z=51511..76214
on x=-63039..-54227,y=-33537..-19281,z=34615..54260
on x=-91314..-63751,y=-3032..6841,z=-23321..2232
on x=-3127..19287,y=32794..47325,z=-76096..-49513
on x=-71132..-47802,y=4545..20375,z=48670..70063
on x=-61151..-40280,y=30652..36424,z=-62946..-37982
on x=14119..36433,y=-95152..-75989,z=6144..26828
on x=22834..51857,y=38327..58265,z=-65978..-49040
off x=66244..89751,y=-24261..7534,z=15888..42514
on x=-89728..-64157,y=-24044..4131,z=19969..28747
off x=-35080..-19430,y=56612..91727,z=8626..23420
off x=-47718..-31733,y=-43188..-28331,z=-67776..-45597
on x=-74294..-57200,y=-36792..-5040,z=-54121..-41055
off x=-24382..-20518,y=44282..50318,z=-68960..-42650
off x=-28521..-11994,y=-8661..4706,z=-88439..-56964
on x=52049..74171,y=-44537..-30138,z=-47237..-27418
on x=-1707..15178,y=34753..55182,z=-74195..-46652
off x=31059..42725,y=43145..70092,z=-38459..-30046
on x=40446..59879,y=-59586..-36260,z=-33512..-11076
off x=-79707..-50997,y=33225..51747,z=14860..47325
on x=-19465..-7616,y=10119..31262,z=-87813..-71548
on x=-83962..-64896,y=-20394..-7180,z=-61988..-32043
off x=57772..82725,y=-8053..15222,z=973..22968
off x=12596..37443,y=48270..79255,z=-49385..-33356
on x=-1003..8848,y=3538..36480,z=67569..78791
on x=-82583..-61600,y=-56407..-35035,z=-26389..-4025
off x=-441..23101,y=-65805..-48288,z=-52691..-32101
off x=60604..90029,y=-19348..-12737,z=-42042..-27174
off x=17436..39271,y=72348..90756,z=-25418..-8051
off x=26847..53845,y=46859..73289,z=23426..31266
off x=16841..27203,y=23421..55101,z=49100..83605
off x=25714..42561,y=-8143..13044,z=64035..91107
on x=29558..48710,y=-57841..-33714,z=33263..67264
off x=11715..35392,y=39866..51678,z=60099..69063
on x=23402..48483,y=37984..59658,z=48734..59709
on x=75216..93398,y=-37876..-11754,z=-1464..22273
off x=38528..43781,y=5542..42957,z=52809..77368
on x=72051..74887,y=-3880..3267,z=26293..34756
off x=-6816..4852,y=1566..29804,z=-80492..-65423
on x=49708..81155,y=32161..56409,z=-32648..-13317
on x=38909..68249,y=37014..67847,z=13517..42846
on x=-54894..-16193,y=-67206..-56964,z=-57382..-33779
on x=-81586..-61862,y=-24449..-420,z=-43066..-15910
on x=29328..40904,y=60475..81198,z=-31636..-14673
off x=-5756..14438,y=-80552..-71779,z=-14292..-6865
on x=-61722..-56718,y=23303..45126,z=-62045..-39044
off x=29463..53594,y=-69311..-47154,z=-65164..-43563
on x=-29305..-7147,y=-56581..-39066,z=-71283..-49802
off x=26856..50097,y=-61266..-31296,z=-66719..-39032
on x=46464..63140,y=-64133..-42261,z=-11759..5149
off x=-83817..-61709,y=-37291..-21874,z=-519..9751
off x=55841..74697,y=40336..59356,z=11147..34426
on x=34828..69659,y=-20348..-3038,z=-58724..-55121
off x=21197..38486,y=-72990..-45057,z=-53372..-35381
off x=-73182..-49019,y=28385..50982,z=-42019..-21521
off x=-76884..-61701,y=18507..39972,z=1310..29815
on x=55547..71247,y=4141..26473,z=-56178..-52622
on x=13772..43566,y=55179..85749,z=-13447..14016
on x=-55863..-32769,y=38694..59920,z=-33084..-7650
off x=-71553..-51565,y=-7760..1771,z=44677..67548
on x=15461..31815,y=-68075..-55208,z=33755..38037
off x=-757..36383,y=-21000..466,z=-82460..-62406
on x=31348..41123,y=-55197..-29777,z=42323..69200
off x=-5382..9760,y=-59558..-41324,z=-73937..-45324
on x=-6236..21866,y=-82614..-52320,z=33120..35911
off x=4099..31840,y=-71104..-64545,z=-49523..-23826
off x=29700..42212,y=48414..79717,z=13133..39395
on x=30163..49570,y=-32012..-6858,z=-82363..-58792
on x=-46359..-40371,y=-69671..-55358,z=6944..32266
off x=35348..60233,y=-59451..-46944,z=-50174..-21191
on x=-59278..-40919,y=48706..74528,z=-32748..-24764
on x=-57659..-37141,y=-74346..-56091,z=-17851..-3011
off x=-68343..-39351,y=-17836..3402,z=-70369..-50558
on x=-17324..10446,y=27985..43066,z=-84705..-64368
off x=-2280..7517,y=61082..89231,z=-19465..-2882
on x=5543..33886,y=77122..80758,z=-10232..26039
off x=19644..31561,y=42033..74969,z=45658..57072
on x=28283..49889,y=49674..76561,z=13613..37459
on x=45096..53724,y=18463..39530,z=38390..74144
off x=41400..61615,y=55595..76548,z=-25393..-1387
off x=16748..34122,y=29923..56425,z=-75021..-51740
on x=-15179..5656,y=-95572..-69068,z=11214..25476
off x=-58988..-47130,y=30229..46889,z=-44974..-35744
off x=-38977..-14492,y=-36334..-3133,z=-87758..-60247
off x=-67544..-49093,y=58841..65953,z=-34695..2783
on x=-44817..-12547,y=-69513..-42436,z=39463..67412
off x=-44782..-35211,y=63582..79211,z=-35165..-9576
off x=-51917..-19062,y=-70443..-39929,z=-56733..-29318
off x=-32721..-9720,y=-70269..-48267,z=39356..68334
on x=-89499..-64841,y=-7134..14311,z=10526..42888
off x=-15686..10883,y=-68334..-64832,z=40994..55889
off x=15665..28627,y=66455..83258,z=-19131..2585
on x=-36618..-12260,y=-1197..23827,z=-84792..-62643
on x=-63442..-42432,y=31128..47260,z=-58742..-50931
off x=59788..75917,y=-43859..-30744,z=-37530..-27877
on x=-97459..-75879,y=-2528..12488,z=-25702..8626
off x=4312..20664,y=43578..62639,z=45490..65994
off x=-42832..-21422,y=-36295..-10208,z=64453..78449
on x=45985..62219,y=41630..64002,z=-35004..-28441
off x=30577..58921,y=60165..62928,z=2996..24752
on x=-63410..-43768,y=18828..35057,z=-54580..-27363
on x=-37744..-7907,y=57733..80242,z=-9272..25957
off x=37094..69910,y=-11677..3264,z=57810..73004
off x=-58324..-35044,y=-65535..-55260,z=-14769..16228
on x=29859..52630,y=-10518..7762,z=-70264..-49235
on x=57003..84333,y=-43825..-36782,z=-2738..13139
on x=71783..92840,y=-12502..2933,z=-27092..1613
on x=40360..50398,y=-23637..-8074,z=-66669..-60640
on x=43892..72948,y=-1818..13786,z=-66670..-46862
off x=-77329..-51638,y=5621..37354,z=-38107..-25102
on x=-16374..13066,y=-43732..-18415,z=-82490..-64333
off x=-13344..-10566,y=-39722..-23766,z=-88355..-56712
on x=-1142..4694,y=56137..86923,z=-53607..-22509
off x=-57266..-32196,y=3936..11070,z=66725..88936
on x=46021..63903,y=35240..49664,z=15607..37579
on x=57444..70046,y=3467..37797,z=41207..53935
on x=-70116..-53894,y=34009..53610,z=5772..25407
on x=1370..17649,y=-45129..-26001,z=-71085..-60208
on x=27244..51676,y=16417..41941,z=50284..75127
off x=-7215..16100,y=13132..33300,z=52638..88374
on x=-67708..-56526,y=28446..49266,z=-54764..-36982
off x=36565..53117,y=-69659..-48686,z=-56660..-30523
on x=-34438..-14244,y=-45433..-35154,z=-66685..-45700
off x=-91754..-62736,y=6030..27794,z=-36516..-23095
on x=-20638..-13653,y=-9532..17224,z=63461..84278
on x=-59626..-50588,y=-32678..-6316,z=46959..59720
off x=-20225..749,y=-69753..-43037,z=-70716..-40645
off x=-56667..-40496,y=11366..43347,z=46773..65399
off x=-58207..-36567,y=42530..65883,z=-24484..-7023
off x=-34762..-20011,y=42739..59302,z=-49523..-35094
on x=-61220..-42210,y=-66752..-48262,z=8014..23734
off x=-49232..-41437,y=-63307..-37354,z=24865..47979
on x=26703..52532,y=-78499..-46465,z=-25018..-8738
off x=21105..43246,y=38644..70375,z=42805..60720
on x=-29375..-9597,y=-86639..-63948,z=-642..25463
on x=56583..64693,y=22117..52883,z=-40318..-24339
on x=-35643..-27958,y=47024..56238,z=36245..52842
off x=-33039..-14225,y=64997..87100,z=-41179..-4967
off x=59162..83173,y=25323..44364,z=2725..23248
off x=52877..68876,y=-45091..-16834,z=-42624..-16917
on x=38829..70185,y=8104..18659,z=45852..67774
off x=-27424..-2771,y=-93872..-68133,z=-3046..23499
off x=39387..48068,y=-14087..2670,z=-70270..-50908
off x=-67568..-31653,y=-63342..-45027,z=-44056..-28022
off x=73339..75776,y=19469..34170,z=9060..24104
on x=18259..51005,y=48630..76031,z=7479..26749
on x=14513..37579,y=-33597..-15184,z=63582..76318
on x=-41275..-31697,y=-24246..-37,z=57091..73485
off x=-31890..-16118,y=-76794..-49970,z=29480..57799
on x=71419..87971,y=15207..25964,z=-19283..7832
on x=-41791..-24849,y=59031..75550,z=-18258..9027
on x=-38199..-24871,y=42794..71254,z=-42870..-21798
on x=-25039..-8806,y=-76747..-56020,z=-57258..-29947
off x=-22405..10912,y=-55580..-41017,z=-75320..-53817
on x=-49793..-22756,y=-27786..-9284,z=58862..86007
off x=25510..36784,y=-35757..-20885,z=-75794..-46116
on x=-3712..14342,y=65221..88505,z=-9736..11415
off x=-17899..7630,y=-87586..-63559,z=-18626..2791
off x=-14610..11209,y=24694..36426,z=-89209..-72203
on x=-41903..-27211,y=-37226..-32667,z=-61406..-49458
on x=-29172..-15874,y=-29621..8729,z=-94236..-66936
off x=-7596..-2397,y=-24666..-3179,z=68145..98782
off x=-30179..-17490,y=-26796..7612,z=-78764..-61938
off x=-50707..-22641,y=-62067..-42787,z=-61450..-36116
on x=-2926..22736,y=-56652..-31989,z=54504..85199
on x=-12251..16818,y=-45483..-39539,z=-85412..-54335
off x=-30871..-10215,y=25326..41186,z=65924..74927
off x=-27548..-2218,y=-90837..-53885,z=24861..40128
off x=-15719..-8624,y=-24279..7866,z=-78569..-62304
on x=5300..29443,y=-60482..-32603,z=53463..77364
off x=-36883..-4698,y=-11779..15251,z=-85176..-63993
off x=77136..95419,y=-991..22518,z=-30101..-5527
off x=-77467..-49063,y=-3059..21180,z=-69555..-36161
off x=43217..54077,y=56300..68390,z=-17902..7166
off x=-27450..-5699,y=-85434..-62891,z=12577..21069
on x=-34456..-17300,y=-38896..-25828,z=-88087..-66157
off x=-6542..22866,y=48683..62179,z=51476..66042
off x=-85081..-63427,y=24901..39908,z=-22256..-2736
on x=-84263..-51335,y=-43993..-23210,z=-50786..-14571
off x=70496..91875,y=-99..13516,z=-15338..-1176
on x=-3414..20761,y=-58271..-50023,z=-70568..-58707
on x=-37366..-24760,y=-40714..-28220,z=-68669..-57693
on x=55366..69711,y=19336..39334,z=41575..56327
off x=7756..37863,y=6813..30407,z=-86788..-58086
on x=64340..71944,y=-58382..-21540,z=-26270..-7157
off x=-66006..-47470,y=-36577..-20368,z=19166..34254
on x=-58240..-46662,y=-3017..27043,z=55289..74468
off x=-39417..-32733,y=-29342..-7099,z=-79724..-67801
on x=-79339..-46658,y=-7270..19942,z=-50655..-39180
off x=-60143..-38745,y=-19956..11524,z=-84176..-55543
off x=-3874..10037,y=-64263..-39967,z=-74772..-50336
on x=-11752..2774,y=-57741..-44508,z=51849..72929
on x=-11710..-4855,y=-72067..-49425,z=-62392..-47771
off x=43931..74857,y=41059..57790,z=-36316..-17211
off x=3946..34651,y=-53908..-25012,z=52699..70802
off x=-46656..-15008,y=17844..47261,z=55932..84912
off x=26684..42064,y=56114..63695,z=14465..39503
on x=-40489..-22313,y=8243..32746,z=-74516..-48795
off x=-22851..-6555,y=-82055..-68517,z=-28862..-6378
off x=-74113..-54822,y=24351..54331,z=7776..25070
off x=-45651..-16942,y=18572..51284,z=62915..80308
on x=-70429..-46638,y=-63316..-43477,z=-9658..15603
on x=10379..47780,y=72033..88868,z=-19821..-11434
on x=-22601..1937,y=4579..19393,z=-80796..-60988
on x=54161..77065,y=-58754..-49409,z=338..31784
on x=28966..60740,y=50370..68031,z=8613..32275

View File

@ -1,78 +0,0 @@
use std::{fs, env, collections::HashMap, hash::Hash};
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
struct Cuboid {
pub s: bool,
pub x: (i32, i32),
pub y: (i32, i32),
pub z: (i32, i32)
}
impl Cuboid {
fn insersects(&self, o: &Cuboid) -> Option<Cuboid> {
if (self.x.1 < o.x.0 || self.x.0 > o.x.1)
|| (self.y.1 < o.y.0 || self.y.0 > o.y.1)
|| (self.z.1 < o.z.0 || self.z.0 > o.z.1) {
return None;
}
return Some(Cuboid { s: self.s && o.s,
x: (std::cmp::max(self.x.0, o.x.0), std::cmp::min(self.x.1, o.x.1)),
y: (std::cmp::max(self.y.0, o.y.0), std::cmp::min(self.y.1, o.y.1)),
z: (std::cmp::max(self.z.0, o.z.0), std::cmp::min(self.z.1, o.z.1)),
});
}
fn get_nb_cubes(&self) -> usize {
return (self.x.1 - self.x.0 + 1) as usize
* (self.y.1 - self.y.0 + 1) as usize
* (self.z.1 - self.z.0 + 1) as usize;
}
}
fn read_input(path: &str) -> String {
return fs::read_to_string(path).expect("Cannot read file.");
}
fn parse_input(s: &str) -> Vec<Cuboid> {
let mut v = vec![];
for l in s.lines() {
let a = l.split_once(" ").unwrap();
let c = a.1.split(",")
.map(|e| e.split_once("=").unwrap().1.split_once("..").unwrap())
.map(|e| (e.0.parse::<i32>().unwrap(), e.1.parse::<i32>().unwrap()))
.collect::<Vec<(i32, i32)>>();
v.push(Cuboid { s: a.0 == "on", x: c[0], y: c[1], z: c[2] });
}
return v;
}
fn compute_reboot(a: &Vec<Cuboid>) -> i64 {
let mut c: HashMap<Cuboid, i8> = HashMap::new();
for c1 in a.iter() {
let mut t = HashMap::new();
for (c2, i) in &c {
let n = c1.insersects(c2);
if n.is_some() {
t.insert(n.unwrap(), *t.get(&n.unwrap()).unwrap_or(&0) - i);
}
}
if c1.s { t.insert(*c1, *t.get(&c1).unwrap_or(&0) + 1); }
for e in t {
c.insert(e.0, *c.get(&e.0).unwrap_or(&0) + e.1);
}
}
return c.iter()
.fold(0, |acc, e| acc + e.0.get_nb_cubes() as i64 * *e.1 as i64);
}
fn main() {
let args: Vec<String> = env::args().collect();
for arg in args.iter().skip(1) {
let input = read_input(&arg);
let vec_in = parse_input(&input);
println!("[{}]", &arg);
println!("\t[Part 1] => Answer is '{}'.", compute_reboot(&vec_in[0..20].to_vec()));
println!("\t[Part 2] => Answer is '{}'.", compute_reboot(&vec_in));
}
}

View File

@ -1,8 +0,0 @@
[package]
name = "day23"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -1,5 +0,0 @@
#############
#...........#
###A#D#B#D###
#B#C#A#C#
#########

View File

@ -1,215 +0,0 @@
use std::{fs, env, collections::{HashSet, HashMap}};
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
enum Amphipod {
Amber,
Bronze,
Copper,
Desert,
Placeholder
}
impl Amphipod {
fn get_target_room(&self) -> usize {
return match self {
Amphipod::Amber => { 0 }
Amphipod::Bronze => { 1 }
Amphipod::Copper => { 2 }
Amphipod::Desert => { 3 }
_ => { panic!("Amphipod has no target room.") }
};
}
fn get_from_str(s: &str) -> Amphipod {
return match s {
"A" => { Amphipod::Amber }
"B" => { Amphipod::Bronze }
"C" => { Amphipod::Copper }
"D" => { Amphipod::Desert }
_ => { panic!("Amphipod not recognized.") }
};
}
}
type Action = ((usize, bool), (usize, bool), u32);
fn read_input(path: &str) -> String {
return fs::read_to_string(path).expect("Cannot read file.");
}
fn parse_input(s: &str) -> Vec<Vec<Amphipod>> {
let l = s.lines().skip(2)
.map(|l| l.trim().split("#").filter(|e| !e.is_empty())
.collect::<Vec<&str>>())
.filter(|e| !e.is_empty())
.collect::<Vec<Vec<&str>>>();
let mut g = vec![
vec![Amphipod::Placeholder; l.len()];
l.iter().fold(0, |acc, e| std::cmp::max(e.len(), acc))];
for (n, v) in l.iter().rev().enumerate() {
for (i, a) in v.iter().enumerate() {
g[i][n] = Amphipod::get_from_str(*a);
}
}
return g;
}
fn expand_input(r: &mut Vec<Vec<Amphipod>>) {
let mut s = vec![
Amphipod::Amber, Amphipod::Copper,
Amphipod::Bronze, Amphipod::Amber,
Amphipod::Copper, Amphipod::Bronze,
Amphipod::Desert, Amphipod::Desert];
for e in r.iter_mut() {
e.insert(1, s.pop().unwrap());
e.insert(2, s.pop().unwrap());
}
}
fn no_need_to_move(r: &Vec<Vec<Amphipod>>) -> HashSet<(usize, usize)> {
let mut h = HashSet::new();
for (i, v) in r.iter().enumerate() {
for (l, a) in v.iter().enumerate() {
if a.get_target_room() == i && (l == 0 || h.contains(&(i, l - 1))) {
h.insert((i, l));
}
}
}
return h;
}
fn is_room_full(rooms: &Vec<Vec<Amphipod>>, n: usize, s: &HashSet<(usize, usize)>,
room_depth: usize) -> bool {
return rooms[n].len() == room_depth
&& s.iter().filter(|e| e.0 == n).count() == room_depth;
}
fn is_target_room_ready(rooms: &Vec<Vec<Amphipod>>, n: usize, s: &HashSet<(usize, usize)>,
room_depth: usize) -> bool {
return !is_room_full(rooms, n, s, room_depth)
&& s.iter().filter(|e| e.0 == n).count() == rooms[n].len();
}
fn can_cross_hallway(s: usize, t: usize, h: &Vec<Option<Amphipod>>) -> bool {
if h.iter().all(|e| e.is_none()) { return true; }
if s == t { return false; }
let (b, e) = (std::cmp::min(s, t) + 1, std::cmp::max(s, t));
return (b..e).all(|e| h[e].is_none());
}
fn room_to_hallway_pos(n: usize) -> usize {
return n * 2 + 2;
}
fn get_move_cost(f: &(usize, bool), t: &(usize, bool), r: &Vec<Vec<Amphipod>>,
d: usize, a: &Amphipod) -> u32 {
let s = if f.1 { room_to_hallway_pos(f.0) } else { f.0 } as i32;
let e = if t.1 { room_to_hallway_pos(t.0) } else { t.0 } as i32;
return ((s - e).abs() as u32
+ if f.1 { (d - r[f.0].len()) as u32 + 1 } else { 0 }
+ if t.1 { (d - r[t.0].len()) as u32 } else { 0 })
* 10u32.pow(a.get_target_room() as u32);
}
fn get_next_moves(rs: &Vec<Vec<Amphipod>>, d: usize, h: &Vec<Option<Amphipod>>,
s: &HashSet<(usize, usize)>) -> Vec<Action>{
let f = (0..rs.len()).map(|e| room_to_hallway_pos(e)).collect::<Vec<usize>>();
let mut a = vec![];
for (i, e) in h.iter().enumerate() {
if e.is_none() { continue; }
let e = e.unwrap();
let t = e.get_target_room();
if is_target_room_ready(rs, t, s, d)
&& can_cross_hallway(i, room_to_hallway_pos(t), h) {
return vec![((
(i, false),
(t, true),
get_move_cost(&(i, false), &(t, true), rs, d, &e)
))];
}
}
for (n, r) in rs.iter().enumerate() {
if r.is_empty() { continue; }
let l = r.last().unwrap();
let t = l.get_target_room();
if l.get_target_room() != n
&& is_target_room_ready(rs, t, s, d)
&& can_cross_hallway(room_to_hallway_pos(n), room_to_hallway_pos(t), h) {
return vec![((
(n, true),
(t, true),
get_move_cost(&(n, true), &(t, true), rs, d, &l))
)];
}
if !is_room_full(rs, n, s, d) && !is_target_room_ready(rs, n, s, d) {
for (j, o) in h.iter().enumerate() {
if o.is_some() || f.contains(&j) { continue; }
if can_cross_hallway(room_to_hallway_pos(n), j, h) {
a.push((
(n, true),
(j, false),
get_move_cost(&(n, true), &(j, false), rs, d, &l)));
}
}
}
}
return a;
}
fn apply_action(a: &Action, r: &mut Vec<Vec<Amphipod>>, s: &mut u32,
h: &mut Vec<Option<Amphipod>>) {
*s += a.2;
let o;
if a.0.1 {
o = r[a.0.0].pop().unwrap();
} else {
o = h[a.0.0].unwrap();
h[a.0.0] = None;
}
if a.1.1 {
r[a.1.0].push(o);
} else {
h[a.1.0] = Some(o);
}
}
fn compute_sorting(mut r: Vec<Vec<Amphipod>>, mut h: Vec<Option<Amphipod>>, d: usize,
mut s: u32, b: &mut u32, a: &Action,
c: &mut HashMap<(Vec<Vec<Amphipod>>, Vec<Option<Amphipod>>), u32>) -> Option<u32> {
apply_action(a, &mut r, &mut s, &mut h);
if s >= *c.get(&(r.clone(), h.clone())).unwrap_or(&u32::MAX) { return None; }
c.insert((r.clone(), h.clone()), s);
let n = no_need_to_move(&r);
if n.len() == r.len() * d {
*b = s;
return Some(s);
}
let m = get_next_moves(&r, d, &h, &n);
if m.is_empty() { return None; }
let mut o = None;
for mo in m {
let x = compute_sorting(r.clone(), h.clone(), d, s, b, &mo, c);
if x.is_some() && (o.is_none() || x.unwrap() < o.unwrap()) { o = x; }
}
return o;
}
fn main() {
let args: Vec<String> = env::args().collect();
for arg in args.iter().skip(1) {
let input = read_input(&arg);
let mut vec_in = parse_input(&input);
let (mut s1, mut s2) = (u32::MAX, u32::MAX);
let a = ((0, true), (0, true), 0);
let mut c = HashMap::new();
let h = vec![None; 11];
compute_sorting(vec_in.clone(), h.clone(), 2, 0, &mut s1, &a, &mut c);
expand_input(&mut vec_in);
c.clear();
compute_sorting(vec_in, h, 4, 0, &mut s2, &a, &mut c);
println!("[{}]", &arg);
println!("\t[Part 1] => Answer is '{}'.", s1);
println!("\t[Part 2] => Answer is '{}'.", s2);
}
}

View File

@ -1,8 +0,0 @@
[package]
name = "day24"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -1,252 +0,0 @@
inp w
mul x 0
add x z
mod x 26
div z 1
add x 11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 1
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 10
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 10
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 13
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 2
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -10
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 5
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 6
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 0
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 12
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 16
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 12
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -7
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 15
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 13
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 7
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -13
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 6
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x 0
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 5
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 6
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x 0
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 15
mul y x
add z y

View File

@ -1,55 +0,0 @@
use std::{fs, env};
fn read_input(path: &str) -> String {
return fs::read_to_string(path).expect("Cannot read file.");
}
fn parse_input(s: &str) -> Vec<(usize, usize, i32)> {
let mut v = vec![];
let mut p: Vec<(usize, i32)> = vec![];
let mut a = false;
let mut i = 0usize;
for (n, l) in s.lines().enumerate() {
let c = n % (s.lines().count() / 14);
if c == 0 && n != 0 { i += 1; }
let l = l.split_whitespace().collect::<Vec<&str>>();
if c == 4 { a = l[2].parse::<i32>().unwrap() == 1; }
else if c == 5 && !a {
let x = p.pop().unwrap();
let o = x.1 + l[2].parse::<i32>().unwrap();
if o >= 0 { v.push((i, x.0, o)); }
else { v.push((x.0, i, -o)); }
} else if c == 15 && a { p.push((i, l[2].parse::<i32>().unwrap())); }
}
return v;
}
fn get_max(l: &Vec<(usize, usize, i32)>) -> u64 {
let mut x = [0u64; 14];
for i in l {
x[i.0] = 9;
x[i.1] = (9 - i.2) as u64;
}
return x.iter().fold(0, |acc, i| acc * 10 + *i);
}
fn get_min(l: &Vec<(usize, usize, i32)>) -> u64 {
let mut x = [0u64; 14];
for i in l {
x[i.1] = 1;
x[i.0] = (1 + i.2) as u64;
}
return x.iter().fold(0, |acc, i| acc * 10 + *i);
}
fn main() {
let args: Vec<String> = env::args().collect();
for arg in args.iter().skip(1) {
let input = read_input(&arg);
let vec_in = parse_input(&input);
println!("[{}]", &arg);
println!("\t[Part 1] => Answer is '{}'.", get_max(&vec_in));
println!("\t[Part 2] => Answer is '{}'.", get_min(&vec_in));
}
}

View File

@ -1,8 +0,0 @@
[package]
name = "day25"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -1,137 +0,0 @@
v...>.>vvv.>v.v.>>.v>.>>>>.....>v>....v....v.>>.>.>v.vvv>v...>v>>......v.v>v.>vv.>>v...>...v.v...v.v..>.>..>...>>v.>...>.v.>v.>.....>>...vv
>...v..v.>>.vv.v.>vv...>>v>>>.v.>v.v....v.>...vv>v>v..>>.>.vv...v..>v>.vv>>.v.>v..>>>...vv...v>.>>.>.vv.vvv..>..>.>.>..v>vvv>.>.....>vv..>.
v.>v...>>..>>>..>>...>>>>..vv.......vv.>.v.>..>v>v.v...vvv...v.>>>...v..v.v.>.>.>.v.>...>>.v.>....v.>..v.>.v.>v>>.>...v.>>v>.v.>.v.>...>...
....v>>>.>..>>>.v>.v...v.v>v>.v>.v.v>...v.vv>.>..>.vvvv..>v.>.v.>..vvv.>>.v.vv.vvv..>>.v..v>..>.v.>..v.vv.v>>v>v>.v>v......>>>vv>...>v...>.
..>>v>>>..v.v..>..vv>>v>v......v.v>vvvv.v>....>>>...vv..>vvv.v.>.v.>v>.>.>..>.v..>......>v>>v.>.>.v>v>>v.>.....v>..>..vv>.>vv>.>.>...vv>..>
..>>.>>v..>.>v....v>>...v.v>v.v.>.v.>.vv>>>>>>vv...v..v>>>vv..>...vv..>>v..>>>>...>vv....v.v.v..>..>v.>.>>vvv.vv.>.v>..v.vv.>>vv>.>.v.vv.v.
v>>>.>>.v......v>..v.>...v...>v>.v.>.v.vv..>.>>>v>v>.v>v.v>>..>..>..vv.v.>v...v>.>.>v>.vv.v..>...vv...v>.v>>vvv..v...>>v.>v.....v...>>..v.>
v>>.>vv>vv....v>..>v.v.v>.>.v...>.>>>.v>...>v>>>>v..>>.......vv.v.vv.>v.v>v..v.>..v>v.>v.v.v>v>..v.v>.v...>vv..>.>..>..>....>....>...>.vv..
..>...>...v.>vv>.vvvvv>>......v.v..>>v..>.....v.vv.>v>....>.vvv>.>..>v...>.v.v>v>...v...>..>.>.v>v>v..>.>.>vv.v.>v..>>.>>>>.v.>.v>v......>.
.>.vvv...>.>.......v>v.v..>v.....v.>.v.vv>...>v.>.........v.>v>v.v>.v>...>>v>>>v.>v.>v.vv..>.v..v>v>>.>v.v......>..v.v>v...>>.vv>.>.v.v..vv
..v>>v>....>.v.....v...v>v..>v...vv.>v.>vvv>vv.>v>..>...v.>v>..v.>..>>vv.v..v.v.>..>>...v..>.v.v..v....v>>....v.>v>vv..v.v..>.>.>>..v>>.v..
>.>..>>.>vvv.....>v.v..v>v>v>v.>v..>...........v.v..v>.v>>........>v>...v>..v...vv>.vvv>.v.>v.>..>>.v...v>vvv.>>>.>..>..>....vvv..>>...vvvv
.v......>..>>v.v.v.v>...>>.vv.>>.>.>vvv.vvv...v.vv.>.v....v.v.vv...v..vv...>>v......vv>v>>>v>...>>.>vvv>.>>v.>>>>>>>.>.>>>.v.v>v.v>...v.v.v
.>.>v.>>>>..>>vv.v>..v>v>.>.>>.....>v..>vv>.>v>vvv>....>..>>v.vv..>..>>vv...v>.v.......v>>>v>>.v.....v>..vv..v..vv>.>>>.v.>>>>.v..v>>.>vvv.
..>.v...>.v.>>..>>vvv.v...>v.>.v.>vv.>>>..vv.>...>......v>>vv...v......v.>.>.v....v>v..>...>v>v...vvvv.v>.>.........>.v>..>v>>...>..v.v.v>.
>.v..v.>v>.>>.v>v.vv>...v..>...vv...>.>>v...>.>v.v.vvv>..vvv..>..>vv.v.....v.vv.>v.vvv.vv>>.......>.v>..vv.vv.>>>....v..>....vv.vv.>.v.....
...v..>v.v..>v...v..>.v.vv..>.>...v>v>v.v.....vv>>.v>>vvv>.>>.....v.>vv>.v.......>v...>.....v..>..v.v.>v...>..v>vv.v>>>vv...>....>..>.v.vvv
>v>v.>.vvv....vvv>vv>.v.v>..>v..>....vv.>v>v>.>...>>.v>>.>v.v>.>...>>.>.>.>>....v.vvv..vv.>..>..v.>>>>...v.>.>vv..>.v.>>.>.>.v>v.v..>...>..
>.>vv>vv>>.>v..>....v>.>>v>....>v>>v...vv..v>vv.>..>.v.v>>>.v.v.>>v....vv>v..v.>>vv>v>>.v>...v.>....v.>v>.>...>......>vv.v...>...>v>>...>..
.v.>.>..vv.vv.v..v>>.>.>>>vv.>.>.>>..>..>.vv...>>>vvvv....vv..v..v..v.>v.>v>vv>.v....>vv>v.v.>>.>..v..>>.vvv>.>..>.....v>..v...v.v>>.>.>v.v
vv.v.>.....v.vv...vv>>>...>v..>.v..>v.>v.v.>v...v..vvv.v....vvv.v.>>..>.....v.vv.>..v...>.>>....>.>v>....vv..vv>>.>>>....>>.v.v.v.v>vv...v.
v>>>.>vv.>>.>>v....>>>>.>v>.....>v...>.>.v>.vvv>..v.v.>...v.vv.v>....v.v.vv>v.>v>.>>...>v.v....>>..>.v.>..>vv>v>>vv...v.v.>.v>>vvv>.vv>.>.v
>.vv......>vv..vv.>v.>.v...>...>>v>.>.>.>v....>v>.v....>..>.>>v.v..vv..v>>.....>....v.>.>>>...vvvv.v.......v.v.v..v>.>v..v...>.>..>vvv.>>v.
>.>.v.>vv......vv>v..v...vv..v..>...v....>.>>>.vv>.>>>.>v.v>v.>.vv.>>..v.....>>.>.>v.>.>......vv>>v>>......v..v>v>>.>>.>.>...>>>v>....>.>>>
.>v.>.>>..>>>..>.vv...>v..>>v>v..>>.v.....v....vv>v..v..>...v.v..vv..>>>>>...>......>.v>v>.vv..v.....v..v.v.vvv>.>.>....>.>..>>v>v>>.v.>>v>
.>...>.>v..>>>..v>.>v>v.v...>.>.>v...vv>v.v....>.vv>...v>.v.>vv...v..>>>..>>v>..>vvvv>v.v>.>..v>v>.>v.vv.>.>...v...vvv..v.vv>..v..v.v>.v..v
v>>.>>..>.>....>....v.....v>...>vv.>>..>..>.vv>v..v...v.v.>vv.>...v..vv>....>>...v..v..vv..>>...>.>vv.>.vv>v>...>vv.>vv.v>.v>.vv.v>v.....>.
v.>>.>..>>v...>>v..>>>vvvv>>.>>....>>....v.vvvv.>.....>v>.>v.v..v...v.v...v>>>.>>>..v.v>>.>.>.v..>.....v.>..v.v>...v...>..vv>..>>>v>v>.vvv>
v...>>v...v...vvv.v>.>>.>.v>....>vv.v>....>.>..vv.v.>>.>>.v..>..v..>vv....>>.vv>>..v.>>..v.>.>.>>vv>...v.>.>v>>..v>vv..v>....vvv....vvvvv>>
>..>..>v.v..v..>.>>...v...vv.>v.v.>.>>.>>.>.>.v..>v..>v..v>......v.v.>..>>.v....>..>>.v..>.>>....>...v>.......v..v....>>...>.>>.v>..v..v.>.
..vv..>v.....v>v>...v>...v>v..v.v>v.>.....v..>>>>>vvv>v>>...>>...>vv..>.v>.....>>....>...>.>vvv..>..>.>...vvv>vv>>v>...v..v.>vv..v..>vvv...
>.>v..>..>.vv.vvv>...v.>..>>..v.>>vv>...>>v>......>>>......>..>v.v..>vv>vv..>..>>.v.v..>>>.v>>>>.>>v..>.>..v.>>.>v>...vv>>>v.v.....>.......
..v>v>.>..>>v.v>v.v.>>.v.>..>v...>.v>...v..>.v...>v....v.v>.>>...v.>.>..............>>>..v>...>v..>v.vv>.>.>>>>.>.v>>v.....>v..v...>...v.>.
v...v>>vv....v..>>...v.>>..>>v.v>v.v>>.>..>v..>...v..>..vvvvv...>vv.>.>v......vv.>>>..>.>>.v....v.>>>.v.>>..>.>v..>...>.v.>>.>v..>>....v...
vvv.v>v>.vv>....>..v>..>vv>v.vv.>......vvv.vvvv>>..v>>>v..v>>v..>..>>v>..v....>v...v....v>v>.>.v>....v..v.v>>>.v.v....v>.>.v...>.v..v>.v>>.
v>..>..>.>v.vv.v..v>..>>....v..vvvv>v>..v.v..>>..vv.>.>>v....>>...>v..>.>>v.>.vv.v.v>..>.>.v.v.v>v>..v.v.>>.v.......>..v>.>v....>..v>>v>.>.
>.v..>v.v..>v...v..v>>>v>>>...v.>.>....v..>.>>.>..>..>v>>>..>v.v...v.>..>>>v.v..>>.>.v>v....>>..v.>vvvvv.>>.v>vvv.>>>.vv.v.vvv.v.>v...>.>vv
.v...v.v.>v..vv..v..>v>.vvv.v.>..v>v....v.vv.>vv>vv..>>v.>........vvv>..vv.>v..v...>>>>v..v.v>v>.>..v.>>>.vv..>>>v..vv.vvv>.>.v>..v..v.v>.>
.>..>vv>>.v>..>.vv.>..v>.>>>v>>v..>>....v...>>v>>>.vv.v.>>.>>.v.v..vv.....>..>>...vv.v>>>.v.>..vv..>>...>v......v.v>.vv.>>..>.>...>>>..v>>>
.v..>v>v..v>vv>...vv...vv.....>v>...v.vv>>v>vv>vv>>.>vv...v.v>.....>>......>v..v.v..>.v>v>>.>v....>...>..>...>....v.>v>..v.>>>v>.v..v>..v>.
>vv.v.vvv....v>...v>v......>>..>vv>.v.>.>.v.v......>>>.>..v>v....v.v..v>v>>v>v>...vv..v...>.vv.>>>v>......v.>.>.vv...v..v.>...>>.v.>..v....
>.v.>..>..>>v>>.>..v.>>..>>>>v>.v...v.v.>......v>...vvv.>>vv>v....v.>>.v.>>.v....>v>....vv..v.v>.vvv>>.vv.vv...v.>>.v.v.>>>.>.>v>.>v.>v....
v.vv>>>vv.....>.......v.v.vv.>.....>v.v....>..v.>>v>.>>..vvv..v>...>v>.>..>..>.vv.vv.v.>>>.vv>...v.>>v.>.>v....vv.v>>.v.vv.>.>.>.>.v.>>.>vv
>v.v.>v.>vvvv>.vv..v....v>.v>.>...>v.>.v.>vv>..>v...v..>vv>>.....>>vvv>..>.>.v>.>v>v>v.>.>...v.>>.>>.>>.>.>>...v...>.>......>....>.v..v.>.>
vvv>.vv....>.>.v....>v..v.>>v..v.v.v..v.v..>..>>v...v.>>v....>>v.>>v...v....v.v......vv..v.v>...v....v..>..vv...v..>.v>.v>.>..v.......>v.>.
.>>>>.v.....>..>vvvv...v..>.v.>v>>....v.....>.v>>.>>>v.....>..>v>...>.>v.v.......v.>...v>>...>v..v..>...vv.v>v.>v.v>.vv.v>vv...v....>vv...v
....v>>...>v>.vv.v....v..>.>.>..>v.vv.>..>...vvv.>vv.>v...v..>..v.....vv...vv.>vv...>.>v>.vv...>>>>v>>..v>.....v.>v...>v>>...>vv...vv.>..>.
>..>vv...>>..vv.>>v...>.>v.v>....v>v..>vvvv>>.>vv>v.vv>.vv.>>vv...>v>v>........vv>.vv>.>..>>>..>.>>v.....vvvv>>v.>>.vv>v>v>....>.>.v.vv>v.v
v......v>..>vv>>.>v..>>..>...vv.....>v>..v.>..v.v....v>vv..>>>..vv.>>>vv.>v.....vv.v>.>.>..>...v>.v..v.>.v>>>>.>v..vv>..vv...v.v>>.v.v.>..v
..>.........>...>.>..vv.v>.>>>.....v.v.v>.>.v....>...vv>v..v..v.v...v.>>vv.v>.>.>..v.>.v..>..v>.v.vv..>.v..v.>>v..v..>.>>.>....>....v>v.v>v
v>.v...v....v.vv....>.>..>>v...v>..vv.vv.v.>vvv.>>>.vv>..v.>>.v>v>.vv>>v>.v>v>>>.>...>v.vv...>v..>....v.....v...>...vvv.>>>>v.v.>..vv.>v>..
.>...>vv.>v>v>vv.v....v>..>...v>>.v.>v..v.v>>v..v>>.v.....vv.v..>>v>.v.v>>>v>.v.vvv>.....>v...v>....v>.v...v>....>.v>v...>v.v.....>>..>.v.>
..v..v...vv.>.v.>>v...v.>v..>.>..>..>v...vv>...>...>.>...v>vv.vvv.v.>.>vvvv.vv.vv..>....>>...>>.vv>.>..>v.v..>.v.>>.>>>>>v...v.>...v.vv>.>.
.>..vvv.vv..>v>v.v.v.v>.>..v>>.v..v>..>...>.vv>v.v>v.>>vvv>>..>.vvv.v..>.v>.>v...v.v.>.>v.>.v....v>.v>.v>v..>vvvv.v.....>..vv>v.>>..>.v.v>>
v>v.vv.>.>>>>>.v..v>.>.>...>>>..>v>>..>.>>..>>vv.>..v>v..v...>.....>v......>v.vv.>>.v>v>>..>.v.vv..vv.>..>....>....v>..v>v.v...>.>.v..v.>..
.......v>>..>.v>.>.>....v..v.>>.>v>>.v>vvv.v.>..>v>v....v..v....vvv.v....v.....>>.v>>vvv.>vv.v>......>v...v..v>.....>vv..vv.>..>v.v.v..v.v.
v.v..v>.>.v..>v>>.v..v>.>..>...vvv...>.vv...>>......>vv.>v.v..v...v..>v>>vv>>..>>>...v>......v.v..v.v.>>v.>v.vv.>>..>....v>v..>>v>>v...>vv>
v..v>v>..v....>..>..vv.>..>..vv.>>.>..>.v...>.>...v...v>>>..>.>v.v.vv.v.>...v..>..>.......v>.vvvv...>..>>.vvv.>..>....v..>>>v.v>>>>.v...>.v
.>.>>>.>..v...vv..>.vv..vvv.>.vv..v>>v.>v>......v.v.v...>v>v>.....>>..>.>>v.v>.>.>vv>....>...v>.>.>>...>v.vvv..>.>>vvv.>>....v>....>>.>...v
v...>>>.v..>>.>>.>>>..v>>>..>..v.>.>v..v>v..vvv>.vv...v.>..>.>>...>>....vv....v...v.>.v>>v..v...v.>..v..>.v>.>....>>.>...vvv.>..>.v.>.vv...
...v>.....>...v...>vvvv..>.>vvv.>.>.>.v....>.v..>>v..>..v..v.>>vv>v.v....v...v.v>v..>..v.v>v.>v..>.v>>vvvv.v..v..>.>>...>>>v>.v.>v>.......v
>v.>vv.....vvv.>.v..>.>.v>.>...vv...v.vv.v..>>>v.vv.>...>>>.>v.>>.v.>.>v>vv.>..v>.v..>v..>.>..>.v>>..v>>>v..v..v>>>.v.>>>v.>.v........vv.v.
..>v>.>>>..vv>..>....>..v.>.>....vvv.>..>>v....>.>...v....>..vv>>>.>>v.vv.v..>>..v.vv.>.>.vv...v.v>..>......>...v>>.>..>v..>....>.....v.>v>
>.v>v>vvv.v.v>v....>v.>v>.v..vv.>..>v.>.>v..v..v.v......>.vv>v.>.......>vv.v>>>>.>..v>v.>v>>.>........v>...v...v>...>v.......v>.>v...v.v>.v
v>>.v..>vvv>.>.v..v..>v..>>..v>>>>>>vv>.v.>>v.v>v>.v..vvv.>.......v....v>.v.>vvv..v.>...v....>v>.v>.v>.>v...>vvv.....vv.>>>.>.>v>v>..v.v.v.
.v...v>>>v.>>vvv...v.v>>..v>vv..v..>v>.v>v..>>.v>.v>>...>..>vv>..vv>v.........v......>.>>v..v.vv>v...>.>.v>v..v...>..v.>>>..>v..>..>...>>.v
v..>>..vvvvvv.v.>>vv>v..>...>..>.v>...>>vvv>v>..>>.>.v.>v.>>.>>..v>.>v.>..v>>.>vv>.>.>vv.>..v>>..v.>>.>v..>>>>vv>>>..>.v.>..v..v.v>>..v>.>>
.....v>v...>vv>.v>>..v>.v..>>>v.>.....v..>.....>>vv.>.v.>vv>.v>..>>.>v>.v>>>v.v.>v.vv>>>..v...v.>.v.>>..>....v>..>.v>..vv..vv....vv.>v>>v..
>....vv.>..>>.>>.......>.vv...>vv......>v.>vvv......v.vvv..>v>..v..v....>........>.v..vv.v..>..v.>v>.v>.>.>.>.v.v.v.vv...v.....>..>>.......
>.vv....v..>v.v.vvvv...>.vvv.vv..>..>v>>.v...>.>.vv.....v>..v...v>.>...v..>.>.>vv.>..vv..>.v....>..>>.>......v.>>vv...v...v..v.v.v.>.v>..v.
v..v>.>>.>>.>>vvv>.>>>vv..>v>>v>v.v..vv....v>>....>v>.>.vv.v.vv>.>>vvv.>>.>>......>...>..vv>v>.>v.v.vv.>>.>.>.vv..v..v.vv.v>.vvv.v>..>...v.
...>>v.v.v.>.>>...>vvv>..v..v.vvv...>.v>.>.>v..>.vv>..vvv>>.....v..>>.......>v......>v.>.v.vv.>...vv.vv....v.v..v..v>>vvv....>v.....>>v.v..
..>..v>>.>v..>......v.>...v.v.v...>.>>vv>>.vv.>>>>>vv>..>vv..>...v.v>.>vvv>....>.>>....v.>>...v..v...vvvv>...v>>>>>vvv>vv......vv.......>.>
.>v.>>.>>..>.>v...v..>.>>..>....vv...>...>v..>..v>v>....>..v>>v.>.>>>.v.v..>.v..>v>.v.v>.v.>...>...>v>..v.>..>>v>.v..>.v.v..>..>.>>vvv>>.>v
v........v>>>.>..>....>.>.>>...>v..v.>v>...vvv>>v>.....vvv..v..v.>..v>.vvv.>.....>.v.>.>>.v..v.v>>>.>>...>.v.>.>vv.>v>.>>......v.vv.>.v..v>
v.>.v>>.>..v......v>v>...>.>>.>v..>>..>....>v.vv..>..v>vv.v.>v....>...>v>..v...>>v.v...>>.v>..>.>.>..>>.v.....v>.>v...v.v.>vv.>.....>v.v>..
v.>v.>v.>>>v>.v>.>>...>.>vv.>v.......vv......>.>>.>..>vv.>....vvv....v>.>>.>.>v>.....v....v...>vvvvvv>.>.....>.v>v.vv.>.v>.>v>v>v>..>....>>
>vv..vv.v...>vv.v.vvv..vvv>..>....v>.vvvv..>.vv.>.vvv.>v>.>.v..>.........v>.v..vv>...>.>.>..vv...>.....v>v>..>.>..>...vv..vv..v>..>.>>>.>>>
.>>..v..>.>.>>v>>.>vvvv.v.v.>>v.>v....>..vv.......v>v..>.>..>>>vvvv>.v.v.v>v....v>..vv.v.v.v>>...v>.........>........v.vvv..vv.....>.v.>>>>
....>.>vv>>>>.......vv...v>>>.>v.v.v.v.v..>v.>..>>>>...>..v.>>.>>...v..>v...v.>v>v>>>v>v>>.>.>>v>..>>..v>.>v.vv...>..v.>v....>v>v.>v.......
>>>v>.>>.>>v.>v..>.v>..v>.v..>.v....v.>.>...>v.v>.....>>v.>..v..>>.>vv.>.vv.vv.>...>..v..vv...>vv.v.....>.....vv>v.>>....v.>.v....>>.>>.v.>
..v>vv>v>>.v..>v.>>...>..>v....v>>.v..v...>...>.vv>.>.....v>>v.....v.>v.v.v>.>.v...>..vvvvv...vv....>...>.........>.v.v..v.v...vv>v.>.v.vv.
..v..v>.v>v..v...v..vvv.vv.>......>.>.........>>...v...>vv>..v..vv>...>.vv..........>>.>>>v>>.>>>.vv....>.>vv>..v.>.>.v.v..>>v>>vv>.v.>....
v..>>.>..>>.v..>>v>..v..v.>.vv>.>vv.>.>.vv.>.>v.v>....v.v...>.>>v....v..>.v>vv...>v>.v...>v.>..vv.>v>>.vv>>>.v....>>v..>.>v>.>.>v>.vv.>.v..
.>v.>>v>>v>v>.>.>v.>.>>..v>.v...v>>.>..>>..v>>>>.>v..>v>.....>..>..>.>>>.vvvv.v.>>....vv>..v>v>.>..>...v.v..>v...v...>...v.>.>.v.v.v..>....
v>.v...vvvv..>v..v>.....>...vv...>v.>.....vv..v>.>....>v..v>.v.>>.v>.>vv.>...vv.......>...v...>.v....v..v..>vv>v.>..vvv...v>vv.v>v.v>..>.vv
v>.vv>.>..>.v>>.....v...v>..>>.>..v...>.>..>v..>>v>.vv.vvv..>...>>..>>>...>..>.>>>v....v.......v>.>>v.vv>.v>v.v>.....>>.v.>....>v>>.>....>v
v...>..vv>v>v.v>..>v.....>.....>..>>.>.....>vvvvv.v...>.v..>vv.v>v.>v....>vvv...>..v.v..v>.vv>>>v>v>.......vv.>..v>>.vv.>...v.vv..>v...>.v.
v..v>vv.>.>>>..>.v.>vvv...>.....v.>....>>..>.vv.v.v.>v..>>vvv.>>>...v.>>v>vv>v..>>..v.......>.>>....>>vv.v..>..v....>v....>.v>.v>.....vv...
.vv.>.>vv.vv....>v.v..>v...>>.>>.>.v....>vvv>.vv...>....>....>v.v>>.v.v.>.>...>....v>>..>.v>....v..>.>>vvv>v>.v.>.>>..v.>..>.v>...>..>vv..v
.>v>>....>vv>...>.vvv.>.>v>...v.>>vv>..v>.v.>vvv.v.>>.....>.>>>v>v>....v...v>v.vv.......vv.>.>.>......>...>>..>.v.vv...>.v>>..v..v....v...>
>>.>....v>...>v...v...v.>>.>v.v>vv>..>.>..>.....v.>>..>>.>>..v..>...v...vvv......v>.vvv.>>.v..vv..>v.v.......>.v...v..>>>>...>>.v..v>.v..vv
v..vv....v>....vvv......>>v..v>>v>...vv.vv>..v.v......v...>.vv....>v..>.v>.>v>v...v>>v..v>v......v>>v>v..v>>vv..v.v.>v.>vvv........>...v...
.v>.>vv.vv>.>>>.>v.>...>.>.>v.....>.v.>v.>.>v..>v.v.>v.>...>v.>v..>..v.v>..>v.v.v>vv>>v.v.>>.vv....>v>...>..v....>v..vvv>vvvv..>.v.>.v>>v>.
.vv.......v.....>.v...v>..vv..>v>.vv>>>..vvvvv>>.vvv.>vv.v.....>>v>.....>....>..>...v>>.>>.v>v.vv..>>>v.v>>....v>v.v..>v..>.>.>.>...v.>>.>.
..>....>>>>>.v.v.>.>>v.>....v.v.....v.>v>>v>.v.vvv...v..v>v.....v.....v..>v.>vv.>.>>v.>...v..>...v.>>>.......v.>v>>v.vv>v...>>...v>vv.v.>v.
>>>..v.v...v..>..v.>.>v...>...v>v>.v.......v.v>>vv.v.vv.v.>.>....v....>v>..>...>v.>.v...v..>>vv>vvvvv>..>v.vv...vv.v.>>.>>v..v.>>>v>v.>>>..
>>vv>v..v.v>.>>v..>v.....>>..>v>...v..>.>vv.>.v.v.vv..vv.v.>.>.....>.>v>v..>>...>vv....vv....v.v>>v..v.>v.v>v>.v..>.>v>>v..v..vv.>v>.....>.
vv..>v..v>...>.>v...v..>..>>v.....v.vv..>.>>>v.vv.>vv...v.>..v>.>...>vv>>vv>>>...v..>v..>..v..>vvvvvvv...v>>..>>>.>.>>>v.>>v.v.>v.vvvv..>.>
>>>.>....v..v..>..>>.>vv.>.....>>>v.v.......v..v.>.>>.>.v...v>>v.>>..vv>..v..>.>...v..>..v.v...>.vv.>v..v>vvv..v>.>>vvv....>v>>vvv.vv.>.v..
v>>.v>>vvv...v.....v...v...>...v..>..v>>>>v..>.v...v>>vv>..vv......>.>>v..vv...>.vv>>>.>>>v.>>>.v...>vv>.>>v>>>v>v.>v..v>>v.>.>.>.>.>>v..>.
....vv.v>>v>.vv.v...>>>....>>.v..v.v.>v>vv.v..v......vv>.>.>.......>vv...>v..vv.>.>....>v.>.....v.v.....v.v>.>..v>...>>v>..v>.v>.....>..>vv
>vvv.v>>>.v........v>...>>.>>v...>v>..>v.>v>.v.>>>v>>>..vv...vvv.v>v.>..>v.v..vv>.vv..>...>.>>>v.v...>....>>.>.>v.vv>v>v.v.v>...v..>.>.v.>.
.>vv..>>v.>v.>>v.>v..>v......v>v>v..v.>>>>>.>.....>..>..>>v...>....v>...vv..v>>.....v..>...vv.v.>>v.vvv...>..>.....>>v.>>...v...vv..>vv>.v.
..>v.>>.>>>vv....>>>v>.>.vv.v.v.vvv..v.vv>>...v.v>.>..>.>..v>v>>....>.......>..v>.>>>..>>>........>>..>>>....v...>.vv>>>>.>...vv....vv..v..
.v....>..v.>>v.>>vvv......>>v>>...>..>.vv>v>...vv.>>.vvv>.>...>.>>>.>..>>.>>v..>..>vvv.>v>>vv.....v..>>..v.>..>..>..v..>.>.>>.vvvv..>.>.v>v
v.v.>>>.vv>>..>.>.>>v>>>.....>..v>>.>.v>>>.v>>>>v.v.v>v>>...>....v...vv>>.>>v.v...vv....v.>.>..>.>..>.v>..v..>.>v.>>>>...v.>.v...>>>....v.v
>.>v...>v>v.v...v.>.>vv>v.>.vv>vv.>>..>v.v>..>..>....v>>>.....>>..>..>.vv.....v.v>.....>.>>v...>v>v..>..>>...v>...>>.>>...>..v...v.v..>vvv.
>v>>v..v.>>v>.>>...>.vv>.>.>v.v...v>....vv..>.v..>>v>..>..>>>>..>.>v...v..>.v.....>>......v.>.v.....>.>>v.v>>.>vvvv.>v.>vv>vv>v>...v..vv>..
.v>..>.v.v...>vv>..>.v..>..>>.vvv...v.>.v.>>v>...>...>.>v>..v.vv..>>.vv.v>>v>...>..v.>>...>...vvv.>.v..v.v>>..vv.v...>...v..vv>>..>.v...v..
v>>>.v.vv...vv>v..v...v.>>v.v..vv......>>..vv.vv>v.vv.>..v>>vv>.>.v.>.vv..v>>v.>.vvv..>>.v>v>.>.v.>..vv.>...vv.vv..vv.>.>.v...vv.>v.v..>.vv
>...v>>v.vv>.>..>.>>>.vv>vv.v.v>....v>v.v.>.>....>v.v>v.>....vv.v.>>vv...>.>>.>..v..v...v>>v..>>.>...v>>>>...>v..........vv>v.>.v.....>..>.
.>>v.>.vvvv>>>..v..v>v....v...>...v.v....>.>...v>.>.>.v>vv>v>>.v..v.>vv>..>>..vv>>.>>v..>>..>..>>v..>v..v......>.>v....>v..v>...vv>v..v..v.
....v..>.>>v..>..>....vv.>.>>v>...>>..vv.>>v...v..>v>.v..v.v.>>.....>v...>>.v>.>>...v>..v..v.v...v>v.>v.>...v..vv>...>>>>..v.>v...vv.vvv.v.
v.v.v...vv.v.>v.>.>...v...>vv....vv.>...>v>>.>v>..>vv.v.>.>.v.>.>v>>>..>vv......>...vv...v>....>>..v>>..v>..>v......v.v>....v..>.>vv.>vv.>.
.>>>..>>.v..>.....>v.>vv.....v.v.>vvv>>v.v....v>....>vv..>.v.v..>.>v>v>>..vv.>...>>.>.>>v>..>.>>..vv>......vv.>>..v>v>..v.v.v>.>..>>v..>.v.
>..>..v.v........v.>.>.>..vvv..>>..>v.v>>>.>.>>>v>>v.>..>v......>.>.v.>..vv...v....v.>...v.vv....>v.v..vv......>.v..>vvv.>v.......>..v>>>>>
..>.>v....v.>..v.>v>..>..>.>>v>.>..>v...v...>.>.v..vvvv..>vvv>..v..>v>...v.>.>.v.v...>>>..>vv.....v.vvv.v.>.v.>.>v>.v.>.v.v..>.>..>>.>..v>.
>>..v>..>..v..>...>..>v>vv>v.v>...v.v>>>...v>.v>.v>....>...>..v.....v>.>.v.>.>>....>>.>>>>..>v>....>...>.>..>..>..>...v..>........vvv...>>.
.v..v.v.>>>.>>>..v..v.v.vv>v.v>........>.>....v.v.v.>.>.v..v.>v.....>v..>.>...>.>...>.v.>vv.>>.>>vv.vv.v>v>...>v.v..vv>vv...>.v>.v>v.>>v...
.>v.v.v.>v.vv.....>..>.>v>vv....v>.v>.v>.>.>.>>>.>...vvv.v.v.v>v.>.vv...>.vv.>.>v.v......v.vvv..>>>.............v.>>......vv>>>.v>..>v>..v.
.>.>>..>>.....>v>v..v..>>...>v..vv...>vv..>v.>....>.>...>..vv>>.>v.v>vv..vvvv.>>.>>v.v>..v>v>>>v>>.>>..>.>..vvvvvv.v.......vv.v.>..>.>.>.v.
>v..>>....v.>....vv.>v>>......>v..>...v>.>.>..>>..>..>>.v.>.v.>>.>.v>v.v>.>>.>.......>v>vv..>.vv.>>vv.>.....>v.v>>.v...v..>...>>v..v.>.>>>.
...v..>.>>v>.....>.>>v....v..v>..v..v>>vvv>.>.v>>>v>......v>..>>v>.>v>.v>..>.v>>..>v>....v...>.>>>>v.vvv>...>...>.v..>v>.v.v>v.vv..v>>.>..>
>.v..v..>.>.v...>>>>..>>...vv......>.>..>..>.>.v...>.>.v>.........v>v...v>..v.>..>v>v.>.vv.v.vv.>.v..>.v.>>......>v..>>.>..v..v.v...>v..v..
.....v.>>...>....v..vvv...>..>..>.v.v..>v.>>v.>>>..vv>.v>vv...>.>...>>.>>.v..v...>vv>.....>>..v....>.v>>>vv>......>>.v.>..>v...>...>vv..vv.
..>..vvv.v.>..>v.>.>.>>.v>>>.>>>.>..v.vv...vv.>..vv>.>..>..>.v..>v..>>..>>v.>>.v.>vvv...v.>.>...>v....>vvvv>v.>v....v..>.>...>..v>.v.>...>>
..>.>v>.....>>>vv>v>..>>..v.>>.v>v..v.v.>v.v.v...>.vv.>.>.....>.vv....>>v.>v..>v.vvv>>.v.v..>....>.v....>...>.>.....>v>....>>.....>>vvvv>>>
.v..>..>>.v.>....v....>.v..v>.v.v.>.>v......>v......v.......>...>>v....v>>.v.v.>>v.v..vvv.>....vv.v........v.>>.v>>.v..v>.>>.vv>..v.v.vvvv.
>.>...v.>v..vvv.>...>....v>v..>v>.v...v>...v..>..>.v>>.>>....>...v.>v>>.v......>...>..v.v>....>.v.v..>v>>..v>>.>vv>..v>.vv>v.>..v....>>v..v
v.v.v.>.....>.>vv..>>.>.v.v.........>..>v.v>>.>..v...>>.>.>v.v>>>vv.v..vv>..>vv......v....vvv>....>v...>>v.>.>...v>.>.>.....>.>.>.v.vv>>.vv
>...>>vvv.....>>.>..vv>v>vvv>........v>v>>v..v..v..>vv.>.v.v.>v....v>.>..v>.>..>vv.v.>.v>..>v.....vv.v.v.....v..>v..>.>.v>>vv....>.>..v>...
.....>v>.v...v....>v.>.vv..>.>v.v>.>v.v>.vv..>.v>..>vv...>..>.>>>>>v>..v>vv>v.v>.vvv.>v..>>.v>v.v>.>.>.v.vv.v>.>>v..v>v.v....vv..v>.>.v.>.>
>.>.>>>.>>...>>vv..v>v..vvv.vv.v.v.v..v...v...v.>.>>v>.>v>.....>.>v...v..v.>....v>>.v>.>>....>v>>v..>..>v>.v...>...>>.>vv..>.v>v..>v..>v..v
.v...v.vvv..vv.>...v>.....vv.>.........v>v..>.>.>>...>>.vv...>...>vv>.vv.>......>>v..>>.>.>v....v.v>>..vv......vv>>>v>.>....>v>v...>v>.>...
.>>..v>vv>.>.vv.>v.vv..v....vvvvv.>>v>vv...>.v>v>v..v..v.v.>.>>vv.....v>...>>v..v....vv..>v..vv..>>>..v..v.>.v....>v>.v.>....vv..v...vv..vv
vv>..v>.>.v>.v>...>>...v>.>.>vv..>.>.v..>v>.>.>>...>....v>v..>v.vv.>..>....>vv.v....vvv>...vv.>.>.>.....v.>.vv........v...v..v....>v>>...v.

View File

@ -1,76 +0,0 @@
use std::{fs, env, collections::HashSet};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum Direction {
East,
South,
Empty
}
fn read_input(path: &str) -> String {
return fs::read_to_string(path).expect("Cannot read file.");
}
fn parse_input(s: &str) -> Vec<Vec<Direction>> {
let mut f: Vec<Vec<Direction>> = vec![];
for (r, l) in s.lines().enumerate() {
f.push(vec![]);
for c in l.chars() {
f[r].push(match c {
'>' => { Direction::East }
'v' => { Direction::South }
_ => { Direction::Empty }
});
}
}
return f;
}
fn get_next(i: usize, m: usize) -> usize {
if i == m - 1 { return 0; }
return i + 1;
}
fn apply_step(v: &mut Vec<Vec<Direction>>) -> usize {
let mut f = HashSet::new();
let mut o = v.clone();
for r in 0..v.len() {
for c in 0..v[r].len() {
let n = get_next(c, v[r].len());
if v[r][c] != Direction::East { continue; }
if v[r][n] != Direction::Empty { continue; }
if o[r][n] != Direction::Empty { continue; }
if f.contains(&(r, c)) { continue; }
f.insert((r, n));
v[r][n] = Direction::East;
v[r][c] = Direction::Empty;
}
}
o = v.clone();
for r in 0..v.len() {
let n = get_next(r, v.len());
for c in 0..v[r].len() {
if v[r][c] != Direction::South { continue; }
if v[n][c] != Direction::Empty { continue; }
if o[n][c] != Direction::Empty { continue; }
if f.contains(&(r, c)) { continue; }
f.insert((n, c));
v[n][c] = Direction::South;
v[r][c] = Direction::Empty;
}
}
return f.len();
}
fn main() {
let args: Vec<String> = env::args().collect();
for arg in args.iter().skip(1) {
let input = read_input(&arg);
let mut vec_in = parse_input(&input);
let mut i = 1;
while apply_step(&mut vec_in) != 0 { i += 1; }
println!("[{}]", &arg);
println!("\t[Part 1] => Answer is '{}'.", i);
}
}