diff --git a/.gitignore b/.gitignore index 36f1f41..2ce38df 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ /2021/*/build/ /2021/*/.idea/ /2021/*/.gradle/ - +.gitignore +.DS_Store diff --git a/2022/day01_1/build.gradle.kts b/2022/day01_1/build.gradle.kts new file mode 100644 index 0000000..f174151 --- /dev/null +++ b/2022/day01_1/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.6.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day01_1/gradle.properties b/2022/day01_1/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day01_1/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day01_1/gradle/wrapper/gradle-wrapper.jar b/2022/day01_1/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7454180 Binary files /dev/null and b/2022/day01_1/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day01_1/gradle/wrapper/gradle-wrapper.properties b/2022/day01_1/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..2e6e589 --- /dev/null +++ b/2022/day01_1/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/2022/day01_1/gradlew b/2022/day01_1/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day01_1/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day01_1/gradlew.bat b/2022/day01_1/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day01_1/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day01_1/settings.gradle.kts b/2022/day01_1/settings.gradle.kts new file mode 100644 index 0000000..f7785aa --- /dev/null +++ b/2022/day01_1/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day01_1" + diff --git a/2022/day01_1/src/main/kotlin/Main.kt b/2022/day01_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..cdd898c --- /dev/null +++ b/2022/day01_1/src/main/kotlin/Main.kt @@ -0,0 +1,38 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 1, Part 1 starting!!") + println(" reading data from: ${args[0]}") + + val listOfElves:ArrayList = ArrayList() + listOfElves.add(Elf()) + + File(args[0]).forEachLine { + processLine(it, listOfElves) + } + + println("Count of elves: ${listOfElves.size}") + val mostCaloriesCarried = listOfElves.maxOf { it.calories } + println("Maximum carried by an elf: $mostCaloriesCarried") +} + +class Elf { + var calories:Int = 0 + private set + + fun addFood(newFood:Int) { + calories += newFood + } +} + +fun processLine(line:String, elves:ArrayList) { + // read each line, blank links separate elves + if(line.isBlank()) { + // blank line, new elf + elves.add(Elf()) + } else { + // add more food to last elf in line + val elf = elves.last() + elf.addFood(line.toInt()) + } +} \ No newline at end of file diff --git a/2022/day01_1/src/main/resources/input b/2022/day01_1/src/main/resources/input new file mode 100644 index 0000000..6c1f923 --- /dev/null +++ b/2022/day01_1/src/main/resources/input @@ -0,0 +1,2266 @@ +6669 +6434 +6564 +1032 +1098 +1829 +2608 +7322 +2690 +7061 +1664 +5769 + +6160 +1082 +3958 +5272 +2188 +5618 +3418 +2302 +2926 +3338 +1082 +2024 +4195 +4083 + +3276 +5581 +3421 +3403 +4356 +2989 +1278 +1868 +3630 +4702 +3409 +4887 +2383 + +7104 +7496 +5265 +8078 +8788 +7402 +3601 +2641 +1252 +4994 + +4074 +7524 +8889 +9290 +8892 +5785 +2163 +1074 +6747 + +7452 +8006 +12427 +7919 +4012 +6850 + +34591 +26861 + +13028 +12695 +12762 +11006 +15937 + +17218 +12408 +17554 +11415 + +1118 +7240 +6400 +3431 +1032 +3283 +4667 +6100 +5076 +1101 +6952 +3527 + +7633 +4385 +4510 +4073 +3052 +11738 + +33554 + +3448 +16054 +10839 + +4496 +2697 +4731 +5150 +5327 +4039 +4004 +2148 +6150 +4001 +2882 +5780 +4327 + +4095 +2064 +6701 +3828 +2427 +4775 +2583 +2000 +1390 +7391 +1701 +3796 + +10355 +1262 +8781 +6350 + +11053 +11527 +1389 +6007 +12383 +11033 + +7951 +4258 +9815 +10061 +7579 +3769 +11431 + +3597 +35622 + +2129 +2994 +4260 +5269 +4179 +1612 +3509 +3581 +4544 +3713 +3202 +6458 +1203 +1095 + +17196 +13475 +12666 + +3549 +6432 +6593 +6723 +1272 +4023 +2112 +2844 +5135 +5103 +1585 +4773 +5635 + +8731 +16378 +5076 +2999 + +11136 +1525 +8684 +9731 +9753 +5366 +7399 + +8996 +1483 +4922 +1191 +2761 +9333 +9247 +3797 +3940 + +5876 +4139 +2158 +5905 +5445 +2438 +2814 +3853 +3432 +2289 +5783 +3839 +2811 +4361 + +3260 +6058 +3620 +2171 +4387 +4011 +4552 +1646 +3400 +2941 +6776 +2793 +6702 + +2318 +3118 +4920 +1293 +5593 +2308 +6819 +5949 +3819 +1742 +1074 +4565 +5891 + +5260 +8430 +6832 +6248 +2162 +7770 +1692 +4345 +7140 +6748 + +2921 +2075 +6039 +2875 +1479 +5835 +2350 +5981 +2684 +2560 +1608 +1495 +1358 +2047 +5003 + +13864 +8452 +10716 +6642 +14875 + +9704 +7477 +3664 +7751 +11616 +11067 +3496 + +12744 +11268 +7987 +15133 + +2859 +6255 +1302 +4053 +6133 +4181 +3008 +3450 +4421 +6065 +2732 +7142 + +7502 +3436 +2987 +8648 +1103 +1477 +7647 +9669 +6285 + +69741 + +60977 + +3987 +10933 +1170 +12375 + +6773 +2923 +8707 +3434 +5872 +5793 +5573 +6338 +7182 +2158 + +5522 +5345 +4425 +6178 +5236 +1397 +6165 +2173 +3547 +5225 +3949 +2238 +2594 +6032 + +7998 +6850 +1552 +3087 +6978 +7829 +1957 +1432 +7504 +2382 +3534 + +16000 +12845 +12638 +8250 + +5712 +1853 +2986 +6472 +1543 +1147 +5670 +5085 +3519 +5847 +4603 +1394 +2353 +1668 + +3542 +2995 +5413 +1108 +1783 +3902 +5173 +4228 +3997 +1759 +5652 +5896 +2109 +5697 +4198 + +3625 +7049 +4471 +11613 +1668 +9077 +3143 + +4473 +3397 +12107 +1364 +5698 +8030 +12081 + +2337 +3212 +3567 +1115 +3963 +1753 +1769 +6966 +3093 +4758 +5271 +3635 + +4387 +3770 +2931 +3029 +2657 +1109 +1592 +4884 +5784 +1911 +2938 +2501 +5851 +3793 + +1438 +7877 +7911 +2781 +1486 +4302 +6924 +3930 +6489 + +3794 +5964 +3072 +2292 +5199 +2157 +2357 +3649 +4888 +4522 +5408 +4743 +2753 +1717 + +8856 +7753 +8504 +1696 +5469 +7135 +7838 +6572 +4414 + +3860 +6400 +4018 +4506 +6979 +5493 +1950 +2544 +7426 +1405 +6440 +6253 + +8397 +2488 +4483 +3346 +8035 +3996 +6236 +4951 +2849 +6277 + +2113 +5149 +2409 +3971 +2762 +1704 +1799 +3929 +3224 +2149 +5804 +2026 +2269 +1107 +3140 + +2851 +10610 + +2901 +2215 +3138 +4848 +2612 +5624 +4878 +4137 +4093 +4660 +3369 +1970 +1176 +2141 +2298 + +50004 + +37286 +4713 + +2844 +1432 +2303 +4938 +3770 +1589 +5731 +5173 +3512 +5820 +3910 +6687 + +8039 +11639 +2325 +11278 +8313 + +7488 +15716 +1889 +4665 + +10258 +1862 +10452 +8650 +8039 +8984 +8778 +6486 + +8827 +12823 +25875 + +4658 +12284 +10171 +5966 +13525 + +7011 +2322 +8908 +8383 +3992 + +8965 +4198 +18224 +19587 + +5325 +20017 + +13271 +10542 +5223 +3178 + +1563 +4352 +6234 +2095 +1565 +1904 +6494 +6102 +3930 +4529 +5226 +5391 +1159 +4928 + +1588 +4779 +3001 +3698 +5784 +5327 +2149 +3020 +5362 +5751 +5704 +3296 +4746 +2595 +3169 + +5627 +24442 +5459 + +1867 +7808 +1287 +4179 +1395 +5759 +3916 +3549 +7235 +1740 +3753 + +11451 +8529 +1874 +6475 +1205 +8217 +9286 + +2929 +3725 +6071 +2336 +1725 +7049 +2041 +1694 +1231 + +3587 +6327 +8078 +4723 +10069 +5008 +8537 +7827 + +4148 +4758 +3453 +1189 +5086 +1045 +2429 +5157 +4454 +3198 +3080 +5980 +6011 +3575 +5044 + +7858 +7552 +7965 +3623 +7309 +4740 +6151 +1926 +2370 +6310 + +1734 +11654 +8498 + +2099 +4433 +3831 +6238 +4152 +1749 +4146 +5282 +3683 +4976 +5297 +1710 +4181 +4213 + +1981 +1318 +5839 +4815 +6083 +3841 +2842 +3246 +3884 +5193 +3451 +5147 +2518 + +2960 +3167 +5279 +2233 +6509 +5722 +3576 +6488 +4366 +1564 +6941 + +7515 +1502 +4892 +4008 +3196 +1730 +7263 +5971 +6213 +6673 +7824 + +5835 + +2444 +4473 +6654 +2285 +2184 +6397 +3411 +2602 +5380 +6952 +1234 +1474 +6842 + +3876 +7019 +1240 +6349 +4016 +2340 +8085 +1932 +5186 +4549 +6375 + +19405 +2299 +5583 + +13376 +12685 +9717 +12221 +2883 + +9537 +8867 +13398 +6781 +13954 + +2874 +1486 +5232 +5947 +2140 +7588 +1404 +8295 +6127 +7705 + +22842 +26153 + +8396 +2626 +3725 +5917 +2949 +1524 + +30131 + +5851 +1366 +3574 +1450 +5377 +6713 +3783 +3281 +4981 +6910 +5229 +4359 + +9099 +2211 +2814 +4583 +4690 +7122 +9334 + +17546 + +1378 +6567 +5300 +3819 +5604 +5316 +7159 +3564 +4302 +1442 +5763 +6610 + +1891 +8030 +3579 +4977 +3620 +2421 +7637 +1481 +9177 + +3298 +3865 +6812 +5409 +6482 +7245 +7049 +4319 +3040 +6027 +7195 +6023 + +28329 + +3409 +4600 +6903 +4511 +4341 +6742 +6967 +4247 +6802 +3453 +1515 + +2517 +13539 +3030 +11819 + +2974 +3749 +3971 +4509 +9599 +1036 +8176 + +1000 +2863 +1029 +2452 +2286 +2891 +5244 +3929 +5734 +2075 +5107 +2622 +4680 +1847 + +9653 +4720 +5078 +1589 +2431 +3149 +3261 +7308 +6953 + +5916 +7409 +3773 +7286 +4552 +9685 +2114 + +38289 + +1591 +10416 +3921 +16121 + +3217 +10969 +5198 +9305 +8671 +9606 +9759 + +60758 + +26875 + +12555 +12735 +14656 +4437 +4307 + +1528 +4259 +3310 +5563 +2281 +4305 +2573 +5733 +2725 +1519 +3299 +2055 +4674 +6146 + +21988 +17405 +15500 + +1775 +3126 +5002 +9407 +6048 +3346 +8368 +2185 +2825 + +24510 + +25200 +37377 + +9852 +1000 +2688 +11027 +11129 +11742 + +16298 +12093 +16906 +1567 + +1677 +3068 +6035 +6271 +6344 +5794 +1933 +6032 +4308 +6874 +6225 +1046 +6712 + +2194 +4404 +8838 +6737 +8595 +2478 +1033 +3489 + +5439 +14385 +13397 +3570 +13810 + +1726 +5761 +4318 +2813 +3351 +3168 +1539 +3847 +4422 +6071 +3376 +1093 +1979 +3206 +4011 + +2491 +4041 +3106 +2550 +3206 +5553 +3473 +5805 +1934 +4179 +1963 +4113 +3996 +2351 +3437 + +8747 +3481 +11813 +7672 +4711 + +4393 +2158 +3121 +6931 +7801 +3706 +4801 +3971 +1195 +1553 +1058 + +20051 +11463 + +1299 +6007 +6845 +1866 +2461 +3548 +4175 + +10323 +9098 +5566 +8553 +8768 +1022 +10088 + +5388 +4289 +5067 +5871 +5451 +4891 +8796 +6506 +3323 + +2652 +1923 +5235 +1539 +9256 +5794 +6153 +1379 +3568 + +12764 +15021 +11371 +1577 +4189 + +1960 +7462 +6862 +6710 +2350 +1689 +8322 +1575 +5367 +1074 + +4411 +4588 +3164 +1456 +6084 +2628 +5635 +2845 +3593 +3027 +6316 +5661 +2890 +2470 + +5592 +5071 +4290 +4402 +6091 +2907 +1531 +6229 +6159 +1791 +3833 +2435 +3919 +3160 + +18373 +2699 +6711 +14268 + +7693 +1264 +4217 +5299 +3786 +4555 +1112 +3392 +2535 +6768 +3618 + +11723 +6939 +7761 + +15672 +15601 +13101 +6229 + +23344 + +7787 +4343 +6661 +2629 +3189 +5155 +7999 +2351 +1308 +2726 +3177 + +18631 +18125 + +9177 +3897 +3655 +3449 +8336 +4366 +3363 +2145 +8594 + +1820 +9067 +2171 +2487 +15998 + +16221 +3430 +14946 +6869 +5305 + +4483 +7157 +1588 +2629 +5109 +7299 +1688 +4386 +6960 +6538 +1525 + +1289 +1340 +1520 +3601 +4316 +2653 +6140 +6219 +5044 +4306 +2573 +4028 +1828 +5844 + +7277 +5775 +2893 +3958 +6228 +6786 +7203 +7119 +5786 +6477 + +4367 +10361 +5973 +9197 +2832 +7900 +6711 +8279 + +9606 +6118 +10025 +10242 +8279 +8938 +6688 +7905 + +2478 +1918 +5575 +1840 +4897 +5871 +6309 +2778 +1937 +5396 +3249 +3456 +1002 + +12936 +11011 +11487 +11919 +13937 +8622 + +3853 +13287 +8285 +7842 + +11250 +7923 +8049 +3931 +7625 +4918 + +6516 +8209 +1752 +6258 +8501 +7426 + +10432 +3916 +12055 +13687 +1774 +8053 + +4682 +6779 +7258 +6929 +6899 +2643 +7021 +4960 +1732 +4065 +2854 +3593 + +13273 +11558 +5225 +3607 +5637 +11317 + +65129 + +6830 +3890 +4718 +6376 +3029 +8343 +7250 +7484 +3379 + +16188 +11694 +16583 +18745 + +4379 +2764 +4045 +3392 +1546 +3255 +2029 +3239 +1565 +5060 +1208 +1340 +5419 +3466 +4620 + +5408 +11519 +10387 +7305 +5770 +1733 +5462 + +9975 +4492 +14939 + +6365 +5846 +1825 +2851 +5483 +4801 +4109 +2581 +4729 +5149 +5573 +3345 +5426 +2060 + +15826 +6853 +10422 +12615 + +26180 + +5520 +1816 +1983 +4838 +2454 +4060 +2788 +6199 +6235 +2288 +4959 +4117 +3684 +3781 + +33317 +13949 + +1439 +1401 +4390 +4539 +5877 +2857 +3622 +3524 +4414 +1908 +2148 +1941 +4218 +1323 + +9364 +14727 +3282 + +22309 +24789 +7850 + +3434 +19391 +9665 + +1420 +3456 +4714 +4667 +2824 +3442 +1875 +2679 +4123 +1089 +2733 +4700 +5369 +1177 +1161 + +1710 +4521 +2164 +5986 +2485 +5614 +6494 +5043 +6334 +4947 +1423 +3351 +4010 +4360 + +3366 +3591 +8590 +3852 +9035 +8474 +1698 +5448 + +4560 +2248 +7197 +1821 +5411 +4522 +4914 +7806 +1387 +5702 +1780 + +3156 +2143 +5586 +2022 +3913 +5090 +5977 +4643 +3195 +5785 +6892 +5048 + +3839 +1261 +10477 +8350 +5769 +12750 + +19348 +9824 +15316 +17581 + +7925 +7634 + +2947 +4578 +1499 +1778 +10217 +5597 +3943 +8172 + +2012 +3917 +8065 +5627 +7562 +5489 +4334 +1648 +6666 +8287 + +15138 +7610 +12478 +12309 +13290 + +6296 +1234 +7587 +5783 +3061 +5613 +3283 +4447 +7188 +4577 +4102 + +8355 +2352 +1164 +1204 +2809 +6145 +6475 +3972 +1539 + +1805 +1214 +4153 +1685 +2472 +4620 +2784 +1859 +1390 +3591 +2560 +6291 +2805 + +11842 +20590 +15179 + +22669 +16927 +13861 + +2691 +9308 +3682 +1107 + +6906 +5502 +2120 +6862 +8843 +5379 +9651 +8263 +7238 + +3026 +5505 +2220 +1215 +4409 +2544 +3819 +7524 +3042 +4252 +1241 + +11244 +2129 +8844 +10557 +4463 +2319 + +5365 +2200 +1589 +4451 +5736 +1895 +4986 +3211 +1235 +4028 +1707 +1051 +6037 + +14311 +5746 + +2013 +8567 +3579 +6440 +3637 +10568 +8596 +7767 + +5653 +7015 +5853 +3670 +4265 +3003 +4139 +3132 +7538 +3629 + +3173 +1436 +3076 +5275 +4686 +5149 +6179 +2238 +1339 +2123 +4221 +6509 +5150 +2728 + +35818 + +11419 +8083 +12069 +3666 +2300 + +28844 +10855 + +30505 +18426 + +3369 +3085 +7409 +7308 +6556 +9671 +5416 +5981 +7558 + +5259 +9105 +15313 +6050 + +3203 +3414 +11117 +6231 +6049 +11632 +4816 + +11686 +5815 +11464 +7186 +9842 +5953 +8553 + +9330 +1817 +3529 +1761 +1823 +3942 +9471 +2207 + +8304 +9429 +12445 +3950 +16005 + +4809 +3869 +6968 +3204 +3621 +5925 +3967 +5180 +5238 +3013 +5291 +1371 + +4656 +2372 +1950 +4696 +1060 +3802 +5178 +5875 +3804 +5357 +3257 +1949 +3892 +5813 +3996 + +10281 +24432 +9867 + +7152 +5979 +4947 +6123 +6631 +6929 +4675 +3974 +5293 +6265 +4023 +6536 + +2200 +2917 +4479 +3671 +7268 +3545 +6762 +5921 +1814 +3704 +2767 +4692 + +9984 +5140 +2532 +4146 +13613 +11710 + +2027 +2367 +7666 +8617 +7563 +6593 +5060 +4431 +2666 +5080 + +7837 +6223 +2698 +8080 +3586 +8054 +6153 + +4364 +5979 +13237 +9841 +8704 + +5197 +4477 +5255 +8748 +11477 +1361 +4220 + +12430 +4451 +1038 +9999 +7577 + +59250 + +3857 +2158 +7069 +4813 +1980 +1636 +3646 +6760 +2842 +4217 +7578 + +1360 +2241 +2170 +2623 +2647 +5193 +3950 +4758 +5644 +2097 +3768 +5600 +3042 +3976 + +3905 +7116 +9941 +1927 +2265 +4489 + +6072 +3192 +6263 +3496 +3332 +2584 +5862 +6093 +6069 +4497 +1483 +6109 +4352 +1235 + +18487 +10619 +16127 +11370 + +2449 +2250 +2025 +3522 +5687 +5202 +4474 +5911 +3270 +5929 +4208 +2694 +5863 +3789 +2120 + +2591 +9936 +3145 +4471 +2234 +2250 +1547 +3760 + +13060 +12425 +20060 + +1786 +6317 +2087 +1998 +4111 +2185 +5446 +2732 +3731 +6082 +4513 +6370 +2494 +3197 + +5581 +5685 +1428 +1539 +1704 +5007 +2207 +4835 +1700 +4340 +1818 +3276 +1724 +1555 + +16085 +18634 + +1834 +2654 +5257 +2329 +4180 +4424 +4947 +5484 +1141 +4607 +5401 +2856 +2045 +4916 +5992 + +2925 +4945 +4969 +1400 +6410 +1093 +2398 +1949 +2701 +2763 +6314 +1105 +1580 +2804 + +52492 + +4181 +8013 +15867 + +2465 +4182 +6901 +1949 +5107 + +3078 +5461 +5477 +5344 +5974 +9751 + +26600 + +3943 +9282 +9655 +4304 +11368 + +4386 +7039 +7871 +9075 +2279 +10752 +1240 +5754 + +6914 +7359 +6766 +5693 +7719 +5043 +8665 +7241 +3498 +8771 + +12438 + +2288 +2764 +2633 +3416 +3396 +3172 +2004 +3583 +1862 +3027 +3928 +3165 + +3265 +2973 +2084 +5073 +1835 +2803 +2420 +3924 +4277 +5862 +1330 +5599 +3553 +3640 +5041 + +8709 +1629 + +5938 +9575 +1789 +6720 + +3623 +4874 +8500 +6566 +6965 +9388 +2106 +8552 + +9147 +4821 +5991 +9194 +3138 +2877 +5089 +4677 +3841 + +2865 +4858 +4642 +3755 +5958 +8076 +5599 +7931 + +5112 +2846 +2713 +3603 +5395 +4539 +4324 +2518 +1850 +5995 + +44743 + +1052 +3226 +3355 +4357 +4745 +4324 +4606 +3155 +3877 +1188 +4762 +1587 +2101 +1792 +4723 + +2071 +4440 +7135 +5825 +6083 +4034 +4572 +6942 + +3345 +5000 +1167 +1951 +4713 +2062 +4786 +7635 +1304 +6163 +5063 + +7060 +1738 +2658 +1217 +1388 +7416 +3719 +3903 +2305 +1051 +4437 +2496 + +9603 + +17966 +16434 +6253 + +8045 +8593 +9128 +6057 +10943 +11143 +2626 + +1961 +2742 +5305 +4780 +4307 +2465 +4472 +2946 +1404 +2195 +4822 +5607 +1027 +5697 + +26688 + +1004 +1382 +1194 +4638 +3773 +5037 +3731 +2676 +3567 +1159 +1136 +2883 diff --git a/2022/day01_1/src/main/resources/small_input b/2022/day01_1/src/main/resources/small_input new file mode 100644 index 0000000..2094f91 --- /dev/null +++ b/2022/day01_1/src/main/resources/small_input @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 diff --git a/2022/day01_2/build.gradle.kts b/2022/day01_2/build.gradle.kts new file mode 100644 index 0000000..f174151 --- /dev/null +++ b/2022/day01_2/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.6.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day01_2/gradle.properties b/2022/day01_2/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day01_2/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day01_2/gradle/wrapper/gradle-wrapper.jar b/2022/day01_2/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7454180 Binary files /dev/null and b/2022/day01_2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day01_2/gradle/wrapper/gradle-wrapper.properties b/2022/day01_2/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..2e6e589 --- /dev/null +++ b/2022/day01_2/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/2022/day01_2/gradlew b/2022/day01_2/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day01_2/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day01_2/gradlew.bat b/2022/day01_2/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day01_2/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day01_2/settings.gradle.kts b/2022/day01_2/settings.gradle.kts new file mode 100644 index 0000000..148a307 --- /dev/null +++ b/2022/day01_2/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day01_2" + diff --git a/2022/day01_2/src/main/kotlin/Main.kt b/2022/day01_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..4607ea4 --- /dev/null +++ b/2022/day01_2/src/main/kotlin/Main.kt @@ -0,0 +1,47 @@ +import java.io.File + +class Elf { + var calories:Int = 0 + private set + + fun addFood(newFood:Int) { + calories += newFood + } +} + +fun main(args: Array) { + println("AOC 2022, Day 1, Part 2 starting!!") + + val listOfElves:ArrayList = ArrayList() + listOfElves.add(Elf()) + + File(args[0]).forEachLine { + processLine(it, listOfElves) + } + + val sortedElves = listOfElves.sortedByDescending { it.calories } + + println("The top 3 Elves:") + + var combinedTotal = 0 + for(i in 0 .. 2) { + println("${i + 1} carries ${sortedElves[i].calories}") + combinedTotal += sortedElves[i].calories + } + + println("For a combined total: $combinedTotal") + + println("AOC 2022, Day 1, Part 2 completed.") +} + +fun processLine(line:String, elves:ArrayList) { + // read each line, blank links separate elves + if(line.isBlank()) { + // blank line, new elf + elves.add(Elf()) + } else { + // add more food to last elf in line + val elf = elves.last() + elf.addFood(line.toInt()) + } +} \ No newline at end of file diff --git a/2022/day01_2/src/main/resources/input b/2022/day01_2/src/main/resources/input new file mode 100644 index 0000000..6c1f923 --- /dev/null +++ b/2022/day01_2/src/main/resources/input @@ -0,0 +1,2266 @@ +6669 +6434 +6564 +1032 +1098 +1829 +2608 +7322 +2690 +7061 +1664 +5769 + +6160 +1082 +3958 +5272 +2188 +5618 +3418 +2302 +2926 +3338 +1082 +2024 +4195 +4083 + +3276 +5581 +3421 +3403 +4356 +2989 +1278 +1868 +3630 +4702 +3409 +4887 +2383 + +7104 +7496 +5265 +8078 +8788 +7402 +3601 +2641 +1252 +4994 + +4074 +7524 +8889 +9290 +8892 +5785 +2163 +1074 +6747 + +7452 +8006 +12427 +7919 +4012 +6850 + +34591 +26861 + +13028 +12695 +12762 +11006 +15937 + +17218 +12408 +17554 +11415 + +1118 +7240 +6400 +3431 +1032 +3283 +4667 +6100 +5076 +1101 +6952 +3527 + +7633 +4385 +4510 +4073 +3052 +11738 + +33554 + +3448 +16054 +10839 + +4496 +2697 +4731 +5150 +5327 +4039 +4004 +2148 +6150 +4001 +2882 +5780 +4327 + +4095 +2064 +6701 +3828 +2427 +4775 +2583 +2000 +1390 +7391 +1701 +3796 + +10355 +1262 +8781 +6350 + +11053 +11527 +1389 +6007 +12383 +11033 + +7951 +4258 +9815 +10061 +7579 +3769 +11431 + +3597 +35622 + +2129 +2994 +4260 +5269 +4179 +1612 +3509 +3581 +4544 +3713 +3202 +6458 +1203 +1095 + +17196 +13475 +12666 + +3549 +6432 +6593 +6723 +1272 +4023 +2112 +2844 +5135 +5103 +1585 +4773 +5635 + +8731 +16378 +5076 +2999 + +11136 +1525 +8684 +9731 +9753 +5366 +7399 + +8996 +1483 +4922 +1191 +2761 +9333 +9247 +3797 +3940 + +5876 +4139 +2158 +5905 +5445 +2438 +2814 +3853 +3432 +2289 +5783 +3839 +2811 +4361 + +3260 +6058 +3620 +2171 +4387 +4011 +4552 +1646 +3400 +2941 +6776 +2793 +6702 + +2318 +3118 +4920 +1293 +5593 +2308 +6819 +5949 +3819 +1742 +1074 +4565 +5891 + +5260 +8430 +6832 +6248 +2162 +7770 +1692 +4345 +7140 +6748 + +2921 +2075 +6039 +2875 +1479 +5835 +2350 +5981 +2684 +2560 +1608 +1495 +1358 +2047 +5003 + +13864 +8452 +10716 +6642 +14875 + +9704 +7477 +3664 +7751 +11616 +11067 +3496 + +12744 +11268 +7987 +15133 + +2859 +6255 +1302 +4053 +6133 +4181 +3008 +3450 +4421 +6065 +2732 +7142 + +7502 +3436 +2987 +8648 +1103 +1477 +7647 +9669 +6285 + +69741 + +60977 + +3987 +10933 +1170 +12375 + +6773 +2923 +8707 +3434 +5872 +5793 +5573 +6338 +7182 +2158 + +5522 +5345 +4425 +6178 +5236 +1397 +6165 +2173 +3547 +5225 +3949 +2238 +2594 +6032 + +7998 +6850 +1552 +3087 +6978 +7829 +1957 +1432 +7504 +2382 +3534 + +16000 +12845 +12638 +8250 + +5712 +1853 +2986 +6472 +1543 +1147 +5670 +5085 +3519 +5847 +4603 +1394 +2353 +1668 + +3542 +2995 +5413 +1108 +1783 +3902 +5173 +4228 +3997 +1759 +5652 +5896 +2109 +5697 +4198 + +3625 +7049 +4471 +11613 +1668 +9077 +3143 + +4473 +3397 +12107 +1364 +5698 +8030 +12081 + +2337 +3212 +3567 +1115 +3963 +1753 +1769 +6966 +3093 +4758 +5271 +3635 + +4387 +3770 +2931 +3029 +2657 +1109 +1592 +4884 +5784 +1911 +2938 +2501 +5851 +3793 + +1438 +7877 +7911 +2781 +1486 +4302 +6924 +3930 +6489 + +3794 +5964 +3072 +2292 +5199 +2157 +2357 +3649 +4888 +4522 +5408 +4743 +2753 +1717 + +8856 +7753 +8504 +1696 +5469 +7135 +7838 +6572 +4414 + +3860 +6400 +4018 +4506 +6979 +5493 +1950 +2544 +7426 +1405 +6440 +6253 + +8397 +2488 +4483 +3346 +8035 +3996 +6236 +4951 +2849 +6277 + +2113 +5149 +2409 +3971 +2762 +1704 +1799 +3929 +3224 +2149 +5804 +2026 +2269 +1107 +3140 + +2851 +10610 + +2901 +2215 +3138 +4848 +2612 +5624 +4878 +4137 +4093 +4660 +3369 +1970 +1176 +2141 +2298 + +50004 + +37286 +4713 + +2844 +1432 +2303 +4938 +3770 +1589 +5731 +5173 +3512 +5820 +3910 +6687 + +8039 +11639 +2325 +11278 +8313 + +7488 +15716 +1889 +4665 + +10258 +1862 +10452 +8650 +8039 +8984 +8778 +6486 + +8827 +12823 +25875 + +4658 +12284 +10171 +5966 +13525 + +7011 +2322 +8908 +8383 +3992 + +8965 +4198 +18224 +19587 + +5325 +20017 + +13271 +10542 +5223 +3178 + +1563 +4352 +6234 +2095 +1565 +1904 +6494 +6102 +3930 +4529 +5226 +5391 +1159 +4928 + +1588 +4779 +3001 +3698 +5784 +5327 +2149 +3020 +5362 +5751 +5704 +3296 +4746 +2595 +3169 + +5627 +24442 +5459 + +1867 +7808 +1287 +4179 +1395 +5759 +3916 +3549 +7235 +1740 +3753 + +11451 +8529 +1874 +6475 +1205 +8217 +9286 + +2929 +3725 +6071 +2336 +1725 +7049 +2041 +1694 +1231 + +3587 +6327 +8078 +4723 +10069 +5008 +8537 +7827 + +4148 +4758 +3453 +1189 +5086 +1045 +2429 +5157 +4454 +3198 +3080 +5980 +6011 +3575 +5044 + +7858 +7552 +7965 +3623 +7309 +4740 +6151 +1926 +2370 +6310 + +1734 +11654 +8498 + +2099 +4433 +3831 +6238 +4152 +1749 +4146 +5282 +3683 +4976 +5297 +1710 +4181 +4213 + +1981 +1318 +5839 +4815 +6083 +3841 +2842 +3246 +3884 +5193 +3451 +5147 +2518 + +2960 +3167 +5279 +2233 +6509 +5722 +3576 +6488 +4366 +1564 +6941 + +7515 +1502 +4892 +4008 +3196 +1730 +7263 +5971 +6213 +6673 +7824 + +5835 + +2444 +4473 +6654 +2285 +2184 +6397 +3411 +2602 +5380 +6952 +1234 +1474 +6842 + +3876 +7019 +1240 +6349 +4016 +2340 +8085 +1932 +5186 +4549 +6375 + +19405 +2299 +5583 + +13376 +12685 +9717 +12221 +2883 + +9537 +8867 +13398 +6781 +13954 + +2874 +1486 +5232 +5947 +2140 +7588 +1404 +8295 +6127 +7705 + +22842 +26153 + +8396 +2626 +3725 +5917 +2949 +1524 + +30131 + +5851 +1366 +3574 +1450 +5377 +6713 +3783 +3281 +4981 +6910 +5229 +4359 + +9099 +2211 +2814 +4583 +4690 +7122 +9334 + +17546 + +1378 +6567 +5300 +3819 +5604 +5316 +7159 +3564 +4302 +1442 +5763 +6610 + +1891 +8030 +3579 +4977 +3620 +2421 +7637 +1481 +9177 + +3298 +3865 +6812 +5409 +6482 +7245 +7049 +4319 +3040 +6027 +7195 +6023 + +28329 + +3409 +4600 +6903 +4511 +4341 +6742 +6967 +4247 +6802 +3453 +1515 + +2517 +13539 +3030 +11819 + +2974 +3749 +3971 +4509 +9599 +1036 +8176 + +1000 +2863 +1029 +2452 +2286 +2891 +5244 +3929 +5734 +2075 +5107 +2622 +4680 +1847 + +9653 +4720 +5078 +1589 +2431 +3149 +3261 +7308 +6953 + +5916 +7409 +3773 +7286 +4552 +9685 +2114 + +38289 + +1591 +10416 +3921 +16121 + +3217 +10969 +5198 +9305 +8671 +9606 +9759 + +60758 + +26875 + +12555 +12735 +14656 +4437 +4307 + +1528 +4259 +3310 +5563 +2281 +4305 +2573 +5733 +2725 +1519 +3299 +2055 +4674 +6146 + +21988 +17405 +15500 + +1775 +3126 +5002 +9407 +6048 +3346 +8368 +2185 +2825 + +24510 + +25200 +37377 + +9852 +1000 +2688 +11027 +11129 +11742 + +16298 +12093 +16906 +1567 + +1677 +3068 +6035 +6271 +6344 +5794 +1933 +6032 +4308 +6874 +6225 +1046 +6712 + +2194 +4404 +8838 +6737 +8595 +2478 +1033 +3489 + +5439 +14385 +13397 +3570 +13810 + +1726 +5761 +4318 +2813 +3351 +3168 +1539 +3847 +4422 +6071 +3376 +1093 +1979 +3206 +4011 + +2491 +4041 +3106 +2550 +3206 +5553 +3473 +5805 +1934 +4179 +1963 +4113 +3996 +2351 +3437 + +8747 +3481 +11813 +7672 +4711 + +4393 +2158 +3121 +6931 +7801 +3706 +4801 +3971 +1195 +1553 +1058 + +20051 +11463 + +1299 +6007 +6845 +1866 +2461 +3548 +4175 + +10323 +9098 +5566 +8553 +8768 +1022 +10088 + +5388 +4289 +5067 +5871 +5451 +4891 +8796 +6506 +3323 + +2652 +1923 +5235 +1539 +9256 +5794 +6153 +1379 +3568 + +12764 +15021 +11371 +1577 +4189 + +1960 +7462 +6862 +6710 +2350 +1689 +8322 +1575 +5367 +1074 + +4411 +4588 +3164 +1456 +6084 +2628 +5635 +2845 +3593 +3027 +6316 +5661 +2890 +2470 + +5592 +5071 +4290 +4402 +6091 +2907 +1531 +6229 +6159 +1791 +3833 +2435 +3919 +3160 + +18373 +2699 +6711 +14268 + +7693 +1264 +4217 +5299 +3786 +4555 +1112 +3392 +2535 +6768 +3618 + +11723 +6939 +7761 + +15672 +15601 +13101 +6229 + +23344 + +7787 +4343 +6661 +2629 +3189 +5155 +7999 +2351 +1308 +2726 +3177 + +18631 +18125 + +9177 +3897 +3655 +3449 +8336 +4366 +3363 +2145 +8594 + +1820 +9067 +2171 +2487 +15998 + +16221 +3430 +14946 +6869 +5305 + +4483 +7157 +1588 +2629 +5109 +7299 +1688 +4386 +6960 +6538 +1525 + +1289 +1340 +1520 +3601 +4316 +2653 +6140 +6219 +5044 +4306 +2573 +4028 +1828 +5844 + +7277 +5775 +2893 +3958 +6228 +6786 +7203 +7119 +5786 +6477 + +4367 +10361 +5973 +9197 +2832 +7900 +6711 +8279 + +9606 +6118 +10025 +10242 +8279 +8938 +6688 +7905 + +2478 +1918 +5575 +1840 +4897 +5871 +6309 +2778 +1937 +5396 +3249 +3456 +1002 + +12936 +11011 +11487 +11919 +13937 +8622 + +3853 +13287 +8285 +7842 + +11250 +7923 +8049 +3931 +7625 +4918 + +6516 +8209 +1752 +6258 +8501 +7426 + +10432 +3916 +12055 +13687 +1774 +8053 + +4682 +6779 +7258 +6929 +6899 +2643 +7021 +4960 +1732 +4065 +2854 +3593 + +13273 +11558 +5225 +3607 +5637 +11317 + +65129 + +6830 +3890 +4718 +6376 +3029 +8343 +7250 +7484 +3379 + +16188 +11694 +16583 +18745 + +4379 +2764 +4045 +3392 +1546 +3255 +2029 +3239 +1565 +5060 +1208 +1340 +5419 +3466 +4620 + +5408 +11519 +10387 +7305 +5770 +1733 +5462 + +9975 +4492 +14939 + +6365 +5846 +1825 +2851 +5483 +4801 +4109 +2581 +4729 +5149 +5573 +3345 +5426 +2060 + +15826 +6853 +10422 +12615 + +26180 + +5520 +1816 +1983 +4838 +2454 +4060 +2788 +6199 +6235 +2288 +4959 +4117 +3684 +3781 + +33317 +13949 + +1439 +1401 +4390 +4539 +5877 +2857 +3622 +3524 +4414 +1908 +2148 +1941 +4218 +1323 + +9364 +14727 +3282 + +22309 +24789 +7850 + +3434 +19391 +9665 + +1420 +3456 +4714 +4667 +2824 +3442 +1875 +2679 +4123 +1089 +2733 +4700 +5369 +1177 +1161 + +1710 +4521 +2164 +5986 +2485 +5614 +6494 +5043 +6334 +4947 +1423 +3351 +4010 +4360 + +3366 +3591 +8590 +3852 +9035 +8474 +1698 +5448 + +4560 +2248 +7197 +1821 +5411 +4522 +4914 +7806 +1387 +5702 +1780 + +3156 +2143 +5586 +2022 +3913 +5090 +5977 +4643 +3195 +5785 +6892 +5048 + +3839 +1261 +10477 +8350 +5769 +12750 + +19348 +9824 +15316 +17581 + +7925 +7634 + +2947 +4578 +1499 +1778 +10217 +5597 +3943 +8172 + +2012 +3917 +8065 +5627 +7562 +5489 +4334 +1648 +6666 +8287 + +15138 +7610 +12478 +12309 +13290 + +6296 +1234 +7587 +5783 +3061 +5613 +3283 +4447 +7188 +4577 +4102 + +8355 +2352 +1164 +1204 +2809 +6145 +6475 +3972 +1539 + +1805 +1214 +4153 +1685 +2472 +4620 +2784 +1859 +1390 +3591 +2560 +6291 +2805 + +11842 +20590 +15179 + +22669 +16927 +13861 + +2691 +9308 +3682 +1107 + +6906 +5502 +2120 +6862 +8843 +5379 +9651 +8263 +7238 + +3026 +5505 +2220 +1215 +4409 +2544 +3819 +7524 +3042 +4252 +1241 + +11244 +2129 +8844 +10557 +4463 +2319 + +5365 +2200 +1589 +4451 +5736 +1895 +4986 +3211 +1235 +4028 +1707 +1051 +6037 + +14311 +5746 + +2013 +8567 +3579 +6440 +3637 +10568 +8596 +7767 + +5653 +7015 +5853 +3670 +4265 +3003 +4139 +3132 +7538 +3629 + +3173 +1436 +3076 +5275 +4686 +5149 +6179 +2238 +1339 +2123 +4221 +6509 +5150 +2728 + +35818 + +11419 +8083 +12069 +3666 +2300 + +28844 +10855 + +30505 +18426 + +3369 +3085 +7409 +7308 +6556 +9671 +5416 +5981 +7558 + +5259 +9105 +15313 +6050 + +3203 +3414 +11117 +6231 +6049 +11632 +4816 + +11686 +5815 +11464 +7186 +9842 +5953 +8553 + +9330 +1817 +3529 +1761 +1823 +3942 +9471 +2207 + +8304 +9429 +12445 +3950 +16005 + +4809 +3869 +6968 +3204 +3621 +5925 +3967 +5180 +5238 +3013 +5291 +1371 + +4656 +2372 +1950 +4696 +1060 +3802 +5178 +5875 +3804 +5357 +3257 +1949 +3892 +5813 +3996 + +10281 +24432 +9867 + +7152 +5979 +4947 +6123 +6631 +6929 +4675 +3974 +5293 +6265 +4023 +6536 + +2200 +2917 +4479 +3671 +7268 +3545 +6762 +5921 +1814 +3704 +2767 +4692 + +9984 +5140 +2532 +4146 +13613 +11710 + +2027 +2367 +7666 +8617 +7563 +6593 +5060 +4431 +2666 +5080 + +7837 +6223 +2698 +8080 +3586 +8054 +6153 + +4364 +5979 +13237 +9841 +8704 + +5197 +4477 +5255 +8748 +11477 +1361 +4220 + +12430 +4451 +1038 +9999 +7577 + +59250 + +3857 +2158 +7069 +4813 +1980 +1636 +3646 +6760 +2842 +4217 +7578 + +1360 +2241 +2170 +2623 +2647 +5193 +3950 +4758 +5644 +2097 +3768 +5600 +3042 +3976 + +3905 +7116 +9941 +1927 +2265 +4489 + +6072 +3192 +6263 +3496 +3332 +2584 +5862 +6093 +6069 +4497 +1483 +6109 +4352 +1235 + +18487 +10619 +16127 +11370 + +2449 +2250 +2025 +3522 +5687 +5202 +4474 +5911 +3270 +5929 +4208 +2694 +5863 +3789 +2120 + +2591 +9936 +3145 +4471 +2234 +2250 +1547 +3760 + +13060 +12425 +20060 + +1786 +6317 +2087 +1998 +4111 +2185 +5446 +2732 +3731 +6082 +4513 +6370 +2494 +3197 + +5581 +5685 +1428 +1539 +1704 +5007 +2207 +4835 +1700 +4340 +1818 +3276 +1724 +1555 + +16085 +18634 + +1834 +2654 +5257 +2329 +4180 +4424 +4947 +5484 +1141 +4607 +5401 +2856 +2045 +4916 +5992 + +2925 +4945 +4969 +1400 +6410 +1093 +2398 +1949 +2701 +2763 +6314 +1105 +1580 +2804 + +52492 + +4181 +8013 +15867 + +2465 +4182 +6901 +1949 +5107 + +3078 +5461 +5477 +5344 +5974 +9751 + +26600 + +3943 +9282 +9655 +4304 +11368 + +4386 +7039 +7871 +9075 +2279 +10752 +1240 +5754 + +6914 +7359 +6766 +5693 +7719 +5043 +8665 +7241 +3498 +8771 + +12438 + +2288 +2764 +2633 +3416 +3396 +3172 +2004 +3583 +1862 +3027 +3928 +3165 + +3265 +2973 +2084 +5073 +1835 +2803 +2420 +3924 +4277 +5862 +1330 +5599 +3553 +3640 +5041 + +8709 +1629 + +5938 +9575 +1789 +6720 + +3623 +4874 +8500 +6566 +6965 +9388 +2106 +8552 + +9147 +4821 +5991 +9194 +3138 +2877 +5089 +4677 +3841 + +2865 +4858 +4642 +3755 +5958 +8076 +5599 +7931 + +5112 +2846 +2713 +3603 +5395 +4539 +4324 +2518 +1850 +5995 + +44743 + +1052 +3226 +3355 +4357 +4745 +4324 +4606 +3155 +3877 +1188 +4762 +1587 +2101 +1792 +4723 + +2071 +4440 +7135 +5825 +6083 +4034 +4572 +6942 + +3345 +5000 +1167 +1951 +4713 +2062 +4786 +7635 +1304 +6163 +5063 + +7060 +1738 +2658 +1217 +1388 +7416 +3719 +3903 +2305 +1051 +4437 +2496 + +9603 + +17966 +16434 +6253 + +8045 +8593 +9128 +6057 +10943 +11143 +2626 + +1961 +2742 +5305 +4780 +4307 +2465 +4472 +2946 +1404 +2195 +4822 +5607 +1027 +5697 + +26688 + +1004 +1382 +1194 +4638 +3773 +5037 +3731 +2676 +3567 +1159 +1136 +2883 diff --git a/2022/day01_2/src/main/resources/small_input b/2022/day01_2/src/main/resources/small_input new file mode 100644 index 0000000..2094f91 --- /dev/null +++ b/2022/day01_2/src/main/resources/small_input @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 diff --git a/2022/day02_1/.idea/.gitignore b/2022/day02_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day02_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day02_1/.idea/compiler.xml b/2022/day02_1/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day02_1/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day02_1/.idea/gradle.xml b/2022/day02_1/.idea/gradle.xml new file mode 100644 index 0000000..5404067 --- /dev/null +++ b/2022/day02_1/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day02_1/.idea/jarRepositories.xml b/2022/day02_1/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day02_1/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day02_1/.idea/misc.xml b/2022/day02_1/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day02_1/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day02_1/.idea/sonarlint/issuestore/index.pb b/2022/day02_1/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/2022/day02_1/.idea/vcs.xml b/2022/day02_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day02_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day02_1/build.gradle.kts b/2022/day02_1/build.gradle.kts new file mode 100644 index 0000000..f174151 --- /dev/null +++ b/2022/day02_1/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.6.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day02_1/gradle.properties b/2022/day02_1/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day02_1/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day02_1/gradle/wrapper/gradle-wrapper.jar b/2022/day02_1/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7454180 Binary files /dev/null and b/2022/day02_1/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day02_1/gradle/wrapper/gradle-wrapper.properties b/2022/day02_1/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..2e6e589 --- /dev/null +++ b/2022/day02_1/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/2022/day02_1/gradlew b/2022/day02_1/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day02_1/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day02_1/gradlew.bat b/2022/day02_1/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day02_1/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day02_1/settings.gradle.kts b/2022/day02_1/settings.gradle.kts new file mode 100644 index 0000000..6408c15 --- /dev/null +++ b/2022/day02_1/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day02_1" + diff --git a/2022/day02_1/src/main/kotlin/Main.kt b/2022/day02_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..69ada6d --- /dev/null +++ b/2022/day02_1/src/main/kotlin/Main.kt @@ -0,0 +1,114 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 2, Part 1 starting!!") + + val turns = ArrayList() + + File(args[0]).forEachLine { + processLine(it, turns) + } + + val scores = turns.sumOf { it.theScore() } + + println("The sum of scores: $scores") + + println("AOC 2022, Day 2, Part 1 completed!!") +} + +class RockPaperScissorsTurn constructor (private val opponent:Char, private val mine:Char) { + // Opponent A = rock = 1 + // Opponent B = paper = 2 + // Opponent C = scissor = 3 + + private fun opponentMove() : String { + return when (opponent) { + 'A' -> "Rock" + 'B' -> "Paper" + 'C' -> "Scissor" + else -> "INVALID" + } + } + + private fun myMove() : String { + return when (mine) { + 'X' -> "Rock" + 'Y' -> "Paper" + 'Z' -> "Scissor" + else -> "INVALID" + } + } + + // Mine X = rock + // Mine Y = paper + // Mine Z = scissor + + // Outcome loss = 0 + // Outcome tie = 3 + // outcome win = 6 + + // score = opponent X + outcome Y + fun theScore() : Int { + var score = when(mine) { + 'X' -> 1 + 'Y' -> 2 + 'Z' -> 3 + else -> -1 + } + + + println(" ${opponentMove()} vs ${myMove()}...") + score += outcome(opponent, mine) + + return score + } + + private fun outcome(opponent: Char, mine: Char) : Int { + // rock vs rock = tie + if((opponent == 'A') && (mine == 'X')) { + return 3 + } + // rock vs paper = win + if((opponent == 'A') && (mine == 'Y')) { + return 6 + } + // rock vs scissor = loss + if((opponent == 'A') && (mine == 'Z')) { + return 0 + } + + // paper vs rock = loss + if((opponent == 'B') && (mine == 'X')) { + return 0 + } + // paper vs paper = tie + if((opponent == 'B') && (mine == 'Y')) { + return 3 + } + // paper vs scissors = win + if((opponent == 'B') && (mine == 'Z')) { + return 6 + } + + // scissor vs rock = win + if((opponent == 'C') && (mine == 'X')) { + return 6 + } + // scissor vs paper = loss + if((opponent == 'C') && (mine == 'Y')) { + return 0 + } + // scissor vs scissor = tie + if((opponent == 'C') && (mine == 'Z')) { + return 3 + } + throw Exception("outside params!") + } +} + +fun processLine(line:String, turns: ArrayList) { + val opponent = line[0] + val mine = line[2] + + turns.add(RockPaperScissorsTurn(opponent, mine)) +} \ No newline at end of file diff --git a/2022/day02_1/src/main/resources/input b/2022/day02_1/src/main/resources/input new file mode 100644 index 0000000..cf8495b --- /dev/null +++ b/2022/day02_1/src/main/resources/input @@ -0,0 +1,2500 @@ +C Z +C Z +A Y +A X +C Z +C Z +A X +C X +A X +C X +A X +A X +A X +A X +C Y +A X +A X +A Y +C Z +C X +C Z +C Y +B Y +C Y +C X +C X +A Z +C Y +A Z +A Z +B X +A Y +A X +B Y +C X +A X +A X +C Z +C Y +B X +A Y +C Z +C Y +C Z +C Z +A X +C Z +C Y +C X +C Z +A X +C Z +A Y +A X +A X +A X +A X +C X +A X +A X +C X +A X +C Y +C Y +A X +C Z +C Y +A X +C Z +C Y +C Z +C Z +B X +C Z +C X +C X +B Z +A X +A X +C Z +C X +C X +A X +A Y +C X +C Y +A X +C Z +A Z +C Z +A Z +A Z +C X +A X +A X +C Z +C Y +C Z +A X +A X +C X +A X +C X +A X +A Z +A Y +C Y +A Y +C Z +A X +A Y +C X +A Z +C Y +C Z +C Z +A Y +C Z +A Z +C Z +A Z +A Z +A X +C X +A Y +A X +C Z +A X +C Z +C Z +A X +C Z +C X +A Z +A X +A Z +A X +C Z +A X +C X +A X +A X +C X +C Z +C Y +C Z +A Y +C Z +C Z +A X +C X +B X +C X +A X +C Y +C Z +C Z +C Z +A Z +C Y +A X +C X +B X +B X +C Y +C X +A X +C X +C X +A Y +C Z +A X +A X +A X +C Z +A X +C Z +C Y +C Z +C X +A X +C Z +A X +C Z +C X +C X +A X +C Z +C Z +C X +A Y +B X +B Z +A Z +C Z +A X +A X +A X +C X +C X +C Y +C Z +A Y +B Z +A X +C X +C X +C X +C Y +C X +A X +A X +A Z +A X +A X +C Z +C Z +C Z +A X +C X +C X +C Y +A X +C Z +A Z +C X +A X +C X +C Z +A X +A X +C Z +C X +C Y +A X +C Y +C Z +A Z +C X +A X +A X +A X +A Z +C X +C X +A X +A X +B X +C Y +C X +C Z +C Y +A X +C X +C Z +C Y +C Y +C X +C Y +B X +C X +C Y +A X +C Z +C Y +A X +A X +C X +A X +A X +A Z +C X +A Z +C X +C X +C X +C Y +A Z +C Z +A X +B X +C X +A X +A Z +C X +C Z +B X +C X +A X +A Y +A Z +C Z +C Z +C X +A Z +C Z +C Z +C X +C Y +C Z +C Z +C X +A Z +C Z +C X +A X +A X +A X +A Z +A Z +C Z +A X +C X +A X +C X +C Z +C X +C X +A X +C X +B Y +A X +B X +A X +C X +C Z +A X +C X +A X +A X +C Z +C X +C X +C X +C Z +A X +B X +A Z +C X +B Z +C Z +B Z +C Z +A Y +A X +B Y +A X +A X +C Z +C X +A X +B X +C X +B Z +C Z +A X +A X +A X +A X +A X +A X +A X +C Y +A Y +C X +C Z +C X +C Y +C Z +C X +A X +C Z +A X +A Z +C X +C Z +C Y +A X +C X +C Z +A X +A Y +C X +A X +C Y +A Y +C Y +A Z +C Z +A X +C Z +C Z +A X +C Z +A Z +C X +C Z +B X +C X +A X +A Y +A X +C Z +A Y +A Y +C X +B Z +C X +A X +A X +A X +A X +A X +C X +C Z +A Z +A X +C Y +C Z +A X +A Z +B Z +A Z +A X +C Y +C X +C X +C X +B Z +A X +C Y +A X +A X +A X +C Y +A X +B X +C X +C X +C Z +C Z +A X +C Y +A Z +A X +C X +A X +C X +C X +C Z +A X +C Y +C Y +A X +A Z +A Z +A X +C X +A X +C Y +B X +A X +C Y +C X +B X +C Z +A X +A X +C X +C Z +C Z +C X +C Y +C Y +A X +C Z +C X +C Y +C X +A X +A X +A X +B Y +C X +A X +C X +C X +A X +C Z +C Z +C X +B X +A Y +A Y +C Z +C Y +C X +C Y +B Y +A Z +C X +A X +A Z +A Y +C X +A Z +C Z +C Y +C Z +A X +C X +C Z +C X +C X +A X +C Z +A Z +C X +C Y +C X +A X +A Z +C Z +C X +A Z +B Z +C Y +B X +A Y +B X +B Y +A Y +A X +A Z +C X +C X +A X +C X +C Z +C Y +A Z +A X +C Z +A X +A X +A Z +A X +A X +C Z +A X +C X +A X +A X +A Y +C Z +A X +C Z +A Z +A X +A X +A Y +C Z +A Z +A Z +A X +C X +A X +A X +C Z +C X +C X +C X +C Y +C X +A X +B X +B X +C Z +C Z +C Z +C X +B Y +A Y +B X +B X +C X +C X +C X +A X +C Y +A Z +A X +C X +A X +A X +A X +B X +C Y +A X +C Z +A X +C X +A X +C Z +C X +A X +A Z +A X +A X +A X +C Z +A Y +B X +A X +B X +C Z +A X +A X +C Y +C Z +C Z +A X +C X +A X +A X +A X +A X +A X +C X +A X +C Y +C X +B X +A X +C Y +C Z +A X +A X +C X +A Z +A X +A Z +A X +C Z +A X +B X +C X +A X +C X +A X +C Y +C Z +A X +C Z +C Z +C X +B X +C Z +A X +A Z +C X +A X +C X +C Z +C Z +C Y +C Z +A X +C X +C Z +A Z +C Z +A Z +C X +C Z +A X +A X +B X +A Z +B X +C Y +C Z +C X +A X +C Z +C Z +C Z +B X +C X +C X +A Z +A X +C Y +A X +B Z +B X +A X +C Y +B X +C Z +C Y +C Z +A X +C Y +A X +A X +A Z +A X +A X +C X +C Y +C Z +C Z +C Y +B Y +C Z +A X +A X +C X +C X +C X +A X +C Y +A X +A Y +A X +C X +C Y +C Y +B X +A X +C Z +A X +C Z +C X +A X +A Z +C X +C Y +A X +A Z +A Z +C Y +A X +C Z +C Z +A X +A Z +B X +A X +C Y +C X +B Z +C Z +A X +C Y +A X +C Y +A Z +A X +C X +C Y +B X +A X +B X +A X +A X +B Y +A X +A X +C X +A X +C X +A X +A X +C Y +A X +C Z +C Z +A Z +C X +A Z +C Y +C Z +C X +A X +C Z +A X +C Y +A X +A Z +C Y +C X +C X +C Z +B X +A X +A X +A Z +C Z +C X +A X +C X +A Z +A Z +A X +C X +C Z +B Z +C X +C X +A X +A X +A X +C Y +C X +A X +C Z +A X +B Y +A X +A X +C X +B X +A X +C X +B Y +A Z +C X +C X +A X +A X +A X +C Y +C X +A Z +C X +A X +C Z +C Z +C Y +A X +A X +B Z +C Y +C Z +A X +C Z +A X +C Z +B X +A Z +A Z +C X +A X +C Z +C X +A X +A X +C X +C Z +C X +A X +C X +A X +A X +C Z +C X +A X +A X +A X +A X +C Y +A X +C X +C Z +C Y +C Z +C X +C Z +A X +C X +C Z +C Z +C Z +B X +C X +A Z +A Z +A X +C X +C Z +B Z +C Z +C Z +A Y +A Y +C X +A X +A X +A Z +A X +A Y +A Z +A X +A X +C Z +C Z +A Y +A X +B X +A X +A X +C X +A X +A Z +C Z +C X +C Z +C X +A Z +B X +A X +A X +C X +B Y +A X +C Z +A X +A Y +A Z +A X +C Z +A Z +B X +C Z +C Y +A X +C Y +A X +C X +C X +C X +A X +C X +C Z +C Y +A Z +C X +C Y +A X +A X +C Z +A X +C X +C X +A X +A X +A Z +C X +C Z +A Z +A Z +A X +B X +B X +A X +C Z +A Z +C Z +C X +C Z +B X +C X +C X +B Z +A X +A Z +B Z +B Z +C X +A Z +A X +A Y +C X +A X +C Z +A X +C X +A X +C Z +C X +C X +C X +C Z +B Z +A X +A X +A X +C Z +A X +A X +C X +B Z +C X +C X +A X +B Y +C X +C X +C X +A X +C X +A Z +C Y +B Z +A X +C Z +C Z +C Z +C Z +A Y +C Z +A X +A X +C X +C X +A X +C X +A Z +A X +C Z +C X +A X +C Z +C X +C Z +B Z +A X +C Y +C Z +A X +A X +C Y +A Z +C X +C Z +C Z +C Y +C Z +A X +C X +A X +A X +C X +A X +C Z +A X +A Z +A X +C Z +C Z +B X +C Z +A Y +A Z +A X +C Y +C X +C Y +A X +A Z +A X +A X +A X +C X +B X +C X +A Y +A Y +C Z +A X +A X +A Z +C X +A X +A Z +C Z +C Z +C X +C X +A X +A X +C Z +A X +C Z +C Z +B Z +A X +A X +C Z +A X +C Z +C Y +C X +A X +A Z +A X +A X +A X +C Y +C Z +A X +C Y +C Z +C Z +A X +A Z +A X +C Z +C Y +C Z +C Y +A X +C X +A X +A X +A X +C X +A X +A X +C Y +C X +A X +C X +A Z +A X +C Z +C X +B Z +C Z +A X +C Y +C Z +C X +A X +A X +B Y +A X +B X +C X +A X +A X +C X +C Y +A X +A X +A X +C X +C Z +A X +B X +C Y +C Y +A X +C Y +C X +A X +C X +A X +A X +A X +C X +C X +B Z +A X +C X +A X +C Z +A X +C Y +A X +C Z +C Z +C Y +A X +A Z +A X +C X +C Z +A X +C Z +C X +C Z +A X +C Y +A X +C Z +C Y +C X +A X +A Y +B X +A X +A Y +A X +A X +A X +A X +C Z +C Y +B X +A X +C X +A X +C X +A X +A Y +A X +C Z +A Z +C X +A X +A X +A X +C Z +C Z +C Y +C X +A X +C X +C Y +A Z +C X +A X +C Y +C Z +C Z +A X +A X +C Z +C Z +C X +C X +C X +C Z +C Y +C X +B Z +C Z +A X +C Z +A X +A X +C X +C X +C Y +A Y +A X +C X +A X +C X +C X +A X +A X +A Y +C Z +C Y +A X +A X +A X +A X +C X +C Y +A X +A Y +A X +A X +C X +A Z +C Z +C Z +C Z +C Z +A X +C Z +C X +C X +B X +C X +C Z +C X +A Z +C Z +B X +B Z +C Y +A X +B X +A X +A X +A X +C X +C X +A X +C Y +A X +C Y +B Y +C Y +A X +C X +C Y +C Z +C X +A X +A X +C X +B X +C Z +C X +A X +A Z +A X +C Z +C X +B X +A Z +A X +B Z +C Z +A X +C Y +A X +C Z +B X +C X +C X +C Y +A X +A X +A X +C Z +C X +B Z +C Z +B X +B Z +A X +A Z +A X +C X +C X +C Z +C X +C X +B Y +A X +A X +A X +A X +A X +A X +C X +A Z +A Z +C X +C X +A X +B Y +C X +C X +A Z +A X +B X +A X +C X +C Z +C Y +C Z +C Z +B X +C Y +C X +A X +A X +C X +C Y +C Z +A X +C X +A X +B Z +A X +C Y +C X +C X +A X +C Z +C Z +A X +C X +C X +C X +A X +A Z +C X +A X +C Z +A X +C Z +C Z +A X +C Z +A Z +C X +A X +A X +C Z +A X +A X +A X +C X +A X +A X +C Z +C X +C Y +B X +C X +C Y +C X +A X +A Y +A X +A X +A Z +C Z +A X +C X +C X +C X +C X +B Z +A X +B Y +C X +C X +C Y +C X +C Z +C Z +A X +C X +A X +C X +A Z +C Y +B X +A X +C X +C Z +C Y +B X +C Y +A X +C X +A X +A X +A Z +A X +B X +C X +A X +A Y +A X +C X +C Z +A Z +A X +A X +C Z +A X +C X +A X +C X +A X +C Z +C Y +A X +C X +A X +C Z +A Y +B X +C Z +C Z +A X +A X +A Y +A Z +A X +C X +C Y +C Z +A X +C Z +C Z +B X +A X +A X +A X +C Y +A Z +C Z +C Z +A Z +A X +A X +B X +C X +B X +A X +C Z +A Y +C Z +A X +C X +C Z +C X +A X +C X +A X +A X +C Z +A Z +C X +C X +B Z +C Z +A Y +A X +C X +C Z +A X +C Z +C X +C Y +C X +A Y +C Z +C Z +A X +A X +A X +C Z +C Y +C Z +A X +C Z +A X +C X +A X +A Y +A X +A Z +A X +A Y +A X +A X +A X +A Z +A X +C Z +C Z +C Z +C X +A X +A Z +C X +C Z +A X +C X +C Y +A X +C X +A X +C Y +A X +A X +C Z +C X +A X +C Z +A X +A X +C Z +C X +C Z +C Y +A Y +C Z +C X +B X +A X +A X +A Z +A X +A X +C X +C Z +A X +C X +A Z +B X +A Z +C Z +C Z +A X +B X +A X +A Y +A X +A X +C Z +A X +C Y +C Z +C Y +A X +A X +A X +A X +B Z +B Z +A X +C X +C X +A X +C X +C Y +B X +C Y +B X +A X +B Z +C Z +A X +A X +C X +A Z +A X +C X +C Z +A X +C X +C X +C X +C Z +C Y +A X +A X +A X +C Z +C Z +C X +C Z +B X +A X +C Z +C Z +C Y +A X +A X +C Z +A Z +C X +C Z +C Y +C Z +C Z +A X +C Z +C Y +C X +B X +C Z +A Y +C Z +C X +C X +A X +A X +A X +C Z +B Z +A X +A Z +B X +A Z +A Z +C Z +C Z +C X +C Y +C Y +C Z +A Z +C Y +C X +C Y +A Z +B Y +A X +C Y +A X +A X +A Z +C Z +C Z +C Z +C X +C X +C Z +C Z +A X +C X +A Y +A Y +A X +B Z +A X +C X +A X +C X +A X +A X +A X +C X +C Y +C Z +C Z +A X +C Z +A X +C X +C X +C Z +A X +A X +A X +C X +C Z +A X +A X +A X +A X +C Z +B Y +A X +A X +A X +C Y +A X +A X +A Z +C X +A Z +C Z +A Z +C Z +A X +A Z +A X +A X +A X +A X +A Y +C X +C Z +A X +A Z +C X +A Y +C Z +C Y +A X +B X +A Y +C X +A X +C Z +C X +A X +C Z +C X +A X +C X +C X +C Z +A X +A Y +C Y +C Y +A X +A X +A X +A X +A X +C X +A Y +C Z +C Z +C Y +A X +C Z +C Z +A X +C X +C X +C Y +A X +A X +C X +C X +A Z +A X +C Z +A X +C Z +A X +B X +A Z +B X +C Z +C Z +C X +A X +A Z +C X +A X +A X +C X +C Y +C Z +C X +C X +A X +C Z +C Z +C X +B X +C Z +A X +B X +A Z +C X +A Z +A X +A X +C X +A X +C Z +A X +A X +C Z +C Z +C Z +A X +C X +A Y +C Y +A X +A X +A X +A X +C X +C Z +A X +A X +A X +C X +C Z +A X +C Z +A X +A Y +C Y +C X +C X +A X +A X +A X +A Z +A X +C Z +A X +C Y +B Z +B X +A X +C X +C Z +A X +A X +C Z +B X +B X +C X +C Y +C X +B X +A X +A X +C X +A Z +A X +C X +C X +C X +A X +C Z +A Y +A X +C Y +A X +A X +C Z +A Z +A Z +C X +C X +C Y +C Y +C X +C X +C Z +A X +C X +A X +A X +A X +A X +C Y +C Z +A X +C Z +C X +C X +A X +A X +A Z +C Y +C X +A X +C X +A X +A Z +A X +A Z +A X +A X +A X +C X +A Z +A X +C X +C Y +A Z +A X +B X +C X +C Y +C Z +C X +C Y +C X +C X +A X +C Y +B X +A Z +C Z +B Z +C X +A X +C Z +A X +C X +A X +A X +A X +C Z +C Y +B Z +A X +C X +A Y +C Z +A X +A X +A Z +A Z +A Y +C X +C Z +C X +A Z +C X +C Z +C X +B X +A X +C Z +A X +A X +C Z +A Z +C X +C Y +C X +C X +C Y +A X +A X +C X +A Z +C X +C Z +C X +A Z +A X +A Y +A X +A X +B Z +C Z +C Z +A Y +C X +A X +B X +A X +A Z +C Y +C Z +C X +C Z +C Z +C X +C X +A X +C X +A Z +C Z +C Z +C Z +C Y +C X +A X +C Z +A Z +C Z +C Z +A X +C X +A X +C Z +A X +B X +A X +C Z +C X +C X +A X +C Y +A X +C Z +B X +C Z +C X +A X +C X +C X +C Z +A X +A X +C Z +C Z +C X +C Z +C X +A X +A X +C Z +C X +C X +A X +C Z +A Z +C Z +B X +C X +C Y +C X +C Z +A X +B X +C Z +A X +C Z +A Z +C Z +C X +A X +C Z +C Z +A X +A X +C Z +A X +C Y +A Z +C X +C Z +A X +B Z +B X +A X +A Z +A X +A Z +A X +A X +C Y +A X +C Y +C X +C Y +C Y +C X +A X +A Z +A Z +C X +C Z +B X +A X +C Z +A Z +C X +C Z +C Y +A X +A X +C Z +C Z +C Y +A Z +C Z +C Y +A X +C X +A X +C X +C Z +A Z +B Z +A X +A X +A X +C X +C X +A Y +A Z +C X +C Z +A X +B X +A X +A X +C X +C X +B X +A X +B X +C Z +A Z +C Z +A X +C X +C Z +C Y +A Y +A Z +C Y +C Z +A X +A X +C X +A X +C Z +C Y +A X +C Z +A X +A X +B X +A X +A Z +C X +C Y +A Z +C Z +A X +A Z +C X +C Z +C X +C Z +A X +A X +A X +C X +A X +C Z +C X +C X +C X +C X +A X +C X +B Y +A Z +A Z +C Z +C X +A Y +C X +A X +C X +C Z +B Z +C Z +B X +A X +A Z +A X +C X +A X +C Z +C Z +C Z +A X +C Z +A X +C Z +C X +C X +C X +B X +A X +A X +B X +C X +A X +C Z +A Z +C Y +C Z +A Z +B Z +A Z +C Z +C Z +C X +A X +A X +C X +C X +C Y +A Y +A Z +A X +C Z +C Z +C Y +C X +A X +A X +C Y +A Z +C X +C X +C X +A X +C X +C X +A Z +C X +C Y +A Z +C Z +C Y +A Z +C Z +A X +C X +C Y +C X +C X +C Z +C X +C X +C Z +C X +A X +B Y +A X +C X +B Z +C Z +C X +C Z +C Z +A Y +A Y +A X +A Z +C Z +A X +C X +C Z +A Z +A X +A X +A X +B X +A X +B Z +C X +A X +C X +A Z +C X +A X +C Y +A X +C X +C Y +A Z +C Z +C Z +B X +A X +C X +A X +C X +C Y +A X +C Y +A X +B X +C Y +A X +A X +C X +A X +B Y +C Y +C Y +C Y +C X +A Y +C X +C Z +A X +A Z +A X +A X +C Z +A Z +A Z +C X +A X +A X +B X +C X +C Y +C X +B Z +A X +C X +C Y +C X +C Z +C Y +A X +C X +A X +A X +A Y +C Z +C Z +C Z +A X +A X +A Z +A X +A X +A Z +A X +C Y +C Y +A X +A X +A Z +C X +A X +C Z +A Z +C Z +C Y +C Z +A X +C Z +C X +C Z +A X +C Y +C Y +B X +A X +A Z +C X +A X +A X +C Z +A X +C X +C Z +A Z +A Y +A Y +A X +C X +A Y +A X +A X +B Z +A X +C X +C X +C X +A X +C X +C Z +C Z +A Z +C X +C X +C Y +A X +C X +A X +A X +C Y +C X +A X +C Y +C X +C X +A Y +C Z +C X +C X +C Y +C Z +A Y +A X +C Z +C Z +C Z +C X +C Z +A X +A X +A Z +A X +C Y +C X +C Z +A X +A X +C Z +A X +C X +A X +A Y +C X diff --git a/2022/day02_1/src/main/resources/small_input b/2022/day02_1/src/main/resources/small_input new file mode 100644 index 0000000..db60e36 --- /dev/null +++ b/2022/day02_1/src/main/resources/small_input @@ -0,0 +1,3 @@ +A Y +B X +C Z diff --git a/2022/day02_2/build.gradle.kts b/2022/day02_2/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day02_2/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day02_2/gradle.properties b/2022/day02_2/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day02_2/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day02_2/gradlew b/2022/day02_2/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day02_2/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day02_2/gradlew.bat b/2022/day02_2/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day02_2/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day02_2/settings.gradle.kts b/2022/day02_2/settings.gradle.kts new file mode 100644 index 0000000..2db8c75 --- /dev/null +++ b/2022/day02_2/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day02_2" + diff --git a/2022/day02_2/src/main/kotlin/Main.kt b/2022/day02_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..d7cb289 --- /dev/null +++ b/2022/day02_2/src/main/kotlin/Main.kt @@ -0,0 +1,176 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 2, Part 2 starting!!") + + val turns = ArrayList() + + File(args[0]).forEachLine { + processLine(it, turns) + } + + val scores = turns.sumOf { it.theScore() } + + println("The sum of scores: $scores") + + println("AOC 2022, Day 2, Part 2 completed!!") +} + +class RockPaperScissorsTurn { + constructor (opponentVal:Char, resultVal:Char) { + opponent = opponentVal + result = resultVal + + // Opponent picks rock... + if(opponent == 'A') { + //...need to lose, so my pick is scissor + if(result == 'X') { + mine = 'S' + } + //...need to tie, so pick rock + if(result == 'Y') { + mine = 'R' + } + //...need to win, so pick paper + if(result == 'Z') { + mine = 'P' + } + } + // Opponent picks paper... + if(opponent == 'B') { + //...need to lose, so pick rock + if(result == 'X') { + mine = 'R' + } + //...need to tie, so pick paper + if(result == 'Y') { + mine = 'P' + } + //...need to win, so pick scissor + if(result == 'Z') { + mine = 'S' + } + } + // Opponent pick scissor... + if(opponent == 'C') { + //...need to lose, so pick paper + if(result == 'X') { + mine = 'P' + } + //...need to tie, so pick sicssor + if(result == 'Y') { + mine = 'S' + } + //...need to win, so pick rock + if(result == 'Z') { + mine = 'R' + } + } + } + + // Opponent A = rock = 1 + // Opponent B = paper = 2 + // Opponent C = scissor = 3 + + // Result X = need to lose + // Result Y = need to draw + // Result Z = need to win + + private var opponent:Char = '*' + private var result:Char = '*' + private var mine:Char = '*' + + private fun opponentMove() : String { + return when (opponent) { + 'A' -> "Rock" + 'B' -> "Paper" + 'C' -> "Scissor" + else -> "INVALID" + } + } + + private fun finalResult():String { + return when(result) { + 'X' -> "Need to lose" + 'Y' -> "Need to draw" + 'Z' -> "Need to win" + else -> "INVALID" + } + } + + private fun myMove() : String { + return when (mine) { + 'R' -> "Rock" + 'P' -> "Paper" + 'S' -> "Scissor" + else -> "INVALID" + } + } + + // Outcome loss = 0 + // Outcome tie = 3 + // outcome win = 6 + + // score = opponent X + outcome Y + fun theScore() : Int { + var score = when(mine) { + 'R' -> 1 + 'P' -> 2 + 'S' -> 3 + else -> -1 + } + + score += outcome(opponent, mine) + + return score + } + + private fun outcome(opponent: Char, mine: Char) : Int { + // rock vs rock = tie + if((opponent == 'A') && (mine == 'R')) { + return 3 + } + // rock vs paper = win + if((opponent == 'A') && (mine == 'P')) { + return 6 + } + // rock vs scissor = loss + if((opponent == 'A') && (mine == 'S')) { + return 0 + } + + // paper vs rock = loss + if((opponent == 'B') && (mine == 'R')) { + return 0 + } + // paper vs paper = tie + if((opponent == 'B') && (mine == 'P')) { + return 3 + } + // paper vs scissors = win + if((opponent == 'B') && (mine == 'S')) { + return 6 + } + + // scissor vs rock = win + if((opponent == 'C') && (mine == 'R')) { + return 6 + } + // scissor vs paper = loss + if((opponent == 'C') && (mine == 'P')) { + return 0 + } + // scissor vs scissor = tie + if((opponent == 'C') && (mine == 'S')) { + return 3 + } + throw Exception("outside params! $opponent and $mine") + } +} + +fun processLine(line:String, turns: ArrayList) { + val opponent = line[0] + val result = line[2] + + turns.add(RockPaperScissorsTurn(opponent, result)) +} \ No newline at end of file diff --git a/2022/day02_2/src/main/resources/input b/2022/day02_2/src/main/resources/input new file mode 100644 index 0000000..cf8495b --- /dev/null +++ b/2022/day02_2/src/main/resources/input @@ -0,0 +1,2500 @@ +C Z +C Z +A Y +A X +C Z +C Z +A X +C X +A X +C X +A X +A X +A X +A X +C Y +A X +A X +A Y +C Z +C X +C Z +C Y +B Y +C Y +C X +C X +A Z +C Y +A Z +A Z +B X +A Y +A X +B Y +C X +A X +A X +C Z +C Y +B X +A Y +C Z +C Y +C Z +C Z +A X +C Z +C Y +C X +C Z +A X +C Z +A Y +A X +A X +A X +A X +C X +A X +A X +C X +A X +C Y +C Y +A X +C Z +C Y +A X +C Z +C Y +C Z +C Z +B X +C Z +C X +C X +B Z +A X +A X +C Z +C X +C X +A X +A Y +C X +C Y +A X +C Z +A Z +C Z +A Z +A Z +C X +A X +A X +C Z +C Y +C Z +A X +A X +C X +A X +C X +A X +A Z +A Y +C Y +A Y +C Z +A X +A Y +C X +A Z +C Y +C Z +C Z +A Y +C Z +A Z +C Z +A Z +A Z +A X +C X +A Y +A X +C Z +A X +C Z +C Z +A X +C Z +C X +A Z +A X +A Z +A X +C Z +A X +C X +A X +A X +C X +C Z +C Y +C Z +A Y +C Z +C Z +A X +C X +B X +C X +A X +C Y +C Z +C Z +C Z +A Z +C Y +A X +C X +B X +B X +C Y +C X +A X +C X +C X +A Y +C Z +A X +A X +A X +C Z +A X +C Z +C Y +C Z +C X +A X +C Z +A X +C Z +C X +C X +A X +C Z +C Z +C X +A Y +B X +B Z +A Z +C Z +A X +A X +A X +C X +C X +C Y +C Z +A Y +B Z +A X +C X +C X +C X +C Y +C X +A X +A X +A Z +A X +A X +C Z +C Z +C Z +A X +C X +C X +C Y +A X +C Z +A Z +C X +A X +C X +C Z +A X +A X +C Z +C X +C Y +A X +C Y +C Z +A Z +C X +A X +A X +A X +A Z +C X +C X +A X +A X +B X +C Y +C X +C Z +C Y +A X +C X +C Z +C Y +C Y +C X +C Y +B X +C X +C Y +A X +C Z +C Y +A X +A X +C X +A X +A X +A Z +C X +A Z +C X +C X +C X +C Y +A Z +C Z +A X +B X +C X +A X +A Z +C X +C Z +B X +C X +A X +A Y +A Z +C Z +C Z +C X +A Z +C Z +C Z +C X +C Y +C Z +C Z +C X +A Z +C Z +C X +A X +A X +A X +A Z +A Z +C Z +A X +C X +A X +C X +C Z +C X +C X +A X +C X +B Y +A X +B X +A X +C X +C Z +A X +C X +A X +A X +C Z +C X +C X +C X +C Z +A X +B X +A Z +C X +B Z +C Z +B Z +C Z +A Y +A X +B Y +A X +A X +C Z +C X +A X +B X +C X +B Z +C Z +A X +A X +A X +A X +A X +A X +A X +C Y +A Y +C X +C Z +C X +C Y +C Z +C X +A X +C Z +A X +A Z +C X +C Z +C Y +A X +C X +C Z +A X +A Y +C X +A X +C Y +A Y +C Y +A Z +C Z +A X +C Z +C Z +A X +C Z +A Z +C X +C Z +B X +C X +A X +A Y +A X +C Z +A Y +A Y +C X +B Z +C X +A X +A X +A X +A X +A X +C X +C Z +A Z +A X +C Y +C Z +A X +A Z +B Z +A Z +A X +C Y +C X +C X +C X +B Z +A X +C Y +A X +A X +A X +C Y +A X +B X +C X +C X +C Z +C Z +A X +C Y +A Z +A X +C X +A X +C X +C X +C Z +A X +C Y +C Y +A X +A Z +A Z +A X +C X +A X +C Y +B X +A X +C Y +C X +B X +C Z +A X +A X +C X +C Z +C Z +C X +C Y +C Y +A X +C Z +C X +C Y +C X +A X +A X +A X +B Y +C X +A X +C X +C X +A X +C Z +C Z +C X +B X +A Y +A Y +C Z +C Y +C X +C Y +B Y +A Z +C X +A X +A Z +A Y +C X +A Z +C Z +C Y +C Z +A X +C X +C Z +C X +C X +A X +C Z +A Z +C X +C Y +C X +A X +A Z +C Z +C X +A Z +B Z +C Y +B X +A Y +B X +B Y +A Y +A X +A Z +C X +C X +A X +C X +C Z +C Y +A Z +A X +C Z +A X +A X +A Z +A X +A X +C Z +A X +C X +A X +A X +A Y +C Z +A X +C Z +A Z +A X +A X +A Y +C Z +A Z +A Z +A X +C X +A X +A X +C Z +C X +C X +C X +C Y +C X +A X +B X +B X +C Z +C Z +C Z +C X +B Y +A Y +B X +B X +C X +C X +C X +A X +C Y +A Z +A X +C X +A X +A X +A X +B X +C Y +A X +C Z +A X +C X +A X +C Z +C X +A X +A Z +A X +A X +A X +C Z +A Y +B X +A X +B X +C Z +A X +A X +C Y +C Z +C Z +A X +C X +A X +A X +A X +A X +A X +C X +A X +C Y +C X +B X +A X +C Y +C Z +A X +A X +C X +A Z +A X +A Z +A X +C Z +A X +B X +C X +A X +C X +A X +C Y +C Z +A X +C Z +C Z +C X +B X +C Z +A X +A Z +C X +A X +C X +C Z +C Z +C Y +C Z +A X +C X +C Z +A Z +C Z +A Z +C X +C Z +A X +A X +B X +A Z +B X +C Y +C Z +C X +A X +C Z +C Z +C Z +B X +C X +C X +A Z +A X +C Y +A X +B Z +B X +A X +C Y +B X +C Z +C Y +C Z +A X +C Y +A X +A X +A Z +A X +A X +C X +C Y +C Z +C Z +C Y +B Y +C Z +A X +A X +C X +C X +C X +A X +C Y +A X +A Y +A X +C X +C Y +C Y +B X +A X +C Z +A X +C Z +C X +A X +A Z +C X +C Y +A X +A Z +A Z +C Y +A X +C Z +C Z +A X +A Z +B X +A X +C Y +C X +B Z +C Z +A X +C Y +A X +C Y +A Z +A X +C X +C Y +B X +A X +B X +A X +A X +B Y +A X +A X +C X +A X +C X +A X +A X +C Y +A X +C Z +C Z +A Z +C X +A Z +C Y +C Z +C X +A X +C Z +A X +C Y +A X +A Z +C Y +C X +C X +C Z +B X +A X +A X +A Z +C Z +C X +A X +C X +A Z +A Z +A X +C X +C Z +B Z +C X +C X +A X +A X +A X +C Y +C X +A X +C Z +A X +B Y +A X +A X +C X +B X +A X +C X +B Y +A Z +C X +C X +A X +A X +A X +C Y +C X +A Z +C X +A X +C Z +C Z +C Y +A X +A X +B Z +C Y +C Z +A X +C Z +A X +C Z +B X +A Z +A Z +C X +A X +C Z +C X +A X +A X +C X +C Z +C X +A X +C X +A X +A X +C Z +C X +A X +A X +A X +A X +C Y +A X +C X +C Z +C Y +C Z +C X +C Z +A X +C X +C Z +C Z +C Z +B X +C X +A Z +A Z +A X +C X +C Z +B Z +C Z +C Z +A Y +A Y +C X +A X +A X +A Z +A X +A Y +A Z +A X +A X +C Z +C Z +A Y +A X +B X +A X +A X +C X +A X +A Z +C Z +C X +C Z +C X +A Z +B X +A X +A X +C X +B Y +A X +C Z +A X +A Y +A Z +A X +C Z +A Z +B X +C Z +C Y +A X +C Y +A X +C X +C X +C X +A X +C X +C Z +C Y +A Z +C X +C Y +A X +A X +C Z +A X +C X +C X +A X +A X +A Z +C X +C Z +A Z +A Z +A X +B X +B X +A X +C Z +A Z +C Z +C X +C Z +B X +C X +C X +B Z +A X +A Z +B Z +B Z +C X +A Z +A X +A Y +C X +A X +C Z +A X +C X +A X +C Z +C X +C X +C X +C Z +B Z +A X +A X +A X +C Z +A X +A X +C X +B Z +C X +C X +A X +B Y +C X +C X +C X +A X +C X +A Z +C Y +B Z +A X +C Z +C Z +C Z +C Z +A Y +C Z +A X +A X +C X +C X +A X +C X +A Z +A X +C Z +C X +A X +C Z +C X +C Z +B Z +A X +C Y +C Z +A X +A X +C Y +A Z +C X +C Z +C Z +C Y +C Z +A X +C X +A X +A X +C X +A X +C Z +A X +A Z +A X +C Z +C Z +B X +C Z +A Y +A Z +A X +C Y +C X +C Y +A X +A Z +A X +A X +A X +C X +B X +C X +A Y +A Y +C Z +A X +A X +A Z +C X +A X +A Z +C Z +C Z +C X +C X +A X +A X +C Z +A X +C Z +C Z +B Z +A X +A X +C Z +A X +C Z +C Y +C X +A X +A Z +A X +A X +A X +C Y +C Z +A X +C Y +C Z +C Z +A X +A Z +A X +C Z +C Y +C Z +C Y +A X +C X +A X +A X +A X +C X +A X +A X +C Y +C X +A X +C X +A Z +A X +C Z +C X +B Z +C Z +A X +C Y +C Z +C X +A X +A X +B Y +A X +B X +C X +A X +A X +C X +C Y +A X +A X +A X +C X +C Z +A X +B X +C Y +C Y +A X +C Y +C X +A X +C X +A X +A X +A X +C X +C X +B Z +A X +C X +A X +C Z +A X +C Y +A X +C Z +C Z +C Y +A X +A Z +A X +C X +C Z +A X +C Z +C X +C Z +A X +C Y +A X +C Z +C Y +C X +A X +A Y +B X +A X +A Y +A X +A X +A X +A X +C Z +C Y +B X +A X +C X +A X +C X +A X +A Y +A X +C Z +A Z +C X +A X +A X +A X +C Z +C Z +C Y +C X +A X +C X +C Y +A Z +C X +A X +C Y +C Z +C Z +A X +A X +C Z +C Z +C X +C X +C X +C Z +C Y +C X +B Z +C Z +A X +C Z +A X +A X +C X +C X +C Y +A Y +A X +C X +A X +C X +C X +A X +A X +A Y +C Z +C Y +A X +A X +A X +A X +C X +C Y +A X +A Y +A X +A X +C X +A Z +C Z +C Z +C Z +C Z +A X +C Z +C X +C X +B X +C X +C Z +C X +A Z +C Z +B X +B Z +C Y +A X +B X +A X +A X +A X +C X +C X +A X +C Y +A X +C Y +B Y +C Y +A X +C X +C Y +C Z +C X +A X +A X +C X +B X +C Z +C X +A X +A Z +A X +C Z +C X +B X +A Z +A X +B Z +C Z +A X +C Y +A X +C Z +B X +C X +C X +C Y +A X +A X +A X +C Z +C X +B Z +C Z +B X +B Z +A X +A Z +A X +C X +C X +C Z +C X +C X +B Y +A X +A X +A X +A X +A X +A X +C X +A Z +A Z +C X +C X +A X +B Y +C X +C X +A Z +A X +B X +A X +C X +C Z +C Y +C Z +C Z +B X +C Y +C X +A X +A X +C X +C Y +C Z +A X +C X +A X +B Z +A X +C Y +C X +C X +A X +C Z +C Z +A X +C X +C X +C X +A X +A Z +C X +A X +C Z +A X +C Z +C Z +A X +C Z +A Z +C X +A X +A X +C Z +A X +A X +A X +C X +A X +A X +C Z +C X +C Y +B X +C X +C Y +C X +A X +A Y +A X +A X +A Z +C Z +A X +C X +C X +C X +C X +B Z +A X +B Y +C X +C X +C Y +C X +C Z +C Z +A X +C X +A X +C X +A Z +C Y +B X +A X +C X +C Z +C Y +B X +C Y +A X +C X +A X +A X +A Z +A X +B X +C X +A X +A Y +A X +C X +C Z +A Z +A X +A X +C Z +A X +C X +A X +C X +A X +C Z +C Y +A X +C X +A X +C Z +A Y +B X +C Z +C Z +A X +A X +A Y +A Z +A X +C X +C Y +C Z +A X +C Z +C Z +B X +A X +A X +A X +C Y +A Z +C Z +C Z +A Z +A X +A X +B X +C X +B X +A X +C Z +A Y +C Z +A X +C X +C Z +C X +A X +C X +A X +A X +C Z +A Z +C X +C X +B Z +C Z +A Y +A X +C X +C Z +A X +C Z +C X +C Y +C X +A Y +C Z +C Z +A X +A X +A X +C Z +C Y +C Z +A X +C Z +A X +C X +A X +A Y +A X +A Z +A X +A Y +A X +A X +A X +A Z +A X +C Z +C Z +C Z +C X +A X +A Z +C X +C Z +A X +C X +C Y +A X +C X +A X +C Y +A X +A X +C Z +C X +A X +C Z +A X +A X +C Z +C X +C Z +C Y +A Y +C Z +C X +B X +A X +A X +A Z +A X +A X +C X +C Z +A X +C X +A Z +B X +A Z +C Z +C Z +A X +B X +A X +A Y +A X +A X +C Z +A X +C Y +C Z +C Y +A X +A X +A X +A X +B Z +B Z +A X +C X +C X +A X +C X +C Y +B X +C Y +B X +A X +B Z +C Z +A X +A X +C X +A Z +A X +C X +C Z +A X +C X +C X +C X +C Z +C Y +A X +A X +A X +C Z +C Z +C X +C Z +B X +A X +C Z +C Z +C Y +A X +A X +C Z +A Z +C X +C Z +C Y +C Z +C Z +A X +C Z +C Y +C X +B X +C Z +A Y +C Z +C X +C X +A X +A X +A X +C Z +B Z +A X +A Z +B X +A Z +A Z +C Z +C Z +C X +C Y +C Y +C Z +A Z +C Y +C X +C Y +A Z +B Y +A X +C Y +A X +A X +A Z +C Z +C Z +C Z +C X +C X +C Z +C Z +A X +C X +A Y +A Y +A X +B Z +A X +C X +A X +C X +A X +A X +A X +C X +C Y +C Z +C Z +A X +C Z +A X +C X +C X +C Z +A X +A X +A X +C X +C Z +A X +A X +A X +A X +C Z +B Y +A X +A X +A X +C Y +A X +A X +A Z +C X +A Z +C Z +A Z +C Z +A X +A Z +A X +A X +A X +A X +A Y +C X +C Z +A X +A Z +C X +A Y +C Z +C Y +A X +B X +A Y +C X +A X +C Z +C X +A X +C Z +C X +A X +C X +C X +C Z +A X +A Y +C Y +C Y +A X +A X +A X +A X +A X +C X +A Y +C Z +C Z +C Y +A X +C Z +C Z +A X +C X +C X +C Y +A X +A X +C X +C X +A Z +A X +C Z +A X +C Z +A X +B X +A Z +B X +C Z +C Z +C X +A X +A Z +C X +A X +A X +C X +C Y +C Z +C X +C X +A X +C Z +C Z +C X +B X +C Z +A X +B X +A Z +C X +A Z +A X +A X +C X +A X +C Z +A X +A X +C Z +C Z +C Z +A X +C X +A Y +C Y +A X +A X +A X +A X +C X +C Z +A X +A X +A X +C X +C Z +A X +C Z +A X +A Y +C Y +C X +C X +A X +A X +A X +A Z +A X +C Z +A X +C Y +B Z +B X +A X +C X +C Z +A X +A X +C Z +B X +B X +C X +C Y +C X +B X +A X +A X +C X +A Z +A X +C X +C X +C X +A X +C Z +A Y +A X +C Y +A X +A X +C Z +A Z +A Z +C X +C X +C Y +C Y +C X +C X +C Z +A X +C X +A X +A X +A X +A X +C Y +C Z +A X +C Z +C X +C X +A X +A X +A Z +C Y +C X +A X +C X +A X +A Z +A X +A Z +A X +A X +A X +C X +A Z +A X +C X +C Y +A Z +A X +B X +C X +C Y +C Z +C X +C Y +C X +C X +A X +C Y +B X +A Z +C Z +B Z +C X +A X +C Z +A X +C X +A X +A X +A X +C Z +C Y +B Z +A X +C X +A Y +C Z +A X +A X +A Z +A Z +A Y +C X +C Z +C X +A Z +C X +C Z +C X +B X +A X +C Z +A X +A X +C Z +A Z +C X +C Y +C X +C X +C Y +A X +A X +C X +A Z +C X +C Z +C X +A Z +A X +A Y +A X +A X +B Z +C Z +C Z +A Y +C X +A X +B X +A X +A Z +C Y +C Z +C X +C Z +C Z +C X +C X +A X +C X +A Z +C Z +C Z +C Z +C Y +C X +A X +C Z +A Z +C Z +C Z +A X +C X +A X +C Z +A X +B X +A X +C Z +C X +C X +A X +C Y +A X +C Z +B X +C Z +C X +A X +C X +C X +C Z +A X +A X +C Z +C Z +C X +C Z +C X +A X +A X +C Z +C X +C X +A X +C Z +A Z +C Z +B X +C X +C Y +C X +C Z +A X +B X +C Z +A X +C Z +A Z +C Z +C X +A X +C Z +C Z +A X +A X +C Z +A X +C Y +A Z +C X +C Z +A X +B Z +B X +A X +A Z +A X +A Z +A X +A X +C Y +A X +C Y +C X +C Y +C Y +C X +A X +A Z +A Z +C X +C Z +B X +A X +C Z +A Z +C X +C Z +C Y +A X +A X +C Z +C Z +C Y +A Z +C Z +C Y +A X +C X +A X +C X +C Z +A Z +B Z +A X +A X +A X +C X +C X +A Y +A Z +C X +C Z +A X +B X +A X +A X +C X +C X +B X +A X +B X +C Z +A Z +C Z +A X +C X +C Z +C Y +A Y +A Z +C Y +C Z +A X +A X +C X +A X +C Z +C Y +A X +C Z +A X +A X +B X +A X +A Z +C X +C Y +A Z +C Z +A X +A Z +C X +C Z +C X +C Z +A X +A X +A X +C X +A X +C Z +C X +C X +C X +C X +A X +C X +B Y +A Z +A Z +C Z +C X +A Y +C X +A X +C X +C Z +B Z +C Z +B X +A X +A Z +A X +C X +A X +C Z +C Z +C Z +A X +C Z +A X +C Z +C X +C X +C X +B X +A X +A X +B X +C X +A X +C Z +A Z +C Y +C Z +A Z +B Z +A Z +C Z +C Z +C X +A X +A X +C X +C X +C Y +A Y +A Z +A X +C Z +C Z +C Y +C X +A X +A X +C Y +A Z +C X +C X +C X +A X +C X +C X +A Z +C X +C Y +A Z +C Z +C Y +A Z +C Z +A X +C X +C Y +C X +C X +C Z +C X +C X +C Z +C X +A X +B Y +A X +C X +B Z +C Z +C X +C Z +C Z +A Y +A Y +A X +A Z +C Z +A X +C X +C Z +A Z +A X +A X +A X +B X +A X +B Z +C X +A X +C X +A Z +C X +A X +C Y +A X +C X +C Y +A Z +C Z +C Z +B X +A X +C X +A X +C X +C Y +A X +C Y +A X +B X +C Y +A X +A X +C X +A X +B Y +C Y +C Y +C Y +C X +A Y +C X +C Z +A X +A Z +A X +A X +C Z +A Z +A Z +C X +A X +A X +B X +C X +C Y +C X +B Z +A X +C X +C Y +C X +C Z +C Y +A X +C X +A X +A X +A Y +C Z +C Z +C Z +A X +A X +A Z +A X +A X +A Z +A X +C Y +C Y +A X +A X +A Z +C X +A X +C Z +A Z +C Z +C Y +C Z +A X +C Z +C X +C Z +A X +C Y +C Y +B X +A X +A Z +C X +A X +A X +C Z +A X +C X +C Z +A Z +A Y +A Y +A X +C X +A Y +A X +A X +B Z +A X +C X +C X +C X +A X +C X +C Z +C Z +A Z +C X +C X +C Y +A X +C X +A X +A X +C Y +C X +A X +C Y +C X +C X +A Y +C Z +C X +C X +C Y +C Z +A Y +A X +C Z +C Z +C Z +C X +C Z +A X +A X +A Z +A X +C Y +C X +C Z +A X +A X +C Z +A X +C X +A X +A Y +C X diff --git a/2022/day02_2/src/main/resources/small_input b/2022/day02_2/src/main/resources/small_input new file mode 100644 index 0000000..db60e36 --- /dev/null +++ b/2022/day02_2/src/main/resources/small_input @@ -0,0 +1,3 @@ +A Y +B X +C Z diff --git a/2022/day03_1/.idea/.gitignore b/2022/day03_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day03_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day03_1/.idea/compiler.xml b/2022/day03_1/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day03_1/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day03_1/.idea/gradle.xml b/2022/day03_1/.idea/gradle.xml new file mode 100644 index 0000000..a7087b2 --- /dev/null +++ b/2022/day03_1/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/2022/day03_1/.idea/jarRepositories.xml b/2022/day03_1/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day03_1/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day03_1/.idea/misc.xml b/2022/day03_1/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day03_1/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day03_1/.idea/sonarlint/issuestore/index.pb b/2022/day03_1/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/2022/day03_1/.idea/vcs.xml b/2022/day03_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day03_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day03_1/build.gradle.kts b/2022/day03_1/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day03_1/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day03_1/gradle.properties b/2022/day03_1/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day03_1/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day03_1/gradle/wrapper/gradle-wrapper.jar b/2022/day03_1/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day03_1/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day03_1/gradle/wrapper/gradle-wrapper.properties b/2022/day03_1/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..aa991fc --- /dev/null +++ b/2022/day03_1/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/2022/day03_1/gradlew b/2022/day03_1/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day03_1/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day03_1/gradlew.bat b/2022/day03_1/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day03_1/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day03_1/settings.gradle.kts b/2022/day03_1/settings.gradle.kts new file mode 100644 index 0000000..30cd3ed --- /dev/null +++ b/2022/day03_1/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day03_1" + diff --git a/2022/day03_1/src/main/kotlin/Main.kt b/2022/day03_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..bc4c086 --- /dev/null +++ b/2022/day03_1/src/main/kotlin/Main.kt @@ -0,0 +1,63 @@ +import java.io.File + +data class RuckSack constructor(val contents:CharSequence) + +class Compartment constructor(private val firstCompartment: RuckSack, private val secondCompartment: RuckSack) { + fun getDuplicate():Char { + val hashMap = HashMap() + for(c in firstCompartment.contents) { + val count = hashMap[c] ?: 0 + hashMap[c] = count + 1 + } + + for(c in secondCompartment.contents) { + if(hashMap.containsKey(c)) { + return c + } + } + + return '*' + } +} + +fun main(args: Array) { + println("AOC 2022, Day 3, Part 1 starting!!!") + + val storageCompartment:ArrayList = ArrayList() + + File(args[0]).forEachLine { + processLine(it, storageCompartment) + } + + var totalPriority = 0 + for(compartment in storageCompartment) { + val duplicate = compartment.getDuplicate() + totalPriority += calculatePriority(duplicate) + } + + println("Total priority = $totalPriority") + + println("AOC 2022, Day 3, Part 1 completed!!") +} + +fun calculatePriority(priority:Char):Int { + return if((priority >= 'a') && (priority <= 'z')) { + 1 + calculatePriorityHelper(priority, 'a') + } else { + 27 + calculatePriorityHelper(priority, 'A') + } +} + +fun calculatePriorityHelper(priority: Char, step: Char):Int { + if(priority > step) { + return 1 + calculatePriorityHelper(priority, step.plus(1)) + } + return 0 +} + +fun processLine(line:String, storage:ArrayList) { + val first = line.subSequence(0, line.length / 2) + val second = line.subSequence(line.length /2, line.length) + + storage.add(Compartment(RuckSack(first), RuckSack(second))) +} \ No newline at end of file diff --git a/2022/day03_1/src/main/resources/input b/2022/day03_1/src/main/resources/input new file mode 100644 index 0000000..a30889c --- /dev/null +++ b/2022/day03_1/src/main/resources/input @@ -0,0 +1,300 @@ +hqBqJsqHhHvhHHqlBvlfpHQQwLVzVwtVzjzttjQVSjMjwL +gRTRnCRsFNGbTzLjwcSTMmSz +dGgsRWPGdWgZJqBBqhfpPq +HNCNJHCWJRRLqNJWlfrrrwsmlwGmmf +dddvLdLjdDvjvswlmGwlZQtjrt +dvcpbLVcvNJJHNPHSp +QDprSpLQRLQrQDmQcQFZjbbhZwdRsRFbbBss +gWGGPgNvJlgJzDlNGHCGPNZZgFBbsjbFFBwZwfhdZbZB +lHTlGMHlGCPNvClzGzJHvGcrMcVtLqMLcrrQVcVDrqrm +SrBpJFfldlFNslFJBZwsmwgVGGsCCVmZZD +jLtjvzLQMtWjbbQvDZZwGRJGgwggGZgv +MzqqjznQPqnnjznnctnFlSddPfHflhfBJFNdHd +mPNNGVCRngnSbgNw +WqsqlTssgvqvZWZzhsTzWhScdHtfJJnfbtSJwfczdtSS +sqTvhpqQvWZQLmDpDGMDGrgL +DQRcLQVLbbcbrFPcRtTBBBJnTZrrnmZTrMgJ +slGjjjdlhMfvdMQTvg +jlzNhWHhhWjHlwwwGLDSDtPQVtRzRbSzpp +DzDgfvzfDczfHCHSlgHLCmWG +PrpNPJtpPMBssmmVdmSVVr +PSRMwPnMpBNtNBTnnZwDqzQFfwhjZZqfhh +fzfBwhBJFbCwbwwg +strtgtrPgmPgFRsMdRnZRMFn +mrmLPDvGmmtSLDgmSqvHchhcHQzcQQJHBfBh +NsgwPPDgsPHqsTqqmLbLrDRhmrRVrbVW +lFpGFtfFlvSFplGFzptSGSSlhZbhjhfrmWbhLhmLbCZVZjWr +ccplJQSGcSSpVFvNqqsqPNqPQPTwqd +HFhPNNZGqSZrCDBVZBCB +RJTtwczTzCRVQrRHpR +mfgblfltwgwwmlJgcHNnGhSbFNnFsFjFqG +tSRqNRHpHnMSTqpcmrWWfqfmrCQCrW +lhGDtbgVVgDsDbhfldfwrzrfcdzwcr +vtDDhsgFBTNZFBHS +LcNpLLBNgdmHGmsBCrRBQDDwnwRj +hSWfZVhfPJJhfVWbhzbnQqQnRRRqPvCCrjvjwj +ztJSSJhzzSTJrZSbzzJTfzbZmLmggdmNMFNpmtmMGFFGNpmt +TRdFfLbTnLvZVlZvznQV +pgJGprJNhghhNjjPgPNrhNqqlVVlQVVQqQjfzBfQvZzB +rmGmSwJPwJprrNDbsfMRsdTDcDWHfM +QMpZZTtwMBttJMMbVqPpqLqbVlbqqN +rjCFGrdGRwdDHSnqflPVLqqVNllrfl +DHGDRvhvwTZhJWBQ +LcQCCpLQVhrdcFQCJrmmmwDwvDtJJnnw +TsZqqTzMRqZjfsjTTDjsNJnmnStRSHnnSJmnJSNH +sMMZZbDjZFdbVCFphV +FCcdFFGBsdDrbMNSmSdmQR +tVttHVLhvVgfTTtffNSMQRMZSRmMQNmHSb +gngvvwJtVVTvVvvvfwvJThhCzGcnsCjmCDmscPcGCsGsmz +fsnzRNZswZszPRZSLflPpDhlhvgWHmjWvJjh +bVcCqjbdjbcMdBrddrQphvHHmHWlggpWpppqJJ +FBTdFQGrTjLNsNtL +MSWWgMdgdbWbbfdgsPmddgCmSLZvSFvLQvnLrFNZvZFLlLLl +hjpJjGthjRNRptwJJqVBllnvrrlTTQFZqnTZnn +tjDGHwhHHjwjjJGpwjwjjJpwsdgffmbgMsmbDNcMcdmCPdsm +MlDrrgnTDLlCCmCRFgRSCR +HHhbbNQMccQFSNBmmpJNSJ +MwbMbshsswVbHQsbcVMcrtDllTlLqfTGVzLGrTlT +gSFzqQTpmVpQVpLFLrzJJRthlsQBlPsZsBhZst +rwrNDdbHdBhRhZbsjB +vvvMHwHcwGCwwNfMVSrqffWpSfSFzLmT +RNgMgRCCgCfPNfvNgVQmhPVWWjWjLLdLBj +JhJqqqwGDchsBVbdjldmBLmG +schZzDwTJzFTsctHFMtfftgMttpM +GHHWqWFWfWHqbRWsFZFmqZbhNjNDNppNjrjDcQdbpddhjr +wCLCVPfwgVSnPNrQhnDcjcNpDD +TPgLlggJLVwPVVPPwgTwvtSCFmzGGqzGZsGRqWBGfFRFJFRB +LfFLmGTPHBfpHmzBLdZfBfZTbWWttWSDJtWVDJDtSWJzVCCV +RssRRRhrRwQqMQQwnPngQrwvVSjttjJSjSVtWWCWjbVb +hQPnnRnQgNcQqqQQcsZTNTLpdZZfpZFHNpBp +VTCVVnwfFTvFmTCvWwJHdlhHWBJhJBRWNHgh +ZbSMZbctGtScQSZsSpZpPpplhBhtdJDRDJjhdtlRJRjNRj +rLsbBQSMBGspPGcMPQvnqmwzwmCVLmqVmwTF +GVrrQVHHHQGTllQjPHGrlCQpZZpJFWZFzzjBssDJghzhFZ +NSMmWmtqMWqSNbcctdLcdghpgpppssZgbgzpFzJJFs +cfLqLwMRdtNLMlQrvflWTQPffQ +FjtGflGsbNqjsmjGGGbmqQQQBQBTjdpTpJTWvJBddj +CPrVRMnvvLSRHLnBpwdWTRBQwQzBzR +SnZMZPcHMlqchsvGGb +nnJnswzPCtmZDCpmhphD +rSVVLQQQGQjwpdmdNmpS +VvBcQvGcQgGLBgWrwznfJsncltJsJnssPM +dhbwLStzSGmmmzJJvFgJNvnrgvhv +VTsTsRscRsVBMRVTTsjZVPCnDNvfrPfDvNCfBrPNDJ +scHHQTpJZjHwzLSHHtqHSt +MHmFsBDmGpGTBfmCfWCffhzgvf +wcjwnRLPZRVbtCjtNttGCh +ZLGVJRrnPPPwQwPppqDHFpBFTpqFDr +GzMgVfGRdRVngDjhqcjctrtrzzzs +QbQSHwHSLbWwJJFwJPLPSWTQjrhqtjflThccsclCcscCCmmj +JFbNSbLvHHLQFLvwQJFWSBVgMNGdBBnBMVfddpGngB +sZHNJwMsvHswwvMWqBzhChWPMBzd +bHQQQRDHRcRcDljttBldlPBdggBCqB +QjnDbDjjjncRjbQnfZpvssZNHnppFNpvvp +NdmfPNMHMdNMHcffHBCwwsvsRRllvwlcqjwscw +VLhVGLpLShgvrjwFhjqfls +pppnnQtVpGZVWtzGgVzgSSfnCCDmdPBMDbmmDMmdNMBmWNmm +rrfgCrrMllfnBhBrdCFfWLFmmVFVWQvWwtwV +TmSGSqNzvwwTFVvj +NSGSmNbDzpmSpbHmSJqqlMgdMndcgdccdpgllRRh +bbPtLnLcLJzTjcJbbTcttLcSgwmvWfVvfVvBgfmWVJMJMJMW +ZsDNNGDRsrHzpNRwMlgRlgmMWvffWM +FGzQpZGGLFjnSFbF +DQZVDdWWNBtgWnJCnL +SSHSmbHRFqGrmqJrbbGzjmzCwrvgvwnBwnCvprwvpwwPvv +qFFFSmsRRzzFjcFsSsjmzJzflhlZTTThdhVflZlVDDhMcN +cdvrFddqDtDvqgCDtFtrvvvFSmShPShJVJmMJSJbVBgTlmbM +GzjpHzGHHfQNfJSlPQbJBSTJBM +HWpspsWjNsGRHfpwNszzLfGqnCnZtdvvcZvwqFCcZqMZCv +rhHhDhhDrRNwDRhNRLRqNPHjHSpVpVlljSSMnlHnjS +sVVBsFBJBtBSPSjtjPPZZS +JmddVTzsffcGNwzCqNqR +nQfqFtZWFZnFJWfpGqhDsGLLPLVbrPhr +CzjwMTgBgTNSGLVVDPbjbS +wMCmgNNdgvzGdRQcFGFdfJ +CbqCDnwFpDpCVfBPmPffPfRfpB +svcsjlGJGnlnvjvzgQQgGzsZPhBRcRPhWfBZBhPhWRRhPN +sJngnjSGGTGzgJGrrbCqLHrCLwSFqV +hnRnJrwMHnQRRRwMhRrnJRBLZtBPdPSdtZZjjstsLHBP +pBBzzcbTbzCcFzTvlSCZLCtSvvttdZ +FWmNzBFNDnRqNRDM +lvzlSPRDSpDJmNwNGgFpfsFN +WBHrtrLBbhWHtdrFwFFsjzwfFjsdsF +HWnrHnTWhWTCTzTBnRZqDDDCqZcclRvSJR +qcdVbpcMFQcdMGcMFjjpbCnCGmCnJHDHDGJChzCJCJ +wWwlSfBRgRNBDPJnCgCrgzms +tBTfTRwlwRLNwTRmWtNwQFZtqcjcdcqpbdQMqMdd +jJRzwDdwFdJddcjjFCFvQLvNlBhSBhCC +gMMpbHpmnHpWfnlCSBQCPmPllQSs +nHWHVfTGdTSjZzDT +sCVTsBPltgDSbLvRMMDT +WNrjNmWZwmZwfVLvLRbRNvMp +mrHGrmnjqVzjGqdmCltlhFFllgsHBPCg +wbglgTFRblnMRltJBNrDDWQbtdbN +dqCpcjPLGfHZQBJNGGvQDZ +SPssjVSqPCLpScfCgFRVmTlRwndlRwTR +hWMWMhTTDgWMzGMszQShGWJPCQmPVCNPffPfVJftqNQC +nbnHHwLrnswwPVCPZV +nsRvFHLsvplvrcsSWDDDddjjDlMTjT +HRCnhWZhCddgwRcwhdWZHHQLJzSLsSzjJwSjztsmtzsmLF +VlVVNNVqTlMVbTVVMqvqvrDTjQfFtjstJmzftfzsSbtStJQb +pQvvPpBqNBccPWWhcWWc +glJTndVWCTDDVFvnVndVlCvwmBmqBBwQmwPwmMPggGsPGm +NhcSrhNZHhZzRtHcNRrSMSMSFBMGmsQQGLMPPF +hcpRzbcHjRhRbZRzZRztzRpJVdCdnfCnlFvdDTnJCVDjWd +dqWvjjBdWWqMjdvvMJjWWjMGgcfchhzrhwbrwShwgzSqNb +mmmmsVTlVlsLQmnpsNcfgfwNLgczhcGhzw +RslpsnGGGlWdCZFMMRWR +pfSpZSrdSMVDVVLMMDDZpdgRWMPGqqPGqmqqGGhGHNRN +wwQBwtjvvJlvsnbTbvBRHgPmlqhlqWWHqZZgNm +JnQwJvjTtzTZwJnbzzfCrfLCfdfdddfD +PZcnljZFTVmQdlQh +JCLLqBBCSNCCqzJNzStBpStBmsdhVTdmVWsWmdhfLhWVdfrR +BpMzzqSzppMMqpJqqgzPFcjZjnTjgcjbPjPDPZ +HLHWmqBHHqWbMHFtbgWcdhspPcPchndPpn +ZRVSQZRfVZGRgnfsdhLgLndL +jzJRwJRSJJvSlZQGRVwlSGZDMqmmCCCmtNbCmtCMzFNLbF +fDhlBhhZmQRRfHwLdjHFFWQQjQ +ZMTssVVzvbCqJddsLwwH +TzgTbgGGzztMbbvzvVbGvSPBrlShRrfnNrnBDlNcRDZRZB +bjfqGfvFfcHvRwGFRHjbgQtddlQljWpWnQgdWWll +TSPVVSVwSzSDTDlntDndnlWddt +hTrrNCBCVrCrrVshThHHbZvFGscwbfFGRJcZ +jNhMjcgvMNgWggvttcFtchvPFFzdPPrQrrGGQQszRPQrRG +wSCqCmmppbTwPnGHrQdrGCCD +LlqwGmGScLcVthVt +dGGrWWDqmCnwCCQMQrMbFHbMHsPFgPVZbgFPgg +tLRTBwfvTBJcZFNFZRHSHPVN +zjJLTvjcwDzqqhGD +DzrWszFFrtBBhnhNCClHlnHbSbmlSn +ZLwLcVVZcLVpvRwLgMLpLJgPmmQSNSTNbtTvQmCHQCClCHCt +cfgZJwwVLJZPPVpRwzhzrrfGGBrGtDrBsf +BTsdCQsQnwwdcCqqdCnsFvGFpFBvGzrLLmmzpvfG +pjZjgPVlJVMVtgJSWLPvfFFFbNNmNbvbmL +ggVplgJtHSSggdCHsscChhdnnR +JddZcSlvvGFJNWVWFgQgVtFWhg +nDqsHqCszwjCCPMnfhfBhtdWggfg +bqppHqqHHbPLjLCppbwDdRNvdmcTmlNZGGbTTcNv +lcZDSvztcHHcMSZVHVvMZBqBNNFNhBNTTmssBqBcFB +bbGJQdQPpGfQJQdJfLFhmznhzLLNTFhNhf +JGpWpPJddbPpPwpjbtZSzltDgWDSgvtrVv +lJcNlNjPcmtFzHtHBJFg +VPZdwGGWVrsdPWhWwhzzCzzFppDFMBtttFCr +wshsLVfWTnGswdhwcmRjRmScqTcjlPNq +BsBshRZQQsVdsZQZSdsPDwJDHNNHBztNNFMGGwMF +nSTpLjcvHppzwwNt +jcqncjjvfmgrCfvqrnZbmdmSsdbVWlsmhRdW +FjjqRZjZFZWFqPvNvvPQpmbPDCmt +GSnHSnrScncHhrtncGshVbmTmbpVvppCmpCTmTCmCC +rHfnddwdfctlzFFgwqlj +wBwlBmmhwRVThVBmFHnvHMnfsmFfHq +jzwGSGJNZCCssHfsCPfv +GJbzbZdbwJdtdQphRVWQ +ztFZccVHFWHHLSDBpSBPhhZw +fmjsCmqnNTJnvbTvLRPDlCpBSPBpRShl +JqsGTSNJGqvqvNvttGQQGdFrQctrrF +mNZqjTFrZqrTNTTGSSSbrhrhRFRHcnLCzcCdHcLBdccHLzRC +JDDfJswJDWsvgVgwpWnRBlBzGCnlCLBlcCDl +vVGpfQWJpsPQMVgvppVwgWPJrqSZTrZqhTQTrhjbjqSSjZqt +fMSDzDHzpDDVsStdDgwwFZFrrMPCNngCZP +WmLnbWmvvWTTLWWQWRGQvLvrPFZJcgJFCZNrCgGCFCPNPF +QLhlqhljWvRQbbqlqnfStnHdBqVVfzpq +qWZtSQTSvJJvBfJVBBVFNDNHbbdRVPdpNFRF +fGcwwmCgsLhgwLchbpHdrrrphdPRPh +gMjllmcjwsLMgcwlMnSWzSqjSZJqZqZfjQWv +cdRHPjRFRdFVHGcFfFTHQTHVLSQBsbsqSCLqllBJqqbSqLJC +WwWppWgtNrnzzWDmrrmNvWJClJSSbqLJJCGbsCgJbLLg +MnvWpmwvWnvtGPjVRcHRRHMj +dLMDhdHGrcLTvvvstB +nPqgGGNPqRgRSjgmlWjbbTTPPBvpvpTcswwsTF +NRGmgjRnWgnZJqllmSqjnqSDhQzVrdQHDfDrDJQDMHDJzM +RgmcPmGNQwwNmSRwPPgfmrBlCDlGbvFFvtrCsvlrBB +nfdVnjHdMWnTqflFtbjrllrlsCDl +TZJVMhnfMnVMHnpRRNRzgJRzSzgwPR +nTbsblzlnGllmsNnbDwbcWQWwWBFJBQcWQvPWFJM +HRZRdSRdCdLdRftrHHZfSQBMWJMgMzQPFWMJCFWgvQ +HVzrLrrjRjLGnlTnlDlsjj +RQdTdZhWqlZhTdWTqblhNmTMVnnrQsnnpvgMVMHMgHMrgP +fjSSfjcCzGNBjCjsnpMVpnpzvpzsHp +GGwLGSccwjwLwBcGLGSqZWmmdLZLWThmRNZmWR +ncmBrmfdfcVcfGnQdVWRBRvgqNvDvWqzLRqg +PlpPbSbLFPLpFstsbqRqZMqWZqMWSDRzvq +sjtjHCwJwlHfdfjccmmLLQ +tGMtLHQGWzLHFVQtVfQtMWtbgrZNbdfSbccggrcTjTrfbm +swRChnwqhBCCCmSjcNSdcd +vnlnqDRlsRnJJqswJvGMFVMMdWtpVJFMQQFL +ffcHLzGmfvqqfWfF +rJrrRSPCPMCrPRQMNNWJQjJCnqFVVVTStqVnSBdqppBVtpqd +jNQQPjQMCRQwwQbRQbjMgwbNhwWZHHmzmlchlHHHDcLmWzhD +JzvrRHHJvCRZFPFnPgsQVVQNzQTQDttVsB +GSMjpqdbGNppBtDhPN +MbmqMwGbZPmPHJmv +ggVSVWzCNbbNCbRM +DfVhVsVQcQDmpmQTTQLjPjMjbDGNlbRMlNGG +sftTFJJccnphcfncTsfBvwZvrzgzZzZvBrVnzq +qqlClBNSCNSRQMvdrwFvnBrr +GDfhDtszhhsThpTDzsfpprMrFvQvrnnfvQrwHFbfFH +VtggWhpsmGVTGJWMjWjNjPWjLL +NSnShnjsswSsRPNsrnwcwMHfFwGqbvqCbFfg +LDJtzzmgVVlvqGbzvFfzff +mlJmQQpmJpZpBJJdjBNhrnnRdTTgNN +RtRRvbhDFPHHlhtPhRvPRtqjmzqzzwLjHQHLLLQVmVjq +WNNBBZfgfWnqVQwNqzmQcm +MZGfzSrTTnWrrWsTWnfSGbGllPCbGlJRvlPllCtt +phgcNfqgfpZsjjpdsS +brHHnWPbDPDbTPlDJJvJJPrMVVzRSdFzwdZZzFnsdzzVdVZs +SbStvJMDQgNmmtgg +lzDMDhfFRlfMFTfMGPMbFTlMpBHrmpjjCFjmBmrqBjtCmjjq +VvVswLLHZnJJwdndNsSSNBpCpjqjmNgrmCNtmmqm +nHcZWcSVsScTDlPPlTPb +DFMQSlMDpSpFDtDFccHvmqzvbHZjJmvzmmQH +CSgffrPssdgqRbqzzRqZ +dsdsfGsrBPsTVcMctMVNNhtStW +MDWRDWpgDvWpNptvNMnJCHJHMwHCndJfZn +blcrqTFmmcbhLTTTmlBZbjBJdBfBnCbQBdfn +TzlnhcnzTmhLRvSDsRzDPzWR +nwmmPnnPDjclhhjfFzzzwqbFFNHwVqVq +vSQrbpWCvMWQQWQMLgFJVHqzBzJVNqzBFL +CvCvQtWWQmcbtntPcb +qzvtzCCtLsLLzmQCHqpSsHSmfrnNrTrNWWMNGnWZTMZGBvWn +PglVFJwPhbcghVTBpBnWWhWnTMhB +FgjcJccVpwDcwFgVDsqzddqLqSDSCQQL +PLHsSVGGPvSLTffjMJWJJBjfBL +gNhwgTqDcqwpDqNhFpDFhFWfnndjcMJjMWzzBtntJBnW +DFhhQRRwbCbwRQChppmTHCVGTlslrsvrrSVZ +hHnRfSMmsSVrFvQqrmDPgr +jjcBzjZLpWccJLczBjZjWGwCnNzDvrgPCgQvFggvqrQFnr +jtZGpLwjWBpBWcfMTttfbHRnHTbT +swSHffFTVrJlHFSWrTpMZMPhMNBqBhTvhhqZ +bQbLQGGjQLdRCcQjGZBzpzBZqMBBBVdBqh +RjQDQGmgmVVbVcjjmjgcnWtJfrwsfrtHlwswnfHSFw +bVHbbMFDcbDbcmbbHVRbMRFgzSmdzSSTBtTjBdQTzlSldQjT +nqpqCMwJffqQSzTBQlqd +wvJhnnfrfsJrCNffvspRrPPFMbPMRRPPMZgZHR +FnJZnssHvMdJWJpW +mlDlllGrSGmttwlGvZgrzZNWgggzTzdT +bCltZCthtRcbcFbjFL +JGmHrJwGzzpllRZdzZLRcW +htbPSbVtFbbgjhffgPSfTVSDcHDDDLWscRdsZjdZcRssWc +vhfFbFvVHbtTVgFPhmJBCvBNrqBBrGCqQB +BcNQcvcBchSQNccLLvhTqbJZTrHrrrzzqTZMZMFZ +tpHDsnDRslllCCHtwnpsfjRgrJrVMfMmMrFrzVJFzrVZbZrr +tnDpjCwPLNSPdhPH +qnjvvBwBhSSFPgDQLVVDqgLr +WbszTbHTbsbHJWHLLMVZmJPQDrvmZL +ctlRbtCWWtvlSfjljjhBnBNB +TsnvssDDQlRbzMzjDMqHwq +tSGjZCfFZtCFLtVGWGZFbcqwHbhWdbzbwHbdwbdw +ZGBFJFZVBLjStZPBBZLRvlmsPTvsgrrnrTllvs +PgQdNsQFsdNwWqQBsQrTrTLpbrnTpGngnbTG +hCzzMJVDmfzmBDMCfSfhTMGcnpnTcjGrpjbMGjbL +CVVfvCflSHNHvPdBHW +DwlMjMNjStgmthMghg +PTlpHnJJTcZvTTbHZWZTvpqdHhmLgrgdfrhLLsmshmsLts +vncqTbPqcpCnbCPvccZbDBCGzzNBwjDlVVGFjjVR +QsdGGCztZVRddPgndf +DrNNBbwNHNwlbjFbbCNjNwDWWDPPVfDMgfmVMfnMWmmP +rvJBbbBNcLCtJZQL +NfLlqLhbNPddLPqLhpgHwFFwFHHTwRHWwPFTrT +MSMSCnjBnBjCscjVDVljTvHmmWnrwTrwFTrvTWTT +JCMMBzDMJcZZCjDzSBDNJgdfdQlqlLNdhgGLhp diff --git a/2022/day03_1/src/main/resources/small_input b/2022/day03_1/src/main/resources/small_input new file mode 100644 index 0000000..9919ffa --- /dev/null +++ b/2022/day03_1/src/main/resources/small_input @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw \ No newline at end of file diff --git a/2022/day03_2/.idea/.gitignore b/2022/day03_2/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day03_2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day03_2/.idea/compiler.xml b/2022/day03_2/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day03_2/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day03_2/.idea/gradle.xml b/2022/day03_2/.idea/gradle.xml new file mode 100644 index 0000000..a7087b2 --- /dev/null +++ b/2022/day03_2/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/2022/day03_2/.idea/jarRepositories.xml b/2022/day03_2/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day03_2/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day03_2/.idea/misc.xml b/2022/day03_2/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day03_2/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day03_2/.idea/sonarlint/issuestore/index.pb b/2022/day03_2/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/2022/day03_2/.idea/vcs.xml b/2022/day03_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day03_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day03_2/build.gradle.kts b/2022/day03_2/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day03_2/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day03_2/gradle.properties b/2022/day03_2/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day03_2/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day03_2/gradle/wrapper/gradle-wrapper.jar b/2022/day03_2/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day03_2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day03_2/gradle/wrapper/gradle-wrapper.properties b/2022/day03_2/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..aa991fc --- /dev/null +++ b/2022/day03_2/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/2022/day03_2/gradlew b/2022/day03_2/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day03_2/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day03_2/gradlew.bat b/2022/day03_2/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day03_2/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day03_2/settings.gradle.kts b/2022/day03_2/settings.gradle.kts new file mode 100644 index 0000000..f70ff41 --- /dev/null +++ b/2022/day03_2/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day03_2" + diff --git a/2022/day03_2/src/main/kotlin/Main.kt b/2022/day03_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..cdaebd4 --- /dev/null +++ b/2022/day03_2/src/main/kotlin/Main.kt @@ -0,0 +1,150 @@ +import java.io.File + +data class RuckSack constructor(val contents:CharSequence) + +class Compartment constructor(val firstCompartment: RuckSack, val secondCompartment: RuckSack) + +data class Elf constructor(val compartment: Compartment) + +class ThreeElves { + constructor(firstElf: Elf) { + elves.add(firstElf) + elves.add(Elf(Compartment(RuckSack("***"), RuckSack("***")))) + elves.add(Elf(Compartment(RuckSack("***"), RuckSack("***")))) + } + private val elves = ArrayList() + + private fun getFirstElf():Elf { + return elves[0] + } + + var secondElfSet:Boolean = false + + fun setSecondElf(elf:Elf) { + elves[1] = elf + secondElfSet = true + } + private fun getSecondElf():Elf { + return elves[1] + } + + var thirdElfSet:Boolean = false + + fun setThirdElf(elf:Elf) { + elves[2] = elf + thirdElfSet = true + } + private fun getThirdElf():Elf { + return elves[2] + } + + fun areAllElvesSet():Boolean { + return secondElfSet && thirdElfSet + } + + fun findDuplicate():Char { + val hashSet = HashSet() + for(c in getFirstElf().compartment.firstCompartment.contents) { + hashSet.add(c) + } + for(c in getFirstElf().compartment.secondCompartment.contents) { + hashSet.add(c) + } + + val commonFirstSecond = HashSet() + for(c in getSecondElf().compartment.firstCompartment.contents) { + if(hashSet.contains(c)) { + commonFirstSecond.add(c) + } + } + for(c in getSecondElf().compartment.secondCompartment.contents) { + if(hashSet.contains(c)) { + commonFirstSecond.add(c) + } + } + val commonFirstThird = HashSet() + for(c in getThirdElf().compartment.firstCompartment.contents) { + if(hashSet.contains(c)) { + commonFirstThird.add(c) + } + } + for(c in getThirdElf().compartment.secondCompartment.contents) { + if(hashSet.contains(c)) { + commonFirstThird.add(c) + } + } + + for(c in commonFirstSecond) { + if(commonFirstThird.contains(c)) { + return c + } + } + + return '*' + } +} + +fun main(args: Array) { + println("AOC 2022, Day 3, Part 2 starting!!!") + + val groupOfThreeElves = ArrayList() + + File(args[0]).forEachLine { + processLine(it, groupOfThreeElves) + } + + var totalPriority = 0 + for(groupOfThree in groupOfThreeElves) { +// groupOfThree.getFirstElf().compartment.showBags() +// groupOfThree.getSecondElf().compartment.showBags() +// groupOfThree.getThirdElf().compartment.showBags() + val duplicate = groupOfThree.findDuplicate() + totalPriority += calculatePriority(duplicate) + } + + println("Total priority = $totalPriority") + + println("AOC 2022, Day 3, Part 2 completed!!") +} + +fun processLine(line:String, groups:ArrayList) { + val first = line.subSequence(0, line.length / 2) + val second = line.subSequence(line.length /2, line.length) + val compartment = Compartment(RuckSack(first), RuckSack(second)) + + if(groups.isEmpty()) { + groups.add(ThreeElves(Elf(compartment))) + return + } + + val lastGroup = groups.last() + + if(lastGroup.areAllElvesSet()) { + groups.add(ThreeElves(Elf(compartment))) + return + } + + if (!lastGroup.secondElfSet) { + lastGroup.setSecondElf(Elf(compartment)) + return + } + if (!lastGroup.thirdElfSet) { + lastGroup.setThirdElf(Elf(compartment)) + return + } +} + +fun calculatePriority(priority:Char):Int { + return if((priority >= 'a') && (priority <= 'z')) { + 1 + calculatePriorityHelper(priority, 'a') + } else { + 27 + calculatePriorityHelper(priority, 'A') + } +} + +fun calculatePriorityHelper(priority: Char, step: Char):Int { + if(priority > step) { + return 1 + calculatePriorityHelper(priority, step.plus(1)) + } + return 0 +} \ No newline at end of file diff --git a/2022/day03_2/src/main/resources/input b/2022/day03_2/src/main/resources/input new file mode 100644 index 0000000..a30889c --- /dev/null +++ b/2022/day03_2/src/main/resources/input @@ -0,0 +1,300 @@ +hqBqJsqHhHvhHHqlBvlfpHQQwLVzVwtVzjzttjQVSjMjwL +gRTRnCRsFNGbTzLjwcSTMmSz +dGgsRWPGdWgZJqBBqhfpPq +HNCNJHCWJRRLqNJWlfrrrwsmlwGmmf +dddvLdLjdDvjvswlmGwlZQtjrt +dvcpbLVcvNJJHNPHSp +QDprSpLQRLQrQDmQcQFZjbbhZwdRsRFbbBss +gWGGPgNvJlgJzDlNGHCGPNZZgFBbsjbFFBwZwfhdZbZB +lHTlGMHlGCPNvClzGzJHvGcrMcVtLqMLcrrQVcVDrqrm +SrBpJFfldlFNslFJBZwsmwgVGGsCCVmZZD +jLtjvzLQMtWjbbQvDZZwGRJGgwggGZgv +MzqqjznQPqnnjznnctnFlSddPfHflhfBJFNdHd +mPNNGVCRngnSbgNw +WqsqlTssgvqvZWZzhsTzWhScdHtfJJnfbtSJwfczdtSS +sqTvhpqQvWZQLmDpDGMDGrgL +DQRcLQVLbbcbrFPcRtTBBBJnTZrrnmZTrMgJ +slGjjjdlhMfvdMQTvg +jlzNhWHhhWjHlwwwGLDSDtPQVtRzRbSzpp +DzDgfvzfDczfHCHSlgHLCmWG +PrpNPJtpPMBssmmVdmSVVr +PSRMwPnMpBNtNBTnnZwDqzQFfwhjZZqfhh +fzfBwhBJFbCwbwwg +strtgtrPgmPgFRsMdRnZRMFn +mrmLPDvGmmtSLDgmSqvHchhcHQzcQQJHBfBh +NsgwPPDgsPHqsTqqmLbLrDRhmrRVrbVW +lFpGFtfFlvSFplGFzptSGSSlhZbhjhfrmWbhLhmLbCZVZjWr +ccplJQSGcSSpVFvNqqsqPNqPQPTwqd +HFhPNNZGqSZrCDBVZBCB +RJTtwczTzCRVQrRHpR +mfgblfltwgwwmlJgcHNnGhSbFNnFsFjFqG +tSRqNRHpHnMSTqpcmrWWfqfmrCQCrW +lhGDtbgVVgDsDbhfldfwrzrfcdzwcr +vtDDhsgFBTNZFBHS +LcNpLLBNgdmHGmsBCrRBQDDwnwRj +hSWfZVhfPJJhfVWbhzbnQqQnRRRqPvCCrjvjwj +ztJSSJhzzSTJrZSbzzJTfzbZmLmggdmNMFNpmtmMGFFGNpmt +TRdFfLbTnLvZVlZvznQV +pgJGprJNhghhNjjPgPNrhNqqlVVlQVVQqQjfzBfQvZzB +rmGmSwJPwJprrNDbsfMRsdTDcDWHfM +QMpZZTtwMBttJMMbVqPpqLqbVlbqqN +rjCFGrdGRwdDHSnqflPVLqqVNllrfl +DHGDRvhvwTZhJWBQ +LcQCCpLQVhrdcFQCJrmmmwDwvDtJJnnw +TsZqqTzMRqZjfsjTTDjsNJnmnStRSHnnSJmnJSNH +sMMZZbDjZFdbVCFphV +FCcdFFGBsdDrbMNSmSdmQR +tVttHVLhvVgfTTtffNSMQRMZSRmMQNmHSb +gngvvwJtVVTvVvvvfwvJThhCzGcnsCjmCDmscPcGCsGsmz +fsnzRNZswZszPRZSLflPpDhlhvgWHmjWvJjh +bVcCqjbdjbcMdBrddrQphvHHmHWlggpWpppqJJ +FBTdFQGrTjLNsNtL +MSWWgMdgdbWbbfdgsPmddgCmSLZvSFvLQvnLrFNZvZFLlLLl +hjpJjGthjRNRptwJJqVBllnvrrlTTQFZqnTZnn +tjDGHwhHHjwjjJGpwjwjjJpwsdgffmbgMsmbDNcMcdmCPdsm +MlDrrgnTDLlCCmCRFgRSCR +HHhbbNQMccQFSNBmmpJNSJ +MwbMbshsswVbHQsbcVMcrtDllTlLqfTGVzLGrTlT +gSFzqQTpmVpQVpLFLrzJJRthlsQBlPsZsBhZst +rwrNDdbHdBhRhZbsjB +vvvMHwHcwGCwwNfMVSrqffWpSfSFzLmT +RNgMgRCCgCfPNfvNgVQmhPVWWjWjLLdLBj +JhJqqqwGDchsBVbdjldmBLmG +schZzDwTJzFTsctHFMtfftgMttpM +GHHWqWFWfWHqbRWsFZFmqZbhNjNDNppNjrjDcQdbpddhjr +wCLCVPfwgVSnPNrQhnDcjcNpDD +TPgLlggJLVwPVVPPwgTwvtSCFmzGGqzGZsGRqWBGfFRFJFRB +LfFLmGTPHBfpHmzBLdZfBfZTbWWttWSDJtWVDJDtSWJzVCCV +RssRRRhrRwQqMQQwnPngQrwvVSjttjJSjSVtWWCWjbVb +hQPnnRnQgNcQqqQQcsZTNTLpdZZfpZFHNpBp +VTCVVnwfFTvFmTCvWwJHdlhHWBJhJBRWNHgh +ZbSMZbctGtScQSZsSpZpPpplhBhtdJDRDJjhdtlRJRjNRj +rLsbBQSMBGspPGcMPQvnqmwzwmCVLmqVmwTF +GVrrQVHHHQGTllQjPHGrlCQpZZpJFWZFzzjBssDJghzhFZ +NSMmWmtqMWqSNbcctdLcdghpgpppssZgbgzpFzJJFs +cfLqLwMRdtNLMlQrvflWTQPffQ +FjtGflGsbNqjsmjGGGbmqQQQBQBTjdpTpJTWvJBddj +CPrVRMnvvLSRHLnBpwdWTRBQwQzBzR +SnZMZPcHMlqchsvGGb +nnJnswzPCtmZDCpmhphD +rSVVLQQQGQjwpdmdNmpS +VvBcQvGcQgGLBgWrwznfJsncltJsJnssPM +dhbwLStzSGmmmzJJvFgJNvnrgvhv +VTsTsRscRsVBMRVTTsjZVPCnDNvfrPfDvNCfBrPNDJ +scHHQTpJZjHwzLSHHtqHSt +MHmFsBDmGpGTBfmCfWCffhzgvf +wcjwnRLPZRVbtCjtNttGCh +ZLGVJRrnPPPwQwPppqDHFpBFTpqFDr +GzMgVfGRdRVngDjhqcjctrtrzzzs +QbQSHwHSLbWwJJFwJPLPSWTQjrhqtjflThccsclCcscCCmmj +JFbNSbLvHHLQFLvwQJFWSBVgMNGdBBnBMVfddpGngB +sZHNJwMsvHswwvMWqBzhChWPMBzd +bHQQQRDHRcRcDljttBldlPBdggBCqB +QjnDbDjjjncRjbQnfZpvssZNHnppFNpvvp +NdmfPNMHMdNMHcffHBCwwsvsRRllvwlcqjwscw +VLhVGLpLShgvrjwFhjqfls +pppnnQtVpGZVWtzGgVzgSSfnCCDmdPBMDbmmDMmdNMBmWNmm +rrfgCrrMllfnBhBrdCFfWLFmmVFVWQvWwtwV +TmSGSqNzvwwTFVvj +NSGSmNbDzpmSpbHmSJqqlMgdMndcgdccdpgllRRh +bbPtLnLcLJzTjcJbbTcttLcSgwmvWfVvfVvBgfmWVJMJMJMW +ZsDNNGDRsrHzpNRwMlgRlgmMWvffWM +FGzQpZGGLFjnSFbF +DQZVDdWWNBtgWnJCnL +SSHSmbHRFqGrmqJrbbGzjmzCwrvgvwnBwnCvprwvpwwPvv +qFFFSmsRRzzFjcFsSsjmzJzflhlZTTThdhVflZlVDDhMcN +cdvrFddqDtDvqgCDtFtrvvvFSmShPShJVJmMJSJbVBgTlmbM +GzjpHzGHHfQNfJSlPQbJBSTJBM +HWpspsWjNsGRHfpwNszzLfGqnCnZtdvvcZvwqFCcZqMZCv +rhHhDhhDrRNwDRhNRLRqNPHjHSpVpVlljSSMnlHnjS +sVVBsFBJBtBSPSjtjPPZZS +JmddVTzsffcGNwzCqNqR +nQfqFtZWFZnFJWfpGqhDsGLLPLVbrPhr +CzjwMTgBgTNSGLVVDPbjbS +wMCmgNNdgvzGdRQcFGFdfJ +CbqCDnwFpDpCVfBPmPffPfRfpB +svcsjlGJGnlnvjvzgQQgGzsZPhBRcRPhWfBZBhPhWRRhPN +sJngnjSGGTGzgJGrrbCqLHrCLwSFqV +hnRnJrwMHnQRRRwMhRrnJRBLZtBPdPSdtZZjjstsLHBP +pBBzzcbTbzCcFzTvlSCZLCtSvvttdZ +FWmNzBFNDnRqNRDM +lvzlSPRDSpDJmNwNGgFpfsFN +WBHrtrLBbhWHtdrFwFFsjzwfFjsdsF +HWnrHnTWhWTCTzTBnRZqDDDCqZcclRvSJR +qcdVbpcMFQcdMGcMFjjpbCnCGmCnJHDHDGJChzCJCJ +wWwlSfBRgRNBDPJnCgCrgzms +tBTfTRwlwRLNwTRmWtNwQFZtqcjcdcqpbdQMqMdd +jJRzwDdwFdJddcjjFCFvQLvNlBhSBhCC +gMMpbHpmnHpWfnlCSBQCPmPllQSs +nHWHVfTGdTSjZzDT +sCVTsBPltgDSbLvRMMDT +WNrjNmWZwmZwfVLvLRbRNvMp +mrHGrmnjqVzjGqdmCltlhFFllgsHBPCg +wbglgTFRblnMRltJBNrDDWQbtdbN +dqCpcjPLGfHZQBJNGGvQDZ +SPssjVSqPCLpScfCgFRVmTlRwndlRwTR +hWMWMhTTDgWMzGMszQShGWJPCQmPVCNPffPfVJftqNQC +nbnHHwLrnswwPVCPZV +nsRvFHLsvplvrcsSWDDDddjjDlMTjT +HRCnhWZhCddgwRcwhdWZHHQLJzSLsSzjJwSjztsmtzsmLF +VlVVNNVqTlMVbTVVMqvqvrDTjQfFtjstJmzftfzsSbtStJQb +pQvvPpBqNBccPWWhcWWc +glJTndVWCTDDVFvnVndVlCvwmBmqBBwQmwPwmMPggGsPGm +NhcSrhNZHhZzRtHcNRrSMSMSFBMGmsQQGLMPPF +hcpRzbcHjRhRbZRzZRztzRpJVdCdnfCnlFvdDTnJCVDjWd +dqWvjjBdWWqMjdvvMJjWWjMGgcfchhzrhwbrwShwgzSqNb +mmmmsVTlVlsLQmnpsNcfgfwNLgczhcGhzw +RslpsnGGGlWdCZFMMRWR +pfSpZSrdSMVDVVLMMDDZpdgRWMPGqqPGqmqqGGhGHNRN +wwQBwtjvvJlvsnbTbvBRHgPmlqhlqWWHqZZgNm +JnQwJvjTtzTZwJnbzzfCrfLCfdfdddfD +PZcnljZFTVmQdlQh +JCLLqBBCSNCCqzJNzStBpStBmsdhVTdmVWsWmdhfLhWVdfrR +BpMzzqSzppMMqpJqqgzPFcjZjnTjgcjbPjPDPZ +HLHWmqBHHqWbMHFtbgWcdhspPcPchndPpn +ZRVSQZRfVZGRgnfsdhLgLndL +jzJRwJRSJJvSlZQGRVwlSGZDMqmmCCCmtNbCmtCMzFNLbF +fDhlBhhZmQRRfHwLdjHFFWQQjQ +ZMTssVVzvbCqJddsLwwH +TzgTbgGGzztMbbvzvVbGvSPBrlShRrfnNrnBDlNcRDZRZB +bjfqGfvFfcHvRwGFRHjbgQtddlQljWpWnQgdWWll +TSPVVSVwSzSDTDlntDndnlWddt +hTrrNCBCVrCrrVshThHHbZvFGscwbfFGRJcZ +jNhMjcgvMNgWggvttcFtchvPFFzdPPrQrrGGQQszRPQrRG +wSCqCmmppbTwPnGHrQdrGCCD +LlqwGmGScLcVthVt +dGGrWWDqmCnwCCQMQrMbFHbMHsPFgPVZbgFPgg +tLRTBwfvTBJcZFNFZRHSHPVN +zjJLTvjcwDzqqhGD +DzrWszFFrtBBhnhNCClHlnHbSbmlSn +ZLwLcVVZcLVpvRwLgMLpLJgPmmQSNSTNbtTvQmCHQCClCHCt +cfgZJwwVLJZPPVpRwzhzrrfGGBrGtDrBsf +BTsdCQsQnwwdcCqqdCnsFvGFpFBvGzrLLmmzpvfG +pjZjgPVlJVMVtgJSWLPvfFFFbNNmNbvbmL +ggVplgJtHSSggdCHsscChhdnnR +JddZcSlvvGFJNWVWFgQgVtFWhg +nDqsHqCszwjCCPMnfhfBhtdWggfg +bqppHqqHHbPLjLCppbwDdRNvdmcTmlNZGGbTTcNv +lcZDSvztcHHcMSZVHVvMZBqBNNFNhBNTTmssBqBcFB +bbGJQdQPpGfQJQdJfLFhmznhzLLNTFhNhf +JGpWpPJddbPpPwpjbtZSzltDgWDSgvtrVv +lJcNlNjPcmtFzHtHBJFg +VPZdwGGWVrsdPWhWwhzzCzzFppDFMBtttFCr +wshsLVfWTnGswdhwcmRjRmScqTcjlPNq +BsBshRZQQsVdsZQZSdsPDwJDHNNHBztNNFMGGwMF +nSTpLjcvHppzwwNt +jcqncjjvfmgrCfvqrnZbmdmSsdbVWlsmhRdW +FjjqRZjZFZWFqPvNvvPQpmbPDCmt +GSnHSnrScncHhrtncGshVbmTmbpVvppCmpCTmTCmCC +rHfnddwdfctlzFFgwqlj +wBwlBmmhwRVThVBmFHnvHMnfsmFfHq +jzwGSGJNZCCssHfsCPfv +GJbzbZdbwJdtdQphRVWQ +ztFZccVHFWHHLSDBpSBPhhZw +fmjsCmqnNTJnvbTvLRPDlCpBSPBpRShl +JqsGTSNJGqvqvNvttGQQGdFrQctrrF +mNZqjTFrZqrTNTTGSSSbrhrhRFRHcnLCzcCdHcLBdccHLzRC +JDDfJswJDWsvgVgwpWnRBlBzGCnlCLBlcCDl +vVGpfQWJpsPQMVgvppVwgWPJrqSZTrZqhTQTrhjbjqSSjZqt +fMSDzDHzpDDVsStdDgwwFZFrrMPCNngCZP +WmLnbWmvvWTTLWWQWRGQvLvrPFZJcgJFCZNrCgGCFCPNPF +QLhlqhljWvRQbbqlqnfStnHdBqVVfzpq +qWZtSQTSvJJvBfJVBBVFNDNHbbdRVPdpNFRF +fGcwwmCgsLhgwLchbpHdrrrphdPRPh +gMjllmcjwsLMgcwlMnSWzSqjSZJqZqZfjQWv +cdRHPjRFRdFVHGcFfFTHQTHVLSQBsbsqSCLqllBJqqbSqLJC +WwWppWgtNrnzzWDmrrmNvWJClJSSbqLJJCGbsCgJbLLg +MnvWpmwvWnvtGPjVRcHRRHMj +dLMDhdHGrcLTvvvstB +nPqgGGNPqRgRSjgmlWjbbTTPPBvpvpTcswwsTF +NRGmgjRnWgnZJqllmSqjnqSDhQzVrdQHDfDrDJQDMHDJzM +RgmcPmGNQwwNmSRwPPgfmrBlCDlGbvFFvtrCsvlrBB +nfdVnjHdMWnTqflFtbjrllrlsCDl +TZJVMhnfMnVMHnpRRNRzgJRzSzgwPR +nTbsblzlnGllmsNnbDwbcWQWwWBFJBQcWQvPWFJM +HRZRdSRdCdLdRftrHHZfSQBMWJMgMzQPFWMJCFWgvQ +HVzrLrrjRjLGnlTnlDlsjj +RQdTdZhWqlZhTdWTqblhNmTMVnnrQsnnpvgMVMHMgHMrgP +fjSSfjcCzGNBjCjsnpMVpnpzvpzsHp +GGwLGSccwjwLwBcGLGSqZWmmdLZLWThmRNZmWR +ncmBrmfdfcVcfGnQdVWRBRvgqNvDvWqzLRqg +PlpPbSbLFPLpFstsbqRqZMqWZqMWSDRzvq +sjtjHCwJwlHfdfjccmmLLQ +tGMtLHQGWzLHFVQtVfQtMWtbgrZNbdfSbccggrcTjTrfbm +swRChnwqhBCCCmSjcNSdcd +vnlnqDRlsRnJJqswJvGMFVMMdWtpVJFMQQFL +ffcHLzGmfvqqfWfF +rJrrRSPCPMCrPRQMNNWJQjJCnqFVVVTStqVnSBdqppBVtpqd +jNQQPjQMCRQwwQbRQbjMgwbNhwWZHHmzmlchlHHHDcLmWzhD +JzvrRHHJvCRZFPFnPgsQVVQNzQTQDttVsB +GSMjpqdbGNppBtDhPN +MbmqMwGbZPmPHJmv +ggVSVWzCNbbNCbRM +DfVhVsVQcQDmpmQTTQLjPjMjbDGNlbRMlNGG +sftTFJJccnphcfncTsfBvwZvrzgzZzZvBrVnzq +qqlClBNSCNSRQMvdrwFvnBrr +GDfhDtszhhsThpTDzsfpprMrFvQvrnnfvQrwHFbfFH +VtggWhpsmGVTGJWMjWjNjPWjLL +NSnShnjsswSsRPNsrnwcwMHfFwGqbvqCbFfg +LDJtzzmgVVlvqGbzvFfzff +mlJmQQpmJpZpBJJdjBNhrnnRdTTgNN +RtRRvbhDFPHHlhtPhRvPRtqjmzqzzwLjHQHLLLQVmVjq +WNNBBZfgfWnqVQwNqzmQcm +MZGfzSrTTnWrrWsTWnfSGbGllPCbGlJRvlPllCtt +phgcNfqgfpZsjjpdsS +brHHnWPbDPDbTPlDJJvJJPrMVVzRSdFzwdZZzFnsdzzVdVZs +SbStvJMDQgNmmtgg +lzDMDhfFRlfMFTfMGPMbFTlMpBHrmpjjCFjmBmrqBjtCmjjq +VvVswLLHZnJJwdndNsSSNBpCpjqjmNgrmCNtmmqm +nHcZWcSVsScTDlPPlTPb +DFMQSlMDpSpFDtDFccHvmqzvbHZjJmvzmmQH +CSgffrPssdgqRbqzzRqZ +dsdsfGsrBPsTVcMctMVNNhtStW +MDWRDWpgDvWpNptvNMnJCHJHMwHCndJfZn +blcrqTFmmcbhLTTTmlBZbjBJdBfBnCbQBdfn +TzlnhcnzTmhLRvSDsRzDPzWR +nwmmPnnPDjclhhjfFzzzwqbFFNHwVqVq +vSQrbpWCvMWQQWQMLgFJVHqzBzJVNqzBFL +CvCvQtWWQmcbtntPcb +qzvtzCCtLsLLzmQCHqpSsHSmfrnNrTrNWWMNGnWZTMZGBvWn +PglVFJwPhbcghVTBpBnWWhWnTMhB +FgjcJccVpwDcwFgVDsqzddqLqSDSCQQL +PLHsSVGGPvSLTffjMJWJJBjfBL +gNhwgTqDcqwpDqNhFpDFhFWfnndjcMJjMWzzBtntJBnW +DFhhQRRwbCbwRQChppmTHCVGTlslrsvrrSVZ +hHnRfSMmsSVrFvQqrmDPgr +jjcBzjZLpWccJLczBjZjWGwCnNzDvrgPCgQvFggvqrQFnr +jtZGpLwjWBpBWcfMTttfbHRnHTbT +swSHffFTVrJlHFSWrTpMZMPhMNBqBhTvhhqZ +bQbLQGGjQLdRCcQjGZBzpzBZqMBBBVdBqh +RjQDQGmgmVVbVcjjmjgcnWtJfrwsfrtHlwswnfHSFw +bVHbbMFDcbDbcmbbHVRbMRFgzSmdzSSTBtTjBdQTzlSldQjT +nqpqCMwJffqQSzTBQlqd +wvJhnnfrfsJrCNffvspRrPPFMbPMRRPPMZgZHR +FnJZnssHvMdJWJpW +mlDlllGrSGmttwlGvZgrzZNWgggzTzdT +bCltZCthtRcbcFbjFL +JGmHrJwGzzpllRZdzZLRcW +htbPSbVtFbbgjhffgPSfTVSDcHDDDLWscRdsZjdZcRssWc +vhfFbFvVHbtTVgFPhmJBCvBNrqBBrGCqQB +BcNQcvcBchSQNccLLvhTqbJZTrHrrrzzqTZMZMFZ +tpHDsnDRslllCCHtwnpsfjRgrJrVMfMmMrFrzVJFzrVZbZrr +tnDpjCwPLNSPdhPH +qnjvvBwBhSSFPgDQLVVDqgLr +WbszTbHTbsbHJWHLLMVZmJPQDrvmZL +ctlRbtCWWtvlSfjljjhBnBNB +TsnvssDDQlRbzMzjDMqHwq +tSGjZCfFZtCFLtVGWGZFbcqwHbhWdbzbwHbdwbdw +ZGBFJFZVBLjStZPBBZLRvlmsPTvsgrrnrTllvs +PgQdNsQFsdNwWqQBsQrTrTLpbrnTpGngnbTG +hCzzMJVDmfzmBDMCfSfhTMGcnpnTcjGrpjbMGjbL +CVVfvCflSHNHvPdBHW +DwlMjMNjStgmthMghg +PTlpHnJJTcZvTTbHZWZTvpqdHhmLgrgdfrhLLsmshmsLts +vncqTbPqcpCnbCPvccZbDBCGzzNBwjDlVVGFjjVR +QsdGGCztZVRddPgndf +DrNNBbwNHNwlbjFbbCNjNwDWWDPPVfDMgfmVMfnMWmmP +rvJBbbBNcLCtJZQL +NfLlqLhbNPddLPqLhpgHwFFwFHHTwRHWwPFTrT +MSMSCnjBnBjCscjVDVljTvHmmWnrwTrwFTrvTWTT +JCMMBzDMJcZZCjDzSBDNJgdfdQlqlLNdhgGLhp diff --git a/2022/day03_2/src/main/resources/small_input b/2022/day03_2/src/main/resources/small_input new file mode 100644 index 0000000..9919ffa --- /dev/null +++ b/2022/day03_2/src/main/resources/small_input @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw \ No newline at end of file diff --git a/2022/day04_1/.idea/.gitignore b/2022/day04_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day04_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day04_1/.idea/compiler.xml b/2022/day04_1/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day04_1/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day04_1/.idea/gradle.xml b/2022/day04_1/.idea/gradle.xml new file mode 100644 index 0000000..5404067 --- /dev/null +++ b/2022/day04_1/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day04_1/.idea/jarRepositories.xml b/2022/day04_1/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day04_1/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day04_1/.idea/misc.xml b/2022/day04_1/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day04_1/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day04_1/.idea/vcs.xml b/2022/day04_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day04_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day04_1/build.gradle.kts b/2022/day04_1/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day04_1/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day04_1/gradle.properties b/2022/day04_1/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day04_1/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day04_1/gradle/wrapper/gradle-wrapper.jar b/2022/day04_1/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day04_1/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day04_1/gradle/wrapper/gradle-wrapper.properties b/2022/day04_1/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..aa991fc --- /dev/null +++ b/2022/day04_1/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/2022/day04_1/gradlew b/2022/day04_1/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day04_1/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day04_1/gradlew.bat b/2022/day04_1/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day04_1/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day04_1/settings.gradle.kts b/2022/day04_1/settings.gradle.kts new file mode 100644 index 0000000..b5a8038 --- /dev/null +++ b/2022/day04_1/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day04_1" + diff --git a/2022/day04_1/src/main/kotlin/Main.kt b/2022/day04_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..088723c --- /dev/null +++ b/2022/day04_1/src/main/kotlin/Main.kt @@ -0,0 +1,46 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 4, Part 1 starting!!!") + + val allElfTeams = ArrayList() + + File(args[0]).forEachLine { + processLine(it, allElfTeams) + } + + val overlapCount = allElfTeams.stream().filter { it.hasOverlap() }.count() + + println("The overlap count is: $overlapCount") + + println("AOC 2022, Day 4, Part 1 completed!!") +} + +fun processLine(line:String, allElves:ArrayList) { + val splitByElf = line.split(',') + val firstSpan = splitByElf[0].split('-') + val secondSpan = splitByElf[1].split('-') + + val elfTeam = ElfTeam( + ElfAssignment(firstSpan[0].toInt(), firstSpan[1].toInt()), + ElfAssignment(secondSpan[0].toInt(), secondSpan[1].toInt()) + ) + allElves.add(elfTeam) +} + +class ElfTeam constructor(private var firstElfAssignment:ElfAssignment, private var secondElfAssignment:ElfAssignment){ + + fun hasOverlap():Boolean { + if((firstElfAssignment.startID <= secondElfAssignment.startID) && (firstElfAssignment.endID >= secondElfAssignment.endID)) { + return true + } + + if((secondElfAssignment.startID <= firstElfAssignment.startID) && (secondElfAssignment.endID >= firstElfAssignment.endID)){ + return true + } + + return false + } +} + +data class ElfAssignment constructor(val startID:Int, val endID:Int) \ No newline at end of file diff --git a/2022/day04_1/src/main/resources/input b/2022/day04_1/src/main/resources/input new file mode 100644 index 0000000..eca0084 --- /dev/null +++ b/2022/day04_1/src/main/resources/input @@ -0,0 +1,1000 @@ +28-88,85-88 +9-70,18-18 +76-90,53-89 +17-86,11-17 +8-8,8-82 +16-85,15-95 +20-76,19-20 +56-57,57-66 +95-99,1-96 +14-17,17-67 +95-99,32-98 +30-99,29-98 +12-95,11-94 +3-82,1-72 +4-88,88-88 +2-10,11-59 +8-16,8-16 +22-95,23-94 +46-51,78-99 +61-99,62-94 +30-72,26-73 +6-93,2-92 +16-93,17-96 +1-99,2-88 +23-89,88-93 +30-73,3-73 +9-75,75-76 +75-97,70-99 +4-23,22-23 +5-94,4-4 +16-48,15-22 +10-62,61-97 +34-82,81-87 +16-98,15-99 +16-22,17-22 +20-40,21-58 +67-86,22-87 +6-73,6-33 +27-73,40-55 +57-98,58-97 +94-95,14-80 +16-90,91-91 +2-89,5-89 +17-95,96-96 +46-48,19-47 +50-59,51-60 +45-98,44-97 +99-99,6-97 +3-29,1-29 +26-48,25-49 +10-17,19-57 +28-57,28-56 +79-96,80-97 +5-78,4-25 +35-84,35-84 +24-99,20-98 +80-80,53-79 +88-97,12-88 +9-20,9-72 +75-78,35-54 +11-29,28-91 +48-74,49-75 +56-56,56-98 +41-69,33-42 +6-40,6-40 +49-80,49-79 +12-29,18-70 +19-20,13-80 +96-96,15-95 +5-99,4-4 +47-47,41-46 +53-82,65-85 +88-90,89-90 +12-12,12-88 +52-68,51-67 +1-80,2-81 +75-81,70-76 +35-58,35-57 +19-91,18-19 +18-73,72-74 +9-13,8-10 +5-40,35-37 +43-71,70-71 +24-24,25-43 +60-92,35-60 +43-52,47-53 +8-97,97-99 +57-89,57-89 +69-70,31-69 +48-49,48-79 +5-13,14-97 +9-95,9-83 +80-80,79-83 +30-77,29-78 +67-75,67-76 +20-67,21-87 +22-99,74-99 +12-12,11-96 +26-61,25-67 +19-48,47-91 +4-88,81-89 +75-96,74-97 +37-38,37-75 +3-3,4-76 +7-87,7-8 +1-99,2-99 +11-84,83-84 +71-95,69-95 +92-94,2-93 +7-95,21-95 +28-45,27-46 +16-24,16-63 +62-72,68-71 +36-96,90-98 +14-95,94-99 +26-67,25-55 +21-73,21-90 +35-44,34-43 +48-65,48-65 +80-89,80-99 +3-45,44-44 +27-86,67-85 +4-58,4-58 +12-38,11-39 +61-83,82-83 +4-86,4-85 +40-58,10-41 +8-9,8-98 +70-71,12-70 +40-40,40-78 +4-38,17-39 +5-23,22-94 +43-82,47-83 +32-74,86-96 +5-91,90-97 +10-93,11-86 +82-83,44-82 +61-69,57-68 +31-95,30-32 +42-59,42-98 +11-91,9-92 +42-81,19-63 +71-74,72-87 +88-89,6-88 +83-83,21-75 +50-61,59-62 +95-98,25-57 +13-17,16-87 +4-24,3-23 +4-56,3-5 +51-86,50-87 +49-55,30-56 +8-86,8-85 +3-99,3-3 +10-16,10-19 +6-96,5-95 +1-82,17-69 +35-62,35-55 +32-82,83-83 +9-76,75-75 +1-2,3-99 +86-94,93-99 +41-89,47-89 +2-60,3-61 +21-27,18-29 +5-6,6-54 +13-99,13-76 +71-71,34-70 +29-77,29-77 +7-83,6-64 +22-84,12-21 +93-97,15-94 +94-94,7-89 +24-94,32-99 +31-67,43-67 +46-61,46-60 +11-61,58-60 +5-58,5-5 +30-97,30-97 +65-83,82-83 +96-99,3-97 +11-97,6-12 +38-86,39-87 +24-24,24-66 +98-98,43-99 +5-32,29-33 +22-60,22-60 +9-72,71-71 +4-6,5-86 +27-30,31-94 +47-93,48-94 +1-2,5-91 +14-87,87-87 +26-75,25-96 +9-93,13-70 +6-10,9-95 +11-14,13-87 +69-71,2-69 +89-97,77-96 +5-16,4-14 +31-99,31-99 +30-39,33-88 +16-96,10-99 +20-74,19-73 +71-89,17-90 +50-51,26-50 +50-97,51-98 +4-84,4-84 +71-79,60-96 +39-83,81-82 +87-88,10-88 +93-99,68-99 +22-98,23-89 +12-96,13-97 +12-85,13-83 +3-97,3-98 +30-52,29-52 +11-96,97-97 +76-96,45-91 +22-97,23-98 +1-97,96-96 +4-83,5-84 +7-61,60-87 +62-66,37-61 +83-87,54-93 +40-74,7-40 +56-62,48-63 +88-94,57-89 +91-94,58-75 +1-88,87-87 +33-35,26-38 +9-10,9-94 +13-30,29-97 +95-95,23-95 +5-54,54-61 +16-73,72-73 +28-99,29-29 +32-91,33-90 +17-73,18-72 +20-34,13-20 +7-74,8-8 +43-58,42-59 +35-93,96-98 +31-71,62-89 +7-86,6-87 +37-78,38-79 +10-88,9-89 +5-94,20-94 +82-91,83-99 +14-34,4-14 +13-13,12-72 +1-98,16-98 +6-33,33-72 +35-83,36-36 +95-98,34-96 +23-23,22-68 +37-94,37-94 +42-97,96-99 +11-78,2-5 +23-88,87-87 +42-78,41-77 +58-74,58-78 +15-97,15-16 +3-11,5-83 +91-92,47-92 +63-96,62-99 +40-72,9-71 +64-89,37-69 +53-99,98-98 +28-33,26-34 +89-97,14-95 +16-93,92-97 +5-53,52-79 +52-52,53-96 +25-32,26-31 +35-73,35-74 +10-91,4-13 +2-28,5-28 +87-88,22-88 +31-76,32-75 +82-84,7-83 +38-61,60-60 +3-17,2-18 +74-93,4-94 +4-72,18-71 +69-71,19-70 +26-94,4-95 +44-77,52-78 +32-79,31-80 +45-79,23-46 +11-85,10-84 +75-95,19-76 +5-76,5-6 +60-71,65-70 +53-61,52-82 +4-4,5-95 +6-91,90-98 +45-92,46-92 +20-97,10-84 +21-45,31-46 +67-69,43-68 +49-70,12-70 +85-96,96-97 +7-77,8-69 +44-77,77-78 +13-86,85-85 +17-17,17-37 +77-79,13-78 +4-38,5-87 +22-23,23-47 +78-87,30-87 +12-20,1-11 +47-56,46-54 +3-52,1-2 +3-95,2-3 +9-40,8-13 +81-98,18-94 +42-69,38-89 +8-23,24-24 +16-73,15-17 +92-92,18-92 +3-78,78-79 +2-34,35-35 +19-61,60-83 +3-81,81-82 +7-61,6-40 +15-84,1-16 +52-70,30-69 +15-41,14-40 +32-73,32-74 +24-28,27-54 +2-98,18-98 +85-85,15-86 +1-88,2-88 +45-84,46-83 +20-26,34-52 +40-60,19-43 +51-81,80-81 +58-79,57-91 +12-52,28-38 +18-57,19-96 +4-99,2-3 +99-99,5-99 +52-75,53-53 +24-96,24-95 +9-93,10-87 +77-93,7-78 +17-81,18-80 +1-2,4-42 +24-47,46-73 +57-58,50-58 +21-58,21-82 +31-65,3-65 +5-10,3-8 +55-97,94-96 +31-40,30-34 +18-37,36-94 +18-88,17-27 +57-65,58-64 +55-56,55-56 +12-87,12-88 +69-98,14-52 +53-61,20-52 +40-62,16-63 +1-97,98-98 +2-84,1-2 +8-55,7-56 +91-91,91-92 +5-95,5-95 +9-17,2-16 +73-73,72-91 +44-88,5-87 +47-83,48-82 +1-23,22-83 +11-84,12-86 +90-93,5-92 +63-75,7-70 +60-89,89-90 +2-93,93-93 +14-60,13-28 +36-89,36-36 +49-99,4-97 +15-42,15-41 +12-90,90-91 +71-96,99-99 +37-37,37-70 +40-72,39-73 +25-60,26-59 +49-94,49-49 +20-80,21-81 +11-29,24-54 +12-88,55-89 +9-71,8-70 +4-69,5-68 +37-72,48-73 +26-98,27-58 +85-91,13-95 +8-41,8-8 +56-98,30-55 +21-92,20-97 +33-99,3-32 +1-61,3-94 +15-98,14-97 +60-99,59-61 +54-82,53-91 +21-33,17-41 +74-97,75-96 +10-51,52-52 +5-70,4-69 +41-93,42-92 +6-96,7-97 +17-28,2-27 +17-83,6-11 +53-99,54-96 +5-5,4-80 +36-81,53-72 +60-77,65-94 +44-87,87-88 +19-93,19-20 +63-80,43-70 +15-46,14-45 +61-78,77-78 +79-94,70-95 +20-41,20-20 +4-11,4-10 +10-98,4-10 +94-95,67-90 +9-56,10-10 +4-93,3-94 +49-59,49-83 +10-94,11-90 +20-21,20-92 +19-95,17-62 +1-95,69-96 +6-91,49-90 +12-98,11-99 +56-89,56-80 +42-96,42-97 +41-92,13-52 +78-94,57-86 +2-82,2-81 +1-1,1-60 +17-71,71-96 +10-88,9-34 +17-17,17-18 +35-99,34-90 +8-97,8-35 +73-85,74-85 +3-56,47-55 +1-4,3-76 +66-93,66-93 +27-27,26-66 +6-79,27-80 +49-89,48-89 +60-99,83-95 +64-64,48-64 +63-64,57-65 +15-17,30-95 +59-62,59-66 +4-29,5-99 +52-72,70-70 +5-91,1-98 +16-19,16-34 +35-35,1-34 +33-85,28-89 +7-78,6-79 +36-79,10-35 +52-74,51-75 +45-77,47-95 +26-26,26-93 +1-3,3-93 +69-88,8-69 +63-64,14-63 +46-46,45-88 +11-37,12-18 +5-92,6-91 +67-68,68-69 +31-89,32-32 +49-89,50-90 +3-4,4-94 +1-96,2-86 +6-91,7-90 +77-78,8-78 +38-76,38-77 +2-98,97-99 +43-48,48-71 +12-76,11-77 +25-40,25-41 +16-55,15-55 +1-91,2-91 +42-82,42-42 +32-90,31-33 +13-98,13-97 +18-80,18-65 +92-97,7-78 +1-3,2-69 +3-88,2-89 +6-94,7-67 +22-98,5-97 +24-32,33-96 +5-70,83-93 +1-61,60-61 +1-99,78-96 +88-98,4-89 +95-97,50-96 +56-93,55-97 +13-76,52-65 +86-87,40-87 +35-62,34-69 +26-44,27-60 +47-66,65-66 +2-97,1-87 +1-96,3-85 +13-82,16-82 +25-85,3-86 +36-63,3-99 +12-98,97-99 +4-6,2-5 +38-67,65-67 +77-96,27-30 +15-95,14-14 +22-87,22-60 +12-19,12-81 +16-79,8-80 +34-94,3-93 +26-62,25-62 +9-91,8-9 +94-98,30-33 +14-68,68-91 +79-95,84-95 +92-95,93-96 +2-96,95-99 +25-58,9-57 +7-87,6-6 +44-84,43-83 +78-88,77-87 +67-70,61-71 +35-64,64-65 +40-40,5-39 +9-74,9-74 +70-81,82-82 +11-58,10-11 +2-13,13-83 +56-71,70-88 +4-8,7-94 +5-88,4-93 +40-88,39-88 +14-84,69-83 +5-30,29-30 +91-94,92-94 +4-73,2-45 +69-98,30-70 +44-72,73-73 +32-41,32-38 +76-81,68-81 +62-75,62-69 +23-36,35-69 +95-96,26-95 +15-89,14-64 +8-75,9-97 +15-17,14-58 +16-18,18-92 +57-77,58-76 +90-98,23-91 +1-97,96-96 +37-96,1-38 +8-99,9-53 +4-9,10-10 +11-27,11-22 +83-95,80-86 +88-90,54-89 +53-66,53-57 +14-14,15-90 +6-9,8-98 +6-99,32-93 +28-70,29-70 +6-64,64-98 +18-68,19-69 +16-42,16-43 +3-91,2-91 +1-95,2-94 +18-19,8-19 +2-99,9-97 +76-86,42-86 +83-94,25-84 +21-64,9-87 +89-95,29-90 +4-96,3-97 +20-96,19-20 +28-74,28-29 +19-22,22-93 +62-87,83-97 +72-73,23-73 +22-52,21-51 +39-39,39-98 +9-95,9-95 +53-95,66-95 +36-87,19-37 +86-87,34-86 +12-56,11-11 +48-97,47-81 +26-62,54-58 +21-63,22-64 +27-90,90-90 +54-70,64-68 +7-84,92-94 +15-35,35-57 +19-91,20-92 +99-99,78-95 +46-89,46-47 +8-68,9-57 +4-77,1-69 +21-36,35-58 +24-30,26-30 +50-90,91-91 +2-31,8-64 +3-98,98-98 +43-70,70-71 +24-79,25-78 +30-30,31-73 +7-10,11-90 +1-95,2-2 +70-82,82-93 +90-90,4-59 +2-82,2-68 +4-19,4-31 +33-68,10-39 +13-22,21-91 +24-67,24-25 +1-9,4-10 +3-3,2-50 +42-84,43-83 +23-84,62-83 +78-79,78-80 +30-58,30-58 +71-71,38-72 +35-43,46-82 +49-55,31-75 +22-98,22-99 +27-57,26-57 +24-24,24-77 +89-92,79-89 +70-95,10-93 +13-36,14-21 +13-98,80-97 +11-14,17-48 +59-92,59-92 +19-26,18-40 +6-32,7-31 +12-48,12-12 +22-87,23-98 +5-96,6-88 +3-85,1-4 +85-88,43-85 +19-89,20-81 +52-52,53-71 +87-96,14-88 +4-5,1-1 +8-79,7-78 +76-77,7-77 +67-99,68-98 +21-68,66-69 +93-94,91-95 +24-88,8-87 +10-52,19-53 +27-86,28-84 +35-95,36-94 +27-86,85-86 +30-31,31-57 +39-87,38-91 +92-92,16-93 +2-83,1-92 +74-74,73-73 +5-25,23-26 +11-12,12-73 +68-80,71-80 +67-92,66-91 +23-33,25-33 +46-77,34-47 +25-78,23-78 +95-97,53-96 +99-99,1-99 +42-43,43-89 +17-18,9-18 +7-48,48-55 +36-61,60-62 +45-82,82-94 +1-96,3-96 +33-66,34-65 +21-81,20-82 +74-76,15-75 +25-25,25-86 +10-79,94-96 +8-94,5-9 +16-89,8-93 +20-21,21-95 +48-94,49-74 +88-89,89-89 +24-60,25-91 +85-85,31-86 +4-82,4-41 +27-88,27-87 +18-94,17-95 +67-76,51-89 +13-49,26-48 +9-88,9-9 +41-86,42-85 +57-96,14-58 +95-95,11-92 +58-58,57-86 +23-93,12-15 +1-97,2-97 +22-22,8-22 +51-91,50-90 +7-25,51-92 +74-88,73-87 +3-82,4-81 +89-98,67-90 +7-99,7-98 +26-62,31-71 +32-88,32-88 +14-65,46-64 +56-82,81-82 +54-64,53-65 +4-85,5-5 +85-86,3-85 +7-58,1-8 +4-82,5-56 +47-92,48-75 +27-79,28-80 +7-34,8-94 +35-40,35-46 +84-94,80-95 +83-99,84-98 +10-81,11-73 +5-91,20-23 +1-2,2-99 +50-50,9-51 +5-78,4-79 +9-99,61-98 +79-79,61-78 +13-20,14-20 +8-93,7-92 +3-27,3-99 +28-66,29-65 +15-97,14-99 +31-43,42-67 +53-57,54-56 +11-89,88-93 +77-82,78-78 +4-99,4-99 +16-75,12-14 +17-52,33-51 +8-83,41-55 +48-90,44-49 +1-4,3-72 +25-91,91-92 +3-10,4-9 +32-98,8-94 +32-33,1-33 +33-43,14-42 +23-83,24-83 +30-31,31-49 +7-84,84-85 +26-50,49-65 +73-85,46-92 +85-86,13-39 +7-78,7-75 +32-93,26-26 +59-96,5-97 +48-99,48-79 +21-24,21-25 +58-95,99-99 +26-27,22-26 +19-19,3-99 +46-97,46-96 +2-3,2-99 +26-92,6-21 +1-99,1-2 +22-31,31-81 +10-65,9-86 +1-99,2-98 +13-78,13-79 +96-96,54-96 +8-94,7-23 +1-97,96-99 +28-70,27-71 +37-95,37-94 +9-90,4-89 +9-92,10-93 +8-80,86-94 +2-2,4-9 +6-41,6-41 +25-76,24-77 +95-98,85-95 +4-82,1-2 +56-73,56-84 +2-99,20-99 +14-17,17-91 +56-74,55-75 +45-97,99-99 +56-56,16-55 +43-93,44-86 +61-84,25-83 +82-99,5-83 +19-37,3-18 +42-42,4-42 +34-41,35-78 +12-79,11-80 +3-72,4-71 +16-99,23-85 +21-46,47-47 +33-65,33-33 +36-57,36-58 +5-82,82-83 +2-95,1-95 +1-37,5-31 +70-70,7-69 +17-86,18-87 +17-91,44-91 +73-88,73-89 +40-89,39-92 +68-97,91-96 +25-97,7-96 +36-83,37-83 +70-74,30-63 +56-93,57-93 +98-99,58-99 +15-95,94-97 +26-40,40-41 +3-99,2-44 +20-32,31-31 +57-97,56-57 +38-61,17-37 +13-62,12-63 +60-76,21-78 +57-66,56-67 +60-97,77-98 +43-68,42-43 +23-56,23-79 +34-44,35-44 +39-74,38-90 +3-84,2-85 +3-31,4-99 +74-85,73-85 +11-19,18-79 +25-25,26-64 +86-91,93-94 +16-95,15-92 +64-71,63-69 +45-45,35-44 +94-97,17-92 +29-97,28-98 +67-71,20-71 +7-86,7-85 +14-45,22-39 +6-66,6-19 +44-93,94-94 +52-62,52-61 +3-3,4-71 +22-80,21-81 +35-98,35-98 +37-44,38-43 +50-64,50-54 +50-99,51-99 +9-24,10-23 +24-24,23-86 +24-72,25-72 +33-61,49-62 +35-72,73-77 +78-79,79-96 +30-30,30-58 +58-76,36-75 +34-69,35-68 +7-91,5-6 +1-91,1-91 +2-2,2-99 +46-78,40-46 +7-78,6-79 +54-70,4-32 +63-76,5-77 +15-60,59-86 +1-75,69-75 +4-66,67-67 +15-99,15-95 +10-17,2-53 +2-46,18-61 +71-71,48-71 +19-98,14-99 +12-48,11-31 +30-30,30-98 +63-92,6-64 +21-94,95-95 +13-66,65-67 +7-11,14-79 +18-18,16-17 +11-45,91-97 +26-34,25-34 +40-60,4-81 +19-69,18-68 +34-79,99-99 +29-39,25-57 +2-98,98-98 +96-99,47-96 +6-45,9-45 +1-11,10-85 +6-77,5-76 +68-79,68-79 +45-55,46-49 +66-69,68-70 +14-80,20-77 +25-69,31-70 +16-53,15-54 +56-99,56-99 +45-47,32-46 +50-63,44-62 +18-75,29-76 +11-11,12-31 +19-91,90-91 +16-95,17-96 +19-95,19-94 +20-95,19-20 +17-96,16-95 +13-16,13-78 +50-62,34-63 +80-99,81-98 +13-81,83-96 +92-98,42-93 +38-89,57-89 +62-65,66-88 +54-85,55-85 +17-87,16-17 +3-6,6-74 +5-99,6-98 +22-41,73-73 +14-78,12-78 +35-51,34-47 +94-94,15-94 +58-75,13-71 +20-51,18-21 +31-60,30-96 +29-89,28-95 +39-40,40-82 +14-85,17-84 +27-57,26-94 +24-91,23-24 +8-72,71-76 +49-69,6-69 +28-28,29-52 +25-88,54-87 +89-90,16-90 +28-99,28-30 +17-17,17-88 +19-67,68-77 +64-64,34-65 +3-97,22-98 +17-98,16-97 +30-89,91-97 +13-30,14-31 +1-4,3-97 +2-93,1-98 +13-83,13-83 +80-90,80-91 +7-10,3-9 +65-79,70-80 +24-92,24-93 +16-94,43-81 +33-86,62-85 +53-78,79-79 +3-70,69-99 +95-95,16-96 +41-69,42-74 +83-83,51-82 +2-39,3-39 +6-15,5-16 +6-49,6-49 +57-95,95-96 +7-78,6-99 +78-83,81-99 +41-99,7-98 +1-98,2-97 +41-90,23-42 +9-61,9-24 +13-79,40-55 +4-13,10-18 +51-55,50-77 +87-90,86-91 +15-16,15-96 +19-29,20-28 +46-46,47-49 +9-82,7-7 +12-55,6-20 +4-41,4-41 +1-94,66-93 +4-91,4-92 +7-61,21-91 +7-90,38-91 +12-32,32-35 +6-94,93-94 +6-7,7-7 diff --git a/2022/day04_1/src/main/resources/small_input b/2022/day04_1/src/main/resources/small_input new file mode 100644 index 0000000..9f9e9cf --- /dev/null +++ b/2022/day04_1/src/main/resources/small_input @@ -0,0 +1,6 @@ +2-4,6-8 +2-3,4-5 +5-7,7-9 +2-8,3-7 +6-6,4-6 +2-6,4-8 diff --git a/2022/day04_2/.idea/.gitignore b/2022/day04_2/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day04_2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day04_2/.idea/compiler.xml b/2022/day04_2/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day04_2/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day04_2/.idea/gradle.xml b/2022/day04_2/.idea/gradle.xml new file mode 100644 index 0000000..5404067 --- /dev/null +++ b/2022/day04_2/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day04_2/.idea/jarRepositories.xml b/2022/day04_2/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day04_2/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day04_2/.idea/misc.xml b/2022/day04_2/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day04_2/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day04_2/.idea/vcs.xml b/2022/day04_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day04_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day04_2/build.gradle.kts b/2022/day04_2/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day04_2/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day04_2/gradle.properties b/2022/day04_2/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day04_2/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day04_2/gradle/wrapper/gradle-wrapper.jar b/2022/day04_2/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day04_2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day04_2/gradle/wrapper/gradle-wrapper.properties b/2022/day04_2/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..aa991fc --- /dev/null +++ b/2022/day04_2/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/2022/day04_2/gradlew b/2022/day04_2/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day04_2/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day04_2/gradlew.bat b/2022/day04_2/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day04_2/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day04_2/settings.gradle.kts b/2022/day04_2/settings.gradle.kts new file mode 100644 index 0000000..9083807 --- /dev/null +++ b/2022/day04_2/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day04_2" + diff --git a/2022/day04_2/src/main/kotlin/Main.kt b/2022/day04_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..7ac3f45 --- /dev/null +++ b/2022/day04_2/src/main/kotlin/Main.kt @@ -0,0 +1,57 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 4, Part 2 starting!!!") + + val allElfTeams = ArrayList() + + File(args[0]).forEachLine { + processLine(it, allElfTeams) + } + + var overlapCount = 0 + for(elfTeam in allElfTeams) { + if(elfTeam.hasOverlap()) { + overlapCount++ + } + } + println("Overlap count is: $overlapCount") + + println("AOC 2022, Day 4, Part 2 completed!!") +} + +fun processLine(line:String, allElves:ArrayList) { + val splitByElf = line.split(',') + val firstSpan = splitByElf[0].split('-') + val secondSpan = splitByElf[1].split('-') + + val elfTeam = ElfTeam( + ElfAssignment(firstSpan[0].toInt(), firstSpan[1].toInt()), + ElfAssignment(secondSpan[0].toInt(), secondSpan[1].toInt()) + ) + allElves.add(elfTeam) +} + +class ElfTeam constructor(private var firstElfAssignment:ElfAssignment, private var secondElfAssignment:ElfAssignment){ + + fun hasOverlap():Boolean { + //println("tlarsen,L38: firstElfAssignment = $firstElfAssignment, secondElfAssignment = $secondElfAssignment") + if((firstElfAssignment.startID <= secondElfAssignment.startID) && (firstElfAssignment.endID >= secondElfAssignment.startID)) { + return true + } + if((firstElfAssignment.startID <= secondElfAssignment.endID) && (firstElfAssignment.startID >= secondElfAssignment.endID)) { + return true + } + + if((secondElfAssignment.startID <= firstElfAssignment.startID) && (secondElfAssignment.endID >= firstElfAssignment.startID)) { + return true + } + if((secondElfAssignment.startID <= firstElfAssignment.endID) && (secondElfAssignment.endID >= firstElfAssignment.endID)) { + return true + } + + return false + } +} + +data class ElfAssignment constructor(val startID:Int, val endID:Int) diff --git a/2022/day04_2/src/main/resources/input b/2022/day04_2/src/main/resources/input new file mode 100644 index 0000000..eca0084 --- /dev/null +++ b/2022/day04_2/src/main/resources/input @@ -0,0 +1,1000 @@ +28-88,85-88 +9-70,18-18 +76-90,53-89 +17-86,11-17 +8-8,8-82 +16-85,15-95 +20-76,19-20 +56-57,57-66 +95-99,1-96 +14-17,17-67 +95-99,32-98 +30-99,29-98 +12-95,11-94 +3-82,1-72 +4-88,88-88 +2-10,11-59 +8-16,8-16 +22-95,23-94 +46-51,78-99 +61-99,62-94 +30-72,26-73 +6-93,2-92 +16-93,17-96 +1-99,2-88 +23-89,88-93 +30-73,3-73 +9-75,75-76 +75-97,70-99 +4-23,22-23 +5-94,4-4 +16-48,15-22 +10-62,61-97 +34-82,81-87 +16-98,15-99 +16-22,17-22 +20-40,21-58 +67-86,22-87 +6-73,6-33 +27-73,40-55 +57-98,58-97 +94-95,14-80 +16-90,91-91 +2-89,5-89 +17-95,96-96 +46-48,19-47 +50-59,51-60 +45-98,44-97 +99-99,6-97 +3-29,1-29 +26-48,25-49 +10-17,19-57 +28-57,28-56 +79-96,80-97 +5-78,4-25 +35-84,35-84 +24-99,20-98 +80-80,53-79 +88-97,12-88 +9-20,9-72 +75-78,35-54 +11-29,28-91 +48-74,49-75 +56-56,56-98 +41-69,33-42 +6-40,6-40 +49-80,49-79 +12-29,18-70 +19-20,13-80 +96-96,15-95 +5-99,4-4 +47-47,41-46 +53-82,65-85 +88-90,89-90 +12-12,12-88 +52-68,51-67 +1-80,2-81 +75-81,70-76 +35-58,35-57 +19-91,18-19 +18-73,72-74 +9-13,8-10 +5-40,35-37 +43-71,70-71 +24-24,25-43 +60-92,35-60 +43-52,47-53 +8-97,97-99 +57-89,57-89 +69-70,31-69 +48-49,48-79 +5-13,14-97 +9-95,9-83 +80-80,79-83 +30-77,29-78 +67-75,67-76 +20-67,21-87 +22-99,74-99 +12-12,11-96 +26-61,25-67 +19-48,47-91 +4-88,81-89 +75-96,74-97 +37-38,37-75 +3-3,4-76 +7-87,7-8 +1-99,2-99 +11-84,83-84 +71-95,69-95 +92-94,2-93 +7-95,21-95 +28-45,27-46 +16-24,16-63 +62-72,68-71 +36-96,90-98 +14-95,94-99 +26-67,25-55 +21-73,21-90 +35-44,34-43 +48-65,48-65 +80-89,80-99 +3-45,44-44 +27-86,67-85 +4-58,4-58 +12-38,11-39 +61-83,82-83 +4-86,4-85 +40-58,10-41 +8-9,8-98 +70-71,12-70 +40-40,40-78 +4-38,17-39 +5-23,22-94 +43-82,47-83 +32-74,86-96 +5-91,90-97 +10-93,11-86 +82-83,44-82 +61-69,57-68 +31-95,30-32 +42-59,42-98 +11-91,9-92 +42-81,19-63 +71-74,72-87 +88-89,6-88 +83-83,21-75 +50-61,59-62 +95-98,25-57 +13-17,16-87 +4-24,3-23 +4-56,3-5 +51-86,50-87 +49-55,30-56 +8-86,8-85 +3-99,3-3 +10-16,10-19 +6-96,5-95 +1-82,17-69 +35-62,35-55 +32-82,83-83 +9-76,75-75 +1-2,3-99 +86-94,93-99 +41-89,47-89 +2-60,3-61 +21-27,18-29 +5-6,6-54 +13-99,13-76 +71-71,34-70 +29-77,29-77 +7-83,6-64 +22-84,12-21 +93-97,15-94 +94-94,7-89 +24-94,32-99 +31-67,43-67 +46-61,46-60 +11-61,58-60 +5-58,5-5 +30-97,30-97 +65-83,82-83 +96-99,3-97 +11-97,6-12 +38-86,39-87 +24-24,24-66 +98-98,43-99 +5-32,29-33 +22-60,22-60 +9-72,71-71 +4-6,5-86 +27-30,31-94 +47-93,48-94 +1-2,5-91 +14-87,87-87 +26-75,25-96 +9-93,13-70 +6-10,9-95 +11-14,13-87 +69-71,2-69 +89-97,77-96 +5-16,4-14 +31-99,31-99 +30-39,33-88 +16-96,10-99 +20-74,19-73 +71-89,17-90 +50-51,26-50 +50-97,51-98 +4-84,4-84 +71-79,60-96 +39-83,81-82 +87-88,10-88 +93-99,68-99 +22-98,23-89 +12-96,13-97 +12-85,13-83 +3-97,3-98 +30-52,29-52 +11-96,97-97 +76-96,45-91 +22-97,23-98 +1-97,96-96 +4-83,5-84 +7-61,60-87 +62-66,37-61 +83-87,54-93 +40-74,7-40 +56-62,48-63 +88-94,57-89 +91-94,58-75 +1-88,87-87 +33-35,26-38 +9-10,9-94 +13-30,29-97 +95-95,23-95 +5-54,54-61 +16-73,72-73 +28-99,29-29 +32-91,33-90 +17-73,18-72 +20-34,13-20 +7-74,8-8 +43-58,42-59 +35-93,96-98 +31-71,62-89 +7-86,6-87 +37-78,38-79 +10-88,9-89 +5-94,20-94 +82-91,83-99 +14-34,4-14 +13-13,12-72 +1-98,16-98 +6-33,33-72 +35-83,36-36 +95-98,34-96 +23-23,22-68 +37-94,37-94 +42-97,96-99 +11-78,2-5 +23-88,87-87 +42-78,41-77 +58-74,58-78 +15-97,15-16 +3-11,5-83 +91-92,47-92 +63-96,62-99 +40-72,9-71 +64-89,37-69 +53-99,98-98 +28-33,26-34 +89-97,14-95 +16-93,92-97 +5-53,52-79 +52-52,53-96 +25-32,26-31 +35-73,35-74 +10-91,4-13 +2-28,5-28 +87-88,22-88 +31-76,32-75 +82-84,7-83 +38-61,60-60 +3-17,2-18 +74-93,4-94 +4-72,18-71 +69-71,19-70 +26-94,4-95 +44-77,52-78 +32-79,31-80 +45-79,23-46 +11-85,10-84 +75-95,19-76 +5-76,5-6 +60-71,65-70 +53-61,52-82 +4-4,5-95 +6-91,90-98 +45-92,46-92 +20-97,10-84 +21-45,31-46 +67-69,43-68 +49-70,12-70 +85-96,96-97 +7-77,8-69 +44-77,77-78 +13-86,85-85 +17-17,17-37 +77-79,13-78 +4-38,5-87 +22-23,23-47 +78-87,30-87 +12-20,1-11 +47-56,46-54 +3-52,1-2 +3-95,2-3 +9-40,8-13 +81-98,18-94 +42-69,38-89 +8-23,24-24 +16-73,15-17 +92-92,18-92 +3-78,78-79 +2-34,35-35 +19-61,60-83 +3-81,81-82 +7-61,6-40 +15-84,1-16 +52-70,30-69 +15-41,14-40 +32-73,32-74 +24-28,27-54 +2-98,18-98 +85-85,15-86 +1-88,2-88 +45-84,46-83 +20-26,34-52 +40-60,19-43 +51-81,80-81 +58-79,57-91 +12-52,28-38 +18-57,19-96 +4-99,2-3 +99-99,5-99 +52-75,53-53 +24-96,24-95 +9-93,10-87 +77-93,7-78 +17-81,18-80 +1-2,4-42 +24-47,46-73 +57-58,50-58 +21-58,21-82 +31-65,3-65 +5-10,3-8 +55-97,94-96 +31-40,30-34 +18-37,36-94 +18-88,17-27 +57-65,58-64 +55-56,55-56 +12-87,12-88 +69-98,14-52 +53-61,20-52 +40-62,16-63 +1-97,98-98 +2-84,1-2 +8-55,7-56 +91-91,91-92 +5-95,5-95 +9-17,2-16 +73-73,72-91 +44-88,5-87 +47-83,48-82 +1-23,22-83 +11-84,12-86 +90-93,5-92 +63-75,7-70 +60-89,89-90 +2-93,93-93 +14-60,13-28 +36-89,36-36 +49-99,4-97 +15-42,15-41 +12-90,90-91 +71-96,99-99 +37-37,37-70 +40-72,39-73 +25-60,26-59 +49-94,49-49 +20-80,21-81 +11-29,24-54 +12-88,55-89 +9-71,8-70 +4-69,5-68 +37-72,48-73 +26-98,27-58 +85-91,13-95 +8-41,8-8 +56-98,30-55 +21-92,20-97 +33-99,3-32 +1-61,3-94 +15-98,14-97 +60-99,59-61 +54-82,53-91 +21-33,17-41 +74-97,75-96 +10-51,52-52 +5-70,4-69 +41-93,42-92 +6-96,7-97 +17-28,2-27 +17-83,6-11 +53-99,54-96 +5-5,4-80 +36-81,53-72 +60-77,65-94 +44-87,87-88 +19-93,19-20 +63-80,43-70 +15-46,14-45 +61-78,77-78 +79-94,70-95 +20-41,20-20 +4-11,4-10 +10-98,4-10 +94-95,67-90 +9-56,10-10 +4-93,3-94 +49-59,49-83 +10-94,11-90 +20-21,20-92 +19-95,17-62 +1-95,69-96 +6-91,49-90 +12-98,11-99 +56-89,56-80 +42-96,42-97 +41-92,13-52 +78-94,57-86 +2-82,2-81 +1-1,1-60 +17-71,71-96 +10-88,9-34 +17-17,17-18 +35-99,34-90 +8-97,8-35 +73-85,74-85 +3-56,47-55 +1-4,3-76 +66-93,66-93 +27-27,26-66 +6-79,27-80 +49-89,48-89 +60-99,83-95 +64-64,48-64 +63-64,57-65 +15-17,30-95 +59-62,59-66 +4-29,5-99 +52-72,70-70 +5-91,1-98 +16-19,16-34 +35-35,1-34 +33-85,28-89 +7-78,6-79 +36-79,10-35 +52-74,51-75 +45-77,47-95 +26-26,26-93 +1-3,3-93 +69-88,8-69 +63-64,14-63 +46-46,45-88 +11-37,12-18 +5-92,6-91 +67-68,68-69 +31-89,32-32 +49-89,50-90 +3-4,4-94 +1-96,2-86 +6-91,7-90 +77-78,8-78 +38-76,38-77 +2-98,97-99 +43-48,48-71 +12-76,11-77 +25-40,25-41 +16-55,15-55 +1-91,2-91 +42-82,42-42 +32-90,31-33 +13-98,13-97 +18-80,18-65 +92-97,7-78 +1-3,2-69 +3-88,2-89 +6-94,7-67 +22-98,5-97 +24-32,33-96 +5-70,83-93 +1-61,60-61 +1-99,78-96 +88-98,4-89 +95-97,50-96 +56-93,55-97 +13-76,52-65 +86-87,40-87 +35-62,34-69 +26-44,27-60 +47-66,65-66 +2-97,1-87 +1-96,3-85 +13-82,16-82 +25-85,3-86 +36-63,3-99 +12-98,97-99 +4-6,2-5 +38-67,65-67 +77-96,27-30 +15-95,14-14 +22-87,22-60 +12-19,12-81 +16-79,8-80 +34-94,3-93 +26-62,25-62 +9-91,8-9 +94-98,30-33 +14-68,68-91 +79-95,84-95 +92-95,93-96 +2-96,95-99 +25-58,9-57 +7-87,6-6 +44-84,43-83 +78-88,77-87 +67-70,61-71 +35-64,64-65 +40-40,5-39 +9-74,9-74 +70-81,82-82 +11-58,10-11 +2-13,13-83 +56-71,70-88 +4-8,7-94 +5-88,4-93 +40-88,39-88 +14-84,69-83 +5-30,29-30 +91-94,92-94 +4-73,2-45 +69-98,30-70 +44-72,73-73 +32-41,32-38 +76-81,68-81 +62-75,62-69 +23-36,35-69 +95-96,26-95 +15-89,14-64 +8-75,9-97 +15-17,14-58 +16-18,18-92 +57-77,58-76 +90-98,23-91 +1-97,96-96 +37-96,1-38 +8-99,9-53 +4-9,10-10 +11-27,11-22 +83-95,80-86 +88-90,54-89 +53-66,53-57 +14-14,15-90 +6-9,8-98 +6-99,32-93 +28-70,29-70 +6-64,64-98 +18-68,19-69 +16-42,16-43 +3-91,2-91 +1-95,2-94 +18-19,8-19 +2-99,9-97 +76-86,42-86 +83-94,25-84 +21-64,9-87 +89-95,29-90 +4-96,3-97 +20-96,19-20 +28-74,28-29 +19-22,22-93 +62-87,83-97 +72-73,23-73 +22-52,21-51 +39-39,39-98 +9-95,9-95 +53-95,66-95 +36-87,19-37 +86-87,34-86 +12-56,11-11 +48-97,47-81 +26-62,54-58 +21-63,22-64 +27-90,90-90 +54-70,64-68 +7-84,92-94 +15-35,35-57 +19-91,20-92 +99-99,78-95 +46-89,46-47 +8-68,9-57 +4-77,1-69 +21-36,35-58 +24-30,26-30 +50-90,91-91 +2-31,8-64 +3-98,98-98 +43-70,70-71 +24-79,25-78 +30-30,31-73 +7-10,11-90 +1-95,2-2 +70-82,82-93 +90-90,4-59 +2-82,2-68 +4-19,4-31 +33-68,10-39 +13-22,21-91 +24-67,24-25 +1-9,4-10 +3-3,2-50 +42-84,43-83 +23-84,62-83 +78-79,78-80 +30-58,30-58 +71-71,38-72 +35-43,46-82 +49-55,31-75 +22-98,22-99 +27-57,26-57 +24-24,24-77 +89-92,79-89 +70-95,10-93 +13-36,14-21 +13-98,80-97 +11-14,17-48 +59-92,59-92 +19-26,18-40 +6-32,7-31 +12-48,12-12 +22-87,23-98 +5-96,6-88 +3-85,1-4 +85-88,43-85 +19-89,20-81 +52-52,53-71 +87-96,14-88 +4-5,1-1 +8-79,7-78 +76-77,7-77 +67-99,68-98 +21-68,66-69 +93-94,91-95 +24-88,8-87 +10-52,19-53 +27-86,28-84 +35-95,36-94 +27-86,85-86 +30-31,31-57 +39-87,38-91 +92-92,16-93 +2-83,1-92 +74-74,73-73 +5-25,23-26 +11-12,12-73 +68-80,71-80 +67-92,66-91 +23-33,25-33 +46-77,34-47 +25-78,23-78 +95-97,53-96 +99-99,1-99 +42-43,43-89 +17-18,9-18 +7-48,48-55 +36-61,60-62 +45-82,82-94 +1-96,3-96 +33-66,34-65 +21-81,20-82 +74-76,15-75 +25-25,25-86 +10-79,94-96 +8-94,5-9 +16-89,8-93 +20-21,21-95 +48-94,49-74 +88-89,89-89 +24-60,25-91 +85-85,31-86 +4-82,4-41 +27-88,27-87 +18-94,17-95 +67-76,51-89 +13-49,26-48 +9-88,9-9 +41-86,42-85 +57-96,14-58 +95-95,11-92 +58-58,57-86 +23-93,12-15 +1-97,2-97 +22-22,8-22 +51-91,50-90 +7-25,51-92 +74-88,73-87 +3-82,4-81 +89-98,67-90 +7-99,7-98 +26-62,31-71 +32-88,32-88 +14-65,46-64 +56-82,81-82 +54-64,53-65 +4-85,5-5 +85-86,3-85 +7-58,1-8 +4-82,5-56 +47-92,48-75 +27-79,28-80 +7-34,8-94 +35-40,35-46 +84-94,80-95 +83-99,84-98 +10-81,11-73 +5-91,20-23 +1-2,2-99 +50-50,9-51 +5-78,4-79 +9-99,61-98 +79-79,61-78 +13-20,14-20 +8-93,7-92 +3-27,3-99 +28-66,29-65 +15-97,14-99 +31-43,42-67 +53-57,54-56 +11-89,88-93 +77-82,78-78 +4-99,4-99 +16-75,12-14 +17-52,33-51 +8-83,41-55 +48-90,44-49 +1-4,3-72 +25-91,91-92 +3-10,4-9 +32-98,8-94 +32-33,1-33 +33-43,14-42 +23-83,24-83 +30-31,31-49 +7-84,84-85 +26-50,49-65 +73-85,46-92 +85-86,13-39 +7-78,7-75 +32-93,26-26 +59-96,5-97 +48-99,48-79 +21-24,21-25 +58-95,99-99 +26-27,22-26 +19-19,3-99 +46-97,46-96 +2-3,2-99 +26-92,6-21 +1-99,1-2 +22-31,31-81 +10-65,9-86 +1-99,2-98 +13-78,13-79 +96-96,54-96 +8-94,7-23 +1-97,96-99 +28-70,27-71 +37-95,37-94 +9-90,4-89 +9-92,10-93 +8-80,86-94 +2-2,4-9 +6-41,6-41 +25-76,24-77 +95-98,85-95 +4-82,1-2 +56-73,56-84 +2-99,20-99 +14-17,17-91 +56-74,55-75 +45-97,99-99 +56-56,16-55 +43-93,44-86 +61-84,25-83 +82-99,5-83 +19-37,3-18 +42-42,4-42 +34-41,35-78 +12-79,11-80 +3-72,4-71 +16-99,23-85 +21-46,47-47 +33-65,33-33 +36-57,36-58 +5-82,82-83 +2-95,1-95 +1-37,5-31 +70-70,7-69 +17-86,18-87 +17-91,44-91 +73-88,73-89 +40-89,39-92 +68-97,91-96 +25-97,7-96 +36-83,37-83 +70-74,30-63 +56-93,57-93 +98-99,58-99 +15-95,94-97 +26-40,40-41 +3-99,2-44 +20-32,31-31 +57-97,56-57 +38-61,17-37 +13-62,12-63 +60-76,21-78 +57-66,56-67 +60-97,77-98 +43-68,42-43 +23-56,23-79 +34-44,35-44 +39-74,38-90 +3-84,2-85 +3-31,4-99 +74-85,73-85 +11-19,18-79 +25-25,26-64 +86-91,93-94 +16-95,15-92 +64-71,63-69 +45-45,35-44 +94-97,17-92 +29-97,28-98 +67-71,20-71 +7-86,7-85 +14-45,22-39 +6-66,6-19 +44-93,94-94 +52-62,52-61 +3-3,4-71 +22-80,21-81 +35-98,35-98 +37-44,38-43 +50-64,50-54 +50-99,51-99 +9-24,10-23 +24-24,23-86 +24-72,25-72 +33-61,49-62 +35-72,73-77 +78-79,79-96 +30-30,30-58 +58-76,36-75 +34-69,35-68 +7-91,5-6 +1-91,1-91 +2-2,2-99 +46-78,40-46 +7-78,6-79 +54-70,4-32 +63-76,5-77 +15-60,59-86 +1-75,69-75 +4-66,67-67 +15-99,15-95 +10-17,2-53 +2-46,18-61 +71-71,48-71 +19-98,14-99 +12-48,11-31 +30-30,30-98 +63-92,6-64 +21-94,95-95 +13-66,65-67 +7-11,14-79 +18-18,16-17 +11-45,91-97 +26-34,25-34 +40-60,4-81 +19-69,18-68 +34-79,99-99 +29-39,25-57 +2-98,98-98 +96-99,47-96 +6-45,9-45 +1-11,10-85 +6-77,5-76 +68-79,68-79 +45-55,46-49 +66-69,68-70 +14-80,20-77 +25-69,31-70 +16-53,15-54 +56-99,56-99 +45-47,32-46 +50-63,44-62 +18-75,29-76 +11-11,12-31 +19-91,90-91 +16-95,17-96 +19-95,19-94 +20-95,19-20 +17-96,16-95 +13-16,13-78 +50-62,34-63 +80-99,81-98 +13-81,83-96 +92-98,42-93 +38-89,57-89 +62-65,66-88 +54-85,55-85 +17-87,16-17 +3-6,6-74 +5-99,6-98 +22-41,73-73 +14-78,12-78 +35-51,34-47 +94-94,15-94 +58-75,13-71 +20-51,18-21 +31-60,30-96 +29-89,28-95 +39-40,40-82 +14-85,17-84 +27-57,26-94 +24-91,23-24 +8-72,71-76 +49-69,6-69 +28-28,29-52 +25-88,54-87 +89-90,16-90 +28-99,28-30 +17-17,17-88 +19-67,68-77 +64-64,34-65 +3-97,22-98 +17-98,16-97 +30-89,91-97 +13-30,14-31 +1-4,3-97 +2-93,1-98 +13-83,13-83 +80-90,80-91 +7-10,3-9 +65-79,70-80 +24-92,24-93 +16-94,43-81 +33-86,62-85 +53-78,79-79 +3-70,69-99 +95-95,16-96 +41-69,42-74 +83-83,51-82 +2-39,3-39 +6-15,5-16 +6-49,6-49 +57-95,95-96 +7-78,6-99 +78-83,81-99 +41-99,7-98 +1-98,2-97 +41-90,23-42 +9-61,9-24 +13-79,40-55 +4-13,10-18 +51-55,50-77 +87-90,86-91 +15-16,15-96 +19-29,20-28 +46-46,47-49 +9-82,7-7 +12-55,6-20 +4-41,4-41 +1-94,66-93 +4-91,4-92 +7-61,21-91 +7-90,38-91 +12-32,32-35 +6-94,93-94 +6-7,7-7 diff --git a/2022/day04_2/src/main/resources/small_input b/2022/day04_2/src/main/resources/small_input new file mode 100644 index 0000000..9f9e9cf --- /dev/null +++ b/2022/day04_2/src/main/resources/small_input @@ -0,0 +1,6 @@ +2-4,6-8 +2-3,4-5 +5-7,7-9 +2-8,3-7 +6-6,4-6 +2-6,4-8 diff --git a/2022/day05_1/.idea/.gitignore b/2022/day05_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day05_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day05_1/.idea/compiler.xml b/2022/day05_1/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day05_1/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day05_1/.idea/gradle.xml b/2022/day05_1/.idea/gradle.xml new file mode 100644 index 0000000..a7087b2 --- /dev/null +++ b/2022/day05_1/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/2022/day05_1/.idea/jarRepositories.xml b/2022/day05_1/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day05_1/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day05_1/.idea/misc.xml b/2022/day05_1/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day05_1/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day05_1/.idea/vcs.xml b/2022/day05_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day05_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day05_1/build.gradle.kts b/2022/day05_1/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day05_1/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day05_1/gradle.properties b/2022/day05_1/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day05_1/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day05_1/gradle/wrapper/gradle-wrapper.jar b/2022/day05_1/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day05_1/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day05_1/gradle/wrapper/gradle-wrapper.properties b/2022/day05_1/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..aa991fc --- /dev/null +++ b/2022/day05_1/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/2022/day05_1/gradlew b/2022/day05_1/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day05_1/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day05_1/gradlew.bat b/2022/day05_1/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day05_1/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day05_1/settings.gradle.kts b/2022/day05_1/settings.gradle.kts new file mode 100644 index 0000000..c7a4865 --- /dev/null +++ b/2022/day05_1/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day05_1" + diff --git a/2022/day05_1/src/main/kotlin/Main.kt b/2022/day05_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..1bac24b --- /dev/null +++ b/2022/day05_1/src/main/kotlin/Main.kt @@ -0,0 +1,80 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 5, Part 1 starting!!!") + + var readingCrates = true + val crateStacks = CrateStacks(args[1].toInt()) + + File(args[0]).forEachLine { + if(readingCrates) { + readingCrates = processLineCrates(it, crateStacks) + } else { + processLineInstructions(it, crateStacks) + } + } + + crateStacks.printAllStacks() + + println("Reporting top of stacks: ${crateStacks.reportTopCrates()}") + + println("AOC 2022, Day 5, Part 1 completed!!") +} + +data class CrateStacks constructor (val stackCount:Int) { + val stacks:ArrayList> = ArrayList() + + init { + for(i in 1 .. stackCount) { + stacks.add(ArrayDeque()) + } + } + + fun printAllStacks() { + println("Current stack configuration:") + + for(i in 1 .. stackCount) { + println("Stack $i: ${stacks[i - 1]}") + } + } + + fun move(moveCrates: Int, from: Int, to: Int) { + println("Command: move $moveCrates from $from to $to") + for(move in 1 .. moveCrates) { + val theCrate = stacks[from - 1].removeFirst() + stacks[to - 1].addFirst(theCrate) + } + printAllStacks() + println("Moves complete") + } + + fun reportTopCrates():String { + var topOfStacks = "" + for(stack in stacks) { + topOfStacks += stack.first() + } + return topOfStacks + } +} + +fun processLineCrates(line: String, crateStacks: CrateStacks):Boolean { + var chunkIndex = 0 + for(chunk in line.chunked(4)) { + if(chunk.isNotBlank() && !chunk.contains(Regex("\\d"))) { + //println("tlarsen,L47: $chunk with ${chunk[1]}") + val theCrateStack = crateStacks.stacks[chunkIndex] + theCrateStack.addLast(chunk[1]) + } + chunkIndex++ + } + + return line.isNotBlank() +} + +fun processLineInstructions(line: String, crateStacks: CrateStacks) { + val split = line.split(' ') + val moveCrates = split[1].toInt() + val from = split[3].toInt() + val to = split[5].toInt() + crateStacks.move(moveCrates, from, to) +} \ No newline at end of file diff --git a/2022/day05_1/src/main/resources/input b/2022/day05_1/src/main/resources/input new file mode 100644 index 0000000..c6ab421 --- /dev/null +++ b/2022/day05_1/src/main/resources/input @@ -0,0 +1,513 @@ +[H] [Z] [J] +[L] [W] [B] [G] [R] +[R] [G] [S] [J] [H] [Q] +[F] [N] [T] [J] [P] [R] [F] +[B] [C] [M] [R] [Q] [F] [G] [P] +[C] [D] [F] [D] [D] [D] [T] [M] [G] +[J] [C] [J] [J] [C] [L] [Z] [V] [B] +[M] [Z] [H] [P] [N] [W] [P] [L] [C] + 1 2 3 4 5 6 7 8 9 + +move 3 from 2 to 1 +move 8 from 6 to 4 +move 4 from 8 to 2 +move 3 from 1 to 9 +move 1 from 2 to 4 +move 3 from 7 to 5 +move 3 from 9 to 2 +move 3 from 3 to 5 +move 1 from 5 to 1 +move 5 from 1 to 8 +move 2 from 1 to 8 +move 3 from 7 to 3 +move 1 from 8 to 9 +move 6 from 9 to 8 +move 3 from 8 to 7 +move 7 from 8 to 9 +move 2 from 5 to 9 +move 2 from 2 to 9 +move 3 from 3 to 7 +move 2 from 8 to 3 +move 7 from 4 to 8 +move 3 from 4 to 1 +move 4 from 8 to 6 +move 4 from 6 to 1 +move 8 from 1 to 2 +move 1 from 1 to 4 +move 3 from 5 to 1 +move 8 from 9 to 8 +move 4 from 3 to 1 +move 5 from 5 to 3 +move 2 from 7 to 1 +move 1 from 7 to 4 +move 1 from 7 to 2 +move 3 from 3 to 5 +move 3 from 9 to 1 +move 9 from 8 to 1 +move 2 from 9 to 7 +move 1 from 8 to 5 +move 4 from 5 to 3 +move 1 from 3 to 4 +move 1 from 9 to 6 +move 1 from 6 to 9 +move 7 from 4 to 9 +move 1 from 7 to 3 +move 1 from 8 to 2 +move 8 from 2 to 1 +move 4 from 3 to 5 +move 2 from 9 to 6 +move 2 from 6 to 2 +move 2 from 4 to 9 +move 8 from 9 to 2 +move 3 from 7 to 9 +move 1 from 3 to 5 +move 2 from 3 to 8 +move 9 from 2 to 1 +move 1 from 8 to 7 +move 4 from 2 to 9 +move 4 from 5 to 6 +move 1 from 8 to 9 +move 27 from 1 to 2 +move 1 from 6 to 4 +move 3 from 6 to 4 +move 7 from 9 to 8 +move 4 from 4 to 1 +move 9 from 2 to 6 +move 2 from 1 to 9 +move 6 from 1 to 3 +move 1 from 5 to 3 +move 3 from 3 to 5 +move 3 from 5 to 3 +move 3 from 3 to 1 +move 4 from 6 to 7 +move 3 from 9 to 2 +move 1 from 6 to 4 +move 4 from 3 to 5 +move 3 from 6 to 5 +move 1 from 6 to 2 +move 15 from 2 to 3 +move 5 from 5 to 9 +move 13 from 3 to 9 +move 2 from 5 to 7 +move 1 from 4 to 2 +move 3 from 3 to 7 +move 11 from 2 to 7 +move 7 from 9 to 5 +move 3 from 5 to 7 +move 6 from 8 to 9 +move 4 from 1 to 2 +move 6 from 1 to 6 +move 3 from 5 to 1 +move 1 from 8 to 2 +move 4 from 2 to 9 +move 1 from 5 to 7 +move 6 from 7 to 6 +move 18 from 7 to 5 +move 1 from 7 to 1 +move 8 from 9 to 5 +move 1 from 2 to 6 +move 15 from 5 to 6 +move 6 from 5 to 3 +move 4 from 3 to 6 +move 26 from 6 to 5 +move 2 from 1 to 7 +move 4 from 5 to 9 +move 8 from 5 to 7 +move 3 from 7 to 9 +move 14 from 9 to 8 +move 7 from 5 to 2 +move 4 from 2 to 1 +move 5 from 1 to 9 +move 12 from 5 to 3 +move 5 from 8 to 5 +move 14 from 3 to 2 +move 1 from 5 to 2 +move 10 from 2 to 6 +move 7 from 9 to 6 +move 6 from 8 to 6 +move 1 from 2 to 7 +move 2 from 9 to 7 +move 2 from 8 to 6 +move 6 from 2 to 7 +move 1 from 1 to 8 +move 15 from 6 to 2 +move 1 from 6 to 9 +move 1 from 5 to 9 +move 1 from 9 to 6 +move 2 from 2 to 4 +move 3 from 9 to 5 +move 5 from 5 to 3 +move 3 from 3 to 6 +move 6 from 2 to 7 +move 1 from 5 to 9 +move 8 from 6 to 9 +move 2 from 6 to 7 +move 3 from 2 to 4 +move 9 from 6 to 7 +move 17 from 7 to 5 +move 1 from 8 to 4 +move 7 from 9 to 3 +move 12 from 5 to 8 +move 3 from 5 to 2 +move 4 from 7 to 8 +move 2 from 5 to 7 +move 1 from 7 to 9 +move 8 from 3 to 7 +move 17 from 7 to 5 +move 3 from 2 to 5 +move 1 from 3 to 6 +move 10 from 5 to 4 +move 5 from 2 to 7 +move 1 from 4 to 2 +move 3 from 9 to 8 +move 7 from 7 to 2 +move 5 from 5 to 1 +move 14 from 4 to 9 +move 3 from 9 to 8 +move 1 from 6 to 9 +move 2 from 1 to 4 +move 2 from 8 to 5 +move 16 from 8 to 6 +move 1 from 6 to 2 +move 11 from 9 to 2 +move 2 from 7 to 5 +move 1 from 1 to 6 +move 11 from 2 to 9 +move 4 from 2 to 8 +move 9 from 5 to 3 +move 1 from 4 to 2 +move 2 from 1 to 8 +move 1 from 2 to 9 +move 2 from 4 to 3 +move 8 from 6 to 9 +move 16 from 9 to 3 +move 16 from 3 to 2 +move 17 from 2 to 6 +move 1 from 9 to 3 +move 1 from 2 to 5 +move 1 from 9 to 4 +move 3 from 2 to 8 +move 1 from 9 to 1 +move 1 from 9 to 6 +move 7 from 3 to 1 +move 5 from 3 to 5 +move 3 from 8 to 3 +move 2 from 3 to 4 +move 6 from 8 to 4 +move 7 from 6 to 4 +move 3 from 6 to 7 +move 3 from 8 to 9 +move 3 from 5 to 2 +move 3 from 1 to 3 +move 1 from 4 to 8 +move 3 from 5 to 1 +move 13 from 4 to 7 +move 14 from 6 to 7 +move 6 from 1 to 9 +move 3 from 9 to 6 +move 1 from 8 to 7 +move 1 from 8 to 7 +move 20 from 7 to 3 +move 1 from 8 to 9 +move 1 from 1 to 9 +move 1 from 1 to 5 +move 1 from 4 to 6 +move 14 from 3 to 9 +move 1 from 2 to 6 +move 3 from 7 to 6 +move 6 from 3 to 2 +move 1 from 3 to 8 +move 2 from 7 to 3 +move 7 from 6 to 3 +move 12 from 3 to 1 +move 1 from 8 to 2 +move 1 from 4 to 9 +move 1 from 5 to 6 +move 1 from 6 to 4 +move 1 from 4 to 2 +move 2 from 2 to 3 +move 16 from 9 to 7 +move 3 from 6 to 7 +move 6 from 9 to 4 +move 4 from 4 to 7 +move 6 from 1 to 8 +move 2 from 3 to 6 +move 3 from 1 to 9 +move 3 from 2 to 3 +move 3 from 3 to 8 +move 5 from 2 to 8 +move 2 from 7 to 8 +move 3 from 1 to 5 +move 1 from 4 to 3 +move 2 from 9 to 8 +move 1 from 6 to 8 +move 2 from 9 to 1 +move 15 from 7 to 1 +move 1 from 6 to 5 +move 10 from 1 to 5 +move 1 from 4 to 1 +move 2 from 1 to 6 +move 9 from 7 to 8 +move 27 from 8 to 3 +move 1 from 6 to 1 +move 1 from 8 to 5 +move 5 from 5 to 6 +move 12 from 3 to 1 +move 3 from 7 to 1 +move 7 from 5 to 1 +move 1 from 6 to 4 +move 3 from 6 to 9 +move 1 from 4 to 2 +move 2 from 6 to 5 +move 1 from 7 to 6 +move 1 from 9 to 2 +move 2 from 5 to 6 +move 2 from 6 to 5 +move 3 from 1 to 3 +move 19 from 3 to 1 +move 2 from 2 to 9 +move 42 from 1 to 7 +move 4 from 9 to 7 +move 1 from 6 to 8 +move 1 from 8 to 5 +move 2 from 1 to 9 +move 3 from 5 to 7 +move 27 from 7 to 4 +move 1 from 1 to 4 +move 3 from 9 to 2 +move 18 from 4 to 9 +move 2 from 5 to 3 +move 1 from 7 to 1 +move 2 from 3 to 4 +move 8 from 7 to 5 +move 15 from 9 to 3 +move 1 from 9 to 7 +move 3 from 7 to 2 +move 2 from 7 to 2 +move 2 from 5 to 3 +move 1 from 1 to 5 +move 1 from 9 to 1 +move 1 from 3 to 1 +move 1 from 4 to 3 +move 8 from 7 to 3 +move 8 from 2 to 4 +move 1 from 9 to 6 +move 23 from 3 to 9 +move 1 from 9 to 6 +move 2 from 6 to 8 +move 1 from 8 to 6 +move 1 from 5 to 3 +move 7 from 4 to 8 +move 7 from 5 to 7 +move 2 from 8 to 3 +move 1 from 1 to 8 +move 3 from 7 to 4 +move 5 from 4 to 3 +move 1 from 1 to 8 +move 3 from 3 to 1 +move 8 from 9 to 7 +move 3 from 8 to 4 +move 1 from 6 to 2 +move 5 from 8 to 7 +move 6 from 3 to 1 +move 1 from 2 to 9 +move 7 from 7 to 9 +move 4 from 1 to 9 +move 2 from 4 to 2 +move 1 from 4 to 9 +move 1 from 1 to 6 +move 8 from 4 to 8 +move 4 from 1 to 5 +move 3 from 5 to 2 +move 2 from 2 to 5 +move 2 from 5 to 6 +move 1 from 3 to 7 +move 2 from 6 to 4 +move 1 from 5 to 7 +move 1 from 6 to 9 +move 1 from 4 to 1 +move 6 from 9 to 2 +move 8 from 9 to 7 +move 4 from 7 to 3 +move 4 from 8 to 3 +move 3 from 8 to 3 +move 8 from 3 to 5 +move 1 from 1 to 7 +move 11 from 9 to 7 +move 5 from 2 to 7 +move 1 from 8 to 1 +move 3 from 2 to 3 +move 1 from 1 to 4 +move 1 from 2 to 5 +move 20 from 7 to 8 +move 7 from 7 to 9 +move 4 from 4 to 7 +move 3 from 9 to 4 +move 5 from 7 to 4 +move 7 from 4 to 7 +move 4 from 9 to 2 +move 1 from 4 to 3 +move 4 from 3 to 5 +move 2 from 5 to 8 +move 4 from 5 to 2 +move 5 from 2 to 6 +move 2 from 6 to 3 +move 22 from 8 to 5 +move 13 from 7 to 9 +move 11 from 9 to 3 +move 2 from 6 to 8 +move 7 from 3 to 1 +move 18 from 5 to 2 +move 1 from 6 to 4 +move 1 from 4 to 9 +move 2 from 8 to 5 +move 2 from 9 to 1 +move 9 from 3 to 1 +move 4 from 5 to 6 +move 2 from 6 to 7 +move 3 from 9 to 5 +move 10 from 5 to 8 +move 6 from 8 to 7 +move 3 from 8 to 1 +move 6 from 2 to 3 +move 1 from 9 to 6 +move 5 from 3 to 4 +move 4 from 1 to 4 +move 17 from 1 to 5 +move 12 from 2 to 7 +move 1 from 3 to 6 +move 16 from 5 to 8 +move 3 from 5 to 6 +move 9 from 8 to 3 +move 8 from 8 to 4 +move 7 from 4 to 1 +move 5 from 1 to 4 +move 4 from 3 to 7 +move 14 from 7 to 3 +move 6 from 4 to 8 +move 9 from 7 to 4 +move 5 from 6 to 1 +move 1 from 7 to 1 +move 1 from 6 to 7 +move 16 from 4 to 5 +move 1 from 4 to 2 +move 1 from 7 to 5 +move 2 from 1 to 7 +move 2 from 7 to 4 +move 4 from 1 to 6 +move 13 from 5 to 6 +move 5 from 6 to 3 +move 22 from 3 to 2 +move 1 from 4 to 7 +move 4 from 5 to 4 +move 1 from 7 to 6 +move 5 from 8 to 5 +move 2 from 3 to 1 +move 13 from 6 to 1 +move 6 from 1 to 4 +move 1 from 8 to 1 +move 6 from 1 to 4 +move 1 from 5 to 4 +move 7 from 4 to 7 +move 3 from 1 to 5 +move 2 from 5 to 7 +move 5 from 5 to 1 +move 8 from 7 to 4 +move 1 from 6 to 4 +move 1 from 7 to 4 +move 9 from 2 to 7 +move 8 from 7 to 6 +move 5 from 6 to 4 +move 1 from 7 to 4 +move 2 from 4 to 9 +move 2 from 6 to 1 +move 8 from 2 to 6 +move 9 from 1 to 8 +move 9 from 6 to 2 +move 1 from 1 to 8 +move 6 from 8 to 4 +move 2 from 9 to 7 +move 2 from 7 to 9 +move 15 from 2 to 8 +move 18 from 4 to 2 +move 14 from 4 to 5 +move 10 from 2 to 4 +move 9 from 2 to 6 +move 1 from 9 to 3 +move 1 from 3 to 1 +move 6 from 5 to 8 +move 3 from 4 to 9 +move 2 from 2 to 1 +move 1 from 1 to 6 +move 3 from 9 to 7 +move 22 from 8 to 6 +move 1 from 8 to 9 +move 2 from 1 to 5 +move 5 from 5 to 4 +move 2 from 5 to 8 +move 2 from 8 to 7 +move 1 from 9 to 7 +move 1 from 5 to 8 +move 1 from 9 to 8 +move 15 from 6 to 4 +move 2 from 5 to 2 +move 11 from 4 to 6 +move 5 from 4 to 1 +move 5 from 4 to 2 +move 2 from 1 to 5 +move 6 from 2 to 8 +move 11 from 6 to 3 +move 12 from 6 to 8 +move 1 from 3 to 9 +move 3 from 3 to 2 +move 6 from 4 to 2 +move 2 from 5 to 8 +move 5 from 7 to 2 +move 11 from 8 to 4 +move 1 from 7 to 4 +move 1 from 9 to 6 +move 7 from 2 to 1 +move 3 from 6 to 5 +move 2 from 5 to 3 +move 1 from 5 to 9 +move 3 from 4 to 9 +move 4 from 9 to 1 +move 4 from 3 to 6 +move 3 from 4 to 8 +move 3 from 8 to 9 +move 2 from 8 to 2 +move 9 from 8 to 7 +move 2 from 3 to 1 +move 2 from 3 to 2 +move 1 from 3 to 6 +move 2 from 9 to 1 +move 8 from 7 to 5 +move 7 from 2 to 7 +move 2 from 8 to 9 +move 4 from 6 to 5 +move 13 from 1 to 5 +move 4 from 1 to 8 +move 3 from 9 to 3 +move 12 from 5 to 9 +move 3 from 8 to 9 +move 1 from 8 to 4 +move 3 from 2 to 7 +move 3 from 3 to 7 +move 1 from 9 to 2 +move 4 from 6 to 4 +move 6 from 5 to 6 +move 2 from 7 to 3 +move 2 from 2 to 1 +move 5 from 6 to 5 +move 1 from 1 to 7 +move 9 from 5 to 4 +move 10 from 9 to 6 +move 1 from 2 to 6 +move 12 from 7 to 6 +move 1 from 7 to 4 +move 23 from 6 to 1 +move 10 from 4 to 3 +move 16 from 1 to 5 +move 5 from 1 to 2 +move 6 from 3 to 7 +move 5 from 4 to 8 diff --git a/2022/day05_1/src/main/resources/small_input b/2022/day05_1/src/main/resources/small_input new file mode 100644 index 0000000..42ef47f --- /dev/null +++ b/2022/day05_1/src/main/resources/small_input @@ -0,0 +1,9 @@ + [D] +[N] [C] +[Z] [M] [P] + 1 2 3 + +move 1 from 2 to 1 +move 3 from 1 to 3 +move 2 from 2 to 1 +move 1 from 1 to 2 diff --git a/2022/day05_2/.idea/.gitignore b/2022/day05_2/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day05_2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day05_2/.idea/compiler.xml b/2022/day05_2/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day05_2/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day05_2/.idea/gradle.xml b/2022/day05_2/.idea/gradle.xml new file mode 100644 index 0000000..a7087b2 --- /dev/null +++ b/2022/day05_2/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/2022/day05_2/.idea/jarRepositories.xml b/2022/day05_2/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day05_2/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day05_2/.idea/misc.xml b/2022/day05_2/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day05_2/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day05_2/.idea/vcs.xml b/2022/day05_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day05_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day05_2/build.gradle.kts b/2022/day05_2/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day05_2/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day05_2/gradle.properties b/2022/day05_2/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day05_2/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day05_2/gradle/wrapper/gradle-wrapper.jar b/2022/day05_2/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day05_2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day05_2/gradlew b/2022/day05_2/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day05_2/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day05_2/gradlew.bat b/2022/day05_2/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day05_2/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day05_2/settings.gradle.kts b/2022/day05_2/settings.gradle.kts new file mode 100644 index 0000000..8130295 --- /dev/null +++ b/2022/day05_2/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day05_2" + diff --git a/2022/day05_2/src/main/kotlin/Main.kt b/2022/day05_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..b1a5089 --- /dev/null +++ b/2022/day05_2/src/main/kotlin/Main.kt @@ -0,0 +1,85 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 5, Part 2 starting!!!") + + var readingCrates = true + val crateStacks = CrateStacks(args[1].toInt()) + + File(args[0]).forEachLine { + if(readingCrates) { + readingCrates = processLineCrates(it, crateStacks) + } else { + processLineInstructions(it, crateStacks) + } + } + + crateStacks.printAllStacks() + + println("Reporting top of stacks: ${crateStacks.reportTopCrates()}") + + println("AOC 2022, Day 5, Part 2 completed!!") +} + +data class CrateStacks constructor (val stackCount:Int) { + val stacks:ArrayList> = ArrayList() + val specialStack:ArrayDeque = ArrayDeque() + + init { + for(i in 1 .. stackCount) { + stacks.add(ArrayDeque()) + } + } + + fun printAllStacks() { + println("Current stack configuration:") + + for(i in 1 .. stackCount) { + println("Stack $i: ${stacks[i - 1]}") + } + } + + fun move(moveCrates: Int, from: Int, to: Int) { + println("Command: move $moveCrates from $from to $to") + for(move in 1 .. moveCrates) { + val theCrate = stacks[from - 1].removeFirst() + specialStack.addFirst(theCrate) + } + while(specialStack.isNotEmpty()) { + val theCrate = specialStack.removeFirst() + stacks[to - 1].addFirst(theCrate) + } + printAllStacks() + println("Moves complete") + } + + fun reportTopCrates():String { + var topOfStacks = "" + for(stack in stacks) { + topOfStacks += stack.first() + } + return topOfStacks + } +} + +fun processLineCrates(line: String, crateStacks: CrateStacks):Boolean { + var chunkIndex = 0 + for(chunk in line.chunked(4)) { + if(chunk.isNotBlank() && !chunk.contains(Regex("\\d"))) { + //println("tlarsen,L47: $chunk with ${chunk[1]}") + val theCrateStack = crateStacks.stacks[chunkIndex] + theCrateStack.addLast(chunk[1]) + } + chunkIndex++ + } + + return line.isNotBlank() +} + +fun processLineInstructions(line: String, crateStacks: CrateStacks) { + val split = line.split(' ') + val moveCrates = split[1].toInt() + val from = split[3].toInt() + val to = split[5].toInt() + crateStacks.move(moveCrates, from, to) +} diff --git a/2022/day05_2/src/main/resources/input b/2022/day05_2/src/main/resources/input new file mode 100644 index 0000000..c6ab421 --- /dev/null +++ b/2022/day05_2/src/main/resources/input @@ -0,0 +1,513 @@ +[H] [Z] [J] +[L] [W] [B] [G] [R] +[R] [G] [S] [J] [H] [Q] +[F] [N] [T] [J] [P] [R] [F] +[B] [C] [M] [R] [Q] [F] [G] [P] +[C] [D] [F] [D] [D] [D] [T] [M] [G] +[J] [C] [J] [J] [C] [L] [Z] [V] [B] +[M] [Z] [H] [P] [N] [W] [P] [L] [C] + 1 2 3 4 5 6 7 8 9 + +move 3 from 2 to 1 +move 8 from 6 to 4 +move 4 from 8 to 2 +move 3 from 1 to 9 +move 1 from 2 to 4 +move 3 from 7 to 5 +move 3 from 9 to 2 +move 3 from 3 to 5 +move 1 from 5 to 1 +move 5 from 1 to 8 +move 2 from 1 to 8 +move 3 from 7 to 3 +move 1 from 8 to 9 +move 6 from 9 to 8 +move 3 from 8 to 7 +move 7 from 8 to 9 +move 2 from 5 to 9 +move 2 from 2 to 9 +move 3 from 3 to 7 +move 2 from 8 to 3 +move 7 from 4 to 8 +move 3 from 4 to 1 +move 4 from 8 to 6 +move 4 from 6 to 1 +move 8 from 1 to 2 +move 1 from 1 to 4 +move 3 from 5 to 1 +move 8 from 9 to 8 +move 4 from 3 to 1 +move 5 from 5 to 3 +move 2 from 7 to 1 +move 1 from 7 to 4 +move 1 from 7 to 2 +move 3 from 3 to 5 +move 3 from 9 to 1 +move 9 from 8 to 1 +move 2 from 9 to 7 +move 1 from 8 to 5 +move 4 from 5 to 3 +move 1 from 3 to 4 +move 1 from 9 to 6 +move 1 from 6 to 9 +move 7 from 4 to 9 +move 1 from 7 to 3 +move 1 from 8 to 2 +move 8 from 2 to 1 +move 4 from 3 to 5 +move 2 from 9 to 6 +move 2 from 6 to 2 +move 2 from 4 to 9 +move 8 from 9 to 2 +move 3 from 7 to 9 +move 1 from 3 to 5 +move 2 from 3 to 8 +move 9 from 2 to 1 +move 1 from 8 to 7 +move 4 from 2 to 9 +move 4 from 5 to 6 +move 1 from 8 to 9 +move 27 from 1 to 2 +move 1 from 6 to 4 +move 3 from 6 to 4 +move 7 from 9 to 8 +move 4 from 4 to 1 +move 9 from 2 to 6 +move 2 from 1 to 9 +move 6 from 1 to 3 +move 1 from 5 to 3 +move 3 from 3 to 5 +move 3 from 5 to 3 +move 3 from 3 to 1 +move 4 from 6 to 7 +move 3 from 9 to 2 +move 1 from 6 to 4 +move 4 from 3 to 5 +move 3 from 6 to 5 +move 1 from 6 to 2 +move 15 from 2 to 3 +move 5 from 5 to 9 +move 13 from 3 to 9 +move 2 from 5 to 7 +move 1 from 4 to 2 +move 3 from 3 to 7 +move 11 from 2 to 7 +move 7 from 9 to 5 +move 3 from 5 to 7 +move 6 from 8 to 9 +move 4 from 1 to 2 +move 6 from 1 to 6 +move 3 from 5 to 1 +move 1 from 8 to 2 +move 4 from 2 to 9 +move 1 from 5 to 7 +move 6 from 7 to 6 +move 18 from 7 to 5 +move 1 from 7 to 1 +move 8 from 9 to 5 +move 1 from 2 to 6 +move 15 from 5 to 6 +move 6 from 5 to 3 +move 4 from 3 to 6 +move 26 from 6 to 5 +move 2 from 1 to 7 +move 4 from 5 to 9 +move 8 from 5 to 7 +move 3 from 7 to 9 +move 14 from 9 to 8 +move 7 from 5 to 2 +move 4 from 2 to 1 +move 5 from 1 to 9 +move 12 from 5 to 3 +move 5 from 8 to 5 +move 14 from 3 to 2 +move 1 from 5 to 2 +move 10 from 2 to 6 +move 7 from 9 to 6 +move 6 from 8 to 6 +move 1 from 2 to 7 +move 2 from 9 to 7 +move 2 from 8 to 6 +move 6 from 2 to 7 +move 1 from 1 to 8 +move 15 from 6 to 2 +move 1 from 6 to 9 +move 1 from 5 to 9 +move 1 from 9 to 6 +move 2 from 2 to 4 +move 3 from 9 to 5 +move 5 from 5 to 3 +move 3 from 3 to 6 +move 6 from 2 to 7 +move 1 from 5 to 9 +move 8 from 6 to 9 +move 2 from 6 to 7 +move 3 from 2 to 4 +move 9 from 6 to 7 +move 17 from 7 to 5 +move 1 from 8 to 4 +move 7 from 9 to 3 +move 12 from 5 to 8 +move 3 from 5 to 2 +move 4 from 7 to 8 +move 2 from 5 to 7 +move 1 from 7 to 9 +move 8 from 3 to 7 +move 17 from 7 to 5 +move 3 from 2 to 5 +move 1 from 3 to 6 +move 10 from 5 to 4 +move 5 from 2 to 7 +move 1 from 4 to 2 +move 3 from 9 to 8 +move 7 from 7 to 2 +move 5 from 5 to 1 +move 14 from 4 to 9 +move 3 from 9 to 8 +move 1 from 6 to 9 +move 2 from 1 to 4 +move 2 from 8 to 5 +move 16 from 8 to 6 +move 1 from 6 to 2 +move 11 from 9 to 2 +move 2 from 7 to 5 +move 1 from 1 to 6 +move 11 from 2 to 9 +move 4 from 2 to 8 +move 9 from 5 to 3 +move 1 from 4 to 2 +move 2 from 1 to 8 +move 1 from 2 to 9 +move 2 from 4 to 3 +move 8 from 6 to 9 +move 16 from 9 to 3 +move 16 from 3 to 2 +move 17 from 2 to 6 +move 1 from 9 to 3 +move 1 from 2 to 5 +move 1 from 9 to 4 +move 3 from 2 to 8 +move 1 from 9 to 1 +move 1 from 9 to 6 +move 7 from 3 to 1 +move 5 from 3 to 5 +move 3 from 8 to 3 +move 2 from 3 to 4 +move 6 from 8 to 4 +move 7 from 6 to 4 +move 3 from 6 to 7 +move 3 from 8 to 9 +move 3 from 5 to 2 +move 3 from 1 to 3 +move 1 from 4 to 8 +move 3 from 5 to 1 +move 13 from 4 to 7 +move 14 from 6 to 7 +move 6 from 1 to 9 +move 3 from 9 to 6 +move 1 from 8 to 7 +move 1 from 8 to 7 +move 20 from 7 to 3 +move 1 from 8 to 9 +move 1 from 1 to 9 +move 1 from 1 to 5 +move 1 from 4 to 6 +move 14 from 3 to 9 +move 1 from 2 to 6 +move 3 from 7 to 6 +move 6 from 3 to 2 +move 1 from 3 to 8 +move 2 from 7 to 3 +move 7 from 6 to 3 +move 12 from 3 to 1 +move 1 from 8 to 2 +move 1 from 4 to 9 +move 1 from 5 to 6 +move 1 from 6 to 4 +move 1 from 4 to 2 +move 2 from 2 to 3 +move 16 from 9 to 7 +move 3 from 6 to 7 +move 6 from 9 to 4 +move 4 from 4 to 7 +move 6 from 1 to 8 +move 2 from 3 to 6 +move 3 from 1 to 9 +move 3 from 2 to 3 +move 3 from 3 to 8 +move 5 from 2 to 8 +move 2 from 7 to 8 +move 3 from 1 to 5 +move 1 from 4 to 3 +move 2 from 9 to 8 +move 1 from 6 to 8 +move 2 from 9 to 1 +move 15 from 7 to 1 +move 1 from 6 to 5 +move 10 from 1 to 5 +move 1 from 4 to 1 +move 2 from 1 to 6 +move 9 from 7 to 8 +move 27 from 8 to 3 +move 1 from 6 to 1 +move 1 from 8 to 5 +move 5 from 5 to 6 +move 12 from 3 to 1 +move 3 from 7 to 1 +move 7 from 5 to 1 +move 1 from 6 to 4 +move 3 from 6 to 9 +move 1 from 4 to 2 +move 2 from 6 to 5 +move 1 from 7 to 6 +move 1 from 9 to 2 +move 2 from 5 to 6 +move 2 from 6 to 5 +move 3 from 1 to 3 +move 19 from 3 to 1 +move 2 from 2 to 9 +move 42 from 1 to 7 +move 4 from 9 to 7 +move 1 from 6 to 8 +move 1 from 8 to 5 +move 2 from 1 to 9 +move 3 from 5 to 7 +move 27 from 7 to 4 +move 1 from 1 to 4 +move 3 from 9 to 2 +move 18 from 4 to 9 +move 2 from 5 to 3 +move 1 from 7 to 1 +move 2 from 3 to 4 +move 8 from 7 to 5 +move 15 from 9 to 3 +move 1 from 9 to 7 +move 3 from 7 to 2 +move 2 from 7 to 2 +move 2 from 5 to 3 +move 1 from 1 to 5 +move 1 from 9 to 1 +move 1 from 3 to 1 +move 1 from 4 to 3 +move 8 from 7 to 3 +move 8 from 2 to 4 +move 1 from 9 to 6 +move 23 from 3 to 9 +move 1 from 9 to 6 +move 2 from 6 to 8 +move 1 from 8 to 6 +move 1 from 5 to 3 +move 7 from 4 to 8 +move 7 from 5 to 7 +move 2 from 8 to 3 +move 1 from 1 to 8 +move 3 from 7 to 4 +move 5 from 4 to 3 +move 1 from 1 to 8 +move 3 from 3 to 1 +move 8 from 9 to 7 +move 3 from 8 to 4 +move 1 from 6 to 2 +move 5 from 8 to 7 +move 6 from 3 to 1 +move 1 from 2 to 9 +move 7 from 7 to 9 +move 4 from 1 to 9 +move 2 from 4 to 2 +move 1 from 4 to 9 +move 1 from 1 to 6 +move 8 from 4 to 8 +move 4 from 1 to 5 +move 3 from 5 to 2 +move 2 from 2 to 5 +move 2 from 5 to 6 +move 1 from 3 to 7 +move 2 from 6 to 4 +move 1 from 5 to 7 +move 1 from 6 to 9 +move 1 from 4 to 1 +move 6 from 9 to 2 +move 8 from 9 to 7 +move 4 from 7 to 3 +move 4 from 8 to 3 +move 3 from 8 to 3 +move 8 from 3 to 5 +move 1 from 1 to 7 +move 11 from 9 to 7 +move 5 from 2 to 7 +move 1 from 8 to 1 +move 3 from 2 to 3 +move 1 from 1 to 4 +move 1 from 2 to 5 +move 20 from 7 to 8 +move 7 from 7 to 9 +move 4 from 4 to 7 +move 3 from 9 to 4 +move 5 from 7 to 4 +move 7 from 4 to 7 +move 4 from 9 to 2 +move 1 from 4 to 3 +move 4 from 3 to 5 +move 2 from 5 to 8 +move 4 from 5 to 2 +move 5 from 2 to 6 +move 2 from 6 to 3 +move 22 from 8 to 5 +move 13 from 7 to 9 +move 11 from 9 to 3 +move 2 from 6 to 8 +move 7 from 3 to 1 +move 18 from 5 to 2 +move 1 from 6 to 4 +move 1 from 4 to 9 +move 2 from 8 to 5 +move 2 from 9 to 1 +move 9 from 3 to 1 +move 4 from 5 to 6 +move 2 from 6 to 7 +move 3 from 9 to 5 +move 10 from 5 to 8 +move 6 from 8 to 7 +move 3 from 8 to 1 +move 6 from 2 to 3 +move 1 from 9 to 6 +move 5 from 3 to 4 +move 4 from 1 to 4 +move 17 from 1 to 5 +move 12 from 2 to 7 +move 1 from 3 to 6 +move 16 from 5 to 8 +move 3 from 5 to 6 +move 9 from 8 to 3 +move 8 from 8 to 4 +move 7 from 4 to 1 +move 5 from 1 to 4 +move 4 from 3 to 7 +move 14 from 7 to 3 +move 6 from 4 to 8 +move 9 from 7 to 4 +move 5 from 6 to 1 +move 1 from 7 to 1 +move 1 from 6 to 7 +move 16 from 4 to 5 +move 1 from 4 to 2 +move 1 from 7 to 5 +move 2 from 1 to 7 +move 2 from 7 to 4 +move 4 from 1 to 6 +move 13 from 5 to 6 +move 5 from 6 to 3 +move 22 from 3 to 2 +move 1 from 4 to 7 +move 4 from 5 to 4 +move 1 from 7 to 6 +move 5 from 8 to 5 +move 2 from 3 to 1 +move 13 from 6 to 1 +move 6 from 1 to 4 +move 1 from 8 to 1 +move 6 from 1 to 4 +move 1 from 5 to 4 +move 7 from 4 to 7 +move 3 from 1 to 5 +move 2 from 5 to 7 +move 5 from 5 to 1 +move 8 from 7 to 4 +move 1 from 6 to 4 +move 1 from 7 to 4 +move 9 from 2 to 7 +move 8 from 7 to 6 +move 5 from 6 to 4 +move 1 from 7 to 4 +move 2 from 4 to 9 +move 2 from 6 to 1 +move 8 from 2 to 6 +move 9 from 1 to 8 +move 9 from 6 to 2 +move 1 from 1 to 8 +move 6 from 8 to 4 +move 2 from 9 to 7 +move 2 from 7 to 9 +move 15 from 2 to 8 +move 18 from 4 to 2 +move 14 from 4 to 5 +move 10 from 2 to 4 +move 9 from 2 to 6 +move 1 from 9 to 3 +move 1 from 3 to 1 +move 6 from 5 to 8 +move 3 from 4 to 9 +move 2 from 2 to 1 +move 1 from 1 to 6 +move 3 from 9 to 7 +move 22 from 8 to 6 +move 1 from 8 to 9 +move 2 from 1 to 5 +move 5 from 5 to 4 +move 2 from 5 to 8 +move 2 from 8 to 7 +move 1 from 9 to 7 +move 1 from 5 to 8 +move 1 from 9 to 8 +move 15 from 6 to 4 +move 2 from 5 to 2 +move 11 from 4 to 6 +move 5 from 4 to 1 +move 5 from 4 to 2 +move 2 from 1 to 5 +move 6 from 2 to 8 +move 11 from 6 to 3 +move 12 from 6 to 8 +move 1 from 3 to 9 +move 3 from 3 to 2 +move 6 from 4 to 2 +move 2 from 5 to 8 +move 5 from 7 to 2 +move 11 from 8 to 4 +move 1 from 7 to 4 +move 1 from 9 to 6 +move 7 from 2 to 1 +move 3 from 6 to 5 +move 2 from 5 to 3 +move 1 from 5 to 9 +move 3 from 4 to 9 +move 4 from 9 to 1 +move 4 from 3 to 6 +move 3 from 4 to 8 +move 3 from 8 to 9 +move 2 from 8 to 2 +move 9 from 8 to 7 +move 2 from 3 to 1 +move 2 from 3 to 2 +move 1 from 3 to 6 +move 2 from 9 to 1 +move 8 from 7 to 5 +move 7 from 2 to 7 +move 2 from 8 to 9 +move 4 from 6 to 5 +move 13 from 1 to 5 +move 4 from 1 to 8 +move 3 from 9 to 3 +move 12 from 5 to 9 +move 3 from 8 to 9 +move 1 from 8 to 4 +move 3 from 2 to 7 +move 3 from 3 to 7 +move 1 from 9 to 2 +move 4 from 6 to 4 +move 6 from 5 to 6 +move 2 from 7 to 3 +move 2 from 2 to 1 +move 5 from 6 to 5 +move 1 from 1 to 7 +move 9 from 5 to 4 +move 10 from 9 to 6 +move 1 from 2 to 6 +move 12 from 7 to 6 +move 1 from 7 to 4 +move 23 from 6 to 1 +move 10 from 4 to 3 +move 16 from 1 to 5 +move 5 from 1 to 2 +move 6 from 3 to 7 +move 5 from 4 to 8 diff --git a/2022/day05_2/src/main/resources/small_input b/2022/day05_2/src/main/resources/small_input new file mode 100644 index 0000000..42ef47f --- /dev/null +++ b/2022/day05_2/src/main/resources/small_input @@ -0,0 +1,9 @@ + [D] +[N] [C] +[Z] [M] [P] + 1 2 3 + +move 1 from 2 to 1 +move 3 from 1 to 3 +move 2 from 2 to 1 +move 1 from 1 to 2 diff --git a/2022/day06_1/.idea/.gitignore b/2022/day06_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day06_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day06_1/.idea/compiler.xml b/2022/day06_1/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day06_1/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day06_1/.idea/gradle.xml b/2022/day06_1/.idea/gradle.xml new file mode 100644 index 0000000..5404067 --- /dev/null +++ b/2022/day06_1/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day06_1/.idea/jarRepositories.xml b/2022/day06_1/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day06_1/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day06_1/.idea/misc.xml b/2022/day06_1/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day06_1/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day06_1/.idea/vcs.xml b/2022/day06_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day06_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day06_1/build.gradle.kts b/2022/day06_1/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day06_1/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day06_1/gradle.properties b/2022/day06_1/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day06_1/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day06_1/gradle/wrapper/gradle-wrapper.jar b/2022/day06_1/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day06_1/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day06_1/gradlew b/2022/day06_1/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day06_1/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day06_1/gradlew.bat b/2022/day06_1/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day06_1/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day06_1/settings.gradle.kts b/2022/day06_1/settings.gradle.kts new file mode 100644 index 0000000..bd314e8 --- /dev/null +++ b/2022/day06_1/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day06_1" + diff --git a/2022/day06_1/src/main/kotlin/Main.kt b/2022/day06_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..d6dc10f --- /dev/null +++ b/2022/day06_1/src/main/kotlin/Main.kt @@ -0,0 +1,45 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 6, Part 1 starting!!!") + + val packetMarker = ArrayDeque() + var markerIndex = 0 + File(args[0]).forEachLine { + for(ch in it.toCharArray()) { + if(packetMarker.size < 4) { + packetMarker.addFirst(ch) + } else { + // start adding more from the front but drop the last + packetMarker.removeLast() + packetMarker.addFirst(ch) + } + + if(checkForMarker(packetMarker)) { + markerIndex++ + println("Packet Marker starts at : $markerIndex.") + println("Packet Marker looks like: $packetMarker") + break + } + markerIndex++ + } + } + + + + println("AOC 2022, Day 6, Part 1 completed!!") +} + +fun checkForMarker(packetMarker:ArrayDeque):Boolean { + if(packetMarker.size < 3) { + return false + } + + var count = 0 + for(ch in packetMarker) { + count += packetMarker.count { it == ch } + } + + // if this count is anything but 4 then there are duplicates + return count == 4 +} \ No newline at end of file diff --git a/2022/day06_1/src/main/resources/input b/2022/day06_1/src/main/resources/input new file mode 100644 index 0000000..443dbf0 --- /dev/null +++ b/2022/day06_1/src/main/resources/input @@ -0,0 +1 @@ +plhlsssjsrscspsffmrffwvfvrvvmbbnjnrnrfnndlnlznlznlnccdbbhvbvgvmvzmzvmzmbbrcclsslzslzzsztzftzzhggnjgnjnhnmnqnqqfdfnnrwnwsnwwvgvqqgpptvtrvvfmmzjzmmjssmwsmmhzzvvwzwcwrcrllpbppdgdvvwqvvsnsrnsncnwntnggwqgqhqrqprqrddjvddqsqhshchfffzddswdsshhcnhnqqfjffvlvwvssdqqwrwvrvhrvrzzgwggcjcgclcwchhzvzmzrrjwjqwwvbwwrmmvmpmzpzgpgsghgrrtmmlfmmnzzmpzzvmvjjsqqshqshsqqgtqggpvvrtttwbbhnbnlbnlnhnthtjhjshhrmrjjlclpprmrnrsrwrbwrwwjnwnbwbhbmbggdbgghllcvlvddzbdbdvdwvdvjvqvcvczvcvclvvrggrngrrwcwbcczgghnhznhnttbcbvcvttrrpbrppndppvvvgvtgvvhfvhhttppjmjllznlnldnldlwlnwlnlttgzzcfcggwmgmqgmmshmhqqdfqfpfqppprzrhrnrhnrrtsrrgpgnpngnqnmmrtrvtrrfccszszffvlfvlvssvdvvpggvcvscvvpmpgpqpfqqhttrhhsbhbqhhzggzrgrqrfqffwllggrgqqjzqzzsgglvgllsgllptltblbggvrggctczzllvsvcscrrzjrzzjnnbvvtntpntnvtntcntcnnwsnnnvjnnsccsddcvvgzgwggbnbwnwbwmwttzzsgzzjpzztwztwwhhzggplgplggwwwphpmmhchsccmwmttvjtjftffzbfffjljbbqvvstsggbbqrbqrbrhbbrmbmppvrpphptpggqgddtmdtmdmbbbcdbbgssmzzthhtjjrgjrgrzzchzhttgddjnjrjmjllrcrqqsvsjjjhvvphhgjhgjhjccwmcmjcmjmhmzznmmcbcscddcsssnppsnpnmnqmmtztftqtjtqqgvgvjjfnjffqbqbfqqwfqfcfsfttvccnssjvvpfvpvttvpvccwhwfwlwlclljqqststllgqgzqqfpflpplpssnntstqqpnnsrnsrrsvrsvsrvsrrtztmtptpcpssgnnfvflffscsqszzsppfnftfptfpfnfbbwzbzfbbtggrzrnntztnznhnnlbnbrbdddjhjchhdshhnzhnnsrnrrqwrrdsdlsstdsslqsqdqvqzvqvwqqlmmwzmwzwztzlzczhqfrclvgvnlchrggsrjhntctdbpfdcffwjngdvdrjmgvwvptlvlhvhshqphmrdznqbtchcvrwfrpvwhzmrwlcjwnrsgrqcbsgpwjthstvqzlwjjmqbvhhdfdsmqnmnswmwjtpgjhdpgcnvmlcjwjzrjhmrqmqnrqrmgdnbdgznwhgzncmcbzpntcdflvrbfdzwgpnqjqmrcqpbrzwhwdgtgshhmrwvhnrwslvcswjvdgglfrdvmqdspppwmvfzvdbvpcnhmvgfqwnvjvvzrvttwvbjrbjlllmwtlcltvqmwshnqsdtjrptvqjvdjgzwgzzhcdbwjzhdgsptfrtmmqvhsnsnpgwbncbnnvwmmrrjgfccbzcpcjmqvqsbvjrstzblsrngphwndfdswjnnnfdgpcbslvbjglqqnbbtjljsmdgcslmwlvgwpsqthlmmqfgpgmcvrpvvtzcjdrwcjgrbwthblwpwpbzvjvhzsphmfhfwvsthlfnhhfcmpsnmgrvrntlzpdvqwtrghnslnfhcjwrsvrngqqtwvcsfhbjwmsnmsmgvdhnzjgljtchbtwlfppvbtdclbdjdmwzcntvgfjlcwdplnjwqnzqhnfgcnbrgftqpdmqzrrhglbzzvjcdnbtfnvmsrbjdzhbqmhnsmprgvjzzgvllhqnzgpstqzcnlgsrcwzlhwqvcjlwnnjslmdtwqcpbrntrmrmmtscjwwtzjhghtqvvpldzvhtmspzlnlfgrfhmsndbdgpgvphwwgqhrtlwztgqqsrwnrnqphqfsrtbztqbrgmfbtpjwhhrglhbzmmjptppnfdzlpbqfcbdwzdtqbrvfmtdzdjlnzvqfnzmttpqgzgmrqwmdtmdzrttffpdlgwdhnlrhnnztphvrbzcrlvcpswlngcjhdzqwwwpzdmhhwpnzwgjsdsdbdvpfsrwmwvsggpcqbchwjpgljnbtpvjzbbvgsbsbjmtwtbjtzzsfvrmfvnmcngvvdsvljvjbrlfgstjrhtjplttzhjfbmphvbqdsmwfwspqpcvmgzgjnqlphshlgdwcvtmpwcfgdcbqwpnshfgrfjvlrtqbffwwtbnwtvjlsdgwgfmhlrsmfrjzcwccdzfwwdwhwdsjbllhjsqmnqvngvdmbvbssfjtjfbtngrdwgldcrtpmvrbrmpvwwsfrlnbqsqzfnftpbhslqccnbqwgbdbfpblpmwbgjzmnptnhdjzqjhdrhqbtfhsrdqwlmwzqlsmmslgfzpvtgtsrlszvqrhrzclbqhzzwwfmhrrvsrnsjbdjsqqlsmgdmgbdtmvfjmsbwjqmqrvrhqbchpqrwvlvwpvhjlbdzfjvrwmchccrsrfvhzmpfjqwnrbvqmgwjcbndjdtfgnrzrqwgzhrdvghdrvgtplcrthgchmvwtdrchfwpdszzzhqpmrlzvfdnfnlwghmmwvsscbrdbchhgttsnbzdbqgddqfvcgvqwltnqtcwrmhtftnlwvlglsvvctccnntznsjnmmgqlzmplsdspnjtmzlbvrfzfclnhgjzmvntdwhspqwtpgndspnjqjqwrpwhjhpvjwfptpndnwvcjdwsvdtcrtwpsprgmrspgmcsdgtjbbgsgvcjhrcldlvgvqwqwthplzgwbzmszjfrlnznvgphnqzcwsztvvljlrlzrndbzccstprhntnlmshhclnrsmsvvvsbmpfdjsmspwcqtmlrrdmfzjjjhmsmdfqddzpgtbzbsnhhhpsfrdrdvpvpnjmvnhdrzrqggrpqdcmctvqfrtfmjjqjwgzzbrdfplhzjbnqlmjlcgvmsbpgdlfjmbgqtrvzzdgtlmbqthjrdtlstqtzqvfjvmmstsmtsbnjvstjjvrrjqcbjvhfpslpvjmdznrcnsvlpbpzmslqtpczmvhdwzrhwbwtfvrrmbszvrhwsjrclcscgngwvblbbrqprgshwzhlqgwmpfsmqsvpjbdccdmtnnhqfwvlgjlszmmmdmtmpzwhplzsjztrnwngbvspqqbmghwzgvfjdrblfmtwcvnczsrflmsjmrsvzldmttjwcmnvwcbjfvznhgntnqfbfchcqqshhjldgltqhdlqldlpfjnjvtbvbntzdjzstcqbzdnmsvcdgvjmmvtdfvdplqfndqqlzlspmjgdfbgsvwzqzsvvbbldltbtzwzpqrzfmfzgdbpqnwtrfcgwmlbpzrgscbjvfdwnjzjdfzltsbppnljzrgggplmttpmgwnhdlwfhwzsrcflnrqqzwsbqllwjqlrgwbhvcvqdvjvpbzgnfbbbtccvplzggplbrsbldllwmttwtvltsfljfbbprtvlfshhwdhdgvzfzjttvnphpnjnzsbvfwflfpqwnhvwjdsrtbwsjzqhgfldnssfbbzzqqrwtjvwjschmndgqzjtpsbfhwtmqbtfstrbghgtnldjqtshdnrwzvwddchhvdbsfjnqzfjdpvhvwwjspftgbtgwzdfgzzhpvjpdlrrdfnpftshthwzjzmzdghnfdqcbmjhfdgzrcgrzbrjtmhwbjhcpgjdsmnqzncdlwhqqzqblgdbbdsmrqgbdbmdczvvpnbbjdwrlmrwgnnbbzpcnsjgcmshgzwnjzwjlrdmvmhvjrzphgpczppqvwjthcdphprhhrggjdpzmgtpjjfvpczzrvsssfrrptnzlstrhmbhvzmwjnddshrrtgspbllvqlsptrtvtldsgnjjbwtfmtbjdvmgbptjlzhpttjmvpgnjphswhtdq diff --git a/2022/day06_1/src/main/resources/small_input0 b/2022/day06_1/src/main/resources/small_input0 new file mode 100644 index 0000000..7980a82 --- /dev/null +++ b/2022/day06_1/src/main/resources/small_input0 @@ -0,0 +1 @@ +mjqjpqmgbljsphdztnvjfqwrcgsmlb diff --git a/2022/day06_1/src/main/resources/small_input1 b/2022/day06_1/src/main/resources/small_input1 new file mode 100644 index 0000000..9e3311c --- /dev/null +++ b/2022/day06_1/src/main/resources/small_input1 @@ -0,0 +1 @@ +bvwbjplbgvbhsrlpgdmjqwftvncz \ No newline at end of file diff --git a/2022/day06_1/src/main/resources/small_input2 b/2022/day06_1/src/main/resources/small_input2 new file mode 100644 index 0000000..cca46f5 --- /dev/null +++ b/2022/day06_1/src/main/resources/small_input2 @@ -0,0 +1 @@ +nppdvjthqldpwncqszvftbrmjlhg \ No newline at end of file diff --git a/2022/day06_1/src/main/resources/small_input3 b/2022/day06_1/src/main/resources/small_input3 new file mode 100644 index 0000000..848af1c --- /dev/null +++ b/2022/day06_1/src/main/resources/small_input3 @@ -0,0 +1 @@ +nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg \ No newline at end of file diff --git a/2022/day06_2/.idea/.gitignore b/2022/day06_2/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day06_2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day06_2/.idea/compiler.xml b/2022/day06_2/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day06_2/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day06_2/.idea/gradle.xml b/2022/day06_2/.idea/gradle.xml new file mode 100644 index 0000000..a7087b2 --- /dev/null +++ b/2022/day06_2/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/2022/day06_2/.idea/jarRepositories.xml b/2022/day06_2/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day06_2/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day06_2/.idea/misc.xml b/2022/day06_2/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day06_2/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day06_2/.idea/vcs.xml b/2022/day06_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day06_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day06_2/build.gradle.kts b/2022/day06_2/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day06_2/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day06_2/gradle.properties b/2022/day06_2/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day06_2/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day06_2/gradle/wrapper/gradle-wrapper.jar b/2022/day06_2/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day06_2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day06_2/gradlew b/2022/day06_2/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day06_2/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day06_2/gradlew.bat b/2022/day06_2/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day06_2/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day06_2/settings.gradle.kts b/2022/day06_2/settings.gradle.kts new file mode 100644 index 0000000..9f74b95 --- /dev/null +++ b/2022/day06_2/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day06_2" + diff --git a/2022/day06_2/src/main/kotlin/Main.kt b/2022/day06_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..08cea5b --- /dev/null +++ b/2022/day06_2/src/main/kotlin/Main.kt @@ -0,0 +1,45 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 6, Part 2 starting!!!") + + val packetMarker = ArrayDeque() + var markerIndex = 0 + File(args[0]).forEachLine { + for(ch in it.toCharArray()) { + if(packetMarker.size < 14) { + packetMarker.addFirst(ch) + } else { + // start adding more from the front but drop the last + packetMarker.removeLast() + packetMarker.addFirst(ch) + } + + if(checkForMarker(packetMarker)) { + markerIndex++ + println("Packet Marker starts at : $markerIndex.") + println("Packet Marker looks like: $packetMarker") + break + } + markerIndex++ + } + } + + + + println("AOC 2022, Day 6, Part 2 completed!!") +} + +fun checkForMarker(packetMarker:ArrayDeque):Boolean { + if(packetMarker.size < 13) { + return false + } + + var count = 0 + for(ch in packetMarker) { + count += packetMarker.count { it == ch } + } + + // if this count is anything but 4 then there are duplicates + return count == 14 +} \ No newline at end of file diff --git a/2022/day06_2/src/main/resources/input b/2022/day06_2/src/main/resources/input new file mode 100644 index 0000000..443dbf0 --- /dev/null +++ b/2022/day06_2/src/main/resources/input @@ -0,0 +1 @@ +plhlsssjsrscspsffmrffwvfvrvvmbbnjnrnrfnndlnlznlznlnccdbbhvbvgvmvzmzvmzmbbrcclsslzslzzsztzftzzhggnjgnjnhnmnqnqqfdfnnrwnwsnwwvgvqqgpptvtrvvfmmzjzmmjssmwsmmhzzvvwzwcwrcrllpbppdgdvvwqvvsnsrnsncnwntnggwqgqhqrqprqrddjvddqsqhshchfffzddswdsshhcnhnqqfjffvlvwvssdqqwrwvrvhrvrzzgwggcjcgclcwchhzvzmzrrjwjqwwvbwwrmmvmpmzpzgpgsghgrrtmmlfmmnzzmpzzvmvjjsqqshqshsqqgtqggpvvrtttwbbhnbnlbnlnhnthtjhjshhrmrjjlclpprmrnrsrwrbwrwwjnwnbwbhbmbggdbgghllcvlvddzbdbdvdwvdvjvqvcvczvcvclvvrggrngrrwcwbcczgghnhznhnttbcbvcvttrrpbrppndppvvvgvtgvvhfvhhttppjmjllznlnldnldlwlnwlnlttgzzcfcggwmgmqgmmshmhqqdfqfpfqppprzrhrnrhnrrtsrrgpgnpngnqnmmrtrvtrrfccszszffvlfvlvssvdvvpggvcvscvvpmpgpqpfqqhttrhhsbhbqhhzggzrgrqrfqffwllggrgqqjzqzzsgglvgllsgllptltblbggvrggctczzllvsvcscrrzjrzzjnnbvvtntpntnvtntcntcnnwsnnnvjnnsccsddcvvgzgwggbnbwnwbwmwttzzsgzzjpzztwztwwhhzggplgplggwwwphpmmhchsccmwmttvjtjftffzbfffjljbbqvvstsggbbqrbqrbrhbbrmbmppvrpphptpggqgddtmdtmdmbbbcdbbgssmzzthhtjjrgjrgrzzchzhttgddjnjrjmjllrcrqqsvsjjjhvvphhgjhgjhjccwmcmjcmjmhmzznmmcbcscddcsssnppsnpnmnqmmtztftqtjtqqgvgvjjfnjffqbqbfqqwfqfcfsfttvccnssjvvpfvpvttvpvccwhwfwlwlclljqqststllgqgzqqfpflpplpssnntstqqpnnsrnsrrsvrsvsrvsrrtztmtptpcpssgnnfvflffscsqszzsppfnftfptfpfnfbbwzbzfbbtggrzrnntztnznhnnlbnbrbdddjhjchhdshhnzhnnsrnrrqwrrdsdlsstdsslqsqdqvqzvqvwqqlmmwzmwzwztzlzczhqfrclvgvnlchrggsrjhntctdbpfdcffwjngdvdrjmgvwvptlvlhvhshqphmrdznqbtchcvrwfrpvwhzmrwlcjwnrsgrqcbsgpwjthstvqzlwjjmqbvhhdfdsmqnmnswmwjtpgjhdpgcnvmlcjwjzrjhmrqmqnrqrmgdnbdgznwhgzncmcbzpntcdflvrbfdzwgpnqjqmrcqpbrzwhwdgtgshhmrwvhnrwslvcswjvdgglfrdvmqdspppwmvfzvdbvpcnhmvgfqwnvjvvzrvttwvbjrbjlllmwtlcltvqmwshnqsdtjrptvqjvdjgzwgzzhcdbwjzhdgsptfrtmmqvhsnsnpgwbncbnnvwmmrrjgfccbzcpcjmqvqsbvjrstzblsrngphwndfdswjnnnfdgpcbslvbjglqqnbbtjljsmdgcslmwlvgwpsqthlmmqfgpgmcvrpvvtzcjdrwcjgrbwthblwpwpbzvjvhzsphmfhfwvsthlfnhhfcmpsnmgrvrntlzpdvqwtrghnslnfhcjwrsvrngqqtwvcsfhbjwmsnmsmgvdhnzjgljtchbtwlfppvbtdclbdjdmwzcntvgfjlcwdplnjwqnzqhnfgcnbrgftqpdmqzrrhglbzzvjcdnbtfnvmsrbjdzhbqmhnsmprgvjzzgvllhqnzgpstqzcnlgsrcwzlhwqvcjlwnnjslmdtwqcpbrntrmrmmtscjwwtzjhghtqvvpldzvhtmspzlnlfgrfhmsndbdgpgvphwwgqhrtlwztgqqsrwnrnqphqfsrtbztqbrgmfbtpjwhhrglhbzmmjptppnfdzlpbqfcbdwzdtqbrvfmtdzdjlnzvqfnzmttpqgzgmrqwmdtmdzrttffpdlgwdhnlrhnnztphvrbzcrlvcpswlngcjhdzqwwwpzdmhhwpnzwgjsdsdbdvpfsrwmwvsggpcqbchwjpgljnbtpvjzbbvgsbsbjmtwtbjtzzsfvrmfvnmcngvvdsvljvjbrlfgstjrhtjplttzhjfbmphvbqdsmwfwspqpcvmgzgjnqlphshlgdwcvtmpwcfgdcbqwpnshfgrfjvlrtqbffwwtbnwtvjlsdgwgfmhlrsmfrjzcwccdzfwwdwhwdsjbllhjsqmnqvngvdmbvbssfjtjfbtngrdwgldcrtpmvrbrmpvwwsfrlnbqsqzfnftpbhslqccnbqwgbdbfpblpmwbgjzmnptnhdjzqjhdrhqbtfhsrdqwlmwzqlsmmslgfzpvtgtsrlszvqrhrzclbqhzzwwfmhrrvsrnsjbdjsqqlsmgdmgbdtmvfjmsbwjqmqrvrhqbchpqrwvlvwpvhjlbdzfjvrwmchccrsrfvhzmpfjqwnrbvqmgwjcbndjdtfgnrzrqwgzhrdvghdrvgtplcrthgchmvwtdrchfwpdszzzhqpmrlzvfdnfnlwghmmwvsscbrdbchhgttsnbzdbqgddqfvcgvqwltnqtcwrmhtftnlwvlglsvvctccnntznsjnmmgqlzmplsdspnjtmzlbvrfzfclnhgjzmvntdwhspqwtpgndspnjqjqwrpwhjhpvjwfptpndnwvcjdwsvdtcrtwpsprgmrspgmcsdgtjbbgsgvcjhrcldlvgvqwqwthplzgwbzmszjfrlnznvgphnqzcwsztvvljlrlzrndbzccstprhntnlmshhclnrsmsvvvsbmpfdjsmspwcqtmlrrdmfzjjjhmsmdfqddzpgtbzbsnhhhpsfrdrdvpvpnjmvnhdrzrqggrpqdcmctvqfrtfmjjqjwgzzbrdfplhzjbnqlmjlcgvmsbpgdlfjmbgqtrvzzdgtlmbqthjrdtlstqtzqvfjvmmstsmtsbnjvstjjvrrjqcbjvhfpslpvjmdznrcnsvlpbpzmslqtpczmvhdwzrhwbwtfvrrmbszvrhwsjrclcscgngwvblbbrqprgshwzhlqgwmpfsmqsvpjbdccdmtnnhqfwvlgjlszmmmdmtmpzwhplzsjztrnwngbvspqqbmghwzgvfjdrblfmtwcvnczsrflmsjmrsvzldmttjwcmnvwcbjfvznhgntnqfbfchcqqshhjldgltqhdlqldlpfjnjvtbvbntzdjzstcqbzdnmsvcdgvjmmvtdfvdplqfndqqlzlspmjgdfbgsvwzqzsvvbbldltbtzwzpqrzfmfzgdbpqnwtrfcgwmlbpzrgscbjvfdwnjzjdfzltsbppnljzrgggplmttpmgwnhdlwfhwzsrcflnrqqzwsbqllwjqlrgwbhvcvqdvjvpbzgnfbbbtccvplzggplbrsbldllwmttwtvltsfljfbbprtvlfshhwdhdgvzfzjttvnphpnjnzsbvfwflfpqwnhvwjdsrtbwsjzqhgfldnssfbbzzqqrwtjvwjschmndgqzjtpsbfhwtmqbtfstrbghgtnldjqtshdnrwzvwddchhvdbsfjnqzfjdpvhvwwjspftgbtgwzdfgzzhpvjpdlrrdfnpftshthwzjzmzdghnfdqcbmjhfdgzrcgrzbrjtmhwbjhcpgjdsmnqzncdlwhqqzqblgdbbdsmrqgbdbmdczvvpnbbjdwrlmrwgnnbbzpcnsjgcmshgzwnjzwjlrdmvmhvjrzphgpczppqvwjthcdphprhhrggjdpzmgtpjjfvpczzrvsssfrrptnzlstrhmbhvzmwjnddshrrtgspbllvqlsptrtvtldsgnjjbwtfmtbjdvmgbptjlzhpttjmvpgnjphswhtdq diff --git a/2022/day06_2/src/main/resources/small_input0 b/2022/day06_2/src/main/resources/small_input0 new file mode 100644 index 0000000..7980a82 --- /dev/null +++ b/2022/day06_2/src/main/resources/small_input0 @@ -0,0 +1 @@ +mjqjpqmgbljsphdztnvjfqwrcgsmlb diff --git a/2022/day06_2/src/main/resources/small_input1 b/2022/day06_2/src/main/resources/small_input1 new file mode 100644 index 0000000..9e3311c --- /dev/null +++ b/2022/day06_2/src/main/resources/small_input1 @@ -0,0 +1 @@ +bvwbjplbgvbhsrlpgdmjqwftvncz \ No newline at end of file diff --git a/2022/day06_2/src/main/resources/small_input2 b/2022/day06_2/src/main/resources/small_input2 new file mode 100644 index 0000000..cca46f5 --- /dev/null +++ b/2022/day06_2/src/main/resources/small_input2 @@ -0,0 +1 @@ +nppdvjthqldpwncqszvftbrmjlhg \ No newline at end of file diff --git a/2022/day06_2/src/main/resources/small_input3 b/2022/day06_2/src/main/resources/small_input3 new file mode 100644 index 0000000..848af1c --- /dev/null +++ b/2022/day06_2/src/main/resources/small_input3 @@ -0,0 +1 @@ +nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg \ No newline at end of file diff --git a/2022/day07_1/.idea/.gitignore b/2022/day07_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day07_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day07_1/.idea/compiler.xml b/2022/day07_1/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day07_1/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day07_1/.idea/gradle.xml b/2022/day07_1/.idea/gradle.xml new file mode 100644 index 0000000..5404067 --- /dev/null +++ b/2022/day07_1/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day07_1/.idea/jarRepositories.xml b/2022/day07_1/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day07_1/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day07_1/.idea/misc.xml b/2022/day07_1/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day07_1/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day07_1/.idea/vcs.xml b/2022/day07_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day07_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day07_1/build.gradle.kts b/2022/day07_1/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day07_1/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day07_1/gradle.properties b/2022/day07_1/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day07_1/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day07_1/gradle/wrapper/gradle-wrapper.jar b/2022/day07_1/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day07_1/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day07_1/gradlew b/2022/day07_1/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day07_1/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day07_1/gradlew.bat b/2022/day07_1/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day07_1/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day07_1/settings.gradle.kts b/2022/day07_1/settings.gradle.kts new file mode 100644 index 0000000..0d8a484 --- /dev/null +++ b/2022/day07_1/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day07_1" + diff --git a/2022/day07_1/src/main/kotlin/Main.kt b/2022/day07_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..a77651f --- /dev/null +++ b/2022/day07_1/src/main/kotlin/Main.kt @@ -0,0 +1,163 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 7, Part 1 starting!!!") + + val fileSystem = FileSystem() + + File(args[0]).forEachLine { + processLine(it, fileSystem) + } + + fileSystem.dumpFileSystem() + + val answer = fileSystem.calculateAnswer(100000) + println("Answer: $answer") + if(answer != 1490523L) { + println("ERROR DID NOT WORK") + } + + println("AOC 2022, Day 7, Part 1 completed!!") +} + +fun processLine(line:String, fileSystem: FileSystem) { + if(line[0] == '$') { + val command = line.substring(2, 4) + // command == "ls" does nothing + if(command == "cd") { + val param = line.substring(5) + fileSystem.changeDirectory(param) + } + } else { + // Is this line a NNN FileName + if(line[0].isDigit()) { + val splitLine = line.split(' ') + val fileSize = splitLine[0].toLong() + val fileName = splitLine[1] + fileSystem.addFile(MyFileData(fileName, fileSize, MyDirectoryData(fileSystem.currentDirectory))) + } else { + val dirName = line.substring(4) + fileSystem.addDirectory(MyDirectoryData(dirName)) + } + } +} + +abstract class MyFileObject { + abstract val objectName:String + abstract val objectType:String +} +data class MyDirectoryData ( + override val objectName:String +) : MyFileObject() { + override val objectType: String + get() = "directory" +} + +data class MyFileData ( + override val objectName: String, + val fileSize:Long, + val directory:MyDirectoryData): MyFileObject() { + override val objectType: String + get() = "file" +} + +class FileSystem { + var currentDirectory: String = "/" + private val files:HashMap = HashMap() + private val directories:HashMap = HashMap() + + fun changeDirectory(newDirectory: String) { + //println("tlarsen,L66: Start requested $newDirectory -> changing directory from $currentDirectory") + if (newDirectory == "/") { + currentDirectory = newDirectory + //println("tlarsen,L69: requested $newDirectory -> changing directory from $currentDirectory to $newDirectory") + return + } + if(newDirectory.compareTo("..") == 0) { + // move up one directory + val directories = currentDirectory.split('/') + var tempDirectory = "" + + for(i in 0 until directories.lastIndex) { + if(directories[i].isEmpty()) { + continue + } else { + tempDirectory += "/${directories[i]}" + } + } + + if(tempDirectory.isEmpty()) { + tempDirectory = "/" + //throw Exception("tempDirectory is empty! currentDirectory = $currentDirectory, newDirectory = $newDirectory, directories = $directories") + //println("tlarsen,L96: tempDirectory was empty! currentDirectory = $currentDirectory, newDirectory = $newDirectory, directories = $directories\"") + } + //println("tlarsen,L89: requested $newDirectory -> changing directory from $currentDirectory to $tempDirectory") + currentDirectory = tempDirectory + } else { + + //val oldCurrentDirectory = currentDirectory + + if ((currentDirectory == "/") || (currentDirectory.isEmpty())) { + currentDirectory = "/$newDirectory" + } else { + currentDirectory += "/$newDirectory" + } + //println("tlarsen,L101: requested $newDirectory -> changing directory from $oldCurrentDirectory to $currentDirectory") + } + } + + fun addFile(file:MyFileData) { + files[file] = MyDirectoryData(currentDirectory) + } + + fun addDirectory(directory: MyDirectoryData) { + directories[directory] = MyDirectoryData(currentDirectory) + } + + fun dumpFileSystem() { + println("Dumping file system: ${files.size} Files, ${directories.size} Directories:") + + println("****files: ") + for(file in files) { + //println(" File: ${file.value.objectName}/${file.key.objectName}, size: ${file.key.fileSize}") + println("${file.value.objectName}/${file.key.objectName} ${file.key.fileSize}") + } + } + fun calculateAnswer(atMost: Int):Long { + val answerHashMap:HashMap = HashMap() + answerHashMap.put("/", 0) + + for(directory in directories) { + if(directory.value.objectName.compareTo("/") != 0) { + answerHashMap.put("${directory.value.objectName}/${directory.key.objectName}", 0) + } else { + //println("tlarsen,L137: ${directory.key.objectName} and ${directory.value.objectName}") + answerHashMap.put("/${directory.key.objectName}", 0) + } + } + + for(file in files) { + val splitDirectory = file.value.objectName.split("/") + + var theDirectory = "/" + for(directory in splitDirectory) { + if(directory.isEmpty()) { + theDirectory = "/" + } else { + theDirectory += "/$directory" + } + + if(theDirectory.startsWith("//")) { + theDirectory = "/$directory" + } + + //var dirTotal = answerHashMap[theDirectory]!! + var dirTotal = answerHashMap.getOrDefault(theDirectory, 0) + dirTotal += file.key.fileSize + answerHashMap[theDirectory] = dirTotal + } + } + + return answerHashMap.filter { it.value < atMost }.values.sum() + } +} \ No newline at end of file diff --git a/2022/day07_1/src/main/resources/input b/2022/day07_1/src/main/resources/input new file mode 100644 index 0000000..cf8a6c4 --- /dev/null +++ b/2022/day07_1/src/main/resources/input @@ -0,0 +1,1135 @@ +$ cd / +$ ls +233998 glh.fcb +184686 jzn +dir qcznqph +dir qtbprrq +299692 rbssdzm.ccn +dir vtb +$ cd qcznqph +$ ls +32148 lhsrj.fnr +dir lnj +dir mtr +dir mznnlph +dir pdtpt +24836 rsjcg.lrh +dir vrj +dir wrqcfl +$ cd lnj +$ ls +12592 tlh +$ cd .. +$ cd mtr +$ ls +118870 twdhlmp.gbw +$ cd .. +$ cd mznnlph +$ ls +240977 fmmhnhtf +dir gbhcnts +dir gsbjrrd +dir pmwcs +dir qtbprrq +286007 rhnjndsq.gst +dir twdhlmp +283716 twdhlmp.rpr +$ cd gbhcnts +$ ls +dir fctrnwb +dir gbhcnts +46017 gft.hvm +234925 gjsnzbtw.ncd +dir nvnwh +dir srslsjp +dir swtlfsv +66115 tgpmsb +64086 tqnvb +308270 tqwfpnbn.btp +$ cd fctrnwb +$ ls +112643 qhcdd +$ cd .. +$ cd gbhcnts +$ ls +26196 cmttgsmm.bdn +317410 fthqln +dir lwshph +32809 tdmfc +dir tqcllnv +dir twdhlmp +$ cd lwshph +$ ls +214023 ctqvrzs.jvr +104432 gbch +dir gpqgrw +105909 qshbtd.nml +dir rhhsfbdd +dir svvqh +161439 tqnvb +60152 twdhlmp.qzw +$ cd gpqgrw +$ ls +dir mbsgrlld +dir nhb +dir qtbprrq +$ cd mbsgrlld +$ ls +13247 tsztmlfg +dir twdhlmp +$ cd twdhlmp +$ ls +236804 mcrd +$ cd .. +$ cd .. +$ cd nhb +$ ls +86570 gtvnbsv.zbr +$ cd .. +$ cd qtbprrq +$ ls +111178 npg.qph +110775 tlh +$ cd .. +$ cd .. +$ cd rhhsfbdd +$ ls +37729 fmmhnhtf +263415 ljvwzj.btm +$ cd .. +$ cd svvqh +$ ls +185682 wlcl.fhs +$ cd .. +$ cd .. +$ cd tqcllnv +$ ls +dir cbdj +dir ccsfm +55264 tqnvb +267792 wlcl.fhs +$ cd cbdj +$ ls +128247 fmmhnhtf +dir mtnbs +240520 ngmw.clj +30569 qbqltr.lbw +188801 zwdpp +$ cd mtnbs +$ ls +dir bsfbrmh +dir ftmnrwm +$ cd bsfbrmh +$ ls +dir tltvzp +$ cd tltvzp +$ ls +312469 dnst.sbm +$ cd .. +$ cd .. +$ cd ftmnrwm +$ ls +278974 nlztftc.zhb +$ cd .. +$ cd .. +$ cd .. +$ cd ccsfm +$ ls +4017 wlcl.fhs +$ cd .. +$ cd .. +$ cd twdhlmp +$ ls +dir qtbprrq +$ cd qtbprrq +$ ls +dir tdpz +$ cd tdpz +$ ls +210400 fmmhnhtf +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd nvnwh +$ ls +dir jlpbbds +dir pphv +285452 qtbprrq +$ cd jlpbbds +$ ls +7058 vmrcqz +$ cd .. +$ cd pphv +$ ls +290310 msz.swz +$ cd .. +$ cd .. +$ cd srslsjp +$ ls +dir nnz +192902 twdhlmp.vgp +$ cd nnz +$ ls +215711 tlh +$ cd .. +$ cd .. +$ cd swtlfsv +$ ls +274236 frwncp.gff +$ cd .. +$ cd .. +$ cd gsbjrrd +$ ls +dir dnst +dir gbhcnts +61000 gqdf +175813 jvz +dir ldqjzrtp +$ cd dnst +$ ls +124352 dnst +220618 mzsqzbfz.qfd +134211 qmrvh +dir qqlm +dir qtbprrq +223840 tlh +dir twdhlmp +24794 wfb.rtf +$ cd qqlm +$ ls +113976 wlcl.fhs +$ cd .. +$ cd qtbprrq +$ ls +212775 qtbprrq.ngs +$ cd .. +$ cd twdhlmp +$ ls +308083 fzhd +63311 wlcl.fhs +$ cd .. +$ cd .. +$ cd gbhcnts +$ ls +dir dlvhzdbg +$ cd dlvhzdbg +$ ls +305798 twdhlmp +$ cd .. +$ cd .. +$ cd ldqjzrtp +$ ls +93085 dcvfpz.bjl +264488 zssvm.wdp +$ cd .. +$ cd .. +$ cd pmwcs +$ ls +125444 qtbprrq.tgl +$ cd .. +$ cd qtbprrq +$ ls +dir bjnctfv +133127 fmmhnhtf +dir gztmrrff +dir qtbprrq +$ cd bjnctfv +$ ls +dir cpwrcf +dir fdjzsfc +1223 gbhcnts.qvf +272526 gbhcnts.sgs +dir qnsdl +dir snq +dir tmjnvcbl +dir vdjqsbr +271339 wslnqh.rgr +134589 zzqrbr.fcz +$ cd cpwrcf +$ ls +143124 pdr +$ cd .. +$ cd fdjzsfc +$ ls +dir gbhcnts +dir nqpbzvpq +$ cd gbhcnts +$ ls +151265 jrdvt.fcg +11872 tlh +$ cd .. +$ cd nqpbzvpq +$ ls +dir hpwhslq +27858 ljvwzj.prq +dir nzcnb +$ cd hpwhslq +$ ls +136646 bqgj.wvw +252823 ngmw.clj +137072 tqnvb +$ cd .. +$ cd nzcnb +$ ls +99882 twdhlmp.grg +$ cd .. +$ cd .. +$ cd .. +$ cd qnsdl +$ ls +8925 fmmhnhtf +dir mnzqwfnh +206990 vqgrhqgc +$ cd mnzqwfnh +$ ls +271442 bmztfjlc.lzr +$ cd .. +$ cd .. +$ cd snq +$ ls +25995 tqnvb +$ cd .. +$ cd tmjnvcbl +$ ls +dir gclzbvt +$ cd gclzbvt +$ ls +dir jtfddbs +$ cd jtfddbs +$ ls +10564 pdf.tsj +32415 tlh +$ cd .. +$ cd .. +$ cd .. +$ cd vdjqsbr +$ ls +256668 cwbd +265036 fmmhnhtf +$ cd .. +$ cd .. +$ cd gztmrrff +$ ls +52260 bdqcl.bdw +dir lsss +120102 tlh +$ cd lsss +$ ls +13729 wlcl.fhs +$ cd .. +$ cd .. +$ cd qtbprrq +$ ls +dir bttpq +dir lcvgwpt +$ cd bttpq +$ ls +216247 nnlv.dgl +138688 wlcl.fhs +$ cd .. +$ cd lcvgwpt +$ ls +dir dth +198570 tsqgm.zht +dir zbcstsb +$ cd dth +$ ls +dir cqmbtj +120437 hdqp.vhq +dir vpzn +$ cd cqmbtj +$ ls +11882 sdngnzb +$ cd .. +$ cd vpzn +$ ls +dir jqbz +271714 plcq.bfg +$ cd jqbz +$ ls +dir qqhnfglj +136307 stncbrm +177843 tlh +168253 tqnvb +297085 wcn +$ cd qqhnfglj +$ ls +197471 twdhlmp +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd zbcstsb +$ ls +298115 bvljmpc.gss +308872 ljr.lzl +201657 ngmw.clj +170617 ppln +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd twdhlmp +$ ls +dir dbb +277215 ngmw.clj +310263 twdhlmp.wvs +dir vsfrqsnl +$ cd dbb +$ ls +258300 tqnvb +$ cd .. +$ cd vsfrqsnl +$ ls +dir gbhcnts +12285 tlh +$ cd gbhcnts +$ ls +248251 dnst.bcs +91471 gbhcnts.ntr +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd pdtpt +$ ls +164477 flcgj.zwr +dir ljvwzj +51483 ljvwzj.htl +dir pbtr +dir qtbprrq +dir rrhcsn +$ cd ljvwzj +$ ls +dir nsq +133318 qtbprrq.gqq +166365 rnfbl.ljh +130617 tlh +16112 vbw +$ cd nsq +$ ls +dir fwfcmfbz +$ cd fwfcmfbz +$ ls +71451 zcc.ngn +$ cd .. +$ cd .. +$ cd .. +$ cd pbtr +$ ls +dir qtbprrq +$ cd qtbprrq +$ ls +117780 gjqbnrv.sdl +$ cd .. +$ cd .. +$ cd qtbprrq +$ ls +269746 dld +dir fcmbv +42544 mlzvd.vcw +165396 nbtlfm.vzq +dir sbtl +dir twdhlmp +$ cd fcmbv +$ ls +202047 wdzcrg.mcg +$ cd .. +$ cd sbtl +$ ls +dir dbcdf +dir fbz +dir lvz +dir ncnwbsdh +dir rft +23523 zphlfqf.phv +$ cd dbcdf +$ ls +dir dhdw +dir dvtjfhvm +182513 lclmdwr +63921 ngmw.clj +dir qqmddq +318020 tlh +dir twdwfj +83108 vmwlfdlf +121901 wlcl.fhs +$ cd dhdw +$ ls +dir qtbprrq +dir twdhlmp +dir wbllhmd +$ cd qtbprrq +$ ls +111984 fhc.tzm +$ cd .. +$ cd twdhlmp +$ ls +277414 fwfqbb.dpj +$ cd .. +$ cd wbllhmd +$ ls +dir dnst +dir jqz +dir lbdclnfb +dir ljvwzj +dir mzfdg +96340 ngmw.clj +dir twdhlmp +dir wmcfzznt +147877 zwgvvd +$ cd dnst +$ ls +310179 fmmhnhtf +243908 twdhlmp +$ cd .. +$ cd jqz +$ ls +94739 twdhlmp +$ cd .. +$ cd lbdclnfb +$ ls +112509 ljvwzj +$ cd .. +$ cd ljvwzj +$ ls +28274 bshlmj.lzc +84072 tlh +283462 twdhlmp.ccd +$ cd .. +$ cd mzfdg +$ ls +282099 hbbrjc.jff +63535 tlh +$ cd .. +$ cd twdhlmp +$ ls +283817 jltvl.tgl +$ cd .. +$ cd wmcfzznt +$ ls +294565 fmmhnhtf +$ cd .. +$ cd .. +$ cd .. +$ cd dvtjfhvm +$ ls +292813 qgmvm.fsg +$ cd .. +$ cd qqmddq +$ ls +11670 dnst.btd +241275 fmmhnhtf +196615 fpnmptm +dir nnzscbvw +dir qnrr +$ cd nnzscbvw +$ ls +250962 dflhdfz +$ cd .. +$ cd qnrr +$ ls +dir trzj +$ cd trzj +$ ls +36993 gbhcnts.rdh +273052 tlh +$ cd .. +$ cd .. +$ cd .. +$ cd twdwfj +$ ls +162470 hfdhmbcq.hwz +dir qtbprrq +dir scjzbdsz +2609 wlcl.fhs +$ cd qtbprrq +$ ls +dir cfmglhwj +103703 cscftrsr.jbs +71160 dnst.rbw +dir nrmp +311716 qtbprrq +$ cd cfmglhwj +$ ls +dir fmcmjfg +$ cd fmcmjfg +$ ls +82998 ljvwzj.qbd +8407 nhmmwwzl +dir qtbprrq +261949 tlh +$ cd qtbprrq +$ ls +314421 hwqtl +92593 zcdvf +$ cd .. +$ cd .. +$ cd .. +$ cd nrmp +$ ls +94387 fmmhnhtf +$ cd .. +$ cd .. +$ cd scjzbdsz +$ ls +6861 dgzhldd.dhs +dir gbhcnts +dir qtbprrq +dir sfdl +$ cd gbhcnts +$ ls +dir qdsrs +$ cd qdsrs +$ ls +25165 ngmw.clj +$ cd .. +$ cd .. +$ cd qtbprrq +$ ls +151403 tswd.hpf +$ cd .. +$ cd sfdl +$ ls +308622 jcmsnj +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd fbz +$ ls +dir dgjf +dir qtbprrq +$ cd dgjf +$ ls +254198 rvf.hfq +$ cd .. +$ cd qtbprrq +$ ls +dir frlj +231222 njjfqgt.bph +dir rjsw +dir vjhzc +$ cd frlj +$ ls +dir ljvwzj +$ cd ljvwzj +$ ls +57572 ljvwzj.bvh +$ cd .. +$ cd .. +$ cd rjsw +$ ls +131875 lbcq.rlc +272908 mnfs +$ cd .. +$ cd vjhzc +$ ls +279363 fmmhnhtf +238051 zdzbb.rfj +$ cd .. +$ cd .. +$ cd .. +$ cd lvz +$ ls +289192 tqnvb +dir twdhlmp +$ cd twdhlmp +$ ls +dir wqtgwzdn +$ cd wqtgwzdn +$ ls +283475 ghvpfl +$ cd .. +$ cd .. +$ cd .. +$ cd ncnwbsdh +$ ls +dir dfrdwfgm +dir ljvwzj +dir vgh +$ cd dfrdwfgm +$ ls +279286 mrbwmws.nzd +197337 nqgq.fhf +248096 tqs.jfb +35181 wlcl.fhs +$ cd .. +$ cd ljvwzj +$ ls +250455 gmph.scm +147449 ljvwzj +100189 qfr +$ cd .. +$ cd vgh +$ ls +244540 bzwrldnz.ldt +235508 dzm +dir gbhcnts +dir qtv +dir tvtwlt +262356 wlcl.fhs +$ cd gbhcnts +$ ls +160689 srvpbf.szt +191895 tqnvb +$ cd .. +$ cd qtv +$ ls +9491 dnst.szf +268602 ngmw.clj +dir pbcrfzz +39049 rzgqqvlt.nsm +dir tfpl +79589 wwcrv.ncv +$ cd pbcrfzz +$ ls +dir stt +256685 wlcl.fhs +$ cd stt +$ ls +12650 jbdfwj +$ cd .. +$ cd .. +$ cd tfpl +$ ls +92079 dfhj +$ cd .. +$ cd .. +$ cd tvtwlt +$ ls +dir cqv +$ cd cqv +$ ls +dir vdv +$ cd vdv +$ ls +119483 fmmhnhtf +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd rft +$ ls +24341 bjhzvzp.flg +dir glwdmdt +$ cd glwdmdt +$ ls +288082 jdtlwrzh.wcj +$ cd .. +$ cd .. +$ cd .. +$ cd twdhlmp +$ ls +dir gbhcnts +154240 wlcl.fhs +$ cd gbhcnts +$ ls +217462 ddzp +$ cd .. +$ cd .. +$ cd .. +$ cd rrhcsn +$ ls +308440 dzbfl.vcg +dir jbhcpdh +238941 rnqdz +dir szljjhc +$ cd jbhcpdh +$ ls +dir bmg +dir mdqplln +dir twdhlmp +dir zbt +$ cd bmg +$ ls +dir djwfl +dir gbhcnts +dir ljvwzj +142159 mwl.psh +110681 rzmdgbng +dir zqjbb +$ cd djwfl +$ ls +dir dpfcrjl +dir rqtz +$ cd dpfcrjl +$ ls +206939 tlh +$ cd .. +$ cd rqtz +$ ls +232264 tlh +$ cd .. +$ cd .. +$ cd gbhcnts +$ ls +186364 ngmw.clj +248882 twdhlmp +306411 wjqvlzp +$ cd .. +$ cd ljvwzj +$ ls +dir dgqw +$ cd dgqw +$ ls +dir mpczlcrz +dir qtbprrq +dir twdhlmp +dir zjsltthh +$ cd mpczlcrz +$ ls +142906 gvd.nnz +$ cd .. +$ cd qtbprrq +$ ls +179566 fmmhnhtf +309800 jhwwppc.vcp +$ cd .. +$ cd twdhlmp +$ ls +dir bhqjhjvp +$ cd bhqjhjvp +$ ls +dir lmj +dir qmcqggbl +$ cd lmj +$ ls +275070 twdhlmp +$ cd .. +$ cd qmcqggbl +$ ls +dir mhgnpm +$ cd mhgnpm +$ ls +dir rnzzqr +$ cd rnzzqr +$ ls +126574 pgnlrjs.czj +7567 tqnvb +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd zjsltthh +$ ls +dir twdhlmp +$ cd twdhlmp +$ ls +198813 dnst.cqc +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd zqjbb +$ ls +dir czdvd +94020 dnst +46041 qtbprrq.pzm +dir rcfvq +dir rwj +118305 vbcpcz +48725 wlcl.fhs +$ cd czdvd +$ ls +302317 tlf +$ cd .. +$ cd rcfvq +$ ls +dir cjws +$ cd cjws +$ ls +dir dsgf +dir fvqbhq +203941 hgcbcvb +9562 qqjh.mfh +32161 qtbprrq.tgn +225251 sbmpn +dir sdhvcj +$ cd dsgf +$ ls +dir cbwzg +141466 ctpszzvn.qrq +277153 ngmw.clj +100681 vmdwgrp +$ cd cbwzg +$ ls +dir nblvrbv +$ cd nblvrbv +$ ls +129474 dlcbng.sgf +$ cd .. +$ cd .. +$ cd .. +$ cd fvqbhq +$ ls +75755 fmmhnhtf +229463 tlh +$ cd .. +$ cd sdhvcj +$ ls +306751 tqnvb +$ cd .. +$ cd .. +$ cd .. +$ cd rwj +$ ls +130415 cjbz +283701 rgsdtn +$ cd .. +$ cd .. +$ cd .. +$ cd mdqplln +$ ls +169404 dvss.mvd +105385 fmmhnhtf +222834 jhzpwscp.sqg +164293 jsqlprqn.vnp +57167 pwpjfq.bmb +dir qtbprrq +$ cd qtbprrq +$ ls +62823 ljvwzj.flm +252940 tlh +$ cd .. +$ cd .. +$ cd twdhlmp +$ ls +dir dhvgfhc +dir qrlq +$ cd dhvgfhc +$ ls +dir vpldlp +$ cd vpldlp +$ ls +279067 dnst.jfs +9050 fmmhnhtf +88586 mfbj.fgs +$ cd .. +$ cd .. +$ cd qrlq +$ ls +dir qwwftl +$ cd qwwftl +$ ls +103153 tnczww +$ cd .. +$ cd .. +$ cd .. +$ cd zbt +$ ls +99657 fsq.rzj +158138 gbfjfctj.bgg +260423 tqnvb +161379 trg +$ cd .. +$ cd .. +$ cd szljjhc +$ ls +287080 stnp.lgp +173682 wjzvglm.lfm +$ cd .. +$ cd .. +$ cd .. +$ cd vrj +$ ls +129084 ngmw.clj +250696 pdpzzbs +$ cd .. +$ cd wrqcfl +$ ls +dir bjlwb +105899 gsvm +dir jdnjpg +178665 znnmmhqt.hth +$ cd bjlwb +$ ls +207939 gbhcnts +$ cd .. +$ cd jdnjpg +$ ls +260418 tqnvb +302144 twdhlmp.ghg +$ cd .. +$ cd .. +$ cd .. +$ cd qtbprrq +$ ls +95562 fmmhnhtf +dir plf +dir qtbprrq +306396 rqqmm.wvw +dir wpfj +$ cd plf +$ ls +dir fmftrbn +20347 twb.zjd +$ cd fmftrbn +$ ls +dir rfznrm +$ cd rfznrm +$ ls +283327 rlzjcg +$ cd .. +$ cd .. +$ cd .. +$ cd qtbprrq +$ ls +313931 ztmhrjc +$ cd .. +$ cd wpfj +$ ls +3969 wrbhb.jll +$ cd .. +$ cd .. +$ cd vtb +$ ls +14260 fmmhnhtf +dir gbhcnts +dir lwcznw +dir mhp +dir pqcddzsf +272267 qgh +301727 rsjrn.wjg +101787 vqscjb +dir zvn +$ cd gbhcnts +$ ls +7627 tqnvb +$ cd .. +$ cd lwcznw +$ ls +98498 dnst.tds +dir gfh +dir jdg +dir llnl +161511 mtmrr.hvb +dir ppzwbgnz +210908 qtbprrq +dir tvhz +$ cd gfh +$ ls +169547 mjjvvlqj.jmv +$ cd .. +$ cd jdg +$ ls +dir cthptwcf +dir ljvwzj +dir vnlndl +$ cd cthptwcf +$ ls +98711 qwzwz.qct +$ cd .. +$ cd ljvwzj +$ ls +245473 zhptcmcr.fts +$ cd .. +$ cd vnlndl +$ ls +151466 ljvwzj +285091 twdhlmp.mzv +59067 vcdpbg.nmp +$ cd .. +$ cd .. +$ cd llnl +$ ls +141508 phtmjj.qzl +dir qtbprrq +105151 tlh +$ cd qtbprrq +$ ls +62020 hdzljht.fvq +$ cd .. +$ cd .. +$ cd ppzwbgnz +$ ls +298940 pzdqzrn.zlz +$ cd .. +$ cd tvhz +$ ls +96628 hrzr +$ cd .. +$ cd .. +$ cd mhp +$ ls +226604 mbdn.tbq +dir ndgqtvhg +$ cd ndgqtvhg +$ ls +55244 dnst +dir sljbrmhb +$ cd sljbrmhb +$ ls +32711 dnst +$ cd .. +$ cd .. +$ cd .. +$ cd pqcddzsf +$ ls +dir shwrrq +$ cd shwrrq +$ ls +dir dplcwvhg +dir pvtpf +dir qpsmgfjl +247965 rrw.wwv +dir vmrwpt +$ cd dplcwvhg +$ ls +242534 fmmhnhtf +202367 fzmt.qrw +197586 ljvwzj.qgm +dir stp +dir zpz +$ cd stp +$ ls +12921 mlcqtthb.jtd +$ cd .. +$ cd zpz +$ ls +235965 ngmw.clj +$ cd .. +$ cd .. +$ cd pvtpf +$ ls +319563 rdspj.slv +279577 vqpjzrdl.hhj +$ cd .. +$ cd qpsmgfjl +$ ls +131841 cqhrgc.cqz +105373 fbnp +$ cd .. +$ cd vmrwpt +$ ls +176373 phgsdlnj.ggq +$ cd .. +$ cd .. +$ cd .. +$ cd zvn +$ ls +dir gbhcnts +dir gfh +dir ppqjzln +dir qtbprrq +$ cd gbhcnts +$ ls +156292 wlcl.fhs +$ cd .. +$ cd gfh +$ ls +189836 ljvwzj.wpt +10416 zbnhzjvw.jct +$ cd .. +$ cd ppqjzln +$ ls +95088 sszd +$ cd .. +$ cd qtbprrq +$ ls +295187 hnnl +292421 qtbprrq.ppg +220281 wlcl.fhs diff --git a/2022/day07_1/src/main/resources/small_input b/2022/day07_1/src/main/resources/small_input new file mode 100644 index 0000000..bcbb513 --- /dev/null +++ b/2022/day07_1/src/main/resources/small_input @@ -0,0 +1,23 @@ +$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k \ No newline at end of file diff --git a/2022/day07_1/src/main/resources/small_input1 b/2022/day07_1/src/main/resources/small_input1 new file mode 100644 index 0000000..a6a0ae6 --- /dev/null +++ b/2022/day07_1/src/main/resources/small_input1 @@ -0,0 +1,27 @@ +$ cd / +$ ls +101 fileaaa +102 fileaab +103 fileaac +dir diraaa +dir diraab +dir diraac +$ cd diraaa +$ ls +104 fileaaaa +105 fileaaab +106 fileaaac +dir diraaaa +dir diraaab +dir diraaac +$ cd diraaaa +$ ls +107 fileaaaaa +108 fileaaaab +109 fileaaaac +$ cd .. +$ cd diraaab +$ ls +110 fileaaaba +111 fileaaabb +112 fileaaabc \ No newline at end of file diff --git a/2022/day08_1/.idea/.gitignore b/2022/day08_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day08_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day08_1/.idea/compiler.xml b/2022/day08_1/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day08_1/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day08_1/.idea/gradle.xml b/2022/day08_1/.idea/gradle.xml new file mode 100644 index 0000000..a7087b2 --- /dev/null +++ b/2022/day08_1/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/2022/day08_1/.idea/jarRepositories.xml b/2022/day08_1/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day08_1/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day08_1/.idea/misc.xml b/2022/day08_1/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day08_1/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day08_1/.idea/vcs.xml b/2022/day08_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day08_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day08_1/build.gradle.kts b/2022/day08_1/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day08_1/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day08_1/gradle.properties b/2022/day08_1/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day08_1/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day08_1/gradle/wrapper/gradle-wrapper.jar b/2022/day08_1/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day08_1/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day08_1/gradlew b/2022/day08_1/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day08_1/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day08_1/gradlew.bat b/2022/day08_1/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day08_1/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day08_1/settings.gradle.kts b/2022/day08_1/settings.gradle.kts new file mode 100644 index 0000000..ff205e6 --- /dev/null +++ b/2022/day08_1/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day08_1" + diff --git a/2022/day08_1/src/main/kotlin/Main.kt b/2022/day08_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..965e768 --- /dev/null +++ b/2022/day08_1/src/main/kotlin/Main.kt @@ -0,0 +1,105 @@ +import java.io.File +import java.util.Comparator + +fun main(args: Array) { + println("AOC 2022, Day 8, Part 1 starting!!!") + + val forest = Forest() + var lineCount = 0 + File(args[0]).forEachLine { + processLine(it, lineCount, forest) + lineCount++ + } + + println("Count visible trees: ${forest.countVisible()}") + + println("AOC 2022, Day 8, Part 1 completed!!") +} + +fun processLine(line: String, lineCount: Int, forest: Forest) { + var xPos = 0 + for (c in line) { + forest.addNewTree(Tree(MyCoord(xPos, lineCount), c.digitToInt())) + xPos++ + } +} + +data class Tree(val xyCoord:MyCoord, val height:Int) +data class MyCoord(val xPos:Int, val yPos:Int) + +class Forest { + private val allTrees: HashMap = HashMap() + + fun addNewTree(newTree: Tree) { + allTrees[newTree.xyCoord] = newTree + } + + private var maxX: Int = 0 + private var maxY: Int = 0 + + fun countVisible(): Int { + maxX = allTrees.keys.stream().max(Comparator.comparingInt(MyCoord::xPos))!!.get().xPos + maxY = allTrees.keys.stream().max(Comparator.comparingInt(MyCoord::yPos))!!.get().yPos + + var visibleCount = 0 + + for (y in 0..maxY) { + for (x in 0..maxX) { + val theTree = allTrees[MyCoord(x, y)] + if (checkVisibility(theTree!!)) { + visibleCount++ + } + } + } + + return visibleCount + } + + private fun checkVisibility(tree: Tree): Boolean { + // literal edge case: all trees on the edge of the forest are visible + if ((tree.xyCoord.xPos == 0) || (tree.xyCoord.yPos == 0) || (tree.xyCoord.xPos == maxX) || (tree.xyCoord.yPos == maxY)) { + return true + } + + // is tree visible from the left edge? + var isVisibleLeft = true + for (x in (tree.xyCoord.xPos - 1) downTo 0) { + val checkNextTree = allTrees[MyCoord(x, tree.xyCoord.yPos)]!! + if (checkNextTree.height >= tree.height) { + isVisibleLeft = false + break + } + } + + // is tree visible from the right edge? + var isVisibleRight = true + for (x in (tree.xyCoord.xPos + 1)..maxX) { + val checkNextTree = allTrees[MyCoord(x, tree.xyCoord.yPos)]!! + if (checkNextTree.height >= tree.height) { + isVisibleRight = false + break + } + } + + // is tree visible from the top edge? + var isVisibleTop = true + for (y in (tree.xyCoord.yPos - 1) downTo 0) { + val checkNextTree = allTrees[MyCoord(tree.xyCoord.xPos, y)]!! + if (checkNextTree.height >= tree.height) { + isVisibleTop = false + break + } + } + // is tree visible from the bottom edge? + var isVisibleBottom = true + for (y in (tree.xyCoord.yPos + 1)..maxY) { + val checkNextTree = allTrees[MyCoord(tree.xyCoord.xPos, y)]!! + if (checkNextTree.height >= tree.height) { + isVisibleBottom = false + break + } + } + + return isVisibleLeft || isVisibleRight || isVisibleTop || isVisibleBottom + } +} \ No newline at end of file diff --git a/2022/day08_1/src/main/resources/input b/2022/day08_1/src/main/resources/input new file mode 100644 index 0000000..b24a68f --- /dev/null +++ b/2022/day08_1/src/main/resources/input @@ -0,0 +1,99 @@ +202210010310302121322210423201220000314024242432211425434422230130411300321324302223011311211020120 +110110101310322320101034033124303343031143435122351113353455142421341123420341013300312303121102011 +022222013123323313404200430243020022232555432244334344444542122134130133413044342230233130022021112 +112111200212221204100121022244121453412414141145154551512445525421435232112124343223122023223002202 +010223032133232313122112411243113131542422453412413325334141424132125341004123403342031113000321021 +120203310013001113014232132353322341235134523424131353554135433255424414441323410043113010210021012 +001321033020303133033413032514323122112454135451341114535233523552111335315303411442413103332313030 +102233001100013210130402551555541521113335452154222626521451545151431543531541120332311401123233002 +000012220223113031313123321342142243351454565666666364326432622135251241345515402410441240003203231 +323120110213212212143353534544223242346225556633526325233365442515315454452135521422031032430131220 +010220310331203330225142431325531126553665336562254653354425352265653122233143242323103214302312331 +123101224243131422134414233423334544425633524646243233362664535663664554135351555324200233211032302 +100333303112401243331523125333225424454222662442543663456556432565564235231542334341022204140131010 +222320010441120114425514454524226565533325532623432265362636256446244663333511523325400304340133002 +001134131023140453514341254322262544543344626564433544326342336243252564355555514153411041322321023 +303032023104304131222142562326266256323662554334643363347342242532462534263352425422433133134401332 +020340310211345254242454444265454332565537636676554374476536357464242334364525332231411442341304333 +010424244214451151434435346345243633344375647763655474336663454733535632266334124355143530400222002 +020104234232554141451622326322264263647735447654367457344444465643453634336365231214525124433022444 +204201130004331123325262634265424363534754356365344543544653337444375665555552553542414222233041401 +231313304412112545143543446626577766674444573674633355336777737535543536546633462414421512204234400 +033341420245341341444352655236656744666536473763766674637573737455777566262423256254341313453322144 +440314332142235331442343546273646373345664657448647878767773563537357677642454354424141113554434301 +002021425352244536243253565466455346736677674884448677865868476765656674742534363462451133433430431 +312244242113113354564554337535376574767786648687855878644777578636677645574425532235315311343242411 +233122245155144565255556333557536764847587685667467874688477765747736733566463344232665353434242041 +022220452513455555322662755373537664785775876754758887458644778857853773647663236626545124422424320 +022230332331242525645255575733445554454765688768654845485674575556756764377537266433342513111411334 +120341111522144552663266354477644845848748677677644558776677456646677433474757754324325455254224404 +334433112533124466362636446457755674575647767878689757997654655557447467734646643623663324241123341 +044044511253635465446534354447476746444884889989857597797866787787888747443665545532456524224131143 +342122313235634465626773753655655586857767998568657675697899684787888655564663564432663444345124541 +300241415543242222674376454758578748859965896985789659878795778758468578856474655622353223553421340 +432555555434536525465544664745745888686778996656856565599757587746755745784533654644233622425515434 +004155142463225235434575577777764766596665569657879795765857577596467458644447634453564363532531433 +315114345132332442746733438647847847577597775567596889586878967997655654786546753744554456313434213 +323554311133626266375345655745865485788569878887677897756998589576556656784677663746632663332532151 +315144132232553537533354554654464598875898876799867967877875556975854576455736577735632354543155134 +222334432553634533666733477687556985579999867776999997898668878678867858466445453753652435255552353 +341334452524465435553736485655557568559699788977996667669999667955587886767744364375524653661522332 +413445246252544336676458575775678988988586687776978669888789889868875866467477435474464653535223233 +113143446226365337646448856475467575668778966797986666789967987866989544578754333667436355422314512 +323412424644366374665378846687555957879987766978769867869789986867696554454854656763756625325241145 +323421115545525643633547858847889999697776668979678976769897999899659875558684777565446323544324251 +432334334444542573375354656474858797778897676698987797799688968867795956877875445655545264424345232 +313421526625464654745784667555655877667866889997977998979899968958766968688884745767745342336522224 +122211264264562763544488484689975989588788879988798787779667786859558567878485674347334443246223344 +255242155636622443335485578658568685878777677999787778898767686987558788876846566435373364366424533 +413344156256433653574768654788878777978699969878998798887869869888598888664446534547775236363642425 +342124563455467737457658485456878998989988979899998897787987866875698669856575853463673655444534341 +232551266232426674334688468579688769898979978897788788899798868699975575444474737764445664236253252 +525112465464323755636656578776889996878689879787788998889987978986957695855668736377766252323353255 +335335445554653644563344554685858987978878788987977879778999967667869567488847763473767565562443553 +545321524224436644545685678886975585679878668999989988977889988665666777667584866437364423354233323 +111423266342443746543667554476875575666977668887778798797767868895568959486564657554473632445655344 +524212552355364477347365556488688656986668766897897789886896688988559599878748555366373562653454121 +131154335433422345634645655457568556886876787789779979987866669967997578577754745577462646226445314 +235252452335234564367678476887687995897898668678778786687699867598786667847747567563645652263343425 +223253143456366656767765746865557567566666767869789987989986887557956998685474637637366352326243542 +022325555334456567353758847454499775865697766886666678799897866988858868887447554444762544422112415 +343144416534333377537365468647569967688667888678877876698688967696987958488474576533553236464222515 +041455413553636645474356566857777797955967797767896696888698558569799657885773667663642263333432225 +314232125326436446553663846575645898685777676969798987998978856859686786577445377553744443245432243 +321243223546455364367743474758777659578658777997668897788989566685788888684476563345423344554443231 +415125254422442527666573645787574596577688978657789966586986685976985678486637347667436525212454543 +414235135545633363666356438757467669858969857687755898578857676858688644547753747345432366312551541 +440114242344345546336647565757454586855999757667866776678779875958488554786743465373523322335324440 +122344413244444335537455544748467554578788577997879979696958696984755857587433556336643245424414511 +404152532353256326373573456764878788486665786786686989885788858787846674744354647343463555324212243 +430052142415544522224767753334887658877858987557899587585858774486467688656755647656562452215444341 +340214451142655354335334667467484748684647966577756797796876564684745486774456744624442332555544214 +202003423413136555225554443743364668647485745965556658974868564455687766677646333424563244225312413 +124244252232546632354435547477575454458474888785648855588868547656747434644644562666356425513552234 +110004343225254552232245333753757468577454458667486664868686776847774656744433232645435354515511001 +114110243523312246646633667657446557887764577875444674586445668855646455464673426355246121241420242 +144004022115232335325233544457463354556577558686866645777668486456344336776563552654224535341204000 +421204313533552465364335665657756377478687485747568464457586578433533665377544334436324115345110242 +310213102455533546266535624345334376363684858775467657685555747353643644472546632522545411333203111 +114430325255224412546642432664757677554453367648667474866563366653547673545643556525445241221014044 +101202024124311141332246625344457736763773743567676364434654335437667673333633334533321141144401343 +022314412343141552545426345523734644465534437755555546366776455573555736346566554523431445312041141 +310102320115113413255662622463666645774475764474763576347553464576657544655232265213412332113321240 +103421443124221314341526656425352447567466347367455546655457665443752365626234642233144534440401232 +012242102421432341212413443326266462435353334443757554636776575352564544364326345342233211400021132 +222333320014022434154332424323323222343565375555437333746365455224462465255645335454253531041200430 +203301220423445445245343333566523444245653734664355375366356543225425453566551115535422214404241002 +302324443031122331441331256335344224253636533556756445434643354532564454235413132113211343002133211 +311312211414143323513134241534622563433242365626656422526345223354546364435315451551101023211412130 +222110343401032043553425111312244654332653464666435423342453322663424243153233322113032023202020223 +323230200411432130355525221321433355242633433225442453325522522622364253311533334354031100222010013 +310222312143433114242431355515315554643534324342445656666436353223444231435453241400213321330130010 +333003032313304033243534455111112214234262552344526635435332246231323535122413441024143242102302110 +113023202303413323324054115321135342223354425566256536556255312115424353351151533010221413210330113 +201002101132013010411214525353534241113423251253436544643553152152432455455322331331310031222312310 +010000023323114442204233214145222453523254543111213112525444545451354241122320331344023330301010000 +020221201301204043241340212025231451554512545355544454355334235544331435121232034423404333303220120 +211200133121002321411044312343241534545415435535214551522523534521342510432012433211020132222223110 +001010111333021232114033432123014243143421131445211232544521554534542030434313341020033312233321020 +110102200233103010320200140144034422131352541143533213514525422131220112004103004000011012120121220 diff --git a/2022/day08_1/src/main/resources/small_input b/2022/day08_1/src/main/resources/small_input new file mode 100644 index 0000000..16d6fbd --- /dev/null +++ b/2022/day08_1/src/main/resources/small_input @@ -0,0 +1,5 @@ +30373 +25512 +65332 +33549 +35390 diff --git a/2022/day08_2/.idea/.gitignore b/2022/day08_2/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day08_2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day08_2/.idea/compiler.xml b/2022/day08_2/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day08_2/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day08_2/.idea/gradle.xml b/2022/day08_2/.idea/gradle.xml new file mode 100644 index 0000000..a7087b2 --- /dev/null +++ b/2022/day08_2/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/2022/day08_2/.idea/jarRepositories.xml b/2022/day08_2/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day08_2/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day08_2/.idea/misc.xml b/2022/day08_2/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day08_2/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day08_2/.idea/vcs.xml b/2022/day08_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day08_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day08_2/build.gradle.kts b/2022/day08_2/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day08_2/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day08_2/gradle.properties b/2022/day08_2/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day08_2/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day08_2/gradle/wrapper/gradle-wrapper.jar b/2022/day08_2/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day08_2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day08_2/gradlew b/2022/day08_2/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day08_2/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day08_2/gradlew.bat b/2022/day08_2/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day08_2/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day08_2/settings.gradle.kts b/2022/day08_2/settings.gradle.kts new file mode 100644 index 0000000..d9e1831 --- /dev/null +++ b/2022/day08_2/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day08_2" + diff --git a/2022/day08_2/src/main/kotlin/Main.kt b/2022/day08_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..313048e --- /dev/null +++ b/2022/day08_2/src/main/kotlin/Main.kt @@ -0,0 +1,158 @@ +import java.io.File +import java.util.Comparator + +fun main(args: Array) { + println("AOC 2022, Day 8, Part 2 starting!!!") + + val forest = Forest() + var lineCount = 0 + File(args[0]).forEachLine { + processLine(it, lineCount, forest) + lineCount++ + } + + println("Count visible trees: ${forest.countVisible()}") + println("Best scenic score: ${forest.bestScenicScore()}") + + println("AOC 2022, Day 8, Part 2 completed!!") +} + +fun processLine(line: String, lineCount: Int, forest: Forest) { + var xPos = 0 + for (c in line) { + forest.addNewTree(Tree(MyCoord(xPos, lineCount), c.digitToInt())) + xPos++ + } +} + +data class Tree(val xyCoord:MyCoord, val height:Int) +data class MyCoord(val xPos:Int, val yPos:Int) + +class Forest { + private val allTrees: HashMap = HashMap() + + fun addNewTree(newTree: Tree) { + allTrees[newTree.xyCoord] = newTree + } + + private var maxX: Int = 0 + private var maxY: Int = 0 + + fun countVisible(): Int { + maxX = allTrees.keys.stream().max(Comparator.comparingInt(MyCoord::xPos))!!.get().xPos + maxY = allTrees.keys.stream().max(Comparator.comparingInt(MyCoord::yPos))!!.get().yPos + + var visibleCount = 0 + + for (y in 0..maxY) { + for (x in 0..maxX) { + val theTree = allTrees[MyCoord(x, y)] + if (checkVisibility(theTree!!)) { + visibleCount++ + } + } + } + + return visibleCount + } + + fun bestScenicScore():Int { + val scenicScores:ArrayList = ArrayList() + + for (tree in allTrees.values) { + scenicScores.add(calculateScenicScore(tree)) + } + + return scenicScores.max() + } + + private fun calculateScenicScore(tree: Tree):Int { + // count trees seen left + var leftTreeCount = 0 + for(x in (tree.xyCoord.xPos - 1) downTo 0) { + val checkNextTree = allTrees[MyCoord(x, tree.xyCoord.yPos)]!! + leftTreeCount++ + if(checkNextTree.height >= tree.height) { + break + } + } + // count trees seen right + var rightTreeCount = 0 + for (x in (tree.xyCoord.xPos + 1)..maxX) { + val checkNextTree = allTrees[MyCoord(x, tree.xyCoord.yPos)]!! + rightTreeCount++ + if(checkNextTree.height >= tree.height) { + break + } + } + // count trees seen top + var topTreeCount = 0 + for (y in (tree.xyCoord.yPos - 1) downTo 0) { + val checkNextTree = allTrees[MyCoord(tree.xyCoord.xPos, y)]!! + topTreeCount++ + if(checkNextTree.height >= tree.height) { + break + } + } + // count tress seen down + var bottomTreeCount = 0 + for (y in (tree.xyCoord.yPos + 1)..maxY) { + val checkNextTree = allTrees[MyCoord(tree.xyCoord.xPos, y)]!! + bottomTreeCount++ + if(checkNextTree.height >= tree.height) { + break + } + } +// val foo = leftTreeCount * rightTreeCount * topTreeCount * bottomTreeCount +// println("tlarsen,L108: scenic score = $foo") + return leftTreeCount * rightTreeCount * topTreeCount * bottomTreeCount + } + + private fun checkVisibility(tree: Tree): Boolean { + // literal edge case: all trees on the edge of the forest are visible + if ((tree.xyCoord.xPos == 0) || (tree.xyCoord.yPos == 0) || (tree.xyCoord.xPos == maxX) || (tree.xyCoord.yPos == maxY)) { + return true + } + + // is tree visible from the left edge? + var isVisibleLeft = true + for (x in (tree.xyCoord.xPos - 1) downTo 0) { + val checkNextTree = allTrees[MyCoord(x, tree.xyCoord.yPos)]!! + if (checkNextTree.height >= tree.height) { + isVisibleLeft = false + break + } + } + + // is tree visible from the right edge? + var isVisibleRight = true + for (x in (tree.xyCoord.xPos + 1)..maxX) { + val checkNextTree = allTrees[MyCoord(x, tree.xyCoord.yPos)]!! + if (checkNextTree.height >= tree.height) { + isVisibleRight = false + break + } + } + + // is tree visible from the top edge? + var isVisibleTop = true + for (y in (tree.xyCoord.yPos - 1) downTo 0) { + val checkNextTree = allTrees[MyCoord(tree.xyCoord.xPos, y)]!! + if (checkNextTree.height >= tree.height) { + isVisibleTop = false + break + } + } + // is tree visible from the bottom edge? + var isVisibleBottom = true + for (y in (tree.xyCoord.yPos + 1)..maxY) { + val checkNextTree = allTrees[MyCoord(tree.xyCoord.xPos, y)]!! + if (checkNextTree.height >= tree.height) { + isVisibleBottom = false + break + } + } + + return isVisibleLeft || isVisibleRight || isVisibleTop || isVisibleBottom + } +} \ No newline at end of file diff --git a/2022/day08_2/src/main/resources/input b/2022/day08_2/src/main/resources/input new file mode 100644 index 0000000..b24a68f --- /dev/null +++ b/2022/day08_2/src/main/resources/input @@ -0,0 +1,99 @@ +202210010310302121322210423201220000314024242432211425434422230130411300321324302223011311211020120 +110110101310322320101034033124303343031143435122351113353455142421341123420341013300312303121102011 +022222013123323313404200430243020022232555432244334344444542122134130133413044342230233130022021112 +112111200212221204100121022244121453412414141145154551512445525421435232112124343223122023223002202 +010223032133232313122112411243113131542422453412413325334141424132125341004123403342031113000321021 +120203310013001113014232132353322341235134523424131353554135433255424414441323410043113010210021012 +001321033020303133033413032514323122112454135451341114535233523552111335315303411442413103332313030 +102233001100013210130402551555541521113335452154222626521451545151431543531541120332311401123233002 +000012220223113031313123321342142243351454565666666364326432622135251241345515402410441240003203231 +323120110213212212143353534544223242346225556633526325233365442515315454452135521422031032430131220 +010220310331203330225142431325531126553665336562254653354425352265653122233143242323103214302312331 +123101224243131422134414233423334544425633524646243233362664535663664554135351555324200233211032302 +100333303112401243331523125333225424454222662442543663456556432565564235231542334341022204140131010 +222320010441120114425514454524226565533325532623432265362636256446244663333511523325400304340133002 +001134131023140453514341254322262544543344626564433544326342336243252564355555514153411041322321023 +303032023104304131222142562326266256323662554334643363347342242532462534263352425422433133134401332 +020340310211345254242454444265454332565537636676554374476536357464242334364525332231411442341304333 +010424244214451151434435346345243633344375647763655474336663454733535632266334124355143530400222002 +020104234232554141451622326322264263647735447654367457344444465643453634336365231214525124433022444 +204201130004331123325262634265424363534754356365344543544653337444375665555552553542414222233041401 +231313304412112545143543446626577766674444573674633355336777737535543536546633462414421512204234400 +033341420245341341444352655236656744666536473763766674637573737455777566262423256254341313453322144 +440314332142235331442343546273646373345664657448647878767773563537357677642454354424141113554434301 +002021425352244536243253565466455346736677674884448677865868476765656674742534363462451133433430431 +312244242113113354564554337535376574767786648687855878644777578636677645574425532235315311343242411 +233122245155144565255556333557536764847587685667467874688477765747736733566463344232665353434242041 +022220452513455555322662755373537664785775876754758887458644778857853773647663236626545124422424320 +022230332331242525645255575733445554454765688768654845485674575556756764377537266433342513111411334 +120341111522144552663266354477644845848748677677644558776677456646677433474757754324325455254224404 +334433112533124466362636446457755674575647767878689757997654655557447467734646643623663324241123341 +044044511253635465446534354447476746444884889989857597797866787787888747443665545532456524224131143 +342122313235634465626773753655655586857767998568657675697899684787888655564663564432663444345124541 +300241415543242222674376454758578748859965896985789659878795778758468578856474655622353223553421340 +432555555434536525465544664745745888686778996656856565599757587746755745784533654644233622425515434 +004155142463225235434575577777764766596665569657879795765857577596467458644447634453564363532531433 +315114345132332442746733438647847847577597775567596889586878967997655654786546753744554456313434213 +323554311133626266375345655745865485788569878887677897756998589576556656784677663746632663332532151 +315144132232553537533354554654464598875898876799867967877875556975854576455736577735632354543155134 +222334432553634533666733477687556985579999867776999997898668878678867858466445453753652435255552353 +341334452524465435553736485655557568559699788977996667669999667955587886767744364375524653661522332 +413445246252544336676458575775678988988586687776978669888789889868875866467477435474464653535223233 +113143446226365337646448856475467575668778966797986666789967987866989544578754333667436355422314512 +323412424644366374665378846687555957879987766978769867869789986867696554454854656763756625325241145 +323421115545525643633547858847889999697776668979678976769897999899659875558684777565446323544324251 +432334334444542573375354656474858797778897676698987797799688968867795956877875445655545264424345232 +313421526625464654745784667555655877667866889997977998979899968958766968688884745767745342336522224 +122211264264562763544488484689975989588788879988798787779667786859558567878485674347334443246223344 +255242155636622443335485578658568685878777677999787778898767686987558788876846566435373364366424533 +413344156256433653574768654788878777978699969878998798887869869888598888664446534547775236363642425 +342124563455467737457658485456878998989988979899998897787987866875698669856575853463673655444534341 +232551266232426674334688468579688769898979978897788788899798868699975575444474737764445664236253252 +525112465464323755636656578776889996878689879787788998889987978986957695855668736377766252323353255 +335335445554653644563344554685858987978878788987977879778999967667869567488847763473767565562443553 +545321524224436644545685678886975585679878668999989988977889988665666777667584866437364423354233323 +111423266342443746543667554476875575666977668887778798797767868895568959486564657554473632445655344 +524212552355364477347365556488688656986668766897897789886896688988559599878748555366373562653454121 +131154335433422345634645655457568556886876787789779979987866669967997578577754745577462646226445314 +235252452335234564367678476887687995897898668678778786687699867598786667847747567563645652263343425 +223253143456366656767765746865557567566666767869789987989986887557956998685474637637366352326243542 +022325555334456567353758847454499775865697766886666678799897866988858868887447554444762544422112415 +343144416534333377537365468647569967688667888678877876698688967696987958488474576533553236464222515 +041455413553636645474356566857777797955967797767896696888698558569799657885773667663642263333432225 +314232125326436446553663846575645898685777676969798987998978856859686786577445377553744443245432243 +321243223546455364367743474758777659578658777997668897788989566685788888684476563345423344554443231 +415125254422442527666573645787574596577688978657789966586986685976985678486637347667436525212454543 +414235135545633363666356438757467669858969857687755898578857676858688644547753747345432366312551541 +440114242344345546336647565757454586855999757667866776678779875958488554786743465373523322335324440 +122344413244444335537455544748467554578788577997879979696958696984755857587433556336643245424414511 +404152532353256326373573456764878788486665786786686989885788858787846674744354647343463555324212243 +430052142415544522224767753334887658877858987557899587585858774486467688656755647656562452215444341 +340214451142655354335334667467484748684647966577756797796876564684745486774456744624442332555544214 +202003423413136555225554443743364668647485745965556658974868564455687766677646333424563244225312413 +124244252232546632354435547477575454458474888785648855588868547656747434644644562666356425513552234 +110004343225254552232245333753757468577454458667486664868686776847774656744433232645435354515511001 +114110243523312246646633667657446557887764577875444674586445668855646455464673426355246121241420242 +144004022115232335325233544457463354556577558686866645777668486456344336776563552654224535341204000 +421204313533552465364335665657756377478687485747568464457586578433533665377544334436324115345110242 +310213102455533546266535624345334376363684858775467657685555747353643644472546632522545411333203111 +114430325255224412546642432664757677554453367648667474866563366653547673545643556525445241221014044 +101202024124311141332246625344457736763773743567676364434654335437667673333633334533321141144401343 +022314412343141552545426345523734644465534437755555546366776455573555736346566554523431445312041141 +310102320115113413255662622463666645774475764474763576347553464576657544655232265213412332113321240 +103421443124221314341526656425352447567466347367455546655457665443752365626234642233144534440401232 +012242102421432341212413443326266462435353334443757554636776575352564544364326345342233211400021132 +222333320014022434154332424323323222343565375555437333746365455224462465255645335454253531041200430 +203301220423445445245343333566523444245653734664355375366356543225425453566551115535422214404241002 +302324443031122331441331256335344224253636533556756445434643354532564454235413132113211343002133211 +311312211414143323513134241534622563433242365626656422526345223354546364435315451551101023211412130 +222110343401032043553425111312244654332653464666435423342453322663424243153233322113032023202020223 +323230200411432130355525221321433355242633433225442453325522522622364253311533334354031100222010013 +310222312143433114242431355515315554643534324342445656666436353223444231435453241400213321330130010 +333003032313304033243534455111112214234262552344526635435332246231323535122413441024143242102302110 +113023202303413323324054115321135342223354425566256536556255312115424353351151533010221413210330113 +201002101132013010411214525353534241113423251253436544643553152152432455455322331331310031222312310 +010000023323114442204233214145222453523254543111213112525444545451354241122320331344023330301010000 +020221201301204043241340212025231451554512545355544454355334235544331435121232034423404333303220120 +211200133121002321411044312343241534545415435535214551522523534521342510432012433211020132222223110 +001010111333021232114033432123014243143421131445211232544521554534542030434313341020033312233321020 +110102200233103010320200140144034422131352541143533213514525422131220112004103004000011012120121220 diff --git a/2022/day08_2/src/main/resources/small_input b/2022/day08_2/src/main/resources/small_input new file mode 100644 index 0000000..16d6fbd --- /dev/null +++ b/2022/day08_2/src/main/resources/small_input @@ -0,0 +1,5 @@ +30373 +25512 +65332 +33549 +35390 diff --git a/2022/day09_1/.idea/.gitignore b/2022/day09_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2022/day09_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2022/day09_1/.idea/compiler.xml b/2022/day09_1/.idea/compiler.xml new file mode 100644 index 0000000..b73660a --- /dev/null +++ b/2022/day09_1/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day09_1/.idea/gradle.xml b/2022/day09_1/.idea/gradle.xml new file mode 100644 index 0000000..a7087b2 --- /dev/null +++ b/2022/day09_1/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/2022/day09_1/.idea/jarRepositories.xml b/2022/day09_1/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/2022/day09_1/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/day09_1/.idea/misc.xml b/2022/day09_1/.idea/misc.xml new file mode 100644 index 0000000..54d358d --- /dev/null +++ b/2022/day09_1/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/2022/day09_1/.idea/vcs.xml b/2022/day09_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2022/day09_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/day09_1/build.gradle.kts b/2022/day09_1/build.gradle.kts new file mode 100644 index 0000000..2534435 --- /dev/null +++ b/2022/day09_1/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.7.21" + application +} + +group = "me.tlarsen" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +application { + mainClass.set("MainKt") +} \ No newline at end of file diff --git a/2022/day09_1/gradle.properties b/2022/day09_1/gradle.properties new file mode 100644 index 0000000..7fc6f1f --- /dev/null +++ b/2022/day09_1/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/2022/day09_1/gradle/wrapper/gradle-wrapper.jar b/2022/day09_1/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/2022/day09_1/gradle/wrapper/gradle-wrapper.jar differ diff --git a/2022/day09_1/gradlew b/2022/day09_1/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/2022/day09_1/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/2022/day09_1/gradlew.bat b/2022/day09_1/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/2022/day09_1/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/2022/day09_1/settings.gradle.kts b/2022/day09_1/settings.gradle.kts new file mode 100644 index 0000000..5fa7763 --- /dev/null +++ b/2022/day09_1/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "day09_1" + diff --git a/2022/day09_1/src/main/kotlin/Main.kt b/2022/day09_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..19cd4ab --- /dev/null +++ b/2022/day09_1/src/main/kotlin/Main.kt @@ -0,0 +1,148 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2022, Day 9, Part 1 starting!!!") + + val rope = Rope(MyPosition(0,0), MyPosition(0,0)) + File(args[0]).forEachLine { + val split = it.split(' ') + rope.moveCommand(split[0], split[1].toInt()) + } + + println("Tail position: ${rope.countTailSteps()}") + + println("AOC 2022, Day 9, Part 1 completed!!") +} + +data class MyPosition (var xPosition:Int, var yPosition:Int) + +class Rope (private var headPosition:MyPosition, private var tailPosition:MyPosition) { + private val tailRecord:HashMap = HashMap() + + init { + tailRecord[MyPosition(0,0)] = 1 + } + + fun countTailSteps():Int { + return tailRecord.size + } + + fun moveCommand(moveDirection:String, steps:Int) { + when(moveDirection) { + "U" -> moveUp(steps) + "D" -> moveDown(steps) + "L" -> moveLeft(steps) + "R" -> moveRight(steps) + } + } + + private fun moveUp(steps: Int) { + for(step in 0 until steps) { + headPosition.yPosition++ + if(!isTailTouchingHead()) { + tailPosition.xPosition = headPosition.xPosition + tailPosition.yPosition = headPosition.yPosition - 1 + + val pos = MyPosition(tailPosition.xPosition, tailPosition.yPosition) + val total = 1 + tailRecord.getOrDefault(pos, 0) + tailRecord[pos] = total + } + } + } + + private fun moveDown(steps: Int) { + for(step in 0 until steps) { + headPosition.yPosition-- + if(!isTailTouchingHead()) { + tailPosition.xPosition = headPosition.xPosition + tailPosition.yPosition = headPosition.yPosition + 1 + + val pos = MyPosition(tailPosition.xPosition, tailPosition.yPosition) + val total = 1 + tailRecord.getOrDefault(pos, 0) + tailRecord[pos] = total + } + } + } + + private fun moveLeft(steps: Int) { + for(step in 0 until steps) { + headPosition.xPosition-- + if(!isTailTouchingHead()) { + tailPosition.xPosition = headPosition.xPosition + 1 + tailPosition.yPosition = headPosition.yPosition + + val pos = MyPosition(tailPosition.xPosition, tailPosition.yPosition) + val total = 1 + tailRecord.getOrDefault(pos, 0) + tailRecord[pos] = total + } + } + } + + /* +..##.. +...##. +.####. +....#. +s###.. + */ + + private fun moveRight(steps: Int) { + // 1. move head + // 2. check if tail is still touching, if not move tail + for(s in 0 until steps) { + headPosition.xPosition++ + if(!isTailTouchingHead()) { + tailPosition.xPosition = headPosition.xPosition - 1 + tailPosition.yPosition = headPosition.yPosition + + val pos = MyPosition(tailPosition.xPosition, tailPosition.yPosition) + val total = 1 + tailRecord.getOrDefault(pos, 0) + tailRecord[pos] = total + } + } + } + + private fun isTailTouchingHead():Boolean { + // head and tail is on top of each other + if((headPosition.xPosition == tailPosition.xPosition) && + (headPosition.yPosition == tailPosition.yPosition)) { + return true + } + if((headPosition.xPosition == tailPosition.xPosition) && + (headPosition.yPosition == (tailPosition.yPosition - 1))) { + return true + } + if((headPosition.xPosition == tailPosition.xPosition) && + (headPosition.yPosition == (tailPosition.yPosition + 1))) { + return true + } + if((headPosition.xPosition == (tailPosition.xPosition - 1)) && + (headPosition.yPosition == tailPosition.yPosition)) { + return true + } + if((headPosition.xPosition == (tailPosition.xPosition + 1)) && + (headPosition.yPosition == tailPosition.yPosition)) { + return true + } + + // The four diagonal positions are also valid + if((headPosition.xPosition == (tailPosition.xPosition - 1)) && + (headPosition.yPosition == (tailPosition.yPosition - 1))) { + return true + } + if((headPosition.xPosition == (tailPosition.xPosition + 1)) && + (headPosition.yPosition == (tailPosition.yPosition + 1))) { + return true + } + if((headPosition.xPosition == (tailPosition.xPosition - 1)) && + (headPosition.yPosition == (tailPosition.yPosition + 1))) { + return true + } + if((headPosition.xPosition == (tailPosition.xPosition + 1)) && + (headPosition.yPosition == (tailPosition.yPosition - 1))) { + return true + } + + return false + } +} \ No newline at end of file diff --git a/2022/day09_1/src/main/resources/input b/2022/day09_1/src/main/resources/input new file mode 100644 index 0000000..875fe38 --- /dev/null +++ b/2022/day09_1/src/main/resources/input @@ -0,0 +1,2000 @@ +U 1 +D 1 +R 1 +L 2 +D 2 +U 1 +R 2 +D 2 +U 1 +R 1 +L 1 +D 2 +R 2 +U 2 +L 1 +D 1 +U 1 +L 1 +D 2 +U 1 +D 1 +L 1 +U 2 +R 1 +L 1 +R 1 +L 1 +U 2 +L 2 +U 2 +L 1 +U 2 +D 1 +U 2 +D 1 +L 2 +U 1 +D 1 +U 2 +R 2 +D 2 +R 1 +D 2 +L 1 +U 1 +L 2 +D 2 +L 2 +R 1 +U 1 +L 2 +D 1 +U 1 +R 2 +L 2 +D 1 +R 1 +L 1 +R 2 +U 1 +R 2 +D 1 +U 1 +L 2 +D 1 +R 2 +D 1 +U 2 +R 1 +D 1 +R 2 +U 1 +L 2 +D 2 +U 2 +R 2 +L 1 +D 2 +R 1 +D 1 +U 2 +D 2 +L 2 +R 2 +L 2 +D 1 +R 2 +D 2 +L 1 +U 1 +D 1 +L 2 +U 1 +R 1 +D 1 +U 2 +D 1 +L 2 +D 2 +R 2 +L 2 +R 2 +U 2 +L 1 +R 1 +L 1 +D 2 +R 2 +U 1 +R 1 +D 2 +R 1 +L 1 +R 3 +L 3 +D 1 +R 2 +D 2 +U 1 +D 1 +R 2 +D 1 +L 3 +U 3 +L 1 +U 3 +L 1 +D 2 +R 3 +L 2 +R 1 +U 3 +R 2 +D 3 +L 2 +D 1 +R 1 +L 2 +U 3 +D 2 +U 3 +R 1 +L 2 +D 2 +R 2 +U 3 +D 1 +L 2 +D 1 +R 1 +D 3 +U 1 +R 1 +D 3 +L 1 +D 3 +U 1 +L 3 +R 1 +D 1 +L 1 +U 3 +R 2 +D 1 +U 3 +L 1 +D 1 +L 3 +R 2 +D 1 +L 2 +U 1 +L 2 +U 1 +R 1 +L 2 +D 2 +R 2 +L 1 +R 2 +U 3 +D 3 +R 3 +L 3 +R 1 +L 2 +D 1 +U 1 +R 2 +D 2 +R 2 +D 1 +U 1 +D 3 +U 2 +R 3 +U 3 +R 3 +U 2 +R 1 +L 2 +D 1 +R 2 +U 1 +R 2 +D 2 +R 3 +L 2 +R 1 +D 2 +L 3 +U 3 +R 1 +D 1 +L 1 +R 1 +D 1 +R 3 +U 2 +D 3 +U 3 +R 2 +D 4 +L 3 +U 3 +L 2 +R 4 +U 1 +D 4 +R 1 +U 3 +L 1 +D 4 +L 3 +R 1 +D 3 +R 1 +L 2 +R 3 +L 3 +R 1 +D 1 +R 4 +L 3 +R 2 +L 1 +R 4 +U 3 +D 2 +R 3 +D 1 +R 1 +L 3 +R 4 +L 4 +U 3 +L 4 +R 4 +U 2 +D 2 +R 3 +L 4 +U 4 +L 3 +D 4 +R 1 +U 1 +L 3 +U 2 +L 2 +R 4 +D 3 +R 2 +U 2 +R 4 +D 1 +R 4 +U 3 +D 3 +R 1 +U 4 +L 1 +R 3 +D 3 +U 3 +L 4 +U 4 +D 4 +L 3 +D 4 +U 4 +R 2 +D 2 +U 3 +D 2 +U 4 +D 2 +L 2 +D 2 +R 2 +D 4 +L 2 +U 3 +D 1 +U 1 +R 2 +U 3 +L 4 +U 1 +R 3 +U 3 +D 3 +U 4 +D 2 +R 3 +L 4 +R 4 +D 3 +U 2 +R 4 +D 1 +R 4 +U 3 +R 4 +L 4 +D 3 +L 3 +D 3 +U 4 +R 4 +D 2 +R 2 +D 1 +R 4 +L 3 +D 5 +L 1 +D 3 +L 4 +R 2 +U 2 +L 3 +R 3 +U 5 +D 1 +U 1 +R 5 +D 5 +L 1 +R 4 +L 4 +R 4 +D 4 +R 4 +D 3 +L 4 +U 2 +L 2 +D 5 +U 5 +L 1 +R 2 +D 2 +R 2 +D 2 +U 2 +R 5 +U 2 +R 2 +U 4 +L 2 +U 3 +R 5 +U 2 +R 2 +D 2 +R 4 +U 5 +D 5 +R 3 +U 4 +L 5 +U 3 +D 2 +R 5 +U 3 +L 5 +U 2 +R 1 +L 1 +R 3 +L 2 +R 5 +L 5 +U 1 +R 2 +L 2 +D 1 +R 3 +L 5 +D 5 +U 4 +R 4 +L 3 +R 2 +D 2 +L 3 +D 3 +R 4 +U 2 +R 5 +D 1 +R 1 +D 3 +L 4 +R 3 +D 4 +L 4 +D 5 +R 3 +L 1 +U 1 +D 5 +U 2 +L 5 +D 3 +U 4 +D 5 +U 1 +R 2 +D 5 +L 2 +U 1 +D 4 +R 3 +D 2 +U 5 +L 4 +R 2 +D 4 +U 4 +R 4 +D 5 +R 2 +L 2 +R 5 +U 5 +R 6 +D 6 +U 4 +L 6 +D 4 +R 1 +L 1 +D 6 +R 4 +L 1 +U 4 +D 3 +U 3 +D 2 +U 6 +R 1 +U 4 +L 6 +R 5 +D 4 +R 6 +D 3 +R 1 +L 5 +D 3 +R 3 +D 6 +R 6 +D 2 +R 6 +D 1 +L 1 +R 5 +U 1 +D 5 +L 6 +R 4 +U 3 +L 2 +D 4 +U 1 +D 2 +R 4 +L 6 +D 6 +U 5 +D 2 +R 4 +L 4 +U 3 +D 1 +R 3 +L 1 +D 1 +L 1 +D 4 +L 6 +U 1 +L 2 +D 6 +R 1 +L 5 +U 6 +L 1 +D 2 +L 4 +R 3 +D 3 +R 6 +L 6 +R 5 +U 2 +R 4 +D 4 +U 5 +D 1 +U 5 +R 4 +L 3 +R 6 +U 4 +L 3 +R 3 +L 3 +U 6 +D 3 +L 3 +R 1 +L 5 +R 1 +D 2 +L 6 +R 6 +D 5 +R 6 +U 3 +R 3 +L 5 +D 6 +R 2 +D 3 +R 4 +D 1 +R 4 +D 5 +U 4 +D 1 +L 2 +D 7 +L 7 +D 3 +U 4 +R 1 +D 4 +R 3 +L 1 +U 2 +L 1 +D 1 +R 4 +D 7 +U 5 +R 5 +U 1 +L 3 +R 3 +L 4 +R 2 +U 3 +R 3 +U 2 +L 4 +R 3 +U 2 +L 1 +D 4 +U 7 +L 5 +D 7 +L 2 +D 6 +R 1 +D 4 +R 2 +D 7 +L 5 +D 4 +R 3 +L 1 +U 5 +D 1 +U 7 +L 3 +U 5 +L 3 +U 2 +R 2 +L 7 +U 1 +R 5 +U 3 +L 2 +D 7 +L 2 +R 5 +D 3 +L 7 +D 7 +U 6 +R 6 +L 5 +U 2 +D 7 +L 5 +R 5 +D 4 +R 5 +L 7 +D 1 +U 7 +R 2 +L 3 +R 6 +L 3 +R 6 +L 2 +R 5 +L 2 +R 2 +D 7 +U 4 +R 7 +U 2 +D 5 +R 4 +U 4 +R 1 +L 4 +R 1 +U 1 +L 1 +U 7 +R 1 +L 7 +D 3 +L 6 +U 6 +L 6 +U 2 +D 7 +L 7 +R 1 +D 5 +U 4 +L 5 +U 7 +L 6 +U 3 +R 5 +L 5 +D 5 +L 8 +R 8 +L 5 +D 2 +L 2 +R 7 +D 6 +L 2 +U 7 +R 6 +D 3 +U 2 +L 4 +D 5 +R 4 +D 6 +R 4 +D 3 +R 3 +L 5 +R 5 +L 7 +R 6 +D 5 +U 7 +R 1 +U 1 +R 1 +L 6 +R 6 +L 3 +U 2 +D 6 +U 4 +R 5 +U 4 +R 4 +D 4 +U 1 +L 1 +D 4 +U 4 +L 3 +R 1 +U 1 +R 8 +U 8 +D 2 +R 7 +U 8 +R 8 +U 3 +D 5 +U 2 +R 3 +D 5 +R 4 +L 6 +U 3 +L 4 +D 6 +U 2 +L 2 +D 5 +U 1 +R 2 +D 7 +L 4 +R 6 +L 4 +D 5 +L 3 +R 7 +U 5 +D 3 +L 5 +D 8 +L 8 +U 7 +D 8 +R 6 +U 5 +R 2 +U 5 +D 5 +U 7 +R 3 +L 6 +D 1 +U 6 +L 3 +R 5 +U 5 +R 2 +L 4 +U 8 +D 8 +L 7 +R 1 +U 8 +L 4 +U 1 +D 1 +R 3 +D 8 +L 4 +U 7 +L 5 +D 2 +U 6 +D 1 +L 5 +R 1 +U 6 +R 1 +D 7 +U 3 +L 7 +R 9 +D 5 +L 5 +U 5 +R 7 +U 3 +L 7 +R 3 +U 3 +L 3 +U 5 +D 8 +R 4 +L 1 +U 7 +D 3 +L 7 +U 6 +D 4 +U 7 +D 6 +R 9 +L 8 +R 4 +L 7 +U 7 +R 7 +L 4 +U 1 +L 5 +D 5 +L 6 +U 6 +D 6 +R 7 +L 3 +R 9 +U 2 +R 6 +D 8 +L 3 +R 6 +L 7 +D 2 +U 9 +D 2 +L 6 +D 9 +R 6 +D 1 +U 7 +L 8 +U 5 +L 9 +R 7 +D 9 +L 7 +D 9 +U 6 +R 5 +L 7 +D 8 +R 4 +L 4 +U 5 +D 3 +R 2 +D 3 +R 1 +L 3 +R 8 +D 6 +U 3 +D 3 +U 4 +R 6 +U 2 +R 3 +U 5 +R 7 +D 1 +U 9 +D 4 +U 5 +D 9 +R 4 +U 2 +D 5 +U 2 +R 8 +U 9 +L 9 +R 3 +L 6 +D 4 +L 2 +D 6 +U 8 +R 3 +L 2 +U 1 +L 3 +R 4 +L 1 +D 1 +U 5 +R 9 +D 10 +U 4 +L 1 +U 10 +D 2 +L 9 +R 10 +U 8 +L 2 +U 10 +R 2 +L 2 +D 10 +R 10 +U 9 +R 6 +L 9 +D 2 +U 6 +R 8 +U 9 +L 7 +R 5 +U 2 +D 8 +R 4 +D 5 +U 7 +D 2 +R 2 +U 2 +D 1 +R 1 +D 9 +L 10 +R 3 +D 5 +R 8 +U 5 +R 1 +U 3 +L 3 +U 7 +R 10 +U 4 +D 7 +U 3 +L 3 +R 6 +U 6 +D 7 +R 3 +U 2 +D 9 +R 7 +D 1 +L 3 +D 6 +L 4 +D 5 +L 3 +U 7 +R 2 +D 8 +U 1 +L 8 +R 4 +D 8 +L 2 +D 6 +L 9 +R 9 +U 1 +R 10 +L 3 +U 8 +D 9 +R 8 +D 8 +U 2 +D 8 +L 4 +U 2 +D 3 +L 4 +R 6 +L 4 +D 4 +L 6 +U 1 +R 1 +D 4 +L 7 +R 8 +U 8 +L 9 +D 5 +R 1 +U 2 +D 8 +U 8 +L 10 +D 9 +L 1 +R 4 +U 10 +R 7 +D 1 +U 9 +L 5 +R 3 +U 2 +R 3 +L 3 +U 7 +R 8 +L 10 +R 4 +D 5 +U 3 +L 10 +R 4 +U 7 +L 8 +U 4 +L 2 +R 10 +D 11 +L 10 +D 10 +L 11 +R 9 +D 9 +R 5 +L 5 +D 10 +R 11 +U 1 +R 11 +U 5 +R 9 +U 8 +L 1 +R 7 +U 7 +D 5 +R 5 +L 6 +R 8 +L 10 +R 9 +U 6 +D 9 +L 7 +U 7 +L 9 +R 5 +D 8 +R 8 +U 6 +R 11 +L 7 +D 9 +R 6 +L 5 +R 9 +U 8 +L 3 +U 9 +L 2 +R 9 +L 8 +R 1 +L 9 +R 4 +L 2 +U 1 +R 8 +L 8 +D 2 +L 8 +R 3 +D 8 +L 1 +R 11 +L 3 +R 8 +D 3 +L 10 +R 10 +D 5 +R 9 +D 4 +U 3 +L 6 +R 2 +U 10 +D 7 +U 8 +L 4 +D 7 +U 4 +D 7 +L 7 +R 9 +L 1 +R 6 +D 10 +U 4 +D 11 +U 7 +R 4 +U 10 +L 7 +R 9 +D 11 +U 11 +R 6 +U 9 +L 5 +D 10 +R 9 +L 10 +R 1 +D 4 +R 2 +L 4 +U 5 +L 4 +D 11 +U 8 +R 12 +L 10 +D 7 +R 4 +U 9 +R 5 +D 8 +U 9 +L 3 +R 3 +L 3 +U 11 +L 3 +D 9 +U 2 +R 3 +D 2 +L 4 +U 7 +R 10 +U 2 +D 10 +U 7 +L 1 +U 10 +L 1 +D 10 +U 12 +R 5 +L 4 +R 10 +U 6 +D 2 +R 6 +U 11 +D 1 +U 2 +L 1 +D 12 +R 2 +U 3 +D 7 +U 2 +L 9 +D 7 +R 3 +U 5 +R 10 +U 7 +D 5 +L 6 +U 11 +D 11 +L 1 +D 10 +R 1 +L 5 +U 10 +L 11 +R 10 +U 2 +D 7 +U 10 +L 10 +U 11 +D 7 +R 6 +D 3 +L 11 +U 4 +R 8 +U 6 +D 2 +U 8 +R 3 +L 7 +R 5 +U 8 +D 3 +L 12 +U 12 +D 10 +U 7 +L 10 +R 8 +D 8 +U 11 +R 3 +U 10 +R 6 +D 2 +U 3 +D 12 +L 5 +U 11 +R 9 +L 4 +U 6 +R 11 +D 1 +L 6 +U 5 +D 12 +L 9 +U 6 +L 13 +D 7 +L 10 +U 13 +L 11 +U 6 +D 11 +U 11 +L 6 +U 5 +D 2 +L 10 +D 5 +R 6 +D 13 +R 9 +D 4 +L 2 +R 11 +U 13 +L 3 +R 10 +U 2 +L 13 +U 10 +D 4 +L 2 +R 5 +L 8 +U 4 +D 1 +U 3 +D 10 +U 13 +D 2 +L 11 +R 7 +L 5 +R 7 +D 10 +R 13 +D 6 +R 11 +L 11 +R 9 +L 11 +D 13 +U 3 +L 6 +U 7 +L 12 +D 1 +R 7 +L 7 +U 1 +D 6 +R 6 +U 11 +D 2 +L 10 +R 5 +L 6 +R 6 +U 2 +R 11 +D 10 +U 9 +L 4 +U 7 +R 3 +U 9 +R 11 +U 6 +L 5 +D 1 +U 13 +L 11 +D 1 +L 9 +R 8 +D 4 +U 4 +L 1 +R 1 +L 6 +R 11 +D 10 +R 3 +U 2 +L 3 +R 1 +U 10 +R 3 +U 2 +L 1 +D 5 +U 11 +R 11 +U 11 +L 3 +U 3 +R 3 +L 3 +U 10 +L 14 +U 14 +D 6 +L 11 +R 6 +U 8 +L 12 +R 11 +U 1 +L 9 +D 11 +U 8 +D 6 +R 2 +L 12 +R 11 +D 2 +R 3 +D 5 +L 4 +U 2 +D 12 +U 12 +L 5 +R 2 +U 13 +R 1 +L 2 +D 13 +R 8 +L 14 +U 14 +L 9 +R 10 +U 5 +D 3 +U 12 +D 13 +R 2 +D 8 +R 10 +L 6 +U 12 +D 12 +R 6 +D 12 +R 13 +L 5 +R 10 +D 10 +L 8 +R 5 +L 2 +U 6 +D 2 +U 9 +L 1 +D 8 +L 7 +D 10 +L 6 +R 1 +L 6 +D 14 +U 6 +R 10 +D 4 +R 2 +D 13 +U 9 +R 11 +U 8 +R 4 +L 6 +R 14 +L 10 +U 14 +D 12 +R 3 +D 12 +L 8 +U 13 +R 4 +L 3 +R 14 +U 11 +D 13 +L 8 +U 1 +D 2 +L 11 +R 7 +D 5 +R 11 +L 1 +D 13 +L 7 +R 4 +U 7 +D 13 +L 2 +R 8 +D 1 +R 13 +L 9 +D 4 +R 12 +D 10 +U 12 +D 7 +U 5 +L 3 +U 9 +D 12 +R 8 +D 13 +R 8 +D 5 +L 14 +U 7 +D 4 +R 14 +D 14 +R 2 +D 5 +L 2 +D 13 +U 7 +L 8 +R 10 +D 9 +U 11 +D 3 +U 3 +D 2 +L 9 +D 2 +U 10 +D 7 +L 5 +R 10 +D 15 +R 1 +U 7 +D 10 +U 14 +R 12 +L 14 +U 7 +R 5 +U 2 +L 3 +R 13 +U 12 +D 1 +L 15 +D 10 +R 6 +U 9 +R 13 +U 3 +D 13 +U 1 +R 4 +L 1 +R 8 +U 14 +L 1 +R 10 +L 12 +D 15 +R 6 +U 13 +L 2 +R 13 +D 9 +U 3 +R 4 +D 11 +U 6 +D 9 +L 12 +R 1 +D 11 +R 11 +U 11 +R 5 +D 2 +L 3 +R 12 +L 8 +R 1 +L 12 +U 9 +L 3 +U 7 +D 2 +U 9 +L 10 +D 1 +U 7 +R 9 +D 11 +L 8 +D 4 +R 2 +U 12 +D 12 +U 6 +R 5 +D 2 +R 1 +D 5 +U 6 +L 10 +D 13 +R 5 +U 12 +L 4 +U 8 +L 12 +U 13 +L 1 +D 4 +L 9 +U 3 +D 15 +U 3 +D 15 +R 1 +D 10 +U 11 +R 7 +U 3 +R 13 +D 3 +U 3 +R 9 +L 12 +D 1 +U 5 +D 1 +R 9 +D 5 +U 15 +D 9 +L 10 +R 6 +L 4 +D 6 +R 5 +U 15 +R 9 +U 16 +D 3 +R 9 +U 11 +D 16 +U 7 +L 1 +U 8 +R 12 +L 1 +R 6 +D 9 +U 11 +L 5 +D 5 +R 14 +D 1 +L 3 +R 8 +L 3 +D 8 +U 11 +R 12 +U 10 +L 3 +U 10 +L 1 +R 9 +L 8 +D 2 +R 5 +U 3 +R 2 +D 9 +R 3 +D 12 +U 5 +D 13 +L 7 +R 15 +L 9 +U 9 +D 7 +R 6 +D 9 +L 7 +R 11 +L 10 +R 9 +U 13 +L 11 +U 10 +L 2 +D 13 +L 13 +R 15 +D 6 +R 15 +U 10 +R 12 +D 8 +U 16 +L 6 +R 9 +U 12 +D 4 +R 6 +U 7 +L 11 +U 12 +L 5 +R 11 +L 16 +R 3 +U 5 +L 14 +R 12 +L 13 +D 1 +L 9 +D 8 +L 6 +R 6 +D 15 +L 14 +R 17 +U 12 +D 12 +R 15 +D 2 +L 11 +R 9 +U 1 +R 5 +U 17 +R 3 +D 16 +U 6 +D 16 +R 8 +L 10 +U 13 +L 9 +D 12 +R 1 +U 4 +R 8 +D 11 +R 15 +D 15 +L 4 +D 10 +L 6 +U 15 +L 1 +R 1 +D 16 +U 7 +R 13 +D 6 +L 14 +R 15 +U 5 +R 4 +U 7 +R 6 +U 17 +L 12 +U 6 +L 5 +R 16 +L 10 +D 6 +R 7 +U 15 +R 3 +U 3 +D 16 +L 8 +R 13 +L 1 +U 2 +R 5 +D 17 +U 10 +L 16 +U 2 +L 3 +D 2 +R 10 +L 6 +R 9 +U 3 +L 5 +U 2 +D 2 +U 4 +D 10 +R 9 +U 8 +L 9 +D 16 +R 3 +U 3 +L 15 +D 11 +R 1 +U 11 +R 11 +L 12 +R 11 +D 17 +R 4 +D 14 +R 10 +U 4 +R 5 +D 12 +U 16 +D 3 +R 1 +L 15 +U 11 +R 1 +D 3 +L 9 +D 3 +L 7 +U 5 +R 12 +U 10 +R 16 +U 12 +D 9 +R 10 +U 2 +R 3 +D 15 +R 14 +L 11 +D 18 +R 12 +D 6 +U 5 +L 8 +U 7 +D 15 +R 8 +D 15 +L 7 +R 18 +L 5 +R 8 +L 10 +D 12 +R 14 +U 2 +L 7 +R 17 +U 4 +L 1 +U 10 +D 18 +L 3 +U 5 +D 12 +L 4 +R 14 +U 5 +L 18 +U 18 +D 14 +R 11 +U 6 +L 4 +R 13 +D 18 +U 18 +R 18 +U 7 +D 4 +L 17 +D 2 +U 11 +L 13 +D 13 +L 14 +U 2 +R 6 +L 3 +D 1 +L 8 +U 3 +R 5 +D 7 +L 2 +D 4 +U 1 +R 1 +U 8 +D 2 +U 3 +R 2 +D 15 +U 1 +R 9 +L 2 +R 2 +U 3 +L 16 +U 16 +R 16 +L 11 +U 9 +D 10 +R 18 +U 14 +D 7 +R 16 +D 7 +R 7 +L 3 +U 17 +R 18 +U 10 +L 15 +R 3 +U 6 +R 1 +U 1 +R 14 +D 12 +R 10 +L 7 +U 11 +D 15 +U 9 +L 11 +U 13 +D 16 +R 8 +U 5 +L 5 +U 10 +R 5 +L 15 +D 6 +L 16 +D 4 +L 19 +R 8 +U 18 +L 7 +D 15 +R 5 +U 9 +L 2 +U 17 +L 2 +U 17 +R 2 +L 13 +D 19 +L 16 +U 6 +D 13 +R 15 +D 13 +U 7 +L 7 +R 8 +D 10 +L 13 +D 4 +L 5 +U 8 +L 12 +R 13 +U 5 +R 9 +U 16 +L 5 +D 14 +L 4 +R 8 +U 4 +L 10 +R 17 +D 12 +L 14 +U 18 +D 3 +U 9 +R 12 +L 3 +R 15 +L 17 +D 4 +R 6 +L 5 +R 8 +D 19 +L 15 +D 5 +L 8 +R 7 +L 13 +D 3 +L 17 +D 12 +R 5 +L 9 +U 3 +L 17 +D 10 +R 17 +L 12 +R 16 +L 7 +D 4 +R 18 +U 10 +R 19 +L 19 +R 1 +U 10 +D 2 +L 8 +U 9 +L 15 +D 1 +R 15 +U 10 +R 18 +U 16 +R 17 +L 16 +D 9 +R 18 +U 16 +L 9 +R 14 +U 7 +L 8 +D 15 +L 7 +U 10 +D 18 +L 13 +R 1 +D 8 +R 14 +L 12 +U 2 diff --git a/2022/day09_1/src/main/resources/small_input b/2022/day09_1/src/main/resources/small_input new file mode 100644 index 0000000..9874df2 --- /dev/null +++ b/2022/day09_1/src/main/resources/small_input @@ -0,0 +1,8 @@ +R 4 +U 4 +L 3 +D 1 +R 4 +D 1 +L 5 +R 2 diff --git a/2022/day09_2/src/main/resources/small_input1 b/2022/day09_2/src/main/resources/small_input1 new file mode 100644 index 0000000..e69de29 diff --git a/2023/day01_1/.gitignore b/2023/day01_1/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/2023/day01_1/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/2023/day01_1/.idea/.gitignore b/2023/day01_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2023/day01_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2023/day01_1/.idea/inspectionProfiles/Project_Default.xml b/2023/day01_1/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2023/day01_1/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2023/day01_1/.idea/kotlinc.xml b/2023/day01_1/.idea/kotlinc.xml new file mode 100644 index 0000000..4a63394 --- /dev/null +++ b/2023/day01_1/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2023/day01_1/.idea/libraries/KotlinJavaRuntime.xml b/2023/day01_1/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..3e44d76 --- /dev/null +++ b/2023/day01_1/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day01_1/.idea/misc.xml b/2023/day01_1/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2023/day01_1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day01_1/.idea/modules.xml b/2023/day01_1/.idea/modules.xml new file mode 100644 index 0000000..bf3df2b --- /dev/null +++ b/2023/day01_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2023/day01_1/.idea/sonarlint/issuestore/index.pb b/2023/day01_1/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..e10b5ff --- /dev/null +++ b/2023/day01_1/.idea/sonarlint/issuestore/index.pb @@ -0,0 +1,3 @@ + +G +src/main/kotlin/Main.kt,d/8/d83ae3847b7d408136086cc5e9e95f5f7c126ed5 \ No newline at end of file diff --git a/2023/day01_1/.idea/sonarlint/securityhotspotstore/index.pb b/2023/day01_1/.idea/sonarlint/securityhotspotstore/index.pb new file mode 100644 index 0000000..e10b5ff --- /dev/null +++ b/2023/day01_1/.idea/sonarlint/securityhotspotstore/index.pb @@ -0,0 +1,3 @@ + +G +src/main/kotlin/Main.kt,d/8/d83ae3847b7d408136086cc5e9e95f5f7c126ed5 \ No newline at end of file diff --git a/2023/day01_1/.idea/vcs.xml b/2023/day01_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2023/day01_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day01_1/day01_1.iml b/2023/day01_1/day01_1.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day01_1/day01_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day01_1/src/main/kotlin/Main.kt b/2023/day01_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..ba650f0 --- /dev/null +++ b/2023/day01_1/src/main/kotlin/Main.kt @@ -0,0 +1,34 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 1, Part 1 starting!!!") + + var answer:Int = 0; + + File(args[0]).forEachLine { + answer += parseLine(it) + } + println("The answer: $answer") + + println("AOC 2023, Day 1, Part 1 completed!!") +} + +fun parseLine(line:String) : Int{ + val answerTens:Int = parseLeftToRight(line) + val answerOnes:Int = parseRightToLeft(line) + return (answerTens * 10) + answerOnes +} + +fun parseLeftToRight(line:String):Int { + if(!line.first().isDigit()) { + return parseLeftToRight(line.drop(1)) + } + return line.first().digitToInt() +} + +fun parseRightToLeft(line:String):Int { + if(!line.last().isDigit()) { + return parseRightToLeft(line.dropLast(1)) + } + return line.last().digitToInt() +} \ No newline at end of file diff --git a/2023/day01_1/src/main/resources/input b/2023/day01_1/src/main/resources/input new file mode 100644 index 0000000..815311e --- /dev/null +++ b/2023/day01_1/src/main/resources/input @@ -0,0 +1,1000 @@ +gsjgklneight6zqfz +7one718onegfqtdbtxfcmd +xvtfhkm8c9 +914two8 +vxzzvdhfqfsix83c1ttvbbstxgdrkfcnmm3 +76mkvhmbkpm +8sixssmlzlhrnineggmrvg6 +threeninedtr7219 +two2geight +3nine9fivetwo9twohxhc8 +llbfmnzzntdcfbslcl3xxvz +two3leighttvpkfmjhhonefour +1b9four +fivefdlqonesj2six +hfptgztwosix8 +fourkcxqfgxbsvjj3472 +xhzs7rdphtxhtwo +eightthree51 +3nmronemlqzfxgonepkh +9vnxqtjjrsg +533fivesixrvqfxjrdhl +bkrljtkjb42fqnp +4mrh734 +threefourfive83l +lcjftnpqfourfivesixtwof3 +sevennineh7two3 +onecgrmb74ctxhg +kmvtdrxvrfivethree2 +seven98mflv +tmoneightzstdjqjncnkpkknzoneonethreefive7 +fourzsqjbffmxf6lsqdttjfive1nine +ccs3onesgmmrb +kflkpscthreehjjgckfrfdhc3krgntwofour +7five2134 +pnfbrjhgprdsvzjrklrclmlgkk69four4 +cheightwofourxt2 +1167threetfqstpkc +6dsk2bhqmonejggkpvffhgnrbsix +five9threefour +one3136four +vvncdsg6jnxlbsb3 +fgftp5 +xxscpztpxteightv4mprlzmdhxtxmpvgfour +g4 +eightmbqbrxjbdx5 +8nineeighttwo6lcsvmvxdqbgpdbtjnnine +jkj86threeskgpnl3four +rtmpn5cbtthreefgxnhhvlkxcbtknnine +7dpn6cqstqrv7sbgzxhgrqrgn +3fivetxgjgndz1 +tfmkd8three2 +rcl55cvnfour9twofive +dmgdbkfjvsnpctj69four5 +xjlrvznbgl78eight +dmhkvgbc6four6eightwofkk +zlhzn898scffour +bdeighttxntvnslbf1nine59 +htjltzmzeight5foureightdvv +45fourl2 +seventhree39fivesixtwokchzgc +fxtbgsxch1lmdsldthreefour8rkxjz9 +five3five8 +threefvfcxnfgskqjdjknrgkvnkl6 +8jzdkxm +plttwo2fourseven99zthrklvcvp +gxjfdnzrcj2847eightnine +2onetwoxdc +35zlpzpvfn77 +nxppmskvrd1one89eightfive +glhp52f +mpptktkhrbbcsdheighteightqkjgckvxs6fourseven +1ninelspvpm +threefqn551 +eight95lhxrtwoh2hbnd +jlbclhxp72fivektxfxbtwonetxl +one7nflzdbdjchbbqqmn +fivesbgsrvzrhz2ncbkhsbrgnpbkgcsrln1zksfqkcxpf +1ftfour22hvdcqrseven +sevenjgrkpbxxnnv1nine6hzkrzzfl +fourthreefour98sevenbthreesix +sixgrrjkl3gdzz86onejpjlbpnthree +vhx3tnzcjvgg +six3one4sixeighttwosbkqdjfhfroneights +669eighteight32seven +jdpzkdnngc6bvqvtxtxfivesixthreedndsqmv +9eight6ssxcdt6fivedsnine +nine3onetjmdqpktwo +ninejjzrklhptsdzbt6tmxnpbrm +eightsevensixtxvxlqtdjfivebnvpdhvfsqbbssfkplzmkvvxh7 +xmeightone5cjgn1nhjsthree5 +xncbclzqqgskthree14bptlrknkmpntxmnf +sevenfour8 +34 +5ccslrvbfive +sixsixlqf72 +kknmskkfivezcmjrgfgclgrz1 +gqxtmrsqxfour12vlonefive +four8594kxsc +364 +hrbfxdpfivesevenjcjdm3nine9sixsh +mml5five +btcqdx7jjsix +4558seven4mjzsix +1mfckqcfk +4pjtbd18ghnnjqmjm6cvcdgjlcrmxpnnts +eight6hd +cdjdhpjccncpmrfour9qxlqfivenxjfssftnq +5bchcbpjxnsbkxgbqgbr +sixlhnzzmkbfourhzp58onetwoseven +kfgkqfivek3br +fnklssmgnine4eight +rbbnjvgpkgbs65sevenmeightsevennine +8ninenzgpldnfgjjmbqpmqvgqcthree5seven2 +seven6pdrgrldhtldhmndbjpj +5three4zmjpslhh +threesixsix45 +szxnvzrkseven2tctf +xqzpninesixseven5dndlqd7 +three6ghhzcvpkfivervsgplxq +eighttwoeightlfntmxptgk2pngplvr39 +33ninenine4fivejseven6 +fivehxbmjvxxrzrqr29npqhhlsjr2ttmnl +slmltqplzl73dxkxrpgn +lxg4371three +tjxsmjnthreefive5fivemshrhhj +5eighttwo +sixbpqtcrjzmveighteightjzgktzss1 +1qxjz57sixzh +4djpqz54122 +threeclg1ng7kgprvd +3143threenine71 +kcxmcthreesixeight23 +4zhvn4five +lmxfone47fbdsixjgl +kzcdzp2 +27twozjbtr +gpvkqdpbpzthreeone5 +bqvneightseven8qll +seven8brjrp272none +3kxhglddkjklkl +5sevennine52nine +3fourgznkfpfsxzsnmoneqsixtsm +twothreemkz6ttrtbj8 +qoneight28fourninempvltzrtzgvfdcdlxv +rllmkpvgqnkdgdrseven2five3 +7eight89fourlkfourfivejkqgffz +four6xr +6sixfive2hhzdkskxnine3nine +two6qmmkhb9eight +cqfxnmrlnhcsdqqxkn2nsncgvdxgmnineeight +7sixsdsfour4mrxeight +44threetcmtzmxzgjonesixnine8seven +dlonethreejh6bgxxmlkdseightwokp +four3lspkhhtsmone +89hjtnrrpvfzjdkzp +xc4sixvzpccdblczvleight7 +2twotwogzqhp9vnbp +rxsplmvb1two8pdtnxtbthreefiveeight +bsfdmnnj8eight +rntszdckhhcmqn21ljzqbhn +nineeight8 +1fhmnzzlfjpdp3ptj8threejqvmstbtp +267 +hkknsfivecrhthvbhhqj1 +six6xcqpnj9fivezcqbrfour4 +8one2gfsgg +mszrrqmr4nine9 +5fournine43three +5one9hvvrthreethreef3 +ninetwo6twofivefivennhjqkhzntkqptfxvdj +9onetwo5fiveeightnine8 +nineseventslmmgnsjbdgsb2sixlmvxpdg6 +8nineonethreehghh +jd1kr +drrsxljl4 +fqhfjdxdlsgjgkhcpjkqpgzjgchsixrvzqn7 +7one2qsnxhfqkseven6 +1vhljtwo1oneightqm +gl3 +two2eight1threethree +64nine +qglkhnfffsnine2three566three +7sixtwo6trbbklgjteighttwo +nkccpeight4sevensevenone +eight9ldkvgqhq3 +ttkqpxpzrxph1zfzhbvbgvn +46lqxxgrmvsix +twosixcqsmjsthree8pqthmd +ninesixdsns66lvnkhrq3 +seven413crqjpkfqleightlgxgck +onesxztkrtxksqklpqcmrlpjlnst6ftwo +jzb1oneightqqr +ninexrmlglbdlfqm4twolnlq +4seven4eightzds +fourngdzkklkxtsix8 +cggtwonebtkxtwothree16seven +three59threesix +3qfglrfcr4nine +9seveneighttwofoureightvvhpgmpnftwo +seven2sixvsmxv86 +mgvqr5two +lggjffzt2six7vxflh23 +hctpninesevenoneonevr3 +7threeqzgzm532mn5 +vltdnjhxgl6rjbmcb79s69eight +snkbpcgclpbflxbz6nkktqqgplm11bdnvpfour +75dllnlkthree93onedflbbmlvmd +sixthree94frdpkdccqkxv5 +hdpsvxl2bszdpgspqgxrzz3 +hztwonethreeeightzjqk8fivepvgrpsrxxsbfqfv +kfmh6sixv74two +one9three5 +lcn2hls3three66gsfmzvlx +tmlhhl72nhhkppscc +eightsevenprzgonethree7nine1 +1rngfnx78196sixrjbbkzp +6seven2182six +fpsl5xbdnjbzonethreezcfqmqonefive +5cxhrqzsfz34xdkvtxblkhvstcmjc +seven36ccqzfmmlvsevennine +5nrvq2nine2 +fljzxvninetqxjjcrsvp7 +1ninetwosevenvdtn4qcxnblgx2two +dcfxp2onefourfive +6czxzpsc +threeone1grvz8pvzvzkdzjfsix +hmbpnqntczjhdlsjonedr9prxvkt6one9 +dccns9threeninexgflfjltmvlssrhkbvktcfourg +sevenhbflnmglrn4rtseventwo55 +threehddkrvsp11 +6threegtk5five +29m5 +nine3threesixsevennineddgchfiveeightwovqq +2jtgvrldnbpfncfxtq +eighttwo6vtgkvpqzthree +5sixseven +twohj3seven3fourblqqbphcbfive +6one7twovjfqlsdgnrtzlzmjxgfljs +1nv +22five27two +3sevenlgeighteight +khpjmtsskfivefivexbjnkdtwogmxcxrqdpl2 +zmvpjtm6gzgztjrtnmgpsevenfive28vjvhmnr +9four71 +9zghgdjs +3oneqcjhsbv9threefive +47rsggonennqmbbckcdd31three +sevenfivesixone5eight +48hcmlcone8x6 +three9threesixjtxhlm3eightgtrskhqfjtgfjbcfdt +5ninefrpqjdhkkcldvhqkljpqpb1 +969nine +ninenine8ctprmxkvnine3xkl +seven648lpmxdn92 +rjhvlnz5two +dlvqhfmp587 +sevensix6 +eightsix34fourlgxrndbjjx9mztwo +czlpflntvpc1qnl2 +9seven8qsixbjoneeight +snnjcseventwo6qst +ndxgj756zqgt +krczgjpbfp199three4six +cjeightwoone8 +ffmddcrh7rrxhpnlkkdl +nine9hhppdvfczxkjninefivecdp +8eight19 +4fiveeightthree2twotwo +nine2four4941seven +fournine5twodqbkbjjmmqsn +nzqgngfxftwo6 +5bmlfbsql2sevenjrxkkdtwoone +jfeightwoppxbpgzdljnmmpvrckv8 +chj66fouronefourvcdd +fourzvgbsgkmgslntrzxtxvjnmhk5v7 +1fnzftqmtj9gqkblpknq6blmlkxbzhdsdljvqfour +116rqpdqq +xslxqcmlchmqlzmkxbk79hnlhthreesnnmnht +sixfive8kjhrfdxrtfour +nlv71clmzbnine6 +42one8lz +qspsdj2gv6vl8six5 +5gctkjzxlr2twoseventhree +rmgmkvqeightpfmrxqmvkg8 +3sixnjrjbbzl3 +1nineseven4three7qhdsxvbmlk +fourjbznsbgsn2pgxrzlkkjtctm3eight5 +36fourninecppsqfflbcbljnfgh2 +eight211ninegnfvhfxqcmpmeight +vbsg73 +3ninetwoonerbzcglkmdg +76ngkrtfonecltwovvgvgznzbmxm +977eighteightwocp +fxskxcdkdeight2225 +seven98rpzjxscseven3vtbbhqjrjfk +sevenseven97jxh +sevenfourfivexsspnqjnlxtbrfour24 +fivefive5two91six +gg2ptrsdxtfjtzztthree8 +eight2ncmps1qsix25 +eight486zfqfmgchtrrbcrjsevenrcqtxnqnrb +7vgn31lvqqvkdqlpddmllbn9 +1hlgrlmctseveneight9xfsfseven +onefourdqzvlh7 +four543ninethree +4seven1one +79twogmjcngj7rseven3 +xxtkcbkgqfldssix4five4nine +tqxnnspd7sevenvljzl2scsbkhqdq +cbz3rczscjfxtzfivenbjqone +threekkcjlmvkfrsgz6r +1sixvppcksdvrz7 +dvngzs74eight9 +qrncqtqxkfrndcrrpjcglfonesix75seven +eight6cksxfdthreefive2eight +four51sixfschln6 +hblmcggzgqsix2two +93two985 +78six6 +6sxmd289nine152 +gmpdcdcr4xzmhq3 +5threehpdmq +eight54xcrlsv8three4 +35twofourfivenine4tjthd +6kch9 +7fjlvptwo2ztrggpmsntwo +7twosix6kmdnvspnqgjxcdtgrspjj7 +tsix8fivethree +2pggbgxnft7 +sixthree69j +24l +cpzltvslq9nfhcv +six46eightsixsixbblvjjkvntmm +7five3 +six2three +seven2xxxhhjnl53sixjtgbnvh6 +fiveeightj1mrfvzfour3p +6foureight588zpjdcxlrshtwonine +xvtwonesix7prcjfsxjksknxqqsmsix +eight3fivexmrs1eightnc +vczdhchhsmlx7zdlcgfzrcgkcnqdvdtphxqqjxnsbd +six2fxqqdtrkgqpgjrvhxtsbqzz +twotwofour4six +9nzcvxthree +kggfkpvhrronep238nine +41seven4sevenfourvrmxkhpcmskbctwo +nbttnvh8nlhldjstkvdxxlvqeightoneights +tjqdkfourthree466 +twothbcvstwotwo2xpnqrldsmdtscnrp +sevennine3 +twodhbtlnzrt418dlszqkbc78 +3four8threeonetwoneh +drtcjpmrlnine3vgf8kssrsssgpnseven +eight78jqjjkgtbcckdndhdvz57q +five59onesixsevenflls +63bbznssjjsvt4 +fqkgmcrxf6gkcninesevennfzhccqtfour9 +5nine2three +gfkhpkfgb9four49rqcjrjkglpzxr +ds28eight33xl +qdgnn9ninecpcv +2sevenrlfkzmktzgsevenzzgxfrmp +twovpthxmxqgr94 +sk3gbmrknrmm +7sevenrpxjvzeightsix +9zxzqglvxqm6jphmvfsqvjjqsl +9kqmnkthcdhtwovbrqzftst3 +eight669zvrdpv +shgjkgthreeznz69pjltseven +ninebc5eight +5l +onesix5five2clxllfour +71three2fivecplsnlgsmthree +twofourone6fm7four26eightwox +7three9ftpvvbzpjzsixssxbqcfsix4 +92eightlsgrmpqtpptxrdfxthreemvlxfpsevenoneightdd +eight7three +drxxcghbsevenninenineljtczntp6 +nine55cpqfkdrthree3 +7fivefp3eight +97nine1ninexprdpvqzps +four3eightpgbdhnmqvhjjhg6frqkpqzbtwoner +3threefivesevenrvr3sixthree +sixs6zl184 +fourlfkxcvqkllbtz45threefivesix +2twodvklqcqdjjdnpx84xgthree4 +eightfour8dnqmlqmxd9cmt8 +t4sixkkfhgmn83eight +eightoneninehqddxnine75vppqhlcm +1threesdvsszeight5dcsgrsv +seven776smjhhb +onevmr62dqzt7 +pqxtspl19threesevenkjvxjdhxkseven +cgkvmx5lffclxgtsnseven +fqjctfrrlmmnpeightone19nineqgsnsqbjk +8twoone +c6eightonep3gxjnsjtwo3 +sixthree36sevenseven +5vgfsdkzbxmvxncxjpsxffcbnr62kmgmhcmkq +nineeightfour9kvdmxg5nnhrf +5blqszh97fhgpbdn44 +nhzbqprgptnineflxgvfkvlp453two +kpcqvjcjcj6dfpsljlrxdlzbf8grsnsdmklp +1zkjbnln +four2xvxrrvs +nine5nfmbxnrgfnine8onekqcnine +oneonedd8 +rr44 +8bckneightnqmkvqhkkmxfour +2pznjcxlj4onenine433 +nhmhkcqbsrrthreeeighttwo3f5 +eight64sixninefivethreecfbbdk +csmoneight1hrsevenfivesevenone756 +9qdrxl +26two3jq +pnrskrrvtonesevenrmkcxcm2five8five +sfvfr8three69three7fs +seven52bkslnnfrbqvmblknq3f4 +zqmtdtp31threesevennine3 +9tbvvjstzmdpqnpbmrb32cbdjgtsjndjrps3ckpmspm +5four4rvmtkppghb9 +24ftjxbdq3nine +ltj2oneeightonesix +76three2sevennine +hfnzxcjfxgseven5cpph3 +2one966dpjlgfqbmceightthreenine +5one9smzz76eight +348tworhzvqjdmqtwo +cjsvvksgzkktwo7hsfkrhkcsbrqcnrz26 +threethreez8 +m3335cdgbxqn5twodmcqk +27eight4 +sfmspqbzr9eight +rscxzq2fqlhbbhvkdbzqzqhzfourninepclrkkdrtwosix +pxbld2twonef +plpbbkvxqpvdxqcstp5threevljjqsqxsevenseven +2sevensix9 +5413sxmtrdjtcmdqpbpcprsix +tpdqxscxjldqvzncbvrpr9cvkqdffvfh8four +six14 +nsmqttrbhrznvonecmlxtdclnbk3 +ninecgbqh6twoctsixthreefive +hqsgonesix3oneightklm +cxxbjptkvkcttddmtwo37one5 +v13two +txxm84kmrpdkxhtbntkhj4four5 +jsrzgnine8nrmzpgf5sqdz +4six9dkxttsthreedgvjkqpk +msnrq7 +t2five4vtwo7sevenrjdrzvb +2rxbdzlszjseven7 +gmmninesix3119ninemdnprsmd +ninesevenpbfx6fourfivefdvhrsctztrheight +qk3two317hnpkqxbmkb3 +oneone6sixdzdmfonefiveone +427sixfive +17njgbgljkpxvhph +4hnfvpbvzxl6three +5sixnllvrvpjpv +3sevenfzjltglsjkdknfnmpsvfive6xdsm2 +1pxp8onesix +xclcfthreeln9ndqhvdxknkjzv4 +6fourtwo2seven1fcd +1eightseven4 +four21eightlfjzb +nine9ninenine81 +eight8zpfsshlqbdlfourmch5four +6sixjdmjjgmsk +ninesix8threetwoxtqdsffxlk6 +dgsddfcnnc3sevenseven532one +lsevennineninefive851dtqzv +nmrxfsmfcscftvzzbggglsfour6 +threesmxqlgmpvtwokvrx361eight +brbkgqcblcxghjp34bpnrctz +sixbzxfbfsjth14pqpvjqfmr +oneseven99 +7four6562zjjxxjlvfdqbssmcx +8fjssqgzthree4five3 +fourckmtsssqgdgcvmqhcqlcqqdhv5eight +bphtzndpdrfivefour8nine5 +ninesix57jvjtwo36vzljdfnndv +eightfourfivesixone2vg +5sevenkdgcmjthdxpxprcdnzpffsixcjmh2 +9cvldprttjk1 +seven6fivesfjjshfqmsjvfpc +eightsixstmhlldl21fourvgsmdlcd1 +5nv1two +tsqxlfnd6rtcvcv5 +eight3zdljlvkbp7hfive5xzgzspsnfour +945sevennrtnn57 +562 +3vtnlsfoursjbgbqmlx6 +8lprsrtvrh9two3 +pssfncbhqpfour1dgcjqpccfzfntphmtjthree1sixfour +rchfmfp18998rsbx +nineonedmlffz5 +seven2sevenonetwo +nine3gxttrkkzpj933mjzhphl +cdpqqhrcrrnspsr378two +fourrprdlkvqj8tntfttwofivesevenqmcsgpljvnl +978sixskr2gkrcgn +jcvldmcdqbjdcxhjcgngsevenfive2cfcmbb4 +szlsvrzzkseventwoone6ninesevensj +gzboneightmsblxgzmsq5seven +seven5eight5 +tsblj5onebkx882 +7kdgdfvx3sevenczgf +94g14onenine +7fournrkdxz4threethree +8eightqtworlcxtv4 +rbkbdsqbfour39eighteightwoxn +cxgmxtoneninennqtmzml6dq +8fivefour9 +8bhspzfsjr9 +fivekzgvvfour8sevensix4vlphpblsp +six63kbbxrfivefive5 +eight5gmkrhrkjjxhb +xtcfivepntwoeight9seven +6nine8fivenine2mf +5fourbthreenineslxfgtqrxcv5four +4vhkxmlsvfg +scphnsbz9h6qnlhcqmgl +tbbcqfxrllszbseventwofivethreeninef1 +zkvtlscldhngtk59 +one6fourrmftxfsvmtwo874 +37threeonefive4 +lrnnspbrgd6jzxtbninesevenngnpsljcr +xhldmfc4five76five +qrzfivexklqcjdnine46 +jkgb6ninesix41threeseven +134628twozlm +8ffrzgtbbfgfive2ninethreem +2132 +7xf +mfhmshvfivenfzjhslq7nfcfgvjhs8 +seven3248 +pvpdpxpg135seven9vpcpgrzlpjblmd +shnslhthreefourtwodnpfr7seven +6hxhhmfivesixseven +vppgmfivethreefivesevensix2two +hp98 +phlskgmgrjsbtq2gkjvrgsd +kkfourthree9fhnpdqcqhtwo +ftnvkprhvllkh9n +71one7twofourfourqtfmc6 +eightfivehssmqsptconefive4 +ninejcfqknhcfpcbcsmnpvn4six5j +one7jvmtxkjzfive +twof9pqcgdfqsq4d7 +krczdrpxbhsngqdvsqb1four7mb7lldv +seven9634tgcsplgmfivetwo +vjvpstpbgtsevennvpsvch97rslh4onefour +zbtgjgq23seven7lbnzdpnkzf +zndbhclr714 +twofive3 +9eight2twojxzdkptwo +gzqfcqpxnfhtb28dvfeight38 +rsqvgsqv9tdlvssj +f78hjftphgcv8bqgrckgldone +fivethreetjg2 +6vtqgdkxsmj +xgjdndnpsevenzfl6tfgxltvcthree +threenine82gqnffkvm +zmlblc4fiveseven3two +msmlvbnqbt9 +144bfcbsjztmdldveight +chceightwofivemcfrxv266 +two9f7gzhhsf6 +ninetwoffour8sevenjngv +foureight22g7twoonemlvq +one78ptfgbbvx +fx5 +5rvz2two +913 +9eightnkvhcksoneqsqgntfthdtjm +one1sixcsccdvbxzx +sevenoneninethree4one7seven2 +jqseightwockmxjd3gfmlhbn6seven7sevenkhcr +sevenqqhs4onemcn +fourseven3nine7pcn +sjjpsthkdfeightcsvlcvhltv6 +qpc16five +3jplhrj2threetwofpvrthree +4sixsix9two +one1eighteight +5tg +256five9 +seven9crnff9eighteight +16five1one4kqllsltrtn +eight3three +seventwoqtlxj8 +74seven5 +2five7mmgsbfc +five7four +bmtkcxvcj997eight +cpgrpgxtgkqr9 +sevenmdqtqhfvnknine929xm +nsix27vzglsevenseven63 +six1nqpsgtrllsnhmbnqxrdvrcx8s +eighttwoflrvzfq262 +twosxtf866hfhxn4fourone +3fourzbrtmd47three +four99eightbcldqfvrm +871 +2twobdtnzzqgvfggjntvgpnqslbdctppnfzpfpcbvzqccq +sdmkzhb8lnpjntj7 +threembr1 +5fd1sevenpsdpdlnb16 +7mnkkvpzrrnslfksrninexmpnfpbzhkx +nfrnvtt8 +24dsffiveqzmjrjznfksrknrfn +5foureight3pn3 +nine9three +nine74cmxrdvcxf3pdhbfour +frjnzrsixone53eight +four41fourhfjnjhpkzp +939rdjhlfpjsix +4kdkcq9two +329fivefive98 +65485 +dfsevensixmdbfour7jhxsfourfour +rqtwonerdkf3eight6fourfour +twoqnfthree5fx +rtwone1two89ntwo9 +sixskqssbccfour7fivevcmsevendqbfcvks +sgtwovmzmzm9 +vk9 +seventhree4 +48mv3eightnine +six7gxnj4six3 +twotwosixlm55dmzdrntzthreeseven +fivemhcdlm8fivemkffllv9 +fkxzdh69twoonesbrfhntk +zfourthreeseven1kllk +6ninethreefiveqdct +nineeight136three5nxvj +fivecpbkhqxpmf46twotxtfrhmvboneone +brrfqninetwohgqnkfctkseven1 +npblhpcpfivehdsnine34 +vksix4fourvrbfmjcrhb78 +72xfmds46threefive +five1kq8eight56three +3sevenfvcsglnjtbhdkqf +6tr6qxqrmstqg +15five5 +fthfvffour85 +seven81fouronefive +dhkknlbfjrnsfcvvkk9seveneightwos +2lngrlvrk4shgktcbpfonefivenine2 +sevenhhlrfqmzn2 +6seven927gdczblhjlmrxnjqfktwoneq +7phbj9fourvbx31seven6 +146 +jnqxslzpsxdftrqczq764 +tmbjdldtwogfvxhnvsfp8tzzp +fourgv68bblxfktsfdg98 +36tnrmd2jrllk2npbrctjcjthm +mx3nine3hkslkb5 +xvmgtlzmrfjcmqgtworc3 +vxscrns1lclnxtwo +foursevenone534 +jdmrj1sixkzdxn +two9threenine +2sevendsmlzh13jlslmvtnine +nine8nine +gthbsq953kxckzppcxqzl3 +xnrgzjzrbp5rptrpbsdgsqfeight5 +1sevendnmxkpdsrmrfkpmxcq22sixmdmvqlgpnbcxf +eight658x14fq +rzvgmdltnz9nvthrjvpzqf +9oneightgl +dsbtb88 +three4fourninelzvqhvjpk6 +seven59fourthreed +3671 +66nineeight8two +eightlszxlsxlcq3sixskqhj4gkblpj +three2eighttwothree +nine853qttjrjptxttwortkhmjss +twosix35 +5948lspjxzpbmthfive +fourthree8 +fourfivevbbqpppqrkkzjqqbnine3 +8nine4xszllqzzonesix2nine +crgnbqrfourrzjbpnnsqthreethreefbnine85 +dx79xjkcpxsndsrbnjlbnine2 +9nine89 +one7qmv1 +dlpbzxfm536392fp +3seventhree8eighttwoeightfive +twongjrfkcb66 +2eightseven8 +zffrln57eighttbqsgzbzhrzxt5kxxlcxb +one5three621ninetwonnprsbmm +3vmslzzp8xcpcgvf +threesix93 +seven3sixfnbbbeighttwo1fivezglzb +kgk7 +48seven2ccztcfnv5tzkrxffour +xczvzdjthreeeight6hnffivexxtmqs79 +three4nine36threehjp +nineqtdtmmpjpkzpxmmfive83sevenseventhree +22jfdpndrcvxbgz +7bljfctkbpc +4bfblqrphseven +fklxmcqxthmnvrlc9 +4seven9zspgftgvd53dsdkhgbns46 +7seven664fdqkcqtr9 +dvxtkqfqbhrllbone3six3 +4ktplgtgzlf3eightfxslssr +six2bhsjknjmgdddgnb6tbhvxbf29nine +two93twofngr8four +oneoneftmqvblcrjnng7jvch97one +9fivexmzstmlrmztwohsqmzfivehseven +5two2hggzchnn +one28ptdlfourgnrjftqd4vxfdrfx7 +six6zvkcszt4tfpkeightvdkjzbb +7oneftjp +1sevenseven9fsp +jqtznvrq8one11fivesix +3ninedkqxtmoneighthkt +8k +931 +clhvprlljttm9 +four14bfgf4eightwoc +xrflnnfb2rlv7twoseven2six +6366hlgklvjvxxlbkxgb +nbkxvp3eightgnznqqjbt5seven +98sntdts +cneightwotdkfxxxjfdpz3zkkthree +five1sfhq1lhhvjb +zdd56tcdchkvnbn +sevenhtpbmbntfivethree9scjfivenine +2spxggcvsvm4msdszqtml +4twoxsevencjgnine +89eightonetwo3ghqbckqkn +fvsgljnzgzfive1slhbxxhsrlmfivexqnkmtnzx +1g1 +94mcreight +threefntlsvvfnine9 +b3hnhvjhtrrv +11fourthree46 +plhclxcjrsgspx3b8fivecbx +mvjxqnqxtwo89bfive +three9nkjrh6two3 +dgprgjdgcrtqxgvknnk9six +dmbljtqg66zxjr95nine2seven +vdxoneight6 +22two9 +7oneppgrjnmrvchvsznsgfivexxdt7 +1three4mzc +bdnhvtsjmdnklsxbtmnztqjtpnz6fivesevenfourzddgsrfmlq +krzm2twotwo65sixfhpplvcgcs +qzcvbvsfive1oneqzc9threesevenseven +threesixninekghkvvzd4 +txqjpmlvdlpm7 +eightsix1l96xrljgg +two63d32six +8nine1fivesixfive3eightwos +sixninenkrpsix2nf4 +four2seven35four9threensbv +ncjhcskrx6 +3eightcpssngjlsqvmsxqqpldhsxsthreelzgzn +6zjnmxrgcz +9bbvkvnbmzshtdzxgqnqmqtthree +four2kqmzfgvpk35rhmqhtrqmfourhjxxfour +9eightfivefrpqtzmkkgkvjbbqmsqvq +eightsevenzpskfbrmcgzjjpnlgr51bdlcmsxhf +pt8two6seveneightjsqxjmlf4six +phjclrmpzm1292gdfivenine +sixfourtwo1 +9tvcnzknine2rdnqfive81 +sixtwopvxjcnmone2kxzxgmn +twosixpcntbtfivenine4two +rxdgeightone86twobzmnlgkdc +4two1twovtldl8one +fiveb1 +212three6twofour84 +74tstlfmrmcj +sixgxtwotmrmzkfsj9 +eighthksxmf144xltwo8 +mthjxjhnqxnhcbxg783 +prptwonehhdlrd71threeone +59fivefnsmzfsix +ninesixonetwo9six6jtptone +eight9ninefivezqvpstsevenjvcjmdcscnzlqsfnhnrnmn +2ckgjml4rcprzj7tp6 +sevenfivesevennhg136 +ninesevenvhl5 +fzflrseven1five5seven +seven5lcfxp +bqhjg4three3 +three8ninegtonetwo46 +cvdpr8 +32fivehfsdhxgjnn +sdndcpccpvdzdgn9fourlnslcmbtwojphzpnvrnp +9cqkgdf7fxgdfcllvnnmzpptninesixone9 +3chllzcgq5fivebffm9 +sqmtj4qlhlcrmrnb38v4dsix +sevennine84bcpvqjcrxpvtcgfhlfhncplktf +qkzxvstdgnfour4two +jkhoneonesixfiveone14lvzn +threethreefivensvlbfour2four +vgqlhqfrlfourlzcgppdbhq57 +bqzpzbtwolprtwo9 +lfjs9six1five2fzcldvnpxtmhsix +kslcntz36nine +nineseven8rzccgfhzsjnjveighttwo +three3fourfivedmjlgqfhmninemst8 +4qxvzgfvctwo73 +75961fivefourzg +spcbt66sevennine4four +hhb1 +dtmoneight9 +3mbctjhfmr2fourthreeseven86 +sixjsbmvzql6gfnttq +1vknfgmznmnzpgvsp3bsksdsevenfourrk +six4six7ninepfxjsshthree +4rqgzpnqcg8skfgksjone3four8 +seven5zkljftwo +76sctscqtsfcninefourrgmsbsxv9six +46fpdqhkfjzgtclfchbbsjcbjhsbkqggzhlb6four +bshbvfourzc79lvvdsqjksmzmqpbvrsrbtg7 +jdqmtfeight59fourtwo +ninefivejsl3 +94z7fouroneeight +5nbmvgheightfive +sixseven5one9ngk3 +eight3jddmgqnzcfjsvrd6five6kmbxss +seveneight9fourthree +eight83 +3spltxvtbg +92shzldthreefpckdtqhm7fivezzkdlz +6two9threeztrzxphhksqc +ninedlone3 +eight4nineonefournsmdgkdszt +9cpxhnksktwo15fivefkq +144eight77 +1sixjscflltdrgclmgrszdfive7lc +ttmfsx9dzgcqjzlzhvlfqrsj4six +846 +fiveseven7 +kqtwone2ninefour7fghmntkn +8r8one +5nnzqqgxl4gbgnzntfrhqzeight +onevpkxvrone8 +79klfd +gzrjvck1sixqnfdjxfive9eightcmhmsjpl +nszqhdfsixsixb3threenfiveqskccbffd +srbn928eight +eight2eightfivekmnjkndgrhjdpvxk3 +9four11oneeight +seven6fivezzktmsixv +fivebvtnzr4threeonetld68 +mgbfjcjbqctt71fgdbmmqdlhpxnpmvx +rjprxbxrfk233 +nxbjxbcvvskeightfiveglpnhbzz27four +kstwo2 +2btbzfournbfcxnvlvcbsjmplnprcrg +mkk6three271 +tfncrvlnfdmntdrmjqqtknsgpq671onethree +eight8twofivex +phreightfive81hftbkbdnztt +onetbhqqlcbqrlfzrqbtbl9ntcgvxr1rhgrspqkgklz +gckbonekhzcjhdb5 +twothree1lfivetwolpdxhn8 +threebqmxgpjfbzrrrrgdt8 +threejvlpxpfm9four4threeone +five68onesevennineone9two +mjqjrqmeight73 +fvfgrdppszgdhmninenineone7759 +lrhchsonek3twobblvn9bdmcbt +mdcqxbz84five6ninetwonergj +eightnine548ttfiveeight7 +74mfftzxhkl4 +seven5mdmrxlp +ptb76ndfpbtljpkhjthdfmsdddjssm +7vkeight +bzzpvht5fourthreeseven8 +rztztsix12nine +fvpqdnphtd1mmrhppbd2 +h8dpbvs2tjlqgfxhhbeight +51one +two86 +sixnine7sixseventwo34 +two45xjcpcnhgbsb1five7 +qqkzvpsixfivepfzdhtl92six4rhp +two6vqtxvxrvzpz +1qqsfrgdbsm8five +threeeightsix36xvtm +nine5eightczhsix3twoprztckvb +pxrsgpszonepdjvxcblqzkr61seven11 +5sevenonesevensix4six1dvhrx +cdxnbseven9qsevenvbv4 +sixlgjt3 +dhpxhpbkq3lc6rkjlpdz4five5pctfzsplrf +1kmsmgjpmkqfckr +sixeight1k44 +52qdfp1b8 +86fourthree42 +six2fourpjtsvskrxtmgxnj2one3dn +rjtfqxvfm88seventhreeeighttwo +fivepgfvxcds64sevenhg +glvhcrgbtphxfsfourthreerqhjxpzone5gh +1sevenone34 +689five9ninetwotwo4 +6two92sixjb1cbhmrq +fiverrvllhbgcsskh2 +foureight6fhtx1five8eight +pqvvjkhtxkxcjkrf9mn +threefive2hs6one6jhkbdh +twoninefzflrqqzvp2xnr8 +one51 +7bjpnfsgpszrfk5fourthreebvvn +six74 +twozcgbrrhxcpznx9dlcgdchpndcdc +nines566 +one72zshxlsix +vseven4fouronenine6 +7four1nine2threekzjbs4 +onecq3four +twodcrx8 +four35sjjhpfftzsixfqctsfonefiveseven +sxqnssjtwothree2 +8fdpjrztwoseventwo5rmqvoneeight +pjlbnl3rg3shchseven +zdcrnpddv2 +eight2foureighttgjcxtf2 +ghhxlxqttvonerh96715twonectr +9hmfxxrsdbsixbtwo7sevensix +32ghjqjfp7three4one +197 +twon8five2 +vtwobrlhqsq1twothreesixthree +xbdxninefour8seven +five39 +621eightsix +21fvdd11tsdzhjspzld4 +7seventwoeightfpnkhxmvc +96sjrcvzxsevenfqt4seven9 +xzxmtsrhbfivenineninerxgcrx9one +5pzgmrgrg2kdgl9one +lqzmttxcpp7cnfstnhtglzhssntjmsixseven6six +two711 +6onevjnvmkkx +eight7dbmznvztwo +9mlpltkt3 +7ninenine4tpjbsbtsgzttlgrtnfvr91four +foursevenq7 +six1sgtbsmgft9 +nineone28fourjtwo8 +76threebgqvh6lfbkdmfvcthreeone3 +13cvtpqnmbv +1sevenzjhtfpbfb73rccvtnmtthree7 +4xhvshhtmxx7sevenf9 +8one1 +931fivetmdmsrrmfxrplkfvfourthreeeight +qzbthffhlg2 +one4eight33 +qfjqt9jlcthreeqkfdpfiveeight8scfnlj +fvczqbtsix2bxkgsnsix5nine7 +9qxnvlnine2phnlqzninefive +tszjsxbsixtwoeight62ffjtdnxxtwofive +one2skxg +five5onexzgzkjvtqrfourfive +twozsxzqtrqbxqqqsbcvfpgdcdpttwo1six +8mqkgptxsixhqmbqshcl +lsdlsxrhdqthreesix2sevenchjxvmsjpvrnpcblgmsix +gngrfrhbxhqkxs5fourr8three4 +jlzszzz9one +twozrbjkjpzseventwonine8dbmfdjcb +3nine36ppqone4czxvkxjzv +ld6eightseven6twosix +1jnbfive +7threeglmcdhpvq4723fivethree +seven148oneightd +sevensevenseven6sixtwosix21 +8twojhdkdrcqgmclqlldv6sevenonedjthcz +ninesevenggsjbpt5ttlrq +59sixfivefive +eight9bsmcgkseventhree66qmgpkkxnpm +fourthree73fiveseven +9five9six8threet +3eight44 +dlcbjflsix5ttvjdxzzeightcffrtfjcjpxtwostrdc +fiveone645fivellfcmqqmnine +hxdtshfive115tfvrzqhgftwojtjrcshgtq +6nqrfrhv17jdxpfmmdt4five +sevenxtpjxnrr1 +krzkthreegjnqrfbsdrkqptd33rsvrzvvffqhreight +472ggfive56hgnvz +12tkpchqtnine +vdbsctv6eightth82 +fivetngxlttf4 +5nss +5onesixsevenphxtmlqhzfcjxrknpv +gldsixrhss186seven6 +gnpksz4 +4919 +pbc19 diff --git a/2023/day01_1/src/main/resources/small_input b/2023/day01_1/src/main/resources/small_input new file mode 100644 index 0000000..1ba8437 --- /dev/null +++ b/2023/day01_1/src/main/resources/small_input @@ -0,0 +1,4 @@ +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet \ No newline at end of file diff --git a/2023/day01_2/day01_2.iml b/2023/day01_2/day01_2.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day01_2/day01_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day01_2/src/main/kotlin/Main.kt b/2023/day01_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..efb1a01 --- /dev/null +++ b/2023/day01_2/src/main/kotlin/Main.kt @@ -0,0 +1,80 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 1, Part 2 starting!!!") + + var answer = 0 + + File(args[0]).forEachLine { + answer += parseLine(it) + } + println("The answer: $answer") + + println("AOC 2023, Day 1, Part 2 completed!!") +} + +fun parseLine(line:String) : Int{ + val answerTens:Int = parseLeftToRight(line) + val answerOnes:Int = parseRightToLeft(line) + return (answerTens * 10) + answerOnes +} + +fun parseLeftToRight(line:String):Int { + if(line.first().isDigit()) { + return line.first().digitToInt() + } + val number = getNumberLeft(line) + if(number != 0) { + return number + } + + // nothing matches, recurse + return parseLeftToRight(line.drop(1)) +} + +fun parseRightToLeft(line:String):Int { + if(line.last().isDigit()) { + return line.last().digitToInt() + } + val number = getNumberRight(line) + if(number != 0) { + return number + } + + // Nothing matches, recurse + return parseRightToLeft(line.dropLast(1)) +} + +val numberToDigit = mapOf( + "one" to 1, + "two" to 2, + "three" to 3, + "four" to 4, + "five" to 5, + "six" to 6, + "seven" to 7, + "eight" to 8, + "nine" to 9 +) + +fun getNumberLeft(line:String): Int { + for(number in numberToDigit) { + val safeEnd = number.key.length.coerceAtMost(line.length) + val leftSubstring = line.substring(0, safeEnd) + if(leftSubstring.compareTo(number.key) == 0) { + return numberToDigit[leftSubstring]?:0 + } + } + return 0 +} + +fun getNumberRight(line:String):Int { + for(number in numberToDigit) { + val safeStart = (line.length - number.key.length).coerceAtLeast(0) + val rightSubstring = line.substring(safeStart, line.length) + if(rightSubstring.compareTo(number.key) == 0) { + return numberToDigit[rightSubstring]?:0 + } + } + return 0 +} \ No newline at end of file diff --git a/2023/day01_2/src/main/resources/input b/2023/day01_2/src/main/resources/input new file mode 100644 index 0000000..815311e --- /dev/null +++ b/2023/day01_2/src/main/resources/input @@ -0,0 +1,1000 @@ +gsjgklneight6zqfz +7one718onegfqtdbtxfcmd +xvtfhkm8c9 +914two8 +vxzzvdhfqfsix83c1ttvbbstxgdrkfcnmm3 +76mkvhmbkpm +8sixssmlzlhrnineggmrvg6 +threeninedtr7219 +two2geight +3nine9fivetwo9twohxhc8 +llbfmnzzntdcfbslcl3xxvz +two3leighttvpkfmjhhonefour +1b9four +fivefdlqonesj2six +hfptgztwosix8 +fourkcxqfgxbsvjj3472 +xhzs7rdphtxhtwo +eightthree51 +3nmronemlqzfxgonepkh +9vnxqtjjrsg +533fivesixrvqfxjrdhl +bkrljtkjb42fqnp +4mrh734 +threefourfive83l +lcjftnpqfourfivesixtwof3 +sevennineh7two3 +onecgrmb74ctxhg +kmvtdrxvrfivethree2 +seven98mflv +tmoneightzstdjqjncnkpkknzoneonethreefive7 +fourzsqjbffmxf6lsqdttjfive1nine +ccs3onesgmmrb +kflkpscthreehjjgckfrfdhc3krgntwofour +7five2134 +pnfbrjhgprdsvzjrklrclmlgkk69four4 +cheightwofourxt2 +1167threetfqstpkc +6dsk2bhqmonejggkpvffhgnrbsix +five9threefour +one3136four +vvncdsg6jnxlbsb3 +fgftp5 +xxscpztpxteightv4mprlzmdhxtxmpvgfour +g4 +eightmbqbrxjbdx5 +8nineeighttwo6lcsvmvxdqbgpdbtjnnine +jkj86threeskgpnl3four +rtmpn5cbtthreefgxnhhvlkxcbtknnine +7dpn6cqstqrv7sbgzxhgrqrgn +3fivetxgjgndz1 +tfmkd8three2 +rcl55cvnfour9twofive +dmgdbkfjvsnpctj69four5 +xjlrvznbgl78eight +dmhkvgbc6four6eightwofkk +zlhzn898scffour +bdeighttxntvnslbf1nine59 +htjltzmzeight5foureightdvv +45fourl2 +seventhree39fivesixtwokchzgc +fxtbgsxch1lmdsldthreefour8rkxjz9 +five3five8 +threefvfcxnfgskqjdjknrgkvnkl6 +8jzdkxm +plttwo2fourseven99zthrklvcvp +gxjfdnzrcj2847eightnine +2onetwoxdc +35zlpzpvfn77 +nxppmskvrd1one89eightfive +glhp52f +mpptktkhrbbcsdheighteightqkjgckvxs6fourseven +1ninelspvpm +threefqn551 +eight95lhxrtwoh2hbnd +jlbclhxp72fivektxfxbtwonetxl +one7nflzdbdjchbbqqmn +fivesbgsrvzrhz2ncbkhsbrgnpbkgcsrln1zksfqkcxpf +1ftfour22hvdcqrseven +sevenjgrkpbxxnnv1nine6hzkrzzfl +fourthreefour98sevenbthreesix +sixgrrjkl3gdzz86onejpjlbpnthree +vhx3tnzcjvgg +six3one4sixeighttwosbkqdjfhfroneights +669eighteight32seven +jdpzkdnngc6bvqvtxtxfivesixthreedndsqmv +9eight6ssxcdt6fivedsnine +nine3onetjmdqpktwo +ninejjzrklhptsdzbt6tmxnpbrm +eightsevensixtxvxlqtdjfivebnvpdhvfsqbbssfkplzmkvvxh7 +xmeightone5cjgn1nhjsthree5 +xncbclzqqgskthree14bptlrknkmpntxmnf +sevenfour8 +34 +5ccslrvbfive +sixsixlqf72 +kknmskkfivezcmjrgfgclgrz1 +gqxtmrsqxfour12vlonefive +four8594kxsc +364 +hrbfxdpfivesevenjcjdm3nine9sixsh +mml5five +btcqdx7jjsix +4558seven4mjzsix +1mfckqcfk +4pjtbd18ghnnjqmjm6cvcdgjlcrmxpnnts +eight6hd +cdjdhpjccncpmrfour9qxlqfivenxjfssftnq +5bchcbpjxnsbkxgbqgbr +sixlhnzzmkbfourhzp58onetwoseven +kfgkqfivek3br +fnklssmgnine4eight +rbbnjvgpkgbs65sevenmeightsevennine +8ninenzgpldnfgjjmbqpmqvgqcthree5seven2 +seven6pdrgrldhtldhmndbjpj +5three4zmjpslhh +threesixsix45 +szxnvzrkseven2tctf +xqzpninesixseven5dndlqd7 +three6ghhzcvpkfivervsgplxq +eighttwoeightlfntmxptgk2pngplvr39 +33ninenine4fivejseven6 +fivehxbmjvxxrzrqr29npqhhlsjr2ttmnl +slmltqplzl73dxkxrpgn +lxg4371three +tjxsmjnthreefive5fivemshrhhj +5eighttwo +sixbpqtcrjzmveighteightjzgktzss1 +1qxjz57sixzh +4djpqz54122 +threeclg1ng7kgprvd +3143threenine71 +kcxmcthreesixeight23 +4zhvn4five +lmxfone47fbdsixjgl +kzcdzp2 +27twozjbtr +gpvkqdpbpzthreeone5 +bqvneightseven8qll +seven8brjrp272none +3kxhglddkjklkl +5sevennine52nine +3fourgznkfpfsxzsnmoneqsixtsm +twothreemkz6ttrtbj8 +qoneight28fourninempvltzrtzgvfdcdlxv +rllmkpvgqnkdgdrseven2five3 +7eight89fourlkfourfivejkqgffz +four6xr +6sixfive2hhzdkskxnine3nine +two6qmmkhb9eight +cqfxnmrlnhcsdqqxkn2nsncgvdxgmnineeight +7sixsdsfour4mrxeight +44threetcmtzmxzgjonesixnine8seven +dlonethreejh6bgxxmlkdseightwokp +four3lspkhhtsmone +89hjtnrrpvfzjdkzp +xc4sixvzpccdblczvleight7 +2twotwogzqhp9vnbp +rxsplmvb1two8pdtnxtbthreefiveeight +bsfdmnnj8eight +rntszdckhhcmqn21ljzqbhn +nineeight8 +1fhmnzzlfjpdp3ptj8threejqvmstbtp +267 +hkknsfivecrhthvbhhqj1 +six6xcqpnj9fivezcqbrfour4 +8one2gfsgg +mszrrqmr4nine9 +5fournine43three +5one9hvvrthreethreef3 +ninetwo6twofivefivennhjqkhzntkqptfxvdj +9onetwo5fiveeightnine8 +nineseventslmmgnsjbdgsb2sixlmvxpdg6 +8nineonethreehghh +jd1kr +drrsxljl4 +fqhfjdxdlsgjgkhcpjkqpgzjgchsixrvzqn7 +7one2qsnxhfqkseven6 +1vhljtwo1oneightqm +gl3 +two2eight1threethree +64nine +qglkhnfffsnine2three566three +7sixtwo6trbbklgjteighttwo +nkccpeight4sevensevenone +eight9ldkvgqhq3 +ttkqpxpzrxph1zfzhbvbgvn +46lqxxgrmvsix +twosixcqsmjsthree8pqthmd +ninesixdsns66lvnkhrq3 +seven413crqjpkfqleightlgxgck +onesxztkrtxksqklpqcmrlpjlnst6ftwo +jzb1oneightqqr +ninexrmlglbdlfqm4twolnlq +4seven4eightzds +fourngdzkklkxtsix8 +cggtwonebtkxtwothree16seven +three59threesix +3qfglrfcr4nine +9seveneighttwofoureightvvhpgmpnftwo +seven2sixvsmxv86 +mgvqr5two +lggjffzt2six7vxflh23 +hctpninesevenoneonevr3 +7threeqzgzm532mn5 +vltdnjhxgl6rjbmcb79s69eight +snkbpcgclpbflxbz6nkktqqgplm11bdnvpfour +75dllnlkthree93onedflbbmlvmd +sixthree94frdpkdccqkxv5 +hdpsvxl2bszdpgspqgxrzz3 +hztwonethreeeightzjqk8fivepvgrpsrxxsbfqfv +kfmh6sixv74two +one9three5 +lcn2hls3three66gsfmzvlx +tmlhhl72nhhkppscc +eightsevenprzgonethree7nine1 +1rngfnx78196sixrjbbkzp +6seven2182six +fpsl5xbdnjbzonethreezcfqmqonefive +5cxhrqzsfz34xdkvtxblkhvstcmjc +seven36ccqzfmmlvsevennine +5nrvq2nine2 +fljzxvninetqxjjcrsvp7 +1ninetwosevenvdtn4qcxnblgx2two +dcfxp2onefourfive +6czxzpsc +threeone1grvz8pvzvzkdzjfsix +hmbpnqntczjhdlsjonedr9prxvkt6one9 +dccns9threeninexgflfjltmvlssrhkbvktcfourg +sevenhbflnmglrn4rtseventwo55 +threehddkrvsp11 +6threegtk5five +29m5 +nine3threesixsevennineddgchfiveeightwovqq +2jtgvrldnbpfncfxtq +eighttwo6vtgkvpqzthree +5sixseven +twohj3seven3fourblqqbphcbfive +6one7twovjfqlsdgnrtzlzmjxgfljs +1nv +22five27two +3sevenlgeighteight +khpjmtsskfivefivexbjnkdtwogmxcxrqdpl2 +zmvpjtm6gzgztjrtnmgpsevenfive28vjvhmnr +9four71 +9zghgdjs +3oneqcjhsbv9threefive +47rsggonennqmbbckcdd31three +sevenfivesixone5eight +48hcmlcone8x6 +three9threesixjtxhlm3eightgtrskhqfjtgfjbcfdt +5ninefrpqjdhkkcldvhqkljpqpb1 +969nine +ninenine8ctprmxkvnine3xkl +seven648lpmxdn92 +rjhvlnz5two +dlvqhfmp587 +sevensix6 +eightsix34fourlgxrndbjjx9mztwo +czlpflntvpc1qnl2 +9seven8qsixbjoneeight +snnjcseventwo6qst +ndxgj756zqgt +krczgjpbfp199three4six +cjeightwoone8 +ffmddcrh7rrxhpnlkkdl +nine9hhppdvfczxkjninefivecdp +8eight19 +4fiveeightthree2twotwo +nine2four4941seven +fournine5twodqbkbjjmmqsn +nzqgngfxftwo6 +5bmlfbsql2sevenjrxkkdtwoone +jfeightwoppxbpgzdljnmmpvrckv8 +chj66fouronefourvcdd +fourzvgbsgkmgslntrzxtxvjnmhk5v7 +1fnzftqmtj9gqkblpknq6blmlkxbzhdsdljvqfour +116rqpdqq +xslxqcmlchmqlzmkxbk79hnlhthreesnnmnht +sixfive8kjhrfdxrtfour +nlv71clmzbnine6 +42one8lz +qspsdj2gv6vl8six5 +5gctkjzxlr2twoseventhree +rmgmkvqeightpfmrxqmvkg8 +3sixnjrjbbzl3 +1nineseven4three7qhdsxvbmlk +fourjbznsbgsn2pgxrzlkkjtctm3eight5 +36fourninecppsqfflbcbljnfgh2 +eight211ninegnfvhfxqcmpmeight +vbsg73 +3ninetwoonerbzcglkmdg +76ngkrtfonecltwovvgvgznzbmxm +977eighteightwocp +fxskxcdkdeight2225 +seven98rpzjxscseven3vtbbhqjrjfk +sevenseven97jxh +sevenfourfivexsspnqjnlxtbrfour24 +fivefive5two91six +gg2ptrsdxtfjtzztthree8 +eight2ncmps1qsix25 +eight486zfqfmgchtrrbcrjsevenrcqtxnqnrb +7vgn31lvqqvkdqlpddmllbn9 +1hlgrlmctseveneight9xfsfseven +onefourdqzvlh7 +four543ninethree +4seven1one +79twogmjcngj7rseven3 +xxtkcbkgqfldssix4five4nine +tqxnnspd7sevenvljzl2scsbkhqdq +cbz3rczscjfxtzfivenbjqone +threekkcjlmvkfrsgz6r +1sixvppcksdvrz7 +dvngzs74eight9 +qrncqtqxkfrndcrrpjcglfonesix75seven +eight6cksxfdthreefive2eight +four51sixfschln6 +hblmcggzgqsix2two +93two985 +78six6 +6sxmd289nine152 +gmpdcdcr4xzmhq3 +5threehpdmq +eight54xcrlsv8three4 +35twofourfivenine4tjthd +6kch9 +7fjlvptwo2ztrggpmsntwo +7twosix6kmdnvspnqgjxcdtgrspjj7 +tsix8fivethree +2pggbgxnft7 +sixthree69j +24l +cpzltvslq9nfhcv +six46eightsixsixbblvjjkvntmm +7five3 +six2three +seven2xxxhhjnl53sixjtgbnvh6 +fiveeightj1mrfvzfour3p +6foureight588zpjdcxlrshtwonine +xvtwonesix7prcjfsxjksknxqqsmsix +eight3fivexmrs1eightnc +vczdhchhsmlx7zdlcgfzrcgkcnqdvdtphxqqjxnsbd +six2fxqqdtrkgqpgjrvhxtsbqzz +twotwofour4six +9nzcvxthree +kggfkpvhrronep238nine +41seven4sevenfourvrmxkhpcmskbctwo +nbttnvh8nlhldjstkvdxxlvqeightoneights +tjqdkfourthree466 +twothbcvstwotwo2xpnqrldsmdtscnrp +sevennine3 +twodhbtlnzrt418dlszqkbc78 +3four8threeonetwoneh +drtcjpmrlnine3vgf8kssrsssgpnseven +eight78jqjjkgtbcckdndhdvz57q +five59onesixsevenflls +63bbznssjjsvt4 +fqkgmcrxf6gkcninesevennfzhccqtfour9 +5nine2three +gfkhpkfgb9four49rqcjrjkglpzxr +ds28eight33xl +qdgnn9ninecpcv +2sevenrlfkzmktzgsevenzzgxfrmp +twovpthxmxqgr94 +sk3gbmrknrmm +7sevenrpxjvzeightsix +9zxzqglvxqm6jphmvfsqvjjqsl +9kqmnkthcdhtwovbrqzftst3 +eight669zvrdpv +shgjkgthreeznz69pjltseven +ninebc5eight +5l +onesix5five2clxllfour +71three2fivecplsnlgsmthree +twofourone6fm7four26eightwox +7three9ftpvvbzpjzsixssxbqcfsix4 +92eightlsgrmpqtpptxrdfxthreemvlxfpsevenoneightdd +eight7three +drxxcghbsevenninenineljtczntp6 +nine55cpqfkdrthree3 +7fivefp3eight +97nine1ninexprdpvqzps +four3eightpgbdhnmqvhjjhg6frqkpqzbtwoner +3threefivesevenrvr3sixthree +sixs6zl184 +fourlfkxcvqkllbtz45threefivesix +2twodvklqcqdjjdnpx84xgthree4 +eightfour8dnqmlqmxd9cmt8 +t4sixkkfhgmn83eight +eightoneninehqddxnine75vppqhlcm +1threesdvsszeight5dcsgrsv +seven776smjhhb +onevmr62dqzt7 +pqxtspl19threesevenkjvxjdhxkseven +cgkvmx5lffclxgtsnseven +fqjctfrrlmmnpeightone19nineqgsnsqbjk +8twoone +c6eightonep3gxjnsjtwo3 +sixthree36sevenseven +5vgfsdkzbxmvxncxjpsxffcbnr62kmgmhcmkq +nineeightfour9kvdmxg5nnhrf +5blqszh97fhgpbdn44 +nhzbqprgptnineflxgvfkvlp453two +kpcqvjcjcj6dfpsljlrxdlzbf8grsnsdmklp +1zkjbnln +four2xvxrrvs +nine5nfmbxnrgfnine8onekqcnine +oneonedd8 +rr44 +8bckneightnqmkvqhkkmxfour +2pznjcxlj4onenine433 +nhmhkcqbsrrthreeeighttwo3f5 +eight64sixninefivethreecfbbdk +csmoneight1hrsevenfivesevenone756 +9qdrxl +26two3jq +pnrskrrvtonesevenrmkcxcm2five8five +sfvfr8three69three7fs +seven52bkslnnfrbqvmblknq3f4 +zqmtdtp31threesevennine3 +9tbvvjstzmdpqnpbmrb32cbdjgtsjndjrps3ckpmspm +5four4rvmtkppghb9 +24ftjxbdq3nine +ltj2oneeightonesix +76three2sevennine +hfnzxcjfxgseven5cpph3 +2one966dpjlgfqbmceightthreenine +5one9smzz76eight +348tworhzvqjdmqtwo +cjsvvksgzkktwo7hsfkrhkcsbrqcnrz26 +threethreez8 +m3335cdgbxqn5twodmcqk +27eight4 +sfmspqbzr9eight +rscxzq2fqlhbbhvkdbzqzqhzfourninepclrkkdrtwosix +pxbld2twonef +plpbbkvxqpvdxqcstp5threevljjqsqxsevenseven +2sevensix9 +5413sxmtrdjtcmdqpbpcprsix +tpdqxscxjldqvzncbvrpr9cvkqdffvfh8four +six14 +nsmqttrbhrznvonecmlxtdclnbk3 +ninecgbqh6twoctsixthreefive +hqsgonesix3oneightklm +cxxbjptkvkcttddmtwo37one5 +v13two +txxm84kmrpdkxhtbntkhj4four5 +jsrzgnine8nrmzpgf5sqdz +4six9dkxttsthreedgvjkqpk +msnrq7 +t2five4vtwo7sevenrjdrzvb +2rxbdzlszjseven7 +gmmninesix3119ninemdnprsmd +ninesevenpbfx6fourfivefdvhrsctztrheight +qk3two317hnpkqxbmkb3 +oneone6sixdzdmfonefiveone +427sixfive +17njgbgljkpxvhph +4hnfvpbvzxl6three +5sixnllvrvpjpv +3sevenfzjltglsjkdknfnmpsvfive6xdsm2 +1pxp8onesix +xclcfthreeln9ndqhvdxknkjzv4 +6fourtwo2seven1fcd +1eightseven4 +four21eightlfjzb +nine9ninenine81 +eight8zpfsshlqbdlfourmch5four +6sixjdmjjgmsk +ninesix8threetwoxtqdsffxlk6 +dgsddfcnnc3sevenseven532one +lsevennineninefive851dtqzv +nmrxfsmfcscftvzzbggglsfour6 +threesmxqlgmpvtwokvrx361eight +brbkgqcblcxghjp34bpnrctz +sixbzxfbfsjth14pqpvjqfmr +oneseven99 +7four6562zjjxxjlvfdqbssmcx +8fjssqgzthree4five3 +fourckmtsssqgdgcvmqhcqlcqqdhv5eight +bphtzndpdrfivefour8nine5 +ninesix57jvjtwo36vzljdfnndv +eightfourfivesixone2vg +5sevenkdgcmjthdxpxprcdnzpffsixcjmh2 +9cvldprttjk1 +seven6fivesfjjshfqmsjvfpc +eightsixstmhlldl21fourvgsmdlcd1 +5nv1two +tsqxlfnd6rtcvcv5 +eight3zdljlvkbp7hfive5xzgzspsnfour +945sevennrtnn57 +562 +3vtnlsfoursjbgbqmlx6 +8lprsrtvrh9two3 +pssfncbhqpfour1dgcjqpccfzfntphmtjthree1sixfour +rchfmfp18998rsbx +nineonedmlffz5 +seven2sevenonetwo +nine3gxttrkkzpj933mjzhphl +cdpqqhrcrrnspsr378two +fourrprdlkvqj8tntfttwofivesevenqmcsgpljvnl +978sixskr2gkrcgn +jcvldmcdqbjdcxhjcgngsevenfive2cfcmbb4 +szlsvrzzkseventwoone6ninesevensj +gzboneightmsblxgzmsq5seven +seven5eight5 +tsblj5onebkx882 +7kdgdfvx3sevenczgf +94g14onenine +7fournrkdxz4threethree +8eightqtworlcxtv4 +rbkbdsqbfour39eighteightwoxn +cxgmxtoneninennqtmzml6dq +8fivefour9 +8bhspzfsjr9 +fivekzgvvfour8sevensix4vlphpblsp +six63kbbxrfivefive5 +eight5gmkrhrkjjxhb +xtcfivepntwoeight9seven +6nine8fivenine2mf +5fourbthreenineslxfgtqrxcv5four +4vhkxmlsvfg +scphnsbz9h6qnlhcqmgl +tbbcqfxrllszbseventwofivethreeninef1 +zkvtlscldhngtk59 +one6fourrmftxfsvmtwo874 +37threeonefive4 +lrnnspbrgd6jzxtbninesevenngnpsljcr +xhldmfc4five76five +qrzfivexklqcjdnine46 +jkgb6ninesix41threeseven +134628twozlm +8ffrzgtbbfgfive2ninethreem +2132 +7xf +mfhmshvfivenfzjhslq7nfcfgvjhs8 +seven3248 +pvpdpxpg135seven9vpcpgrzlpjblmd +shnslhthreefourtwodnpfr7seven +6hxhhmfivesixseven +vppgmfivethreefivesevensix2two +hp98 +phlskgmgrjsbtq2gkjvrgsd +kkfourthree9fhnpdqcqhtwo +ftnvkprhvllkh9n +71one7twofourfourqtfmc6 +eightfivehssmqsptconefive4 +ninejcfqknhcfpcbcsmnpvn4six5j +one7jvmtxkjzfive +twof9pqcgdfqsq4d7 +krczdrpxbhsngqdvsqb1four7mb7lldv +seven9634tgcsplgmfivetwo +vjvpstpbgtsevennvpsvch97rslh4onefour +zbtgjgq23seven7lbnzdpnkzf +zndbhclr714 +twofive3 +9eight2twojxzdkptwo +gzqfcqpxnfhtb28dvfeight38 +rsqvgsqv9tdlvssj +f78hjftphgcv8bqgrckgldone +fivethreetjg2 +6vtqgdkxsmj +xgjdndnpsevenzfl6tfgxltvcthree +threenine82gqnffkvm +zmlblc4fiveseven3two +msmlvbnqbt9 +144bfcbsjztmdldveight +chceightwofivemcfrxv266 +two9f7gzhhsf6 +ninetwoffour8sevenjngv +foureight22g7twoonemlvq +one78ptfgbbvx +fx5 +5rvz2two +913 +9eightnkvhcksoneqsqgntfthdtjm +one1sixcsccdvbxzx +sevenoneninethree4one7seven2 +jqseightwockmxjd3gfmlhbn6seven7sevenkhcr +sevenqqhs4onemcn +fourseven3nine7pcn +sjjpsthkdfeightcsvlcvhltv6 +qpc16five +3jplhrj2threetwofpvrthree +4sixsix9two +one1eighteight +5tg +256five9 +seven9crnff9eighteight +16five1one4kqllsltrtn +eight3three +seventwoqtlxj8 +74seven5 +2five7mmgsbfc +five7four +bmtkcxvcj997eight +cpgrpgxtgkqr9 +sevenmdqtqhfvnknine929xm +nsix27vzglsevenseven63 +six1nqpsgtrllsnhmbnqxrdvrcx8s +eighttwoflrvzfq262 +twosxtf866hfhxn4fourone +3fourzbrtmd47three +four99eightbcldqfvrm +871 +2twobdtnzzqgvfggjntvgpnqslbdctppnfzpfpcbvzqccq +sdmkzhb8lnpjntj7 +threembr1 +5fd1sevenpsdpdlnb16 +7mnkkvpzrrnslfksrninexmpnfpbzhkx +nfrnvtt8 +24dsffiveqzmjrjznfksrknrfn +5foureight3pn3 +nine9three +nine74cmxrdvcxf3pdhbfour +frjnzrsixone53eight +four41fourhfjnjhpkzp +939rdjhlfpjsix +4kdkcq9two +329fivefive98 +65485 +dfsevensixmdbfour7jhxsfourfour +rqtwonerdkf3eight6fourfour +twoqnfthree5fx +rtwone1two89ntwo9 +sixskqssbccfour7fivevcmsevendqbfcvks +sgtwovmzmzm9 +vk9 +seventhree4 +48mv3eightnine +six7gxnj4six3 +twotwosixlm55dmzdrntzthreeseven +fivemhcdlm8fivemkffllv9 +fkxzdh69twoonesbrfhntk +zfourthreeseven1kllk +6ninethreefiveqdct +nineeight136three5nxvj +fivecpbkhqxpmf46twotxtfrhmvboneone +brrfqninetwohgqnkfctkseven1 +npblhpcpfivehdsnine34 +vksix4fourvrbfmjcrhb78 +72xfmds46threefive +five1kq8eight56three +3sevenfvcsglnjtbhdkqf +6tr6qxqrmstqg +15five5 +fthfvffour85 +seven81fouronefive +dhkknlbfjrnsfcvvkk9seveneightwos +2lngrlvrk4shgktcbpfonefivenine2 +sevenhhlrfqmzn2 +6seven927gdczblhjlmrxnjqfktwoneq +7phbj9fourvbx31seven6 +146 +jnqxslzpsxdftrqczq764 +tmbjdldtwogfvxhnvsfp8tzzp +fourgv68bblxfktsfdg98 +36tnrmd2jrllk2npbrctjcjthm +mx3nine3hkslkb5 +xvmgtlzmrfjcmqgtworc3 +vxscrns1lclnxtwo +foursevenone534 +jdmrj1sixkzdxn +two9threenine +2sevendsmlzh13jlslmvtnine +nine8nine +gthbsq953kxckzppcxqzl3 +xnrgzjzrbp5rptrpbsdgsqfeight5 +1sevendnmxkpdsrmrfkpmxcq22sixmdmvqlgpnbcxf +eight658x14fq +rzvgmdltnz9nvthrjvpzqf +9oneightgl +dsbtb88 +three4fourninelzvqhvjpk6 +seven59fourthreed +3671 +66nineeight8two +eightlszxlsxlcq3sixskqhj4gkblpj +three2eighttwothree +nine853qttjrjptxttwortkhmjss +twosix35 +5948lspjxzpbmthfive +fourthree8 +fourfivevbbqpppqrkkzjqqbnine3 +8nine4xszllqzzonesix2nine +crgnbqrfourrzjbpnnsqthreethreefbnine85 +dx79xjkcpxsndsrbnjlbnine2 +9nine89 +one7qmv1 +dlpbzxfm536392fp +3seventhree8eighttwoeightfive +twongjrfkcb66 +2eightseven8 +zffrln57eighttbqsgzbzhrzxt5kxxlcxb +one5three621ninetwonnprsbmm +3vmslzzp8xcpcgvf +threesix93 +seven3sixfnbbbeighttwo1fivezglzb +kgk7 +48seven2ccztcfnv5tzkrxffour +xczvzdjthreeeight6hnffivexxtmqs79 +three4nine36threehjp +nineqtdtmmpjpkzpxmmfive83sevenseventhree +22jfdpndrcvxbgz +7bljfctkbpc +4bfblqrphseven +fklxmcqxthmnvrlc9 +4seven9zspgftgvd53dsdkhgbns46 +7seven664fdqkcqtr9 +dvxtkqfqbhrllbone3six3 +4ktplgtgzlf3eightfxslssr +six2bhsjknjmgdddgnb6tbhvxbf29nine +two93twofngr8four +oneoneftmqvblcrjnng7jvch97one +9fivexmzstmlrmztwohsqmzfivehseven +5two2hggzchnn +one28ptdlfourgnrjftqd4vxfdrfx7 +six6zvkcszt4tfpkeightvdkjzbb +7oneftjp +1sevenseven9fsp +jqtznvrq8one11fivesix +3ninedkqxtmoneighthkt +8k +931 +clhvprlljttm9 +four14bfgf4eightwoc +xrflnnfb2rlv7twoseven2six +6366hlgklvjvxxlbkxgb +nbkxvp3eightgnznqqjbt5seven +98sntdts +cneightwotdkfxxxjfdpz3zkkthree +five1sfhq1lhhvjb +zdd56tcdchkvnbn +sevenhtpbmbntfivethree9scjfivenine +2spxggcvsvm4msdszqtml +4twoxsevencjgnine +89eightonetwo3ghqbckqkn +fvsgljnzgzfive1slhbxxhsrlmfivexqnkmtnzx +1g1 +94mcreight +threefntlsvvfnine9 +b3hnhvjhtrrv +11fourthree46 +plhclxcjrsgspx3b8fivecbx +mvjxqnqxtwo89bfive +three9nkjrh6two3 +dgprgjdgcrtqxgvknnk9six +dmbljtqg66zxjr95nine2seven +vdxoneight6 +22two9 +7oneppgrjnmrvchvsznsgfivexxdt7 +1three4mzc +bdnhvtsjmdnklsxbtmnztqjtpnz6fivesevenfourzddgsrfmlq +krzm2twotwo65sixfhpplvcgcs +qzcvbvsfive1oneqzc9threesevenseven +threesixninekghkvvzd4 +txqjpmlvdlpm7 +eightsix1l96xrljgg +two63d32six +8nine1fivesixfive3eightwos +sixninenkrpsix2nf4 +four2seven35four9threensbv +ncjhcskrx6 +3eightcpssngjlsqvmsxqqpldhsxsthreelzgzn +6zjnmxrgcz +9bbvkvnbmzshtdzxgqnqmqtthree +four2kqmzfgvpk35rhmqhtrqmfourhjxxfour +9eightfivefrpqtzmkkgkvjbbqmsqvq +eightsevenzpskfbrmcgzjjpnlgr51bdlcmsxhf +pt8two6seveneightjsqxjmlf4six +phjclrmpzm1292gdfivenine +sixfourtwo1 +9tvcnzknine2rdnqfive81 +sixtwopvxjcnmone2kxzxgmn +twosixpcntbtfivenine4two +rxdgeightone86twobzmnlgkdc +4two1twovtldl8one +fiveb1 +212three6twofour84 +74tstlfmrmcj +sixgxtwotmrmzkfsj9 +eighthksxmf144xltwo8 +mthjxjhnqxnhcbxg783 +prptwonehhdlrd71threeone +59fivefnsmzfsix +ninesixonetwo9six6jtptone +eight9ninefivezqvpstsevenjvcjmdcscnzlqsfnhnrnmn +2ckgjml4rcprzj7tp6 +sevenfivesevennhg136 +ninesevenvhl5 +fzflrseven1five5seven +seven5lcfxp +bqhjg4three3 +three8ninegtonetwo46 +cvdpr8 +32fivehfsdhxgjnn +sdndcpccpvdzdgn9fourlnslcmbtwojphzpnvrnp +9cqkgdf7fxgdfcllvnnmzpptninesixone9 +3chllzcgq5fivebffm9 +sqmtj4qlhlcrmrnb38v4dsix +sevennine84bcpvqjcrxpvtcgfhlfhncplktf +qkzxvstdgnfour4two +jkhoneonesixfiveone14lvzn +threethreefivensvlbfour2four +vgqlhqfrlfourlzcgppdbhq57 +bqzpzbtwolprtwo9 +lfjs9six1five2fzcldvnpxtmhsix +kslcntz36nine +nineseven8rzccgfhzsjnjveighttwo +three3fourfivedmjlgqfhmninemst8 +4qxvzgfvctwo73 +75961fivefourzg +spcbt66sevennine4four +hhb1 +dtmoneight9 +3mbctjhfmr2fourthreeseven86 +sixjsbmvzql6gfnttq +1vknfgmznmnzpgvsp3bsksdsevenfourrk +six4six7ninepfxjsshthree +4rqgzpnqcg8skfgksjone3four8 +seven5zkljftwo +76sctscqtsfcninefourrgmsbsxv9six +46fpdqhkfjzgtclfchbbsjcbjhsbkqggzhlb6four +bshbvfourzc79lvvdsqjksmzmqpbvrsrbtg7 +jdqmtfeight59fourtwo +ninefivejsl3 +94z7fouroneeight +5nbmvgheightfive +sixseven5one9ngk3 +eight3jddmgqnzcfjsvrd6five6kmbxss +seveneight9fourthree +eight83 +3spltxvtbg +92shzldthreefpckdtqhm7fivezzkdlz +6two9threeztrzxphhksqc +ninedlone3 +eight4nineonefournsmdgkdszt +9cpxhnksktwo15fivefkq +144eight77 +1sixjscflltdrgclmgrszdfive7lc +ttmfsx9dzgcqjzlzhvlfqrsj4six +846 +fiveseven7 +kqtwone2ninefour7fghmntkn +8r8one +5nnzqqgxl4gbgnzntfrhqzeight +onevpkxvrone8 +79klfd +gzrjvck1sixqnfdjxfive9eightcmhmsjpl +nszqhdfsixsixb3threenfiveqskccbffd +srbn928eight +eight2eightfivekmnjkndgrhjdpvxk3 +9four11oneeight +seven6fivezzktmsixv +fivebvtnzr4threeonetld68 +mgbfjcjbqctt71fgdbmmqdlhpxnpmvx +rjprxbxrfk233 +nxbjxbcvvskeightfiveglpnhbzz27four +kstwo2 +2btbzfournbfcxnvlvcbsjmplnprcrg +mkk6three271 +tfncrvlnfdmntdrmjqqtknsgpq671onethree +eight8twofivex +phreightfive81hftbkbdnztt +onetbhqqlcbqrlfzrqbtbl9ntcgvxr1rhgrspqkgklz +gckbonekhzcjhdb5 +twothree1lfivetwolpdxhn8 +threebqmxgpjfbzrrrrgdt8 +threejvlpxpfm9four4threeone +five68onesevennineone9two +mjqjrqmeight73 +fvfgrdppszgdhmninenineone7759 +lrhchsonek3twobblvn9bdmcbt +mdcqxbz84five6ninetwonergj +eightnine548ttfiveeight7 +74mfftzxhkl4 +seven5mdmrxlp +ptb76ndfpbtljpkhjthdfmsdddjssm +7vkeight +bzzpvht5fourthreeseven8 +rztztsix12nine +fvpqdnphtd1mmrhppbd2 +h8dpbvs2tjlqgfxhhbeight +51one +two86 +sixnine7sixseventwo34 +two45xjcpcnhgbsb1five7 +qqkzvpsixfivepfzdhtl92six4rhp +two6vqtxvxrvzpz +1qqsfrgdbsm8five +threeeightsix36xvtm +nine5eightczhsix3twoprztckvb +pxrsgpszonepdjvxcblqzkr61seven11 +5sevenonesevensix4six1dvhrx +cdxnbseven9qsevenvbv4 +sixlgjt3 +dhpxhpbkq3lc6rkjlpdz4five5pctfzsplrf +1kmsmgjpmkqfckr +sixeight1k44 +52qdfp1b8 +86fourthree42 +six2fourpjtsvskrxtmgxnj2one3dn +rjtfqxvfm88seventhreeeighttwo +fivepgfvxcds64sevenhg +glvhcrgbtphxfsfourthreerqhjxpzone5gh +1sevenone34 +689five9ninetwotwo4 +6two92sixjb1cbhmrq +fiverrvllhbgcsskh2 +foureight6fhtx1five8eight +pqvvjkhtxkxcjkrf9mn +threefive2hs6one6jhkbdh +twoninefzflrqqzvp2xnr8 +one51 +7bjpnfsgpszrfk5fourthreebvvn +six74 +twozcgbrrhxcpznx9dlcgdchpndcdc +nines566 +one72zshxlsix +vseven4fouronenine6 +7four1nine2threekzjbs4 +onecq3four +twodcrx8 +four35sjjhpfftzsixfqctsfonefiveseven +sxqnssjtwothree2 +8fdpjrztwoseventwo5rmqvoneeight +pjlbnl3rg3shchseven +zdcrnpddv2 +eight2foureighttgjcxtf2 +ghhxlxqttvonerh96715twonectr +9hmfxxrsdbsixbtwo7sevensix +32ghjqjfp7three4one +197 +twon8five2 +vtwobrlhqsq1twothreesixthree +xbdxninefour8seven +five39 +621eightsix +21fvdd11tsdzhjspzld4 +7seventwoeightfpnkhxmvc +96sjrcvzxsevenfqt4seven9 +xzxmtsrhbfivenineninerxgcrx9one +5pzgmrgrg2kdgl9one +lqzmttxcpp7cnfstnhtglzhssntjmsixseven6six +two711 +6onevjnvmkkx +eight7dbmznvztwo +9mlpltkt3 +7ninenine4tpjbsbtsgzttlgrtnfvr91four +foursevenq7 +six1sgtbsmgft9 +nineone28fourjtwo8 +76threebgqvh6lfbkdmfvcthreeone3 +13cvtpqnmbv +1sevenzjhtfpbfb73rccvtnmtthree7 +4xhvshhtmxx7sevenf9 +8one1 +931fivetmdmsrrmfxrplkfvfourthreeeight +qzbthffhlg2 +one4eight33 +qfjqt9jlcthreeqkfdpfiveeight8scfnlj +fvczqbtsix2bxkgsnsix5nine7 +9qxnvlnine2phnlqzninefive +tszjsxbsixtwoeight62ffjtdnxxtwofive +one2skxg +five5onexzgzkjvtqrfourfive +twozsxzqtrqbxqqqsbcvfpgdcdpttwo1six +8mqkgptxsixhqmbqshcl +lsdlsxrhdqthreesix2sevenchjxvmsjpvrnpcblgmsix +gngrfrhbxhqkxs5fourr8three4 +jlzszzz9one +twozrbjkjpzseventwonine8dbmfdjcb +3nine36ppqone4czxvkxjzv +ld6eightseven6twosix +1jnbfive +7threeglmcdhpvq4723fivethree +seven148oneightd +sevensevenseven6sixtwosix21 +8twojhdkdrcqgmclqlldv6sevenonedjthcz +ninesevenggsjbpt5ttlrq +59sixfivefive +eight9bsmcgkseventhree66qmgpkkxnpm +fourthree73fiveseven +9five9six8threet +3eight44 +dlcbjflsix5ttvjdxzzeightcffrtfjcjpxtwostrdc +fiveone645fivellfcmqqmnine +hxdtshfive115tfvrzqhgftwojtjrcshgtq +6nqrfrhv17jdxpfmmdt4five +sevenxtpjxnrr1 +krzkthreegjnqrfbsdrkqptd33rsvrzvvffqhreight +472ggfive56hgnvz +12tkpchqtnine +vdbsctv6eightth82 +fivetngxlttf4 +5nss +5onesixsevenphxtmlqhzfcjxrknpv +gldsixrhss186seven6 +gnpksz4 +4919 +pbc19 diff --git a/2023/day01_2/src/main/resources/small_input b/2023/day01_2/src/main/resources/small_input new file mode 100644 index 0000000..4316a6b --- /dev/null +++ b/2023/day01_2/src/main/resources/small_input @@ -0,0 +1,7 @@ +two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen \ No newline at end of file diff --git a/2023/day02_1/day02_1.iml b/2023/day02_1/day02_1.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day02_1/day02_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day02_1/src/main/kotlin/Main.kt b/2023/day02_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..c0ce7c8 --- /dev/null +++ b/2023/day02_1/src/main/kotlin/Main.kt @@ -0,0 +1,85 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 2, Part 1 starting!!!") + + val games:ArrayList = ArrayList() + File(args[0]).forEachLine { + games.add(parseGameLine(it)) + } + + var answer = 0 + games.stream() + .filter { it.checkRedCount() } + .filter { it.checkGreenCount() } + .filter { it.checkBlueCount() } + .forEach { + print("Game #${it.gameNumber} Passed, ") + answer += it.gameNumber } + + println("") + println("Answer: $answer") + + println("AOC 2023, Day 2, Part 1 completed!!") +} + + +fun parseGameLine(line:String):Game { + val gameNumber = line.split(":")[0].drop(5).toInt() + val newGame = Game(gameNumber) + for(turn in line.split(":")[1].split(";")) { + val newTurn = Turn() + for(draw in turn.split(",")) { + val count = draw.trim().split(' ')[0].trim().toInt() + val color = draw.trim().split(' ')[1].trim() + newTurn.addCubes(color, count) + } + newGame.addTurn(newTurn) + } + + return newGame +} + +class Game (val gameNumber:Int) { + private val turns:ArrayList = ArrayList() + + fun addTurn(newTurn:Turn) { + turns.add(newTurn) + } + + fun checkRedCount():Boolean { + for(turn in turns) { + if((turn.cubes["red"] ?: 0) > 12) { + return false + } + } + return true + } + + fun checkGreenCount():Boolean { + for(turn in turns) { + if((turn.cubes["green"] ?: 0) > 13) { + return false + } + } + return true + } + + fun checkBlueCount():Boolean { + for(turn in turns) { + if((turn.cubes["blue"] ?: 0) > 14) { + return false + } + } + return true + } +} + +class Turn { + var cubes:HashMap = HashMap() + + fun addCubes(color:String, count:Int) { + cubes[color] = count + } +} + diff --git a/2023/day02_1/src/main/resources/input b/2023/day02_1/src/main/resources/input new file mode 100644 index 0000000..876d2a0 --- /dev/null +++ b/2023/day02_1/src/main/resources/input @@ -0,0 +1,100 @@ +Game 1: 12 blue; 2 green, 13 blue, 19 red; 13 red, 3 green, 14 blue +Game 2: 12 blue, 1 red, 1 green; 1 red, 12 blue, 3 green; 5 green, 1 red, 9 blue; 1 red, 7 blue, 4 green +Game 3: 1 red; 12 blue, 15 red; 1 green, 10 red, 2 blue; 1 green, 3 red, 9 blue +Game 4: 6 blue, 5 green; 2 blue, 6 green, 6 red; 11 blue, 5 red; 6 green, 11 red, 7 blue; 4 green, 10 red; 1 green, 7 red, 13 blue +Game 5: 10 green, 1 red, 2 blue; 3 red, 4 green, 4 blue; 5 green, 5 red +Game 6: 1 green, 6 blue, 14 red; 9 blue, 5 red; 14 red, 12 blue +Game 7: 1 green, 9 red, 8 blue; 9 blue, 1 green, 6 red; 1 green, 15 blue, 19 red +Game 8: 9 red, 7 green, 2 blue; 6 red, 17 green; 18 red, 16 green, 2 blue; 10 red, 14 green +Game 9: 1 blue, 11 red, 9 green; 8 red, 1 blue, 9 green; 4 blue, 16 red, 9 green; 8 green, 3 blue, 6 red; 8 green, 11 red, 3 blue; 11 red, 2 blue +Game 10: 8 green, 14 blue; 1 red, 6 blue, 9 green; 6 blue, 4 green, 1 red; 16 green, 9 blue +Game 11: 6 green, 11 blue, 1 red; 10 green, 1 red; 7 blue, 2 green, 1 red +Game 12: 3 green, 5 blue, 2 red; 14 blue, 16 green, 4 red; 8 green, 14 blue, 4 red +Game 13: 5 red, 12 blue, 2 green; 2 green, 1 red, 9 blue; 1 red, 2 blue, 3 green; 3 green, 3 red, 7 blue; 2 red, 13 blue; 1 red, 10 blue, 2 green +Game 14: 5 blue, 1 red, 2 green; 8 blue, 1 green, 1 red; 1 blue, 2 green +Game 15: 14 blue, 9 green, 1 red; 2 red, 15 blue, 12 green; 1 blue, 2 green, 1 red; 1 red, 16 green, 15 blue; 1 red, 12 green, 8 blue; 1 red, 17 blue +Game 16: 7 red, 1 green, 18 blue; 7 blue, 5 green, 17 red; 14 blue, 8 red, 6 green +Game 17: 4 green, 5 blue; 5 green, 1 red, 7 blue; 3 green, 6 blue, 4 red; 2 green, 5 blue; 9 green, 6 red, 6 blue +Game 18: 8 red, 6 blue; 4 blue, 19 red; 4 blue, 9 red; 9 blue, 10 red; 2 green, 9 blue, 13 red; 3 blue, 7 red +Game 19: 8 green, 2 red, 17 blue; 11 blue, 4 red, 5 green; 8 blue, 8 green, 10 red; 9 green, 4 blue, 2 red; 4 green, 10 red, 6 blue +Game 20: 9 green, 3 blue, 1 red; 5 blue, 16 green, 3 red; 3 green, 3 red; 2 blue, 1 red, 5 green +Game 21: 7 green, 1 red, 10 blue; 7 green, 5 blue, 7 red; 7 green, 9 blue +Game 22: 5 red, 2 blue, 9 green; 6 red, 11 green; 6 green, 6 red +Game 23: 14 red, 2 blue, 9 green; 9 green, 1 blue, 4 red; 9 red, 1 green, 1 blue; 6 green; 3 blue, 1 green, 9 red; 1 blue, 2 red +Game 24: 3 red, 7 green, 6 blue; 1 green, 5 blue; 6 blue, 1 red, 2 green; 5 red, 1 blue, 4 green; 6 red, 2 blue, 11 green; 2 green, 2 red, 1 blue +Game 25: 5 green, 1 red, 3 blue; 3 blue, 6 green, 3 red; 3 red, 4 green, 1 blue; 6 green, 1 blue, 9 red; 2 blue, 2 red, 1 green +Game 26: 3 green, 4 red, 12 blue; 2 red, 1 green, 15 blue; 7 red, 16 green, 4 blue; 11 blue, 11 green, 3 red; 8 green, 15 blue, 10 red +Game 27: 9 red; 10 red, 2 blue; 3 red; 8 red, 1 green, 2 blue; 1 red, 2 blue; 1 blue, 4 red +Game 28: 5 blue, 8 red, 5 green; 10 blue, 4 red, 5 green; 8 red, 14 blue, 10 green; 10 blue, 4 red, 1 green; 5 red, 17 green, 4 blue +Game 29: 16 green, 11 red, 5 blue; 11 red, 14 blue, 13 green; 13 blue, 8 green; 3 red, 18 green, 15 blue +Game 30: 2 red, 4 blue, 8 green; 6 green, 2 red, 2 blue; 6 green, 6 blue, 2 red +Game 31: 2 red, 1 blue, 16 green; 10 green, 1 blue, 7 red; 1 blue, 14 green, 7 red; 2 blue, 1 green, 1 red; 6 red, 13 green; 2 blue, 6 red, 10 green +Game 32: 4 green, 4 blue; 1 green, 5 red; 6 green, 1 red; 3 green, 5 red, 2 blue; 4 red, 1 blue, 4 green; 6 green, 2 blue, 6 red +Game 33: 5 blue, 2 red, 1 green; 5 blue; 1 blue, 1 green, 10 red; 8 red, 3 blue, 1 green +Game 34: 15 blue, 7 green; 12 green, 17 blue; 10 blue, 11 green; 1 red, 5 blue, 9 green; 2 red, 10 blue, 11 green +Game 35: 2 red, 6 blue; 2 red, 5 blue, 4 green; 2 red, 8 green, 10 blue +Game 36: 4 red, 9 green, 3 blue; 4 red, 6 green; 6 red; 11 red, 4 green +Game 37: 3 blue, 12 green, 14 red; 3 red, 5 green, 7 blue; 2 blue, 2 green, 16 red +Game 38: 17 blue, 16 red, 8 green; 4 green, 17 blue, 4 red; 8 red, 7 blue, 6 green; 2 blue, 9 green, 17 red; 10 blue, 8 green, 11 red +Game 39: 10 blue, 1 red, 4 green; 4 green, 4 red, 6 blue; 11 blue +Game 40: 5 green, 17 blue; 11 blue, 4 green, 7 red; 2 green, 6 red, 13 blue; 7 blue, 12 green, 16 red; 15 red, 3 green, 8 blue; 12 green, 3 blue, 12 red +Game 41: 13 blue, 3 red, 1 green; 2 green, 10 red; 1 blue, 5 red, 3 green; 5 green, 16 blue; 9 blue, 2 green; 14 blue, 4 green, 5 red +Game 42: 2 blue, 15 green, 3 red; 3 red, 17 green; 6 red, 1 blue, 8 green +Game 43: 8 green, 9 red, 3 blue; 1 blue, 13 red; 5 red, 1 blue, 6 green; 2 red, 2 blue; 17 red, 2 blue, 6 green +Game 44: 10 red, 3 blue; 10 blue, 5 green; 4 red, 4 blue, 1 green; 16 blue, 6 red, 7 green; 3 green, 12 blue +Game 45: 12 blue, 2 red; 2 blue, 3 red, 2 green; 8 blue, 3 green; 4 green, 8 blue, 5 red; 3 red, 2 blue, 1 green; 1 red, 2 blue, 7 green +Game 46: 1 blue, 11 red, 6 green; 2 blue, 11 red, 6 green; 8 red, 5 green +Game 47: 2 blue, 9 red; 1 green, 5 blue; 10 red, 2 blue, 2 green; 10 red, 3 green, 3 blue; 3 red, 6 blue, 2 green; 1 red, 1 green, 5 blue +Game 48: 1 red, 7 green; 1 blue, 10 green, 5 red; 4 red, 8 green; 10 red, 10 green; 2 red, 16 green; 11 red, 14 green, 1 blue +Game 49: 1 red, 1 blue, 5 green; 6 green, 5 red; 3 blue, 4 red, 3 green; 3 red, 5 green, 2 blue; 3 blue, 3 red +Game 50: 17 red, 1 green, 7 blue; 4 blue, 1 red, 5 green; 10 red, 13 blue; 17 red +Game 51: 2 red, 1 green; 1 green, 10 blue, 2 red; 5 red, 1 green, 7 blue; 7 blue, 1 red; 9 blue, 5 red, 2 green +Game 52: 8 green, 1 blue; 14 green, 1 red; 10 green, 1 red +Game 53: 17 green, 6 blue; 17 blue, 9 green; 1 red, 12 blue +Game 54: 4 blue, 7 red, 9 green; 7 red, 2 green; 14 green, 10 red, 3 blue; 9 green, 6 blue, 5 red; 2 blue, 3 green, 11 red +Game 55: 11 green, 4 red; 14 green; 3 red, 3 green; 3 green, 4 red, 1 blue; 15 green, 6 red, 2 blue; 4 red, 3 blue, 15 green +Game 56: 8 blue, 5 red, 9 green; 11 green, 5 blue, 6 red; 1 green, 1 blue, 7 red; 7 green, 4 red, 1 blue; 9 blue, 5 red, 1 green; 5 red, 2 blue +Game 57: 11 green, 19 blue, 5 red; 15 green, 5 red, 18 blue; 16 green, 5 red, 10 blue; 19 blue, 3 red; 9 green, 8 blue +Game 58: 4 blue, 12 green; 11 green, 4 blue; 6 blue, 6 green; 1 red, 2 green; 11 green, 3 blue; 13 blue, 6 green +Game 59: 10 blue, 1 red; 1 green, 4 blue; 4 blue +Game 60: 7 red, 2 green, 6 blue; 1 green, 13 red, 12 blue; 9 blue, 9 green, 8 red +Game 61: 7 green, 3 red, 2 blue; 1 red, 1 blue; 5 green, 3 blue; 4 blue, 1 red, 4 green +Game 62: 1 green, 8 blue, 6 red; 7 blue, 3 red, 12 green; 2 blue, 7 red, 6 green +Game 63: 3 red, 2 green; 3 green, 4 blue, 9 red; 3 blue, 3 green, 16 red; 4 red, 1 blue +Game 64: 10 red, 2 green, 15 blue; 4 red, 14 green; 6 red, 14 green, 2 blue +Game 65: 11 red, 14 green, 5 blue; 7 blue, 14 green, 15 red; 1 blue, 14 green; 4 green, 4 blue, 7 red +Game 66: 6 blue, 9 green, 6 red; 6 blue, 2 red, 4 green; 3 blue; 8 blue, 5 green, 8 red; 17 blue, 11 green; 12 green, 11 blue, 4 red +Game 67: 8 red, 4 blue, 6 green; 4 blue, 8 red, 2 green; 1 green, 6 red, 2 blue; 10 red, 1 green, 2 blue; 1 blue, 5 red; 2 red, 1 green, 2 blue +Game 68: 10 green, 9 red, 13 blue; 2 blue, 2 green, 4 red; 11 red, 13 blue; 4 green, 2 red, 8 blue +Game 69: 16 red; 12 red, 1 green, 4 blue; 1 green, 14 red, 9 blue; 12 blue, 2 green, 13 red; 14 red, 2 green, 10 blue; 11 blue +Game 70: 1 red, 19 green; 4 blue, 6 green; 12 green, 2 red +Game 71: 9 green, 2 blue, 3 red; 5 red; 1 red, 1 blue, 5 green +Game 72: 1 green, 19 red; 12 red, 1 green, 1 blue; 16 red, 6 blue; 14 red, 7 blue; 11 blue, 1 green, 13 red; 16 blue, 4 red +Game 73: 1 green, 1 red, 2 blue; 8 green, 2 red, 4 blue; 7 blue, 7 green, 7 red +Game 74: 1 blue, 1 green; 1 red; 1 red, 5 blue, 4 green; 2 blue, 1 red; 1 blue +Game 75: 8 green, 1 red; 3 blue, 1 red, 5 green; 12 green +Game 76: 8 green, 6 red, 2 blue; 7 red, 1 blue; 2 blue, 9 green, 1 red; 8 red, 13 green; 12 green, 2 red; 7 green, 5 red +Game 77: 3 blue, 1 green, 10 red; 13 red; 1 blue, 13 red, 1 green +Game 78: 2 red, 3 green, 14 blue; 3 red, 16 blue, 6 green; 3 blue, 3 red, 9 green; 4 blue, 11 green; 6 green, 2 blue; 2 red, 10 green, 11 blue +Game 79: 5 green, 10 blue, 2 red; 16 green, 15 blue, 1 red; 1 red, 11 green; 1 red, 11 blue, 16 green; 7 blue, 18 green +Game 80: 9 blue, 10 green; 13 green, 9 blue; 1 red, 5 green, 5 blue; 13 green, 5 blue, 1 red +Game 81: 9 green, 15 red, 11 blue; 11 blue, 9 red, 5 green; 2 green, 11 blue, 19 red; 14 green, 15 red, 5 blue +Game 82: 4 green, 6 red, 13 blue; 5 blue, 5 red, 4 green; 2 green, 7 blue +Game 83: 12 blue, 8 red; 6 red, 1 blue, 1 green; 7 red, 1 green, 1 blue; 6 red, 1 green, 9 blue; 10 blue, 3 red; 1 red, 5 blue +Game 84: 9 blue, 13 red; 8 blue, 1 green; 9 blue, 1 green; 3 blue, 5 red, 1 green +Game 85: 14 green, 5 blue, 8 red; 1 blue, 5 green, 1 red; 10 red, 7 blue, 17 green; 3 blue, 6 green; 6 red, 5 blue, 4 green; 5 blue, 4 green, 6 red +Game 86: 14 red; 20 red, 3 blue; 1 green, 12 blue, 15 red; 16 red, 13 blue; 13 red, 12 blue; 2 blue, 20 red +Game 87: 2 blue, 2 red, 10 green; 8 green, 9 red, 1 blue; 11 red, 1 green, 4 blue; 13 red, 1 blue; 11 green, 16 red, 3 blue +Game 88: 5 green, 4 red, 1 blue; 3 blue, 8 red, 10 green; 11 green, 7 red, 4 blue; 11 green, 5 blue, 4 red; 9 red, 9 green; 4 blue, 6 green, 9 red +Game 89: 2 blue, 2 red, 5 green; 2 red, 2 blue, 3 green; 2 red, 1 blue, 7 green; 6 green, 1 red, 2 blue +Game 90: 4 green, 1 blue, 5 red; 2 blue, 2 red, 10 green; 2 green, 8 red, 1 blue; 10 green, 5 red; 2 red, 3 green, 2 blue +Game 91: 16 blue, 5 red, 15 green; 4 green, 7 red, 3 blue; 4 red, 8 green, 12 blue; 4 green, 8 red, 17 blue +Game 92: 13 red, 2 blue, 12 green; 19 green, 7 red; 17 green, 2 blue, 3 red; 6 blue, 11 red, 10 green; 6 red, 15 green, 3 blue; 6 blue, 20 green, 11 red +Game 93: 2 blue, 3 green; 1 blue, 4 red; 1 red +Game 94: 3 red, 5 green, 6 blue; 7 blue, 5 green, 6 red; 9 blue, 1 green, 2 red; 4 blue, 1 green, 4 red +Game 95: 8 green, 9 red, 2 blue; 7 green, 7 red; 2 green, 4 blue, 6 red; 6 blue, 2 red, 2 green +Game 96: 11 blue, 4 red; 1 green, 3 red, 14 blue; 2 green, 3 red, 8 blue; 7 red, 1 green, 3 blue; 8 blue, 6 red, 2 green; 9 blue, 3 red, 3 green +Game 97: 5 green, 13 red, 7 blue; 2 blue, 12 red, 6 green; 10 blue, 11 red, 3 green; 4 green, 11 blue, 15 red; 8 green, 16 blue, 1 red; 15 blue, 4 red, 5 green +Game 98: 3 blue, 1 red; 4 blue; 2 green, 1 blue; 2 green, 1 red, 5 blue +Game 99: 4 green, 3 blue, 9 red; 6 blue, 5 red, 3 green; 2 green, 4 blue, 7 red; 8 red, 4 blue; 2 green, 15 red; 4 red, 5 blue, 3 green +Game 100: 8 red, 4 blue, 4 green; 10 blue, 3 red, 4 green; 10 green, 4 red; 18 red, 9 blue, 2 green; 12 red, 4 green, 2 blue diff --git a/2023/day02_1/src/main/resources/small_input b/2023/day02_1/src/main/resources/small_input new file mode 100644 index 0000000..295c36d --- /dev/null +++ b/2023/day02_1/src/main/resources/small_input @@ -0,0 +1,5 @@ +Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green +Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue +Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red +Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green diff --git a/2023/day02_2/day02_2.iml b/2023/day02_2/day02_2.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day02_2/day02_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day02_2/src/main/kotlin/Main.kt b/2023/day02_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..e523545 --- /dev/null +++ b/2023/day02_2/src/main/kotlin/Main.kt @@ -0,0 +1,84 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 2, Part 2 starting!!!") + + val games:ArrayList = ArrayList() + File(args[0]).forEachLine { + games.add(parseGameLine(it)) + } + + var answer = 0 + games.stream().forEach { answer += it.getFewestRedCount() * it.getFewestGreenCount() * it.getFewestBlueCount() } + + println("Answer: $answer") + + println("AOC 2023, Day 2, Part 2 completed!!") +} + + +fun parseGameLine(line:String):Game { + val gameNumber = line.split(":")[0].drop(5).toInt() + val newGame = Game(gameNumber) + for(turn in line.split(":")[1].split(";")) { + val newTurn = Turn() + for(draw in turn.split(",")) { + val count = draw.trim().split(' ')[0].trim().toInt() + val color = draw.trim().split(' ')[1].trim() + newTurn.addCubes(color, count) + } + newGame.addTurn(newTurn) + } + + return newGame +} + +class Game (val gameNumber:Int) { + private val turns: ArrayList = ArrayList() + + fun addTurn(newTurn: Turn) { + turns.add(newTurn) + } + + fun getFewestRedCount(): Int { + var maxRedCount = 0 + turns.stream().filter { it.cubes.containsKey("red") }.forEach { + val redCount = it.cubes.getOrDefault("red", maxRedCount) + if (redCount > maxRedCount) { + maxRedCount = redCount + } + } + return maxRedCount + } + + fun getFewestGreenCount(): Int { + var maxGreenCount = 0 + turns.stream().filter { it.cubes.containsKey("green") }.forEach { + val redCount = it.cubes.getOrDefault("green", maxGreenCount) + if (redCount > maxGreenCount) { + maxGreenCount = redCount + } + } + return maxGreenCount + } + + fun getFewestBlueCount(): Int { + var maxBlueCount = 0 + turns.stream().filter { it.cubes.containsKey("blue") }.forEach { + val redCount = it.cubes.getOrDefault("blue", maxBlueCount) + if (redCount > maxBlueCount) { + maxBlueCount = redCount + } + } + return maxBlueCount + } + +} + +class Turn { + var cubes:HashMap = HashMap() + + fun addCubes(color:String, count:Int) { + cubes[color] = count + } +} diff --git a/2023/day02_2/src/main/resources/input b/2023/day02_2/src/main/resources/input new file mode 100644 index 0000000..876d2a0 --- /dev/null +++ b/2023/day02_2/src/main/resources/input @@ -0,0 +1,100 @@ +Game 1: 12 blue; 2 green, 13 blue, 19 red; 13 red, 3 green, 14 blue +Game 2: 12 blue, 1 red, 1 green; 1 red, 12 blue, 3 green; 5 green, 1 red, 9 blue; 1 red, 7 blue, 4 green +Game 3: 1 red; 12 blue, 15 red; 1 green, 10 red, 2 blue; 1 green, 3 red, 9 blue +Game 4: 6 blue, 5 green; 2 blue, 6 green, 6 red; 11 blue, 5 red; 6 green, 11 red, 7 blue; 4 green, 10 red; 1 green, 7 red, 13 blue +Game 5: 10 green, 1 red, 2 blue; 3 red, 4 green, 4 blue; 5 green, 5 red +Game 6: 1 green, 6 blue, 14 red; 9 blue, 5 red; 14 red, 12 blue +Game 7: 1 green, 9 red, 8 blue; 9 blue, 1 green, 6 red; 1 green, 15 blue, 19 red +Game 8: 9 red, 7 green, 2 blue; 6 red, 17 green; 18 red, 16 green, 2 blue; 10 red, 14 green +Game 9: 1 blue, 11 red, 9 green; 8 red, 1 blue, 9 green; 4 blue, 16 red, 9 green; 8 green, 3 blue, 6 red; 8 green, 11 red, 3 blue; 11 red, 2 blue +Game 10: 8 green, 14 blue; 1 red, 6 blue, 9 green; 6 blue, 4 green, 1 red; 16 green, 9 blue +Game 11: 6 green, 11 blue, 1 red; 10 green, 1 red; 7 blue, 2 green, 1 red +Game 12: 3 green, 5 blue, 2 red; 14 blue, 16 green, 4 red; 8 green, 14 blue, 4 red +Game 13: 5 red, 12 blue, 2 green; 2 green, 1 red, 9 blue; 1 red, 2 blue, 3 green; 3 green, 3 red, 7 blue; 2 red, 13 blue; 1 red, 10 blue, 2 green +Game 14: 5 blue, 1 red, 2 green; 8 blue, 1 green, 1 red; 1 blue, 2 green +Game 15: 14 blue, 9 green, 1 red; 2 red, 15 blue, 12 green; 1 blue, 2 green, 1 red; 1 red, 16 green, 15 blue; 1 red, 12 green, 8 blue; 1 red, 17 blue +Game 16: 7 red, 1 green, 18 blue; 7 blue, 5 green, 17 red; 14 blue, 8 red, 6 green +Game 17: 4 green, 5 blue; 5 green, 1 red, 7 blue; 3 green, 6 blue, 4 red; 2 green, 5 blue; 9 green, 6 red, 6 blue +Game 18: 8 red, 6 blue; 4 blue, 19 red; 4 blue, 9 red; 9 blue, 10 red; 2 green, 9 blue, 13 red; 3 blue, 7 red +Game 19: 8 green, 2 red, 17 blue; 11 blue, 4 red, 5 green; 8 blue, 8 green, 10 red; 9 green, 4 blue, 2 red; 4 green, 10 red, 6 blue +Game 20: 9 green, 3 blue, 1 red; 5 blue, 16 green, 3 red; 3 green, 3 red; 2 blue, 1 red, 5 green +Game 21: 7 green, 1 red, 10 blue; 7 green, 5 blue, 7 red; 7 green, 9 blue +Game 22: 5 red, 2 blue, 9 green; 6 red, 11 green; 6 green, 6 red +Game 23: 14 red, 2 blue, 9 green; 9 green, 1 blue, 4 red; 9 red, 1 green, 1 blue; 6 green; 3 blue, 1 green, 9 red; 1 blue, 2 red +Game 24: 3 red, 7 green, 6 blue; 1 green, 5 blue; 6 blue, 1 red, 2 green; 5 red, 1 blue, 4 green; 6 red, 2 blue, 11 green; 2 green, 2 red, 1 blue +Game 25: 5 green, 1 red, 3 blue; 3 blue, 6 green, 3 red; 3 red, 4 green, 1 blue; 6 green, 1 blue, 9 red; 2 blue, 2 red, 1 green +Game 26: 3 green, 4 red, 12 blue; 2 red, 1 green, 15 blue; 7 red, 16 green, 4 blue; 11 blue, 11 green, 3 red; 8 green, 15 blue, 10 red +Game 27: 9 red; 10 red, 2 blue; 3 red; 8 red, 1 green, 2 blue; 1 red, 2 blue; 1 blue, 4 red +Game 28: 5 blue, 8 red, 5 green; 10 blue, 4 red, 5 green; 8 red, 14 blue, 10 green; 10 blue, 4 red, 1 green; 5 red, 17 green, 4 blue +Game 29: 16 green, 11 red, 5 blue; 11 red, 14 blue, 13 green; 13 blue, 8 green; 3 red, 18 green, 15 blue +Game 30: 2 red, 4 blue, 8 green; 6 green, 2 red, 2 blue; 6 green, 6 blue, 2 red +Game 31: 2 red, 1 blue, 16 green; 10 green, 1 blue, 7 red; 1 blue, 14 green, 7 red; 2 blue, 1 green, 1 red; 6 red, 13 green; 2 blue, 6 red, 10 green +Game 32: 4 green, 4 blue; 1 green, 5 red; 6 green, 1 red; 3 green, 5 red, 2 blue; 4 red, 1 blue, 4 green; 6 green, 2 blue, 6 red +Game 33: 5 blue, 2 red, 1 green; 5 blue; 1 blue, 1 green, 10 red; 8 red, 3 blue, 1 green +Game 34: 15 blue, 7 green; 12 green, 17 blue; 10 blue, 11 green; 1 red, 5 blue, 9 green; 2 red, 10 blue, 11 green +Game 35: 2 red, 6 blue; 2 red, 5 blue, 4 green; 2 red, 8 green, 10 blue +Game 36: 4 red, 9 green, 3 blue; 4 red, 6 green; 6 red; 11 red, 4 green +Game 37: 3 blue, 12 green, 14 red; 3 red, 5 green, 7 blue; 2 blue, 2 green, 16 red +Game 38: 17 blue, 16 red, 8 green; 4 green, 17 blue, 4 red; 8 red, 7 blue, 6 green; 2 blue, 9 green, 17 red; 10 blue, 8 green, 11 red +Game 39: 10 blue, 1 red, 4 green; 4 green, 4 red, 6 blue; 11 blue +Game 40: 5 green, 17 blue; 11 blue, 4 green, 7 red; 2 green, 6 red, 13 blue; 7 blue, 12 green, 16 red; 15 red, 3 green, 8 blue; 12 green, 3 blue, 12 red +Game 41: 13 blue, 3 red, 1 green; 2 green, 10 red; 1 blue, 5 red, 3 green; 5 green, 16 blue; 9 blue, 2 green; 14 blue, 4 green, 5 red +Game 42: 2 blue, 15 green, 3 red; 3 red, 17 green; 6 red, 1 blue, 8 green +Game 43: 8 green, 9 red, 3 blue; 1 blue, 13 red; 5 red, 1 blue, 6 green; 2 red, 2 blue; 17 red, 2 blue, 6 green +Game 44: 10 red, 3 blue; 10 blue, 5 green; 4 red, 4 blue, 1 green; 16 blue, 6 red, 7 green; 3 green, 12 blue +Game 45: 12 blue, 2 red; 2 blue, 3 red, 2 green; 8 blue, 3 green; 4 green, 8 blue, 5 red; 3 red, 2 blue, 1 green; 1 red, 2 blue, 7 green +Game 46: 1 blue, 11 red, 6 green; 2 blue, 11 red, 6 green; 8 red, 5 green +Game 47: 2 blue, 9 red; 1 green, 5 blue; 10 red, 2 blue, 2 green; 10 red, 3 green, 3 blue; 3 red, 6 blue, 2 green; 1 red, 1 green, 5 blue +Game 48: 1 red, 7 green; 1 blue, 10 green, 5 red; 4 red, 8 green; 10 red, 10 green; 2 red, 16 green; 11 red, 14 green, 1 blue +Game 49: 1 red, 1 blue, 5 green; 6 green, 5 red; 3 blue, 4 red, 3 green; 3 red, 5 green, 2 blue; 3 blue, 3 red +Game 50: 17 red, 1 green, 7 blue; 4 blue, 1 red, 5 green; 10 red, 13 blue; 17 red +Game 51: 2 red, 1 green; 1 green, 10 blue, 2 red; 5 red, 1 green, 7 blue; 7 blue, 1 red; 9 blue, 5 red, 2 green +Game 52: 8 green, 1 blue; 14 green, 1 red; 10 green, 1 red +Game 53: 17 green, 6 blue; 17 blue, 9 green; 1 red, 12 blue +Game 54: 4 blue, 7 red, 9 green; 7 red, 2 green; 14 green, 10 red, 3 blue; 9 green, 6 blue, 5 red; 2 blue, 3 green, 11 red +Game 55: 11 green, 4 red; 14 green; 3 red, 3 green; 3 green, 4 red, 1 blue; 15 green, 6 red, 2 blue; 4 red, 3 blue, 15 green +Game 56: 8 blue, 5 red, 9 green; 11 green, 5 blue, 6 red; 1 green, 1 blue, 7 red; 7 green, 4 red, 1 blue; 9 blue, 5 red, 1 green; 5 red, 2 blue +Game 57: 11 green, 19 blue, 5 red; 15 green, 5 red, 18 blue; 16 green, 5 red, 10 blue; 19 blue, 3 red; 9 green, 8 blue +Game 58: 4 blue, 12 green; 11 green, 4 blue; 6 blue, 6 green; 1 red, 2 green; 11 green, 3 blue; 13 blue, 6 green +Game 59: 10 blue, 1 red; 1 green, 4 blue; 4 blue +Game 60: 7 red, 2 green, 6 blue; 1 green, 13 red, 12 blue; 9 blue, 9 green, 8 red +Game 61: 7 green, 3 red, 2 blue; 1 red, 1 blue; 5 green, 3 blue; 4 blue, 1 red, 4 green +Game 62: 1 green, 8 blue, 6 red; 7 blue, 3 red, 12 green; 2 blue, 7 red, 6 green +Game 63: 3 red, 2 green; 3 green, 4 blue, 9 red; 3 blue, 3 green, 16 red; 4 red, 1 blue +Game 64: 10 red, 2 green, 15 blue; 4 red, 14 green; 6 red, 14 green, 2 blue +Game 65: 11 red, 14 green, 5 blue; 7 blue, 14 green, 15 red; 1 blue, 14 green; 4 green, 4 blue, 7 red +Game 66: 6 blue, 9 green, 6 red; 6 blue, 2 red, 4 green; 3 blue; 8 blue, 5 green, 8 red; 17 blue, 11 green; 12 green, 11 blue, 4 red +Game 67: 8 red, 4 blue, 6 green; 4 blue, 8 red, 2 green; 1 green, 6 red, 2 blue; 10 red, 1 green, 2 blue; 1 blue, 5 red; 2 red, 1 green, 2 blue +Game 68: 10 green, 9 red, 13 blue; 2 blue, 2 green, 4 red; 11 red, 13 blue; 4 green, 2 red, 8 blue +Game 69: 16 red; 12 red, 1 green, 4 blue; 1 green, 14 red, 9 blue; 12 blue, 2 green, 13 red; 14 red, 2 green, 10 blue; 11 blue +Game 70: 1 red, 19 green; 4 blue, 6 green; 12 green, 2 red +Game 71: 9 green, 2 blue, 3 red; 5 red; 1 red, 1 blue, 5 green +Game 72: 1 green, 19 red; 12 red, 1 green, 1 blue; 16 red, 6 blue; 14 red, 7 blue; 11 blue, 1 green, 13 red; 16 blue, 4 red +Game 73: 1 green, 1 red, 2 blue; 8 green, 2 red, 4 blue; 7 blue, 7 green, 7 red +Game 74: 1 blue, 1 green; 1 red; 1 red, 5 blue, 4 green; 2 blue, 1 red; 1 blue +Game 75: 8 green, 1 red; 3 blue, 1 red, 5 green; 12 green +Game 76: 8 green, 6 red, 2 blue; 7 red, 1 blue; 2 blue, 9 green, 1 red; 8 red, 13 green; 12 green, 2 red; 7 green, 5 red +Game 77: 3 blue, 1 green, 10 red; 13 red; 1 blue, 13 red, 1 green +Game 78: 2 red, 3 green, 14 blue; 3 red, 16 blue, 6 green; 3 blue, 3 red, 9 green; 4 blue, 11 green; 6 green, 2 blue; 2 red, 10 green, 11 blue +Game 79: 5 green, 10 blue, 2 red; 16 green, 15 blue, 1 red; 1 red, 11 green; 1 red, 11 blue, 16 green; 7 blue, 18 green +Game 80: 9 blue, 10 green; 13 green, 9 blue; 1 red, 5 green, 5 blue; 13 green, 5 blue, 1 red +Game 81: 9 green, 15 red, 11 blue; 11 blue, 9 red, 5 green; 2 green, 11 blue, 19 red; 14 green, 15 red, 5 blue +Game 82: 4 green, 6 red, 13 blue; 5 blue, 5 red, 4 green; 2 green, 7 blue +Game 83: 12 blue, 8 red; 6 red, 1 blue, 1 green; 7 red, 1 green, 1 blue; 6 red, 1 green, 9 blue; 10 blue, 3 red; 1 red, 5 blue +Game 84: 9 blue, 13 red; 8 blue, 1 green; 9 blue, 1 green; 3 blue, 5 red, 1 green +Game 85: 14 green, 5 blue, 8 red; 1 blue, 5 green, 1 red; 10 red, 7 blue, 17 green; 3 blue, 6 green; 6 red, 5 blue, 4 green; 5 blue, 4 green, 6 red +Game 86: 14 red; 20 red, 3 blue; 1 green, 12 blue, 15 red; 16 red, 13 blue; 13 red, 12 blue; 2 blue, 20 red +Game 87: 2 blue, 2 red, 10 green; 8 green, 9 red, 1 blue; 11 red, 1 green, 4 blue; 13 red, 1 blue; 11 green, 16 red, 3 blue +Game 88: 5 green, 4 red, 1 blue; 3 blue, 8 red, 10 green; 11 green, 7 red, 4 blue; 11 green, 5 blue, 4 red; 9 red, 9 green; 4 blue, 6 green, 9 red +Game 89: 2 blue, 2 red, 5 green; 2 red, 2 blue, 3 green; 2 red, 1 blue, 7 green; 6 green, 1 red, 2 blue +Game 90: 4 green, 1 blue, 5 red; 2 blue, 2 red, 10 green; 2 green, 8 red, 1 blue; 10 green, 5 red; 2 red, 3 green, 2 blue +Game 91: 16 blue, 5 red, 15 green; 4 green, 7 red, 3 blue; 4 red, 8 green, 12 blue; 4 green, 8 red, 17 blue +Game 92: 13 red, 2 blue, 12 green; 19 green, 7 red; 17 green, 2 blue, 3 red; 6 blue, 11 red, 10 green; 6 red, 15 green, 3 blue; 6 blue, 20 green, 11 red +Game 93: 2 blue, 3 green; 1 blue, 4 red; 1 red +Game 94: 3 red, 5 green, 6 blue; 7 blue, 5 green, 6 red; 9 blue, 1 green, 2 red; 4 blue, 1 green, 4 red +Game 95: 8 green, 9 red, 2 blue; 7 green, 7 red; 2 green, 4 blue, 6 red; 6 blue, 2 red, 2 green +Game 96: 11 blue, 4 red; 1 green, 3 red, 14 blue; 2 green, 3 red, 8 blue; 7 red, 1 green, 3 blue; 8 blue, 6 red, 2 green; 9 blue, 3 red, 3 green +Game 97: 5 green, 13 red, 7 blue; 2 blue, 12 red, 6 green; 10 blue, 11 red, 3 green; 4 green, 11 blue, 15 red; 8 green, 16 blue, 1 red; 15 blue, 4 red, 5 green +Game 98: 3 blue, 1 red; 4 blue; 2 green, 1 blue; 2 green, 1 red, 5 blue +Game 99: 4 green, 3 blue, 9 red; 6 blue, 5 red, 3 green; 2 green, 4 blue, 7 red; 8 red, 4 blue; 2 green, 15 red; 4 red, 5 blue, 3 green +Game 100: 8 red, 4 blue, 4 green; 10 blue, 3 red, 4 green; 10 green, 4 red; 18 red, 9 blue, 2 green; 12 red, 4 green, 2 blue diff --git a/2023/day02_2/src/main/resources/small_input b/2023/day02_2/src/main/resources/small_input new file mode 100644 index 0000000..1cd7d33 --- /dev/null +++ b/2023/day02_2/src/main/resources/small_input @@ -0,0 +1,5 @@ +Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green +Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue +Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red +Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green \ No newline at end of file diff --git a/2023/day03_1/.idea/.gitignore b/2023/day03_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2023/day03_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2023/day03_1/.idea/inspectionProfiles/Project_Default.xml b/2023/day03_1/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2023/day03_1/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2023/day03_1/.idea/kotlinc.xml b/2023/day03_1/.idea/kotlinc.xml new file mode 100644 index 0000000..5cba058 --- /dev/null +++ b/2023/day03_1/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2023/day03_1/.idea/libraries/KotlinJavaRuntime.xml b/2023/day03_1/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..3937c2d --- /dev/null +++ b/2023/day03_1/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day03_1/.idea/misc.xml b/2023/day03_1/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2023/day03_1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day03_1/.idea/modules.xml b/2023/day03_1/.idea/modules.xml new file mode 100644 index 0000000..d9d9e9b --- /dev/null +++ b/2023/day03_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2023/day03_1/.idea/sonarlint/issuestore/index.pb b/2023/day03_1/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..e10b5ff --- /dev/null +++ b/2023/day03_1/.idea/sonarlint/issuestore/index.pb @@ -0,0 +1,3 @@ + +G +src/main/kotlin/Main.kt,d/8/d83ae3847b7d408136086cc5e9e95f5f7c126ed5 \ No newline at end of file diff --git a/2023/day03_1/.idea/sonarlint/securityhotspotstore/index.pb b/2023/day03_1/.idea/sonarlint/securityhotspotstore/index.pb new file mode 100644 index 0000000..e10b5ff --- /dev/null +++ b/2023/day03_1/.idea/sonarlint/securityhotspotstore/index.pb @@ -0,0 +1,3 @@ + +G +src/main/kotlin/Main.kt,d/8/d83ae3847b7d408136086cc5e9e95f5f7c126ed5 \ No newline at end of file diff --git a/2023/day03_1/.idea/vcs.xml b/2023/day03_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2023/day03_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day03_1/day03_1.iml b/2023/day03_1/day03_1.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day03_1/day03_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day03_1/src/main/kotlin/Main.kt b/2023/day03_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..32ea0c4 --- /dev/null +++ b/2023/day03_1/src/main/kotlin/Main.kt @@ -0,0 +1,156 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 3, Part 1 starting!!!") + + val schematic = Schematic() + File(args[0]).forEachLine { + schematic.addLine(it) + } + + schematic.scanForParts() + + val answer = schematic.getAttachedParts() + + // Search parts for attachments + + println("The answer: $answer") + + println("AOC 2023, Day 3, Part 1 completed!!") +} + +class Schematic { + private val lines:ArrayList = ArrayList() + private var partsList:ArrayList = ArrayList() + + fun addLine(newLine:String) { + lines.add(newLine) + } + + fun scanForParts() { + var y = 0 + for(line in lines) { + var x = 0 + for (c in line) { + if(!c.isDigit() && (c.compareTo('.') != 0)) { + scanForParts(x, y) + } + x++ + } + y++ + } + } + + private fun scanForParts(x:Int, y:Int) { + val attachedParts:HashSet = HashSet() + + val xN1 = x - 1 + xN1.coerceIn(0, getMaxX()) + val xP1 = x + 1 + xP1.coerceIn(0, getMaxX()) + val yN1 = y - 1 + yN1.coerceIn(0, getMaxY()) + val yP1 = y + 1 + yP1.coerceIn(0, getMaxY()) + + val c0 = getCharAtXY(xN1, yN1) + if(c0.isDigit()) { + attachedParts.add(getPartNumberAt(xN1, yN1)) + } + + val c1 = getCharAtXY(x, yN1) + if(c1.isDigit()) { + attachedParts.add(getPartNumberAt(x, yN1)) + } + + val c2 = getCharAtXY(xP1, yN1) + if(c2.isDigit()) { + attachedParts.add(getPartNumberAt(xP1, yN1)) + } + + val c3 = getCharAtXY(xN1, y) + if(c3.isDigit()) { + attachedParts.add(getPartNumberAt(xN1, y)) + } + + val c4 = getCharAtXY(xP1, y) + if(c4.isDigit()){ + attachedParts.add(getPartNumberAt(xP1, y)) + } + + val c5 = getCharAtXY(xN1, yP1) + if(c5.isDigit()) { + attachedParts.add(getPartNumberAt(xN1, yP1)) + } + + val c6 = getCharAtXY(x, yP1) + if(c6.isDigit()) { + attachedParts.add(getPartNumberAt(x, yP1)) + } + + val c7 = getCharAtXY(xP1, yP1) + if(c7.isDigit()) { + attachedParts.add(getPartNumberAt(xP1, yP1)) + } + + partsList.addAll(attachedParts) + } + + private fun getPartNumberAt(x: Int, y: Int):Int { + val theLine = lines[y] + var start = x + var end = x + + while(start >= 1) { + try { + if (theLine[start - 1].isDigit()) { + start-- + } else { + break + } + } catch (e:Exception) { + start = 0 + break + } + } + + while(end < getMaxX()) { + try { + if (theLine[end + 1].isDigit()) { + end++ + } else { + break + } + } catch (e:Exception) { + // break out + end = getMaxX() - 1 + break + } + } + + if((start < 0) || end > getMaxX()) { + throw Exception("For safety do not go out of bounds") + } + + return theLine.substring(start, end + 1).toInt() + } + + private fun getCharAtXY(x:Int, y:Int):Char { + val theLine = lines[y] + return theLine[x] + } + + private fun getMaxX():Int { + return lines[0].length + } + + private fun getMaxY():Int { + return lines.size + } + + fun getAttachedParts():Int { + var answer = 0 + partsList.stream().forEach { answer += it } + return answer + } +} \ No newline at end of file diff --git a/2023/day03_1/src/main/resources/input b/2023/day03_1/src/main/resources/input new file mode 100644 index 0000000..14a7579 --- /dev/null +++ b/2023/day03_1/src/main/resources/input @@ -0,0 +1,140 @@ +...................305.124................................432..............................................576..313.....514................. +.............113...-......&....................&...819...........654..../..........................&901................*....869.257......... +...377..&783../.................................9...........855*......940..463................-.........................844.*....@......679. +......*...........197.261.....817..336.759............&742......548.......&........748......844.............#.......&........254...169..*... +.......36....368.*...............*....*.........*..88......%866.......135.........*..................515.682.....114...%...........*.....768 +...233......*....909..698.........427..........127.*...................*...........450.........482..../.................312.....621......... +.../.......882...............776...................555......180.........971....217.......857.../........212....674.917......736.....441*760. +............................*.....@....907....%940.....%.......+.#..........45*...........$............#..........*...............=......... +..................370.225.425..211...................932..........381..267.............45.....=....549....238........367..&.....488......... +.468.............*.......................761...677.......&.................929..907.....%....79...*.......*....324..*....515................ +....-.#103.504...388...........$..........*.....@........766.%................*....*623.........532..881...573....*..840..............497... +...........*.........305....412..687.......971................676....@640....657........709......................807............98.....+.... +....279...502...62...*.............*..............................................838%.....$.........585..........................*......... +....=...=......*....209.825.482.993..........972............620*664..-759............................*.......184.........952....160.....156. +.......814.....931......*...*............551..*....711...65.................224*115...851.772..104..505.....=........796*................... +....................723.103..275........*......564..*.........830........................*...../..............................232........... +.............$......&....................951........703......=............160+.....138......*........257*809.............$298........284.... +.....684....464.333..................827.....*211..................................#.....855.86.....................$913............*....... +.......*...........*..*......917.163....*.409......294.......................#..39.......................511....358.......$671.......237.... +.......663.......311..163....*...%...158........*....-.442.........958....108.....#.....941*837.........*..........*........................ +............865=..........409....................128...*.......283....................................680.........730.935@........768....... +....../................=.............54.....857.........418.....*..911.......610..643............381...............................@........ +.......925............984...........-...800*.................194.../.........*.......*.........../.....................................@.... +.................................@...............................&......615...16....695.....-..........................*750.............855. +....611..136...................108.540.........362..711......*....420.....................190.......................213.............86...... +204*....@.........288..825..+........&...........*....*......733.........................................7..387.......................*..... +...........795..../.......+.505.834.....228....192...619..........886......467.....942.............................%838.........512...340... +.......957.........................*...*..................962........................*..............211...$..............624................ +.......*....................349....144......./786..350.......*.......................541..21.......$.....284..190*......*............518.... +....484...@....17..........*..../........309..........*....530...118..........208..............253................489.828...........*....... +..........309...........715.....531........+.516#...645.........$........369....*.......*185...@............=.#...........@............&.... +491*192..............................................................233.........711.948.........572.....869..289......932...........149.... +........274.....511.....425..........421.288*965...652=.919........./....*.786...........676.....*..................+.........=............. +.........*.........@......$...*.........................*........*....791...+..113......*....527..897..499+.904...166........580.........389 +.......306.....................353.497..929/.......=....553......495.................884.....&........................794........774........ +...................../...........................582....................................................489..........*...............&...... +.605......537.....247.....................479................74................227*995.761.....@...........+.......958...87.....547.795..... +...*.....*....................289+.....*.....%........967..............*...............*........611.....28....367.................*......... +..690....916.497....................894.440......547$.............596.492......23...............................*...............237.221..786 +.........................681.....=..........580+.................+...............+.......696............@..542..56.......................... +...936..639*947.............+...48.*709..................307.257...-248.697.553.............+.........146.....#.......*241.................. +...*................568....................=378....41.......*............*...%..11......*..........................982.............#........ +..323..704.+724..*....*..195*....812..879...........*.....*....508@.....852....$.....664.......317....*......332..............326.158....... +.......*........610..767.....936...#...&..744.290..839.382.543....................................&.827...../.............323*.........884.. +...........962...............................*...................46....502.265.150...................................639...............*.... +955*818.......*...@...124*512..256...................+....&..............*....*.......170....996...#........................786.......4..... +..............284.697...........*......172...........398.435.......-.....380..........+..........698....428...361................206........ +.822...#..............936$...745..........*..%59..................726...........+.........249......../...*.....*..................%......... +.....870................................978.......761=.......179.............692.........*..........477..550.....676..281.............507... +..............913.................215.........................*..745...#.............882..130..569....................&..........*472..*.... +...27..710.....*.....................*.205*403..............59....+..172................=.............................................697... +....*....*....731.......865.......155..........849*....#..............................................679...854....................&........ +.985..%.............599....#..........191..520.......473..#........./...........708....406..677+...=............................599.....133. +......501...........*........@.........*...*..............446....767...*444........@......&.........49......#...311*413..................... +..................157.......830..13.90.398.945.978............................950.................%.......88................$............... +.............297........618.......+.*............%............317.............../.........709..481............503.........570...305*845..... +......661....*....632.....@..+......524......../.....+...........*...590..............944....*...............*................+..........681 +.......*.....820...@..........829...........671.......206.......239.+......................339..#............106......415..213..........-... +........114........................903.669=............................764...319....373........642...................................-...... +.................*...........................*.......121.......898&.....$......*...*.....................................211#.......579..... +........*.......362......787.440..........842.825.....*......................590...357..........949......523....470..292.................... +.....594.459........98.....*....*.......................355&..*..................*..........554..*.......*.......*....*..222...243.......... +.........................535.....674.........804....#..........455.............847............=.32...23..951.....217.346....+.*....+272..... +..183...........443..........119.......833....#..693......818#........................@..699..............................*....678.......... +...*......455/...%..826.............#.....*.........................$...........868.739....=..753...181....773.........323.508.............. +...382................*...169..510..590.295....212.767....*970......711.........*........#.......*..*............651...........36..766*..... +............&..61..697.....*................46.*....*..691......970............786....953.....775...235..................*550....*.....417.. +..........45.....*........689...645.....549*...821.601.............*......................952..............#..........464.....609........... +.....657.........48...888.......*...................................305......+47..........................254.27......................123... +818......388............*....412....../491.........#336...506..422.................989....15...70..............*..354............@.....*.... +..............506........11......./...........643..........#..=..........703...963*........@.........613.....413....%...485.......265...33.. +....589.......*................207..............%...............................................+................*......*.....94............ +...*.........663...413+....................................819...........655.%...648..823.......770....385......457..150...#.../............ +515.......................475....825......33../350.....459...%..........*....681...*...*..............%..................437.......689...... +....$993..897@..............*.......*837...-...........*..............726........372....922......&198................................*...... +180............*..........679.................71.629=.796......109...........................527..................682.....558.....798....... +........437.742.46.................@.......&...................*......498.......@.............*............./......$........*............... +..761..$...........148.......856....701.377..536*510...604...540.....&........929........172.799.............310.....700...........440.%.... +.....*........808*....=.........@......................*.........577.....................*................&...........$...417.39.....&.229.. +........794.......446..............................214.543...%...*..........935......865..445...../....%.615................=..*............ +..572..+...............................419....932@.........924..72.902.......-..579.-...........997.203................873......945..567.... +.....*.................273.............*...........................*...142............688................755.850...........846.........=.... +...880................*..............883.698.....$.......=........197.*...........316*.........365.........$...*............*............904 +.........385..977..179....+...................652......875.............350...863............73......464.........214.852..478................ +......22....*..@.........93............*682..................*137..309.........*....557.....*........................=.......698.....+.218.. +......*...645......163...............89......*853..................*...386..341.......*...228............718*492...............*..153..*.... +.....576......................857.........513....................509......*.....322.710.........615.......................613.165.......292. +................................@.....370.......598......487...........503..*.....................*...738#..#..$901...$.....#.......648..... +..19*454.............78................/..876..#..........*......+..........937.......383........523........69......326.678.....212....*.... +.....................*.....436.@...646...*..........100....367..325.....361.......207*....50............621...............*..........237.... +757.........714......502...%...54......909.411.....*.....................*..........................=..$................415................. +...$.......&.................................*...471..985...508.472....891.842..$.................418.........&.....&....................... +.................$........906..........*215.338...............*..............*..606.#235......................813..259........229........... +........472...222.........*.....245.572.......................927...769....344.............291.239.....................94....*.............. +...818...$.............291..............288...........163.734......+...........699............*.......981&...514*.............224.....=..... +.....*..................................*.........................................+..189..........452............644...................669.. +....850................326$..............869..&985......784..../..............592.......*..153.....*....887..493.....211........%........... +.............................457....834.....................94..564..........&.........498....*...304....../...*.....*..........845.....&... +.......12*48.753...244..196....=......$..721....90*29.........*.................+.522.......487...............317.....531..311........20.... +.177...............*.....*.................*.............*969.611.......*565..338...*.............712..922$.......770......*....522......... +....*..459......149......165...=........879...........103............497..........258.931..75....*..........400*.....*......972............. +.269...*............#........715.............................*475..........................*....145.............414.....228........893...... +........209......508...................../331......469....894............347.890$..541.....56...............#........#..*................... +......................=...........37................*...........................................$...........197...119.....=...........756... +...........&.......850.....367.34...*............517........178*716..........=...................892......-............883...755............ +.....@496.125.................*......965.....428.....908..................405.....650...................=..493..89.......................... +..............581........396.............596.........*....964........672......159.%....463............768......./.............391........... +.............*...........*.....871.660..*......577.73......@.....932....#....*............*574...186........154......996........*......720.. +............914..132..137......=.......746......*..................*......376.......&661............*560.%.......%....*...264....511........ +...%...151................*851...................................*..284.........754..........190.19.......611...326.841...............89.... +644.....*...797........133.....476..............................810.............*.....866......+.*..............................#903..*..... +........839..*..478...........*........372.#.....744.....227*............477.3.253.%....&..746.....289.&860.....720*708..................... +............443...%.....68*....283.......%..900...%....%..........584......*.$......308....*......*......................592................ +...239................@....250........50........&...%...192.$111.*........74............831....914...#.....886*492..........=............... +...*......425.....181..680..............*......873.502............93.................................503.@..............116........372...... +492..........*.....$.............302...789.................861.......................290.......452........83....626....*.....76.......*..... +......178...528..........*739...@..........................*......804....320....#.........&878.*.....746........./..&...148...$......741.... +...&....*.............262..............325...........599..592.579.....%...+..808...............386..*...............761..................... +663..462...........*..........109..706*.................=.............553........712......*971......674.396...635*.......................... +........../...728.952...413......*......744.......%..........................300..*....782................*.......742..&424........41+...564 +........375...%.........*......450.456.$.........714........851.327..#...+......*...+.......179.630....854.................................. +..251................195...887.....*........*209.......430.*......-.83.596....956..966.274.%.....*........................83.359........411. +....%.......................*..........89.........194..+...491.........................&.....*.762..+741..........598.......*.....910..*.... +..........618+..............677........*..598........+..........-.....58....290...........795...........................*.....580.&....559.. +...................561..............910......-..321....834....602.752*....=..+........191..............463....@..........792..*............. +............216.......%...722*668.....................$..................109............*....222...195*.......689....380.......637.......... +.....846.......*..436..............=827...263@.764*.......*.464.................729.....934...*......................................289+... +.127*.......757.....&......./954...................965..664........./......716*.+...........266....781.........989..........844...$......... +................57.....................&118......=...........385.623...245..............345........*.....615-.....*..........*...768........ +...538...........#..860......................783.460..........*............401.............*796..354..............37......797........725.193 +....*..#620../.........*..........578..54...*..........780..251...634..946....*........................./....702........................*... +..202.......815........724....#..............822..972...................$..........*.....#....@........27.....*...........268.....347....... +.................+..........98.....703..............&....*52.....320.............670...318....734.............47..................+....239.. +.953*919...=......273................=...454.....@....601...........*...958.........................+.................758...=............... +..........905./50.........@...................971..................762.*..................169........915.682..........=......533.......502.. +.....884.................24...........262.........@.....531..698.......234.................................................%.......149..*... +....................834.....994.......*........266.....*......*............................................/.....941.434...812.......*..211. +.............133......*......*.....613...85..........871.......497..346...737....88.....176.....192$........128.*.......&......./163.26..... +....734..543....*.....656....461........*......531..................*........../...*..&................$971.....931......................... +................606....................506............................779.......30...211.....243..........................153...504......... diff --git a/2023/day03_1/src/main/resources/small_input b/2023/day03_1/src/main/resources/small_input new file mode 100644 index 0000000..624ea4f --- /dev/null +++ b/2023/day03_1/src/main/resources/small_input @@ -0,0 +1,10 @@ +467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.. \ No newline at end of file diff --git a/2023/day03_2/.gitignore b/2023/day03_2/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/2023/day03_2/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/2023/day03_2/day03_2.iml b/2023/day03_2/day03_2.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day03_2/day03_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day03_2/src/main/kotlin/Main.kt b/2023/day03_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..c9c7ec9 --- /dev/null +++ b/2023/day03_2/src/main/kotlin/Main.kt @@ -0,0 +1,160 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 3, Part 2 starting!!!") + + val schematic = Schematic() + File(args[0]).forEachLine { + schematic.addLine(it) + } + + schematic.scanForParts() + + val answer = schematic.getAttachedParts() + + // Search parts for attachments + + println("The answer: $answer") + + println("AOC 2023, Day 3, Part 2 completed!!") +} + +class Schematic { + private val lines:ArrayList = ArrayList() + private var gearRatios:ArrayList = ArrayList() + + fun addLine(newLine:String) { + lines.add(newLine) + } + + fun scanForParts() { + var y = 0 + for(line in lines) { + var x = 0 + for (c in line) { + if(!c.isDigit() && (c.compareTo('.') != 0)) { + scanForParts(x, y) + } + x++ + } + y++ + } + } + + private fun scanForParts(x:Int, y:Int) { + val attachedParts:HashSet = HashSet() + + val xN1 = x - 1 + xN1.coerceIn(0, getMaxX()) + val xP1 = x + 1 + xP1.coerceIn(0, getMaxX()) + val yN1 = y - 1 + yN1.coerceIn(0, getMaxY()) + val yP1 = y + 1 + yP1.coerceIn(0, getMaxY()) + + val c0 = getCharAtXY(xN1, yN1) + if(c0.isDigit()) { + attachedParts.add(getPartNumberAt(xN1, yN1)) + } + + val c1 = getCharAtXY(x, yN1) + if(c1.isDigit()) { + attachedParts.add(getPartNumberAt(x, yN1)) + } + + val c2 = getCharAtXY(xP1, yN1) + if(c2.isDigit()) { + attachedParts.add(getPartNumberAt(xP1, yN1)) + } + + val c3 = getCharAtXY(xN1, y) + if(c3.isDigit()) { + attachedParts.add(getPartNumberAt(xN1, y)) + } + + val c4 = getCharAtXY(xP1, y) + if(c4.isDigit()){ + attachedParts.add(getPartNumberAt(xP1, y)) + } + + val c5 = getCharAtXY(xN1, yP1) + if(c5.isDigit()) { + attachedParts.add(getPartNumberAt(xN1, yP1)) + } + + val c6 = getCharAtXY(x, yP1) + if(c6.isDigit()) { + attachedParts.add(getPartNumberAt(x, yP1)) + } + + val c7 = getCharAtXY(xP1, yP1) + if(c7.isDigit()) { + attachedParts.add(getPartNumberAt(xP1, yP1)) + } + + if(attachedParts.size > 1) { + var gearRatio = 1 + attachedParts.stream().forEach { gearRatio *= it } + gearRatios.add(gearRatio) + } + } + + private fun getPartNumberAt(x: Int, y: Int):Int { + val theLine = lines[y] + var start = x + var end = x + + while(start >= 1) { + try { + if (theLine[start - 1].isDigit()) { + start-- + } else { + break + } + } catch (e:Exception) { + start = 0 + break + } + } + + while(end < getMaxX()) { + try { + if (theLine[end + 1].isDigit()) { + end++ + } else { + break + } + } catch (e:Exception) { + // break out + end = getMaxX() - 1 + break + } + } + + if((start < 0) || end > getMaxX()) { + throw Exception("For safety do not go out of bounds") + } + + return theLine.substring(start, end + 1).toInt() + } + + private fun getCharAtXY(x:Int, y:Int):Char { + val theLine = lines[y] + return theLine[x] + } + + private fun getMaxX():Int { + return lines[0].length + } + + private fun getMaxY():Int { + return lines.size + } + + fun getAttachedParts():Int { + var answer = 0 + gearRatios.stream().forEach { answer += it } + return answer + } +} \ No newline at end of file diff --git a/2023/day03_2/src/main/resources/input b/2023/day03_2/src/main/resources/input new file mode 100644 index 0000000..14a7579 --- /dev/null +++ b/2023/day03_2/src/main/resources/input @@ -0,0 +1,140 @@ +...................305.124................................432..............................................576..313.....514................. +.............113...-......&....................&...819...........654..../..........................&901................*....869.257......... +...377..&783../.................................9...........855*......940..463................-.........................844.*....@......679. +......*...........197.261.....817..336.759............&742......548.......&........748......844.............#.......&........254...169..*... +.......36....368.*...............*....*.........*..88......%866.......135.........*..................515.682.....114...%...........*.....768 +...233......*....909..698.........427..........127.*...................*...........450.........482..../.................312.....621......... +.../.......882...............776...................555......180.........971....217.......857.../........212....674.917......736.....441*760. +............................*.....@....907....%940.....%.......+.#..........45*...........$............#..........*...............=......... +..................370.225.425..211...................932..........381..267.............45.....=....549....238........367..&.....488......... +.468.............*.......................761...677.......&.................929..907.....%....79...*.......*....324..*....515................ +....-.#103.504...388...........$..........*.....@........766.%................*....*623.........532..881...573....*..840..............497... +...........*.........305....412..687.......971................676....@640....657........709......................807............98.....+.... +....279...502...62...*.............*..............................................838%.....$.........585..........................*......... +....=...=......*....209.825.482.993..........972............620*664..-759............................*.......184.........952....160.....156. +.......814.....931......*...*............551..*....711...65.................224*115...851.772..104..505.....=........796*................... +....................723.103..275........*......564..*.........830........................*...../..............................232........... +.............$......&....................951........703......=............160+.....138......*........257*809.............$298........284.... +.....684....464.333..................827.....*211..................................#.....855.86.....................$913............*....... +.......*...........*..*......917.163....*.409......294.......................#..39.......................511....358.......$671.......237.... +.......663.......311..163....*...%...158........*....-.442.........958....108.....#.....941*837.........*..........*........................ +............865=..........409....................128...*.......283....................................680.........730.935@........768....... +....../................=.............54.....857.........418.....*..911.......610..643............381...............................@........ +.......925............984...........-...800*.................194.../.........*.......*.........../.....................................@.... +.................................@...............................&......615...16....695.....-..........................*750.............855. +....611..136...................108.540.........362..711......*....420.....................190.......................213.............86...... +204*....@.........288..825..+........&...........*....*......733.........................................7..387.......................*..... +...........795..../.......+.505.834.....228....192...619..........886......467.....942.............................%838.........512...340... +.......957.........................*...*..................962........................*..............211...$..............624................ +.......*....................349....144......./786..350.......*.......................541..21.......$.....284..190*......*............518.... +....484...@....17..........*..../........309..........*....530...118..........208..............253................489.828...........*....... +..........309...........715.....531........+.516#...645.........$........369....*.......*185...@............=.#...........@............&.... +491*192..............................................................233.........711.948.........572.....869..289......932...........149.... +........274.....511.....425..........421.288*965...652=.919........./....*.786...........676.....*..................+.........=............. +.........*.........@......$...*.........................*........*....791...+..113......*....527..897..499+.904...166........580.........389 +.......306.....................353.497..929/.......=....553......495.................884.....&........................794........774........ +...................../...........................582....................................................489..........*...............&...... +.605......537.....247.....................479................74................227*995.761.....@...........+.......958...87.....547.795..... +...*.....*....................289+.....*.....%........967..............*...............*........611.....28....367.................*......... +..690....916.497....................894.440......547$.............596.492......23...............................*...............237.221..786 +.........................681.....=..........580+.................+...............+.......696............@..542..56.......................... +...936..639*947.............+...48.*709..................307.257...-248.697.553.............+.........146.....#.......*241.................. +...*................568....................=378....41.......*............*...%..11......*..........................982.............#........ +..323..704.+724..*....*..195*....812..879...........*.....*....508@.....852....$.....664.......317....*......332..............326.158....... +.......*........610..767.....936...#...&..744.290..839.382.543....................................&.827...../.............323*.........884.. +...........962...............................*...................46....502.265.150...................................639...............*.... +955*818.......*...@...124*512..256...................+....&..............*....*.......170....996...#........................786.......4..... +..............284.697...........*......172...........398.435.......-.....380..........+..........698....428...361................206........ +.822...#..............936$...745..........*..%59..................726...........+.........249......../...*.....*..................%......... +.....870................................978.......761=.......179.............692.........*..........477..550.....676..281.............507... +..............913.................215.........................*..745...#.............882..130..569....................&..........*472..*.... +...27..710.....*.....................*.205*403..............59....+..172................=.............................................697... +....*....*....731.......865.......155..........849*....#..............................................679...854....................&........ +.985..%.............599....#..........191..520.......473..#........./...........708....406..677+...=............................599.....133. +......501...........*........@.........*...*..............446....767...*444........@......&.........49......#...311*413..................... +..................157.......830..13.90.398.945.978............................950.................%.......88................$............... +.............297........618.......+.*............%............317.............../.........709..481............503.........570...305*845..... +......661....*....632.....@..+......524......../.....+...........*...590..............944....*...............*................+..........681 +.......*.....820...@..........829...........671.......206.......239.+......................339..#............106......415..213..........-... +........114........................903.669=............................764...319....373........642...................................-...... +.................*...........................*.......121.......898&.....$......*...*.....................................211#.......579..... +........*.......362......787.440..........842.825.....*......................590...357..........949......523....470..292.................... +.....594.459........98.....*....*.......................355&..*..................*..........554..*.......*.......*....*..222...243.......... +.........................535.....674.........804....#..........455.............847............=.32...23..951.....217.346....+.*....+272..... +..183...........443..........119.......833....#..693......818#........................@..699..............................*....678.......... +...*......455/...%..826.............#.....*.........................$...........868.739....=..753...181....773.........323.508.............. +...382................*...169..510..590.295....212.767....*970......711.........*........#.......*..*............651...........36..766*..... +............&..61..697.....*................46.*....*..691......970............786....953.....775...235..................*550....*.....417.. +..........45.....*........689...645.....549*...821.601.............*......................952..............#..........464.....609........... +.....657.........48...888.......*...................................305......+47..........................254.27......................123... +818......388............*....412....../491.........#336...506..422.................989....15...70..............*..354............@.....*.... +..............506........11......./...........643..........#..=..........703...963*........@.........613.....413....%...485.......265...33.. +....589.......*................207..............%...............................................+................*......*.....94............ +...*.........663...413+....................................819...........655.%...648..823.......770....385......457..150...#.../............ +515.......................475....825......33../350.....459...%..........*....681...*...*..............%..................437.......689...... +....$993..897@..............*.......*837...-...........*..............726........372....922......&198................................*...... +180............*..........679.................71.629=.796......109...........................527..................682.....558.....798....... +........437.742.46.................@.......&...................*......498.......@.............*............./......$........*............... +..761..$...........148.......856....701.377..536*510...604...540.....&........929........172.799.............310.....700...........440.%.... +.....*........808*....=.........@......................*.........577.....................*................&...........$...417.39.....&.229.. +........794.......446..............................214.543...%...*..........935......865..445...../....%.615................=..*............ +..572..+...............................419....932@.........924..72.902.......-..579.-...........997.203................873......945..567.... +.....*.................273.............*...........................*...142............688................755.850...........846.........=.... +...880................*..............883.698.....$.......=........197.*...........316*.........365.........$...*............*............904 +.........385..977..179....+...................652......875.............350...863............73......464.........214.852..478................ +......22....*..@.........93............*682..................*137..309.........*....557.....*........................=.......698.....+.218.. +......*...645......163...............89......*853..................*...386..341.......*...228............718*492...............*..153..*.... +.....576......................857.........513....................509......*.....322.710.........615.......................613.165.......292. +................................@.....370.......598......487...........503..*.....................*...738#..#..$901...$.....#.......648..... +..19*454.............78................/..876..#..........*......+..........937.......383........523........69......326.678.....212....*.... +.....................*.....436.@...646...*..........100....367..325.....361.......207*....50............621...............*..........237.... +757.........714......502...%...54......909.411.....*.....................*..........................=..$................415................. +...$.......&.................................*...471..985...508.472....891.842..$.................418.........&.....&....................... +.................$........906..........*215.338...............*..............*..606.#235......................813..259........229........... +........472...222.........*.....245.572.......................927...769....344.............291.239.....................94....*.............. +...818...$.............291..............288...........163.734......+...........699............*.......981&...514*.............224.....=..... +.....*..................................*.........................................+..189..........452............644...................669.. +....850................326$..............869..&985......784..../..............592.......*..153.....*....887..493.....211........%........... +.............................457....834.....................94..564..........&.........498....*...304....../...*.....*..........845.....&... +.......12*48.753...244..196....=......$..721....90*29.........*.................+.522.......487...............317.....531..311........20.... +.177...............*.....*.................*.............*969.611.......*565..338...*.............712..922$.......770......*....522......... +....*..459......149......165...=........879...........103............497..........258.931..75....*..........400*.....*......972............. +.269...*............#........715.............................*475..........................*....145.............414.....228........893...... +........209......508...................../331......469....894............347.890$..541.....56...............#........#..*................... +......................=...........37................*...........................................$...........197...119.....=...........756... +...........&.......850.....367.34...*............517........178*716..........=...................892......-............883...755............ +.....@496.125.................*......965.....428.....908..................405.....650...................=..493..89.......................... +..............581........396.............596.........*....964........672......159.%....463............768......./.............391........... +.............*...........*.....871.660..*......577.73......@.....932....#....*............*574...186........154......996........*......720.. +............914..132..137......=.......746......*..................*......376.......&661............*560.%.......%....*...264....511........ +...%...151................*851...................................*..284.........754..........190.19.......611...326.841...............89.... +644.....*...797........133.....476..............................810.............*.....866......+.*..............................#903..*..... +........839..*..478...........*........372.#.....744.....227*............477.3.253.%....&..746.....289.&860.....720*708..................... +............443...%.....68*....283.......%..900...%....%..........584......*.$......308....*......*......................592................ +...239................@....250........50........&...%...192.$111.*........74............831....914...#.....886*492..........=............... +...*......425.....181..680..............*......873.502............93.................................503.@..............116........372...... +492..........*.....$.............302...789.................861.......................290.......452........83....626....*.....76.......*..... +......178...528..........*739...@..........................*......804....320....#.........&878.*.....746........./..&...148...$......741.... +...&....*.............262..............325...........599..592.579.....%...+..808...............386..*...............761..................... +663..462...........*..........109..706*.................=.............553........712......*971......674.396...635*.......................... +........../...728.952...413......*......744.......%..........................300..*....782................*.......742..&424........41+...564 +........375...%.........*......450.456.$.........714........851.327..#...+......*...+.......179.630....854.................................. +..251................195...887.....*........*209.......430.*......-.83.596....956..966.274.%.....*........................83.359........411. +....%.......................*..........89.........194..+...491.........................&.....*.762..+741..........598.......*.....910..*.... +..........618+..............677........*..598........+..........-.....58....290...........795...........................*.....580.&....559.. +...................561..............910......-..321....834....602.752*....=..+........191..............463....@..........792..*............. +............216.......%...722*668.....................$..................109............*....222...195*.......689....380.......637.......... +.....846.......*..436..............=827...263@.764*.......*.464.................729.....934...*......................................289+... +.127*.......757.....&......./954...................965..664........./......716*.+...........266....781.........989..........844...$......... +................57.....................&118......=...........385.623...245..............345........*.....615-.....*..........*...768........ +...538...........#..860......................783.460..........*............401.............*796..354..............37......797........725.193 +....*..#620../.........*..........578..54...*..........780..251...634..946....*........................./....702........................*... +..202.......815........724....#..............822..972...................$..........*.....#....@........27.....*...........268.....347....... +.................+..........98.....703..............&....*52.....320.............670...318....734.............47..................+....239.. +.953*919...=......273................=...454.....@....601...........*...958.........................+.................758...=............... +..........905./50.........@...................971..................762.*..................169........915.682..........=......533.......502.. +.....884.................24...........262.........@.....531..698.......234.................................................%.......149..*... +....................834.....994.......*........266.....*......*............................................/.....941.434...812.......*..211. +.............133......*......*.....613...85..........871.......497..346...737....88.....176.....192$........128.*.......&......./163.26..... +....734..543....*.....656....461........*......531..................*........../...*..&................$971.....931......................... +................606....................506............................779.......30...211.....243..........................153...504......... diff --git a/2023/day03_2/src/main/resources/small_input b/2023/day03_2/src/main/resources/small_input new file mode 100644 index 0000000..624ea4f --- /dev/null +++ b/2023/day03_2/src/main/resources/small_input @@ -0,0 +1,10 @@ +467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.. \ No newline at end of file diff --git a/2023/day04_1/.gitignore b/2023/day04_1/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/2023/day04_1/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/2023/day04_1/.idea/.gitignore b/2023/day04_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2023/day04_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2023/day04_1/.idea/inspectionProfiles/Project_Default.xml b/2023/day04_1/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2023/day04_1/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2023/day04_1/.idea/kotlinc.xml b/2023/day04_1/.idea/kotlinc.xml new file mode 100644 index 0000000..5cba058 --- /dev/null +++ b/2023/day04_1/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2023/day04_1/.idea/libraries/KotlinJavaRuntime.xml b/2023/day04_1/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..3937c2d --- /dev/null +++ b/2023/day04_1/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day04_1/.idea/misc.xml b/2023/day04_1/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2023/day04_1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day04_1/.idea/modules.xml b/2023/day04_1/.idea/modules.xml new file mode 100644 index 0000000..6abc551 --- /dev/null +++ b/2023/day04_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2023/day04_1/.idea/sonarlint/issuestore/index.pb b/2023/day04_1/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/2023/day04_1/.idea/sonarlint/securityhotspotstore/index.pb b/2023/day04_1/.idea/sonarlint/securityhotspotstore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/2023/day04_1/.idea/vcs.xml b/2023/day04_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2023/day04_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day04_1/day04_1.iml b/2023/day04_1/day04_1.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day04_1/day04_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day04_1/src/main/kotlin/Main.kt b/2023/day04_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..bac10d5 --- /dev/null +++ b/2023/day04_1/src/main/kotlin/Main.kt @@ -0,0 +1,70 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 4, Part 1 starting!!!") + + val games = HashMap() + + File(args[0]).forEachLine { + parseLine(it,games) + } + + var finalScore = 0 + games.forEach { (_, u) -> finalScore += u} + + println("Final score = $finalScore") + + println("AOC 2023, Day 4, Part 1 completed!!") +} + +fun parseLine(line:String, games:HashMap) { + val cardNumber = getCardNumber(line) + val winningDraws = getWinningDraws(line) + val myCard = getMyCard(line) + var wins = 0 + myCard.stream().forEach { + if (winningDraws.contains(it)) { + wins++ + } + } + + games[cardNumber] = countScore(wins) +} + +fun countScore(wins:Int):Int { + if(wins == 0) { + return 0 + } + if(wins == 1) { + return 1 + } + return 2 * countScore(wins - 1) +} + +fun getCardNumber(line:String):Int { + return line.split(':')[0].substring(5).trim().toInt() +} + +fun getWinningDraws(line:String):List { + val list = ArrayList() + val str = line.split(':')[1].split('|')[0] + for(strNumber in str.split(' ')) { + if(strNumber.isBlank()) { + continue + } + list.add(strNumber.toInt()) + } + return list +} + +fun getMyCard(line: String):List { + val list = ArrayList() + val str = line.split(':')[1].split('|')[1] + for(strNumber in str.split(' ')) { + if(strNumber.isBlank()) { + continue + } + list.add(strNumber.toInt()) + } + return list +} \ No newline at end of file diff --git a/2023/day04_1/src/main/resources/input b/2023/day04_1/src/main/resources/input new file mode 100644 index 0000000..704fc54 --- /dev/null +++ b/2023/day04_1/src/main/resources/input @@ -0,0 +1,190 @@ +Card 1: 2 15 17 11 64 59 45 41 61 19 | 4 36 62 43 94 41 24 25 13 83 97 86 61 90 67 7 15 58 18 19 38 17 49 52 37 +Card 2: 41 62 67 93 88 12 78 51 95 49 | 55 63 89 78 45 11 62 50 81 9 32 82 15 36 74 54 4 58 5 56 44 83 90 49 34 +Card 3: 51 22 38 33 85 23 56 76 60 93 | 94 40 61 37 38 82 93 96 13 50 81 65 56 26 4 18 86 30 8 16 60 27 23 48 51 +Card 4: 51 6 90 10 97 65 19 17 24 3 | 93 82 10 13 17 3 90 74 14 7 77 38 70 97 72 60 6 79 65 94 24 19 51 45 28 +Card 5: 76 61 43 95 41 2 40 58 30 96 | 72 23 69 5 30 3 10 17 78 20 13 86 60 81 90 46 96 39 6 32 31 73 65 95 62 +Card 6: 32 70 49 99 27 26 75 96 91 4 | 15 74 28 2 17 82 55 96 88 11 95 77 12 38 91 3 56 44 7 32 19 94 85 27 97 +Card 7: 38 21 90 66 46 32 55 94 72 75 | 3 10 90 77 41 99 46 82 65 72 9 21 66 94 80 22 97 56 93 61 18 81 34 76 64 +Card 8: 32 36 87 79 4 17 1 77 16 63 | 9 63 23 25 91 82 35 74 28 72 6 52 56 12 39 99 57 46 15 76 85 2 75 77 96 +Card 9: 42 5 58 80 96 88 37 30 49 69 | 26 6 17 71 46 51 45 10 62 33 38 23 42 74 50 61 95 11 93 57 14 22 72 85 86 +Card 10: 10 74 58 71 57 35 34 96 77 18 | 14 27 22 18 70 42 56 94 76 74 85 73 61 34 88 45 39 64 35 87 90 58 91 75 54 +Card 11: 24 26 43 62 66 93 38 51 95 86 | 31 75 23 91 12 3 90 9 36 87 76 58 40 35 56 65 17 74 61 93 20 71 82 92 73 +Card 12: 2 25 63 37 64 81 20 15 28 88 | 67 26 12 6 58 37 69 93 83 52 81 25 19 30 80 54 73 21 86 20 8 57 47 32 60 +Card 13: 48 37 14 80 51 17 85 26 40 33 | 80 7 79 38 8 74 10 78 89 16 81 84 19 49 86 83 63 82 40 58 25 47 53 34 4 +Card 14: 93 27 7 80 63 89 50 96 3 15 | 6 19 40 46 51 29 9 86 39 77 4 54 38 41 67 69 1 56 5 35 30 17 71 2 43 +Card 15: 33 72 28 75 56 22 16 38 44 51 | 81 67 79 73 52 40 69 43 12 77 31 41 23 14 64 58 5 88 95 13 99 6 42 83 38 +Card 16: 36 82 59 39 57 26 61 45 60 65 | 66 51 24 1 4 78 17 16 74 95 34 47 75 6 67 44 48 14 10 89 46 2 31 18 68 +Card 17: 40 50 36 8 54 17 29 13 89 98 | 6 59 60 57 18 30 80 32 46 77 86 35 48 84 91 4 38 99 17 33 3 15 82 83 62 +Card 18: 81 11 66 67 19 65 39 64 20 9 | 25 14 60 2 50 97 43 18 36 24 89 74 94 71 51 45 5 34 52 31 90 6 48 40 55 +Card 19: 41 81 99 97 18 92 79 82 83 62 | 97 34 41 76 87 60 21 63 93 55 77 92 42 56 80 94 81 36 11 1 83 70 52 5 29 +Card 20: 50 94 73 61 56 88 35 48 54 21 | 89 35 83 42 45 12 61 18 68 52 13 25 88 54 6 74 21 57 50 56 34 73 48 94 46 +Card 21: 95 69 16 96 19 86 94 74 33 1 | 19 95 86 16 94 76 17 39 5 1 97 27 44 69 74 96 29 48 14 92 33 7 12 91 42 +Card 22: 17 78 32 62 96 43 68 23 97 52 | 97 28 87 26 23 14 78 39 92 56 31 3 32 52 13 43 80 62 17 69 68 5 96 25 75 +Card 23: 57 93 4 6 2 34 18 80 99 9 | 9 53 58 19 35 6 46 87 86 36 59 17 26 54 39 52 99 20 69 18 25 30 34 41 42 +Card 24: 72 43 5 36 81 31 77 76 58 48 | 75 48 31 88 33 38 37 69 40 25 4 93 35 23 76 36 64 44 6 65 59 15 43 17 28 +Card 25: 14 52 98 94 85 95 27 54 67 34 | 54 14 19 3 24 36 6 52 16 95 76 61 23 8 98 34 28 99 67 85 27 55 70 59 94 +Card 26: 33 15 53 51 14 47 12 83 6 48 | 25 15 51 33 12 53 60 49 98 47 30 89 78 83 88 85 6 7 38 92 48 93 74 14 9 +Card 27: 72 33 73 12 18 13 15 88 82 39 | 23 33 72 13 18 1 12 15 64 8 59 73 48 31 40 57 76 39 52 88 89 36 82 41 67 +Card 28: 42 32 84 56 53 69 5 15 8 63 | 88 32 91 44 62 37 69 72 98 29 8 82 21 5 56 15 6 42 58 61 89 35 96 84 59 +Card 29: 51 41 27 43 38 63 67 26 8 50 | 52 8 1 32 26 59 4 67 27 98 75 11 54 14 50 16 70 66 2 86 62 37 65 38 55 +Card 30: 79 88 87 54 17 18 16 58 57 1 | 54 17 68 89 10 29 97 16 72 57 2 38 12 65 98 11 1 33 64 40 79 63 70 88 18 +Card 31: 61 75 59 95 28 91 57 54 55 82 | 19 57 30 95 54 81 64 28 94 92 3 80 10 63 6 83 88 69 59 15 27 93 96 40 38 +Card 32: 67 44 87 82 49 2 85 79 35 77 | 65 21 63 44 4 52 28 89 11 87 37 97 76 71 64 96 69 79 93 13 33 5 7 58 35 +Card 33: 34 69 25 16 38 4 48 28 39 80 | 90 71 48 27 46 54 19 16 69 12 6 59 25 17 10 81 47 30 28 13 66 38 58 4 80 +Card 34: 65 48 49 80 28 9 22 57 47 95 | 28 59 79 2 4 89 64 98 14 90 18 22 92 52 3 37 95 87 74 54 43 26 51 42 88 +Card 35: 60 8 75 58 47 63 90 71 93 50 | 60 9 24 63 98 66 39 91 46 34 86 67 16 95 53 73 48 87 75 96 44 90 68 26 93 +Card 36: 31 61 33 38 70 46 2 81 73 58 | 49 67 79 3 20 64 96 62 81 82 54 57 70 30 43 56 71 86 6 19 48 93 58 15 27 +Card 37: 86 62 46 70 33 84 90 66 89 96 | 56 39 63 53 45 80 49 61 52 64 12 69 74 26 44 86 96 62 27 31 78 2 28 21 16 +Card 38: 95 40 44 15 99 76 85 20 38 11 | 57 22 23 29 69 90 48 51 66 24 11 32 33 25 92 94 70 88 78 39 28 60 77 55 31 +Card 39: 67 40 10 87 93 47 23 98 96 91 | 14 30 78 72 70 99 52 65 84 12 18 75 59 85 83 89 55 11 82 34 63 10 97 54 69 +Card 40: 95 51 94 2 36 99 98 46 87 82 | 1 40 18 73 50 82 66 14 65 85 83 45 89 58 79 55 84 80 90 72 22 5 38 44 69 +Card 41: 68 75 93 29 66 95 27 46 23 82 | 8 60 39 33 41 36 25 73 94 89 50 71 85 19 51 30 53 45 9 31 83 99 5 32 52 +Card 42: 73 48 37 23 32 19 72 52 58 91 | 35 19 55 9 23 79 62 87 72 58 95 68 20 38 5 48 60 37 73 46 91 12 74 52 32 +Card 43: 42 39 19 59 11 50 88 31 10 9 | 77 11 39 56 42 67 22 12 88 57 75 79 80 6 92 86 99 33 59 90 89 93 68 70 61 +Card 44: 86 12 3 41 71 82 6 48 97 93 | 49 75 31 45 41 83 10 86 8 91 9 70 97 69 52 77 51 36 34 14 81 28 2 40 64 +Card 45: 51 9 72 44 18 14 40 97 2 25 | 83 80 62 22 7 34 88 33 17 23 38 81 70 89 26 35 57 78 46 76 4 61 56 98 55 +Card 46: 22 59 61 94 67 87 21 18 12 69 | 50 22 60 21 67 26 59 94 28 33 30 12 16 69 4 27 95 18 61 53 56 47 85 88 87 +Card 47: 91 58 84 29 4 60 77 41 83 97 | 70 35 40 17 62 41 9 59 26 76 78 16 25 92 91 95 71 77 63 21 6 67 54 46 49 +Card 48: 90 56 13 75 73 2 8 62 21 88 | 38 88 76 75 8 2 82 77 56 73 28 18 59 21 65 90 23 94 5 13 15 79 26 1 36 +Card 49: 84 14 99 51 58 28 63 36 48 91 | 94 46 6 61 2 9 40 38 64 63 91 16 49 81 70 48 80 36 51 58 84 98 96 34 60 +Card 50: 79 98 99 11 7 34 38 52 74 27 | 21 57 11 19 89 94 72 52 81 62 92 79 32 77 28 74 84 86 80 69 83 38 98 3 34 +Card 51: 58 60 15 93 24 72 94 29 59 12 | 71 72 7 86 23 39 65 87 76 22 6 74 69 94 46 52 91 60 96 24 93 47 4 15 59 +Card 52: 6 92 21 7 9 55 17 33 23 16 | 28 69 86 94 34 21 95 51 22 41 99 87 46 1 49 36 90 76 35 30 64 5 44 93 58 +Card 53: 57 10 81 4 93 79 51 87 28 50 | 38 34 97 15 49 89 59 37 25 48 70 41 98 33 78 87 95 85 35 71 32 30 96 67 36 +Card 54: 25 41 26 14 99 98 71 83 31 54 | 68 17 28 80 79 10 31 99 54 83 27 14 25 32 26 85 42 76 33 49 8 24 67 71 41 +Card 55: 38 26 25 70 78 37 13 76 31 73 | 82 10 2 51 13 8 98 12 19 77 84 89 93 22 54 35 23 31 69 42 43 25 39 57 94 +Card 56: 31 25 88 98 23 3 2 58 99 67 | 46 27 75 97 84 53 9 47 64 49 23 92 15 74 44 78 58 56 83 30 31 7 5 2 94 +Card 57: 50 61 25 29 59 1 47 72 65 84 | 72 74 97 28 30 75 56 61 44 40 62 95 4 8 64 22 34 25 14 16 50 92 65 39 13 +Card 58: 73 65 94 47 90 35 95 12 81 78 | 86 87 24 11 1 81 96 33 12 18 74 41 9 22 5 44 48 82 68 67 88 94 20 59 90 +Card 59: 41 27 3 55 16 83 49 75 51 88 | 33 66 74 58 60 72 75 67 78 55 68 95 81 3 39 86 69 94 92 4 5 44 57 26 56 +Card 60: 33 93 56 90 16 46 65 78 13 6 | 55 41 70 6 63 69 90 82 22 17 66 2 53 79 49 25 10 34 47 54 43 58 59 81 68 +Card 61: 72 45 87 76 64 80 96 22 67 98 | 69 25 90 48 67 88 30 34 38 98 19 73 86 8 99 35 44 95 91 36 63 37 2 13 66 +Card 62: 96 68 19 52 97 83 60 67 20 35 | 21 96 30 58 10 7 40 25 92 33 15 69 61 34 6 81 87 75 41 16 51 27 8 4 86 +Card 63: 17 1 45 26 82 78 85 15 89 8 | 49 38 16 22 71 50 81 74 87 61 14 19 64 93 96 23 59 56 76 86 53 6 7 80 41 +Card 64: 3 17 22 94 37 39 67 73 27 4 | 8 27 22 5 28 53 47 52 94 25 29 54 1 59 98 16 78 9 65 91 61 74 73 60 37 +Card 65: 80 48 70 23 99 11 20 31 54 94 | 73 69 21 10 66 90 80 29 55 67 92 20 96 94 79 93 31 30 17 14 27 75 13 95 71 +Card 66: 14 79 31 27 89 95 69 63 12 67 | 36 85 67 24 87 72 89 26 17 31 27 55 10 32 14 63 71 79 13 12 81 69 28 95 30 +Card 67: 87 44 51 53 37 69 39 96 90 16 | 22 63 83 31 32 76 66 68 29 30 53 48 4 72 82 46 95 80 17 21 56 51 89 12 77 +Card 68: 39 27 17 15 50 65 38 94 84 42 | 42 84 17 50 52 47 67 93 13 35 7 26 23 95 39 81 94 15 78 27 43 21 38 55 86 +Card 69: 13 22 8 54 61 77 75 31 1 67 | 68 54 15 23 40 58 67 3 71 78 90 33 44 22 57 19 8 30 74 38 48 41 9 25 65 +Card 70: 10 43 33 21 31 6 94 46 82 83 | 48 62 6 19 67 72 46 81 75 5 54 8 56 92 37 76 96 71 32 36 26 14 30 79 9 +Card 71: 91 9 15 33 37 22 61 74 14 70 | 79 31 18 42 43 40 26 56 95 45 86 76 65 23 3 94 24 35 4 2 68 51 25 12 80 +Card 72: 30 79 24 55 42 8 13 90 68 73 | 37 61 34 94 51 30 3 10 26 19 50 42 40 31 80 86 66 27 83 90 73 79 99 14 76 +Card 73: 25 88 63 85 56 49 30 46 10 99 | 46 68 67 60 11 78 6 85 12 97 91 21 27 81 39 48 69 44 25 63 22 10 3 61 79 +Card 74: 21 3 32 71 98 69 44 78 34 11 | 83 56 29 18 34 9 63 92 53 22 61 45 41 38 82 27 49 5 32 99 69 17 55 66 96 +Card 75: 68 92 32 65 49 38 3 56 17 44 | 47 68 6 1 10 24 66 84 60 2 48 56 57 61 51 35 28 17 82 52 98 81 23 75 38 +Card 76: 30 57 5 8 10 95 45 85 54 3 | 53 2 54 34 23 12 48 16 37 92 85 27 83 8 21 44 81 26 49 67 36 25 52 47 68 +Card 77: 31 84 72 26 83 55 20 42 65 61 | 53 96 17 18 59 21 23 77 78 15 43 58 66 3 60 55 38 45 6 72 44 94 11 79 19 +Card 78: 62 77 52 72 13 24 31 60 29 26 | 74 51 46 67 97 14 71 70 55 94 6 16 65 85 66 80 60 27 32 39 73 61 34 91 69 +Card 79: 69 74 82 58 44 37 86 51 75 20 | 93 70 2 35 30 79 45 56 65 59 22 64 89 36 66 5 34 13 49 43 97 74 7 26 83 +Card 80: 84 16 89 49 81 1 79 44 93 25 | 2 35 29 8 87 21 22 57 9 73 67 82 54 45 71 72 59 5 4 97 70 60 91 7 92 +Card 81: 25 44 10 12 23 79 60 45 96 90 | 62 23 25 40 12 90 42 10 79 45 69 46 9 27 73 59 34 44 29 94 95 86 66 1 58 +Card 82: 42 43 37 18 40 64 75 76 99 3 | 67 42 11 18 91 99 14 90 3 23 73 82 76 40 37 44 28 64 96 16 74 75 55 61 15 +Card 83: 38 89 77 47 66 22 87 59 7 43 | 59 46 7 73 79 23 96 22 28 87 66 32 77 89 98 19 38 18 43 56 15 47 74 95 99 +Card 84: 86 13 97 81 46 12 88 34 92 52 | 88 69 8 2 76 63 95 27 46 31 81 48 75 92 60 33 36 22 34 13 57 30 21 42 98 +Card 85: 57 71 21 43 41 23 18 15 59 93 | 40 8 21 25 19 57 52 71 75 45 16 18 89 99 43 20 27 4 53 98 80 22 7 29 41 +Card 86: 84 43 50 94 92 31 48 8 6 91 | 92 53 6 94 25 41 74 54 62 43 95 79 16 31 8 89 84 30 50 91 58 47 17 96 46 +Card 87: 45 96 17 51 25 40 39 13 78 82 | 66 61 23 13 59 10 1 86 30 62 74 41 34 45 8 65 36 16 78 93 20 92 35 82 90 +Card 88: 29 89 14 85 93 19 56 36 99 15 | 91 14 94 89 96 19 85 71 23 46 21 75 92 7 6 33 60 8 72 81 99 36 29 56 22 +Card 89: 77 79 82 96 75 63 72 59 37 11 | 43 97 11 61 80 68 22 19 71 63 16 18 56 49 9 79 45 36 37 89 1 8 48 4 40 +Card 90: 2 81 33 10 60 57 38 99 95 65 | 3 98 33 80 32 65 45 96 99 61 25 73 74 37 91 6 2 79 38 34 97 89 36 11 5 +Card 91: 31 62 73 12 53 51 64 55 9 20 | 45 76 95 42 81 56 32 62 11 48 93 9 69 79 84 28 46 82 88 96 31 91 13 98 92 +Card 92: 64 5 81 2 59 24 40 74 84 58 | 93 43 67 70 53 20 91 18 49 4 14 52 74 19 79 85 61 86 82 57 38 44 34 9 83 +Card 93: 6 94 85 43 15 67 68 79 81 65 | 15 35 14 78 21 68 86 9 97 99 75 87 23 46 70 30 41 27 18 84 3 50 53 63 79 +Card 94: 61 34 62 94 50 23 69 98 78 60 | 43 9 90 28 49 36 19 97 56 75 62 15 79 70 40 78 24 94 48 88 45 91 66 4 34 +Card 95: 73 26 99 83 45 46 9 50 38 14 | 98 81 63 27 55 28 32 82 92 41 87 60 49 50 99 95 11 89 4 78 17 47 20 15 96 +Card 96: 52 80 3 67 69 57 16 34 40 77 | 70 35 97 2 71 25 1 15 54 26 19 5 83 20 4 99 56 38 51 87 53 47 30 13 96 +Card 97: 54 41 65 23 52 82 81 22 28 47 | 27 90 3 24 15 85 36 88 97 37 4 18 42 50 99 35 83 78 79 46 40 63 92 34 67 +Card 98: 47 56 85 60 12 1 35 88 30 86 | 75 83 15 97 66 74 55 62 9 58 19 82 51 54 61 68 47 7 17 10 39 44 20 96 34 +Card 99: 52 25 39 18 92 17 93 29 6 9 | 22 83 86 51 5 43 20 73 13 66 6 82 24 8 2 11 87 79 57 50 19 35 45 62 49 +Card 100: 27 91 93 24 17 47 80 13 51 8 | 59 78 63 74 81 26 98 64 97 79 6 77 54 83 9 86 69 31 12 10 5 56 34 33 60 +Card 101: 8 45 53 15 57 36 69 47 13 1 | 15 13 79 47 69 36 99 57 25 91 1 8 39 73 90 24 84 93 60 40 53 55 3 45 87 +Card 102: 45 76 11 54 1 15 24 60 20 29 | 25 32 88 5 66 40 16 58 24 70 79 36 29 53 54 86 60 15 78 57 27 92 99 33 30 +Card 103: 46 15 97 62 94 19 99 76 42 93 | 65 19 5 58 3 10 12 24 50 64 54 22 85 31 44 93 30 47 14 21 97 78 2 15 81 +Card 104: 61 83 16 66 81 55 52 36 76 95 | 28 51 36 20 11 6 27 33 92 57 94 96 45 9 15 2 63 72 58 44 5 81 43 1 66 +Card 105: 44 12 34 11 26 72 57 55 38 69 | 41 57 62 26 14 72 89 99 34 69 28 10 68 70 2 50 98 37 12 38 44 71 11 80 55 +Card 106: 43 33 65 67 24 17 58 16 94 9 | 51 54 71 14 95 18 42 45 73 97 24 25 92 49 29 83 38 10 30 61 22 79 43 60 65 +Card 107: 74 9 87 65 8 71 6 51 47 79 | 74 5 6 71 65 82 57 88 66 76 70 8 51 87 54 81 96 79 7 9 47 12 24 52 50 +Card 108: 32 87 49 10 41 34 68 79 33 23 | 16 67 63 69 60 37 8 2 47 78 5 9 34 61 10 42 36 95 68 24 75 77 85 56 18 +Card 109: 98 95 89 44 76 63 83 99 71 79 | 49 64 88 18 67 48 23 37 32 99 65 14 1 63 80 84 60 5 87 94 70 8 96 16 35 +Card 110: 73 30 38 99 23 57 68 39 20 45 | 74 9 1 8 35 42 23 24 83 66 76 90 30 56 82 15 6 49 88 45 96 62 43 27 16 +Card 111: 48 62 64 91 57 12 68 30 25 18 | 78 3 21 29 20 77 91 74 72 1 18 28 19 25 44 52 34 12 64 17 6 7 57 5 14 +Card 112: 62 10 63 18 34 55 72 86 12 45 | 82 7 27 95 76 64 11 31 42 38 75 15 69 29 79 20 17 8 16 39 60 24 87 81 9 +Card 113: 91 58 97 55 46 75 74 53 72 2 | 82 7 17 38 89 81 14 24 33 13 11 91 79 93 96 18 2 35 80 15 45 63 41 46 37 +Card 114: 76 22 44 83 99 59 21 67 12 17 | 78 68 63 53 16 29 31 90 70 18 69 9 40 38 32 8 27 85 67 26 62 56 97 35 94 +Card 115: 11 49 95 65 18 67 29 91 45 25 | 37 44 78 20 88 35 32 60 90 40 26 5 68 53 70 31 74 63 21 4 87 46 12 92 91 +Card 116: 50 25 19 90 91 8 80 44 9 38 | 40 47 45 53 99 1 74 65 49 67 16 29 81 70 78 89 42 80 97 76 66 21 24 95 83 +Card 117: 38 7 34 3 57 30 29 44 52 21 | 5 48 70 24 26 50 32 27 1 4 25 96 54 16 90 61 33 67 89 78 83 22 72 6 47 +Card 118: 35 25 23 73 66 57 86 21 27 8 | 9 98 50 78 75 99 83 10 70 97 49 85 14 73 46 29 16 5 60 82 15 45 62 37 3 +Card 119: 51 84 3 55 90 61 93 18 38 35 | 63 50 60 78 87 74 95 58 26 27 34 11 81 30 28 99 94 89 64 1 96 65 72 56 76 +Card 120: 17 74 98 56 54 31 10 26 60 45 | 20 90 98 46 31 15 89 10 94 26 35 69 79 60 58 11 74 77 50 30 64 56 9 45 12 +Card 121: 27 43 12 84 96 70 61 19 92 46 | 59 18 91 25 23 97 32 72 4 21 95 93 85 60 81 9 58 30 53 94 90 69 48 89 2 +Card 122: 88 85 3 82 19 98 72 38 87 93 | 60 3 31 93 51 81 82 23 69 14 72 21 95 45 76 59 86 53 85 73 19 56 61 39 35 +Card 123: 22 6 50 96 91 15 33 7 29 57 | 72 67 62 78 91 96 23 7 17 69 26 29 75 2 57 20 43 74 82 68 56 92 54 66 48 +Card 124: 73 15 66 38 69 4 83 45 70 95 | 19 71 6 5 15 17 95 1 34 3 68 70 42 75 12 46 38 8 83 39 2 16 74 79 36 +Card 125: 32 86 2 71 72 53 73 67 12 85 | 60 31 70 99 33 45 95 22 79 41 25 3 46 5 20 75 37 55 35 18 36 59 8 63 80 +Card 126: 44 96 40 68 25 34 13 72 2 80 | 47 18 77 23 63 80 17 73 3 79 21 15 11 58 54 96 95 62 51 41 75 44 40 24 97 +Card 127: 4 34 21 87 85 1 44 72 71 24 | 72 46 83 10 50 77 87 49 91 85 1 42 66 38 54 89 35 86 59 65 71 15 34 4 99 +Card 128: 24 86 90 74 48 83 88 13 2 38 | 8 16 10 92 76 44 1 59 34 37 80 52 27 70 66 26 22 43 6 84 30 21 60 77 74 +Card 129: 28 71 81 50 31 13 6 63 58 51 | 5 35 62 15 72 47 76 44 32 34 2 14 50 45 77 18 24 81 78 59 48 40 9 7 26 +Card 130: 19 68 83 40 64 99 55 45 17 9 | 22 77 99 80 90 13 88 44 57 26 85 81 15 56 30 54 18 95 6 83 51 55 94 93 73 +Card 131: 47 44 33 5 59 74 1 21 46 3 | 4 14 87 41 82 63 31 45 47 23 55 94 89 39 86 20 52 66 10 59 48 34 68 21 12 +Card 132: 78 15 99 9 40 5 34 75 3 79 | 70 30 80 23 95 66 85 7 43 27 12 83 22 44 21 10 31 14 26 45 68 57 49 94 53 +Card 133: 54 14 80 44 33 11 53 69 1 71 | 64 2 56 28 84 76 26 32 92 3 39 47 69 9 6 75 50 99 95 30 35 73 98 13 59 +Card 134: 58 85 26 9 2 94 59 23 57 52 | 21 39 80 34 50 27 45 76 16 75 54 92 8 66 53 32 17 74 83 13 1 93 99 88 46 +Card 135: 43 81 39 26 61 75 13 40 72 48 | 9 87 61 99 51 81 59 55 19 13 35 74 60 45 39 40 65 33 78 46 26 8 71 7 44 +Card 136: 76 86 15 32 6 81 29 16 22 92 | 88 73 92 50 75 79 82 61 86 41 30 69 18 76 45 15 67 16 29 81 93 65 32 14 6 +Card 137: 37 65 99 6 61 45 27 86 68 84 | 6 7 61 67 65 33 86 64 59 90 96 54 99 23 85 68 18 55 40 4 10 37 97 77 73 +Card 138: 39 80 50 4 53 73 48 54 12 60 | 63 50 72 33 17 11 24 18 54 58 68 7 30 75 22 85 87 40 19 44 69 90 97 43 36 +Card 139: 8 86 87 39 58 56 80 34 85 81 | 25 9 2 26 19 61 96 72 36 45 6 21 91 7 34 89 59 56 87 8 49 98 85 74 97 +Card 140: 19 21 14 84 81 4 62 24 71 77 | 96 14 77 71 38 24 45 51 40 81 5 19 99 57 48 65 72 4 60 62 41 79 87 49 2 +Card 141: 87 32 58 9 88 63 22 71 83 18 | 37 26 51 34 44 22 84 48 58 65 3 62 45 90 60 70 74 81 57 68 18 47 85 73 40 +Card 142: 17 56 69 87 23 26 25 32 49 47 | 65 83 15 63 73 30 93 85 45 27 84 14 58 76 38 33 8 94 61 74 37 36 52 41 78 +Card 143: 52 86 94 23 28 58 81 71 30 21 | 23 96 75 87 55 50 21 76 9 80 97 69 35 33 27 71 86 94 30 42 84 10 3 14 62 +Card 144: 80 8 67 32 42 49 76 93 41 90 | 21 59 34 80 71 37 28 33 9 68 95 31 26 47 73 94 41 13 48 27 96 7 85 17 62 +Card 145: 22 13 74 92 75 17 19 48 58 55 | 36 31 20 92 11 76 23 51 71 84 59 88 89 38 1 90 97 46 30 41 77 6 17 64 2 +Card 146: 51 81 54 87 95 28 30 44 88 85 | 96 1 35 64 45 97 54 84 4 86 40 49 15 28 19 75 10 2 68 60 66 59 12 18 63 +Card 147: 44 45 70 23 71 37 17 59 97 53 | 88 9 26 22 62 68 6 96 77 31 95 50 54 42 14 5 30 24 48 3 67 75 56 49 7 +Card 148: 38 54 1 75 6 24 70 82 74 94 | 23 34 92 5 14 83 45 88 81 21 43 78 87 56 63 36 48 4 51 60 42 25 18 2 35 +Card 149: 11 87 55 57 8 27 48 67 12 45 | 3 37 54 81 2 15 92 30 5 10 38 98 64 93 99 68 36 50 88 97 35 29 79 46 58 +Card 150: 65 89 66 91 37 3 49 19 29 17 | 24 34 69 99 15 58 56 28 90 7 73 75 72 66 77 49 8 17 21 74 84 67 19 29 54 +Card 151: 86 4 93 67 52 14 43 99 9 38 | 34 60 72 47 24 76 38 67 48 85 14 43 93 92 49 45 18 25 86 9 31 99 63 41 4 +Card 152: 79 39 53 12 11 17 27 51 92 5 | 12 79 51 75 92 2 56 39 81 67 17 5 53 55 72 48 60 11 18 27 98 77 6 66 86 +Card 153: 22 95 26 5 32 14 7 66 8 35 | 60 32 96 25 8 57 73 95 74 27 66 26 7 1 14 5 12 34 21 35 22 87 77 24 85 +Card 154: 79 4 94 63 9 96 21 86 59 46 | 52 76 55 94 57 74 46 15 38 83 32 4 9 73 62 43 36 98 89 18 96 45 79 25 35 +Card 155: 53 58 97 98 67 5 8 46 31 54 | 76 5 46 80 30 54 31 33 51 97 47 67 8 83 10 58 60 73 98 71 62 82 48 95 77 +Card 156: 3 1 23 18 71 21 8 79 84 2 | 59 8 18 87 29 14 46 99 61 90 66 21 68 62 2 86 31 88 23 74 38 10 73 7 84 +Card 157: 24 3 22 90 56 15 78 61 1 81 | 33 70 73 5 71 93 30 67 53 18 62 7 19 85 47 65 43 82 69 75 57 46 44 99 50 +Card 158: 2 8 21 71 24 82 47 53 11 25 | 27 25 35 20 3 53 73 96 38 7 65 89 16 78 97 85 74 18 56 49 32 88 59 42 33 +Card 159: 69 81 74 51 35 90 33 58 97 22 | 89 45 91 1 77 10 72 35 31 42 28 71 97 80 87 22 64 33 95 3 68 56 69 82 67 +Card 160: 99 34 53 3 6 48 93 1 42 13 | 50 35 79 89 26 5 91 10 57 63 30 72 64 17 37 40 90 88 78 18 25 95 67 58 14 +Card 161: 41 39 34 75 50 52 94 71 82 13 | 26 8 87 95 20 91 49 96 65 36 51 24 46 69 83 52 47 41 79 11 50 73 89 70 44 +Card 162: 48 87 68 57 81 52 49 60 28 15 | 92 11 94 54 45 39 7 84 93 67 42 64 26 90 6 79 4 3 23 96 41 37 97 24 50 +Card 163: 67 41 11 38 81 56 45 4 76 70 | 32 87 62 51 58 27 91 37 29 90 22 43 77 97 35 46 93 88 23 31 99 21 79 18 47 +Card 164: 2 79 35 21 96 29 22 10 69 99 | 47 91 17 60 20 31 37 81 53 84 16 77 4 46 75 26 78 93 32 76 52 8 27 59 10 +Card 165: 32 37 54 95 66 64 59 19 28 44 | 96 49 3 75 94 63 98 65 4 7 2 73 50 24 78 31 21 42 82 25 70 79 35 38 1 +Card 166: 24 61 72 44 27 38 81 59 69 89 | 85 29 98 3 73 63 25 1 16 96 57 8 78 92 82 20 79 94 71 62 2 49 97 93 99 +Card 167: 55 22 60 95 80 25 28 56 69 18 | 22 38 29 46 90 41 59 93 94 57 74 43 97 49 27 34 19 64 55 81 33 37 13 15 89 +Card 168: 90 51 39 37 67 12 65 14 6 4 | 64 70 6 37 25 26 4 48 43 91 28 90 27 41 87 74 14 39 56 51 9 67 12 65 34 +Card 169: 57 11 25 88 28 82 60 95 27 26 | 42 82 35 47 87 14 11 88 63 96 65 43 95 25 99 5 26 20 28 57 60 40 76 27 7 +Card 170: 31 34 19 29 1 55 20 61 10 94 | 48 77 3 87 91 37 38 57 75 53 12 60 76 45 4 68 13 73 35 7 30 20 6 14 69 +Card 171: 67 10 59 89 52 53 40 17 64 29 | 88 27 59 1 75 10 95 67 34 40 83 4 82 64 2 52 89 29 53 33 8 71 91 85 17 +Card 172: 87 63 66 32 37 96 3 29 88 90 | 96 18 87 17 14 69 58 65 52 31 1 44 37 60 5 32 41 90 7 49 29 66 35 77 82 +Card 173: 70 84 52 81 63 32 61 94 38 97 | 24 34 63 52 81 99 8 57 66 50 94 84 70 38 61 86 15 32 47 78 45 77 95 76 97 +Card 174: 4 74 29 30 24 87 91 92 5 2 | 55 86 5 70 12 94 96 89 58 29 14 62 4 99 48 81 91 45 27 54 31 22 68 43 76 +Card 175: 91 78 3 20 86 98 89 82 13 57 | 24 76 59 66 73 1 5 82 45 6 92 3 33 43 17 83 12 14 91 71 19 46 54 96 25 +Card 176: 12 55 93 3 43 81 28 59 72 76 | 4 90 55 84 69 74 46 45 65 17 26 71 70 21 29 23 61 99 92 44 40 41 51 8 57 +Card 177: 56 5 89 93 62 17 2 6 50 40 | 35 60 5 47 76 92 15 2 34 28 69 29 19 9 27 49 1 88 57 48 84 8 26 59 91 +Card 178: 1 93 34 57 67 58 84 37 42 91 | 42 69 41 34 91 28 75 70 1 93 4 49 66 6 37 38 32 89 46 44 62 81 9 22 73 +Card 179: 90 95 7 29 42 51 22 39 84 75 | 75 25 80 96 55 41 73 43 26 42 46 7 86 22 84 1 39 50 90 12 3 29 51 95 81 +Card 180: 72 76 4 68 9 41 16 44 61 13 | 63 92 39 68 5 13 11 65 50 25 76 55 71 29 82 31 53 59 2 99 74 16 1 90 41 +Card 181: 29 63 61 82 33 94 51 32 50 84 | 80 85 7 8 54 30 87 56 90 75 69 60 25 43 53 47 72 81 1 59 97 28 52 46 10 +Card 182: 98 45 44 32 19 6 51 49 64 84 | 64 20 90 6 4 54 19 80 51 72 69 99 29 44 45 46 84 65 43 53 74 23 42 66 49 +Card 183: 23 35 4 50 88 87 38 7 19 2 | 76 79 80 5 66 30 74 29 37 94 11 50 1 67 13 27 90 40 70 91 71 12 81 9 33 +Card 184: 55 74 2 73 75 22 32 71 67 27 | 92 19 9 24 74 73 8 67 30 18 14 71 77 45 85 72 15 69 13 27 94 63 98 40 93 +Card 185: 14 73 72 38 16 40 83 28 37 96 | 19 74 49 96 90 48 26 1 95 54 3 82 50 41 43 64 69 80 77 97 52 16 23 25 31 +Card 186: 24 91 35 21 16 71 94 95 25 53 | 60 5 17 58 82 35 45 80 28 16 13 53 68 97 86 8 52 61 65 1 27 67 91 43 3 +Card 187: 96 39 77 52 97 33 80 99 18 15 | 48 8 85 79 81 33 43 90 62 14 36 65 2 32 82 15 91 23 34 68 56 87 11 57 73 +Card 188: 8 35 86 95 94 65 26 11 96 31 | 2 98 50 33 59 93 28 49 87 29 79 8 23 6 54 16 82 96 83 61 27 60 53 62 30 +Card 189: 60 27 78 55 84 1 36 28 20 77 | 45 85 75 8 54 74 58 73 17 68 13 53 47 79 7 65 35 40 51 87 18 37 71 72 21 +Card 190: 41 31 39 33 54 42 71 47 59 24 | 21 96 85 12 81 83 64 87 93 77 92 38 25 52 20 88 65 10 29 16 95 98 22 37 15 diff --git a/2023/day04_1/src/main/resources/small_input b/2023/day04_1/src/main/resources/small_input new file mode 100644 index 0000000..71f208a --- /dev/null +++ b/2023/day04_1/src/main/resources/small_input @@ -0,0 +1,6 @@ +Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 +Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 +Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 +Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 +Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 +Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11 \ No newline at end of file diff --git a/2023/day04_2/.idea/.gitignore b/2023/day04_2/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2023/day04_2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2023/day04_2/.idea/inspectionProfiles/Project_Default.xml b/2023/day04_2/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2023/day04_2/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2023/day04_2/.idea/kotlinc.xml b/2023/day04_2/.idea/kotlinc.xml new file mode 100644 index 0000000..5cba058 --- /dev/null +++ b/2023/day04_2/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2023/day04_2/.idea/libraries/KotlinJavaRuntime.xml b/2023/day04_2/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..3937c2d --- /dev/null +++ b/2023/day04_2/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day04_2/.idea/misc.xml b/2023/day04_2/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2023/day04_2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day04_2/.idea/modules.xml b/2023/day04_2/.idea/modules.xml new file mode 100644 index 0000000..25e2d60 --- /dev/null +++ b/2023/day04_2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2023/day04_2/.idea/sonarlint/issuestore/index.pb b/2023/day04_2/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..f72b8b3 --- /dev/null +++ b/2023/day04_2/.idea/sonarlint/issuestore/index.pb @@ -0,0 +1,13 @@ + +G +src/main/kotlin/Main.kt,d/8/d83ae3847b7d408136086cc5e9e95f5f7c126ed5 +; + day04_2.iml,b/a/ba9008c488eaa4f90f7158e5e77c886629110792 +\ +,.idea/inspectionProfiles/Project_Default.xml,4/9/496a238a6afa168dbaf6efd37bb459331589579c +U +%.idea/libraries/KotlinJavaRuntime.xml,0/2/02ddf5725f2ec9b67991423205d2b1a2009ccd06 +] +-.idea/sonarlint/securityhotspotstore/index.pb,8/8/88a9255124c95bdc913197c120a8d560edc59c8e +S +#.idea/sonarlint/issuestore/index.pb,9/f/9fe84ebb15faf917b7def6236dba604453cc61e0 \ No newline at end of file diff --git a/2023/day04_2/.idea/sonarlint/securityhotspotstore/index.pb b/2023/day04_2/.idea/sonarlint/securityhotspotstore/index.pb new file mode 100644 index 0000000..f72b8b3 --- /dev/null +++ b/2023/day04_2/.idea/sonarlint/securityhotspotstore/index.pb @@ -0,0 +1,13 @@ + +G +src/main/kotlin/Main.kt,d/8/d83ae3847b7d408136086cc5e9e95f5f7c126ed5 +; + day04_2.iml,b/a/ba9008c488eaa4f90f7158e5e77c886629110792 +\ +,.idea/inspectionProfiles/Project_Default.xml,4/9/496a238a6afa168dbaf6efd37bb459331589579c +U +%.idea/libraries/KotlinJavaRuntime.xml,0/2/02ddf5725f2ec9b67991423205d2b1a2009ccd06 +] +-.idea/sonarlint/securityhotspotstore/index.pb,8/8/88a9255124c95bdc913197c120a8d560edc59c8e +S +#.idea/sonarlint/issuestore/index.pb,9/f/9fe84ebb15faf917b7def6236dba604453cc61e0 \ No newline at end of file diff --git a/2023/day04_2/.idea/vcs.xml b/2023/day04_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2023/day04_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day04_2/day04_2.iml b/2023/day04_2/day04_2.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day04_2/day04_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day04_2/src/main/kotlin/Main.kt b/2023/day04_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..5df4633 --- /dev/null +++ b/2023/day04_2/src/main/kotlin/Main.kt @@ -0,0 +1,85 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 4, Part 2 starting!!!") + + val allCards = ArrayList() + val matchedCards = HashMap() + File(args[0]).forEachLine { + allCards.add(parseLine(it)) + } + + allCards.stream().forEach { + val matches = it.countMatches() + val nextCard = it.cardNumber + 1 + println("For Card ${it.cardNumber}, matches = $matches") + for(x in 0 ..(matchedCards[it.cardNumber] ?: 0)) { + for (n in nextCard..(nextCard + (matches - 1))) { + matchedCards[n] = matchedCards[n]?.plus(1) ?: 1 + } + } + } + + // For any cards that doesn't have a matches just increment. + // Otherwise get the matches + 1. + var finalScore = 0 + for(card in allCards) { + if(matchedCards.contains(card.cardNumber)) { + finalScore += (matchedCards[card.cardNumber]!! + 1) + } else { + finalScore++ + } + } + + + println("Final score = $finalScore") + + println("AOC 2023, Day 4, Part 2 completed!!") +} + +class Card(line:String) { + private val rightSideNumbers:List = getRightSideNumbers(line) + private val leftSideNumbers:List = getLeftSideNumbers(line) + val cardNumber:Int = getCardNumber(line) + + fun countMatches():Int { + var matches = 0 + for(n in leftSideNumbers) { + if(rightSideNumbers.contains(n)) + matches++ + } + return matches + } +} + +fun parseLine(line:String):Card { + return Card(line) +} + +fun getCardNumber(line:String):Int { + return line.split(':')[0].substring(5).trim().toInt() +} + +fun getLeftSideNumbers(line:String):List { + val list = ArrayList() + val str = line.split(':')[1].split('|')[0] + for(strNumber in str.split(' ')) { + if(strNumber.isBlank()) { + continue + } + list.add(strNumber.toInt()) + } + return list +} + +fun getRightSideNumbers(line: String):List { + val list = ArrayList() + val str = line.split(':')[1].split('|')[1] + for(strNumber in str.split(' ')) { + if(strNumber.isBlank()) { + continue + } + list.add(strNumber.toInt()) + } + return list +} \ No newline at end of file diff --git a/2023/day04_2/src/main/resources/input b/2023/day04_2/src/main/resources/input new file mode 100644 index 0000000..704fc54 --- /dev/null +++ b/2023/day04_2/src/main/resources/input @@ -0,0 +1,190 @@ +Card 1: 2 15 17 11 64 59 45 41 61 19 | 4 36 62 43 94 41 24 25 13 83 97 86 61 90 67 7 15 58 18 19 38 17 49 52 37 +Card 2: 41 62 67 93 88 12 78 51 95 49 | 55 63 89 78 45 11 62 50 81 9 32 82 15 36 74 54 4 58 5 56 44 83 90 49 34 +Card 3: 51 22 38 33 85 23 56 76 60 93 | 94 40 61 37 38 82 93 96 13 50 81 65 56 26 4 18 86 30 8 16 60 27 23 48 51 +Card 4: 51 6 90 10 97 65 19 17 24 3 | 93 82 10 13 17 3 90 74 14 7 77 38 70 97 72 60 6 79 65 94 24 19 51 45 28 +Card 5: 76 61 43 95 41 2 40 58 30 96 | 72 23 69 5 30 3 10 17 78 20 13 86 60 81 90 46 96 39 6 32 31 73 65 95 62 +Card 6: 32 70 49 99 27 26 75 96 91 4 | 15 74 28 2 17 82 55 96 88 11 95 77 12 38 91 3 56 44 7 32 19 94 85 27 97 +Card 7: 38 21 90 66 46 32 55 94 72 75 | 3 10 90 77 41 99 46 82 65 72 9 21 66 94 80 22 97 56 93 61 18 81 34 76 64 +Card 8: 32 36 87 79 4 17 1 77 16 63 | 9 63 23 25 91 82 35 74 28 72 6 52 56 12 39 99 57 46 15 76 85 2 75 77 96 +Card 9: 42 5 58 80 96 88 37 30 49 69 | 26 6 17 71 46 51 45 10 62 33 38 23 42 74 50 61 95 11 93 57 14 22 72 85 86 +Card 10: 10 74 58 71 57 35 34 96 77 18 | 14 27 22 18 70 42 56 94 76 74 85 73 61 34 88 45 39 64 35 87 90 58 91 75 54 +Card 11: 24 26 43 62 66 93 38 51 95 86 | 31 75 23 91 12 3 90 9 36 87 76 58 40 35 56 65 17 74 61 93 20 71 82 92 73 +Card 12: 2 25 63 37 64 81 20 15 28 88 | 67 26 12 6 58 37 69 93 83 52 81 25 19 30 80 54 73 21 86 20 8 57 47 32 60 +Card 13: 48 37 14 80 51 17 85 26 40 33 | 80 7 79 38 8 74 10 78 89 16 81 84 19 49 86 83 63 82 40 58 25 47 53 34 4 +Card 14: 93 27 7 80 63 89 50 96 3 15 | 6 19 40 46 51 29 9 86 39 77 4 54 38 41 67 69 1 56 5 35 30 17 71 2 43 +Card 15: 33 72 28 75 56 22 16 38 44 51 | 81 67 79 73 52 40 69 43 12 77 31 41 23 14 64 58 5 88 95 13 99 6 42 83 38 +Card 16: 36 82 59 39 57 26 61 45 60 65 | 66 51 24 1 4 78 17 16 74 95 34 47 75 6 67 44 48 14 10 89 46 2 31 18 68 +Card 17: 40 50 36 8 54 17 29 13 89 98 | 6 59 60 57 18 30 80 32 46 77 86 35 48 84 91 4 38 99 17 33 3 15 82 83 62 +Card 18: 81 11 66 67 19 65 39 64 20 9 | 25 14 60 2 50 97 43 18 36 24 89 74 94 71 51 45 5 34 52 31 90 6 48 40 55 +Card 19: 41 81 99 97 18 92 79 82 83 62 | 97 34 41 76 87 60 21 63 93 55 77 92 42 56 80 94 81 36 11 1 83 70 52 5 29 +Card 20: 50 94 73 61 56 88 35 48 54 21 | 89 35 83 42 45 12 61 18 68 52 13 25 88 54 6 74 21 57 50 56 34 73 48 94 46 +Card 21: 95 69 16 96 19 86 94 74 33 1 | 19 95 86 16 94 76 17 39 5 1 97 27 44 69 74 96 29 48 14 92 33 7 12 91 42 +Card 22: 17 78 32 62 96 43 68 23 97 52 | 97 28 87 26 23 14 78 39 92 56 31 3 32 52 13 43 80 62 17 69 68 5 96 25 75 +Card 23: 57 93 4 6 2 34 18 80 99 9 | 9 53 58 19 35 6 46 87 86 36 59 17 26 54 39 52 99 20 69 18 25 30 34 41 42 +Card 24: 72 43 5 36 81 31 77 76 58 48 | 75 48 31 88 33 38 37 69 40 25 4 93 35 23 76 36 64 44 6 65 59 15 43 17 28 +Card 25: 14 52 98 94 85 95 27 54 67 34 | 54 14 19 3 24 36 6 52 16 95 76 61 23 8 98 34 28 99 67 85 27 55 70 59 94 +Card 26: 33 15 53 51 14 47 12 83 6 48 | 25 15 51 33 12 53 60 49 98 47 30 89 78 83 88 85 6 7 38 92 48 93 74 14 9 +Card 27: 72 33 73 12 18 13 15 88 82 39 | 23 33 72 13 18 1 12 15 64 8 59 73 48 31 40 57 76 39 52 88 89 36 82 41 67 +Card 28: 42 32 84 56 53 69 5 15 8 63 | 88 32 91 44 62 37 69 72 98 29 8 82 21 5 56 15 6 42 58 61 89 35 96 84 59 +Card 29: 51 41 27 43 38 63 67 26 8 50 | 52 8 1 32 26 59 4 67 27 98 75 11 54 14 50 16 70 66 2 86 62 37 65 38 55 +Card 30: 79 88 87 54 17 18 16 58 57 1 | 54 17 68 89 10 29 97 16 72 57 2 38 12 65 98 11 1 33 64 40 79 63 70 88 18 +Card 31: 61 75 59 95 28 91 57 54 55 82 | 19 57 30 95 54 81 64 28 94 92 3 80 10 63 6 83 88 69 59 15 27 93 96 40 38 +Card 32: 67 44 87 82 49 2 85 79 35 77 | 65 21 63 44 4 52 28 89 11 87 37 97 76 71 64 96 69 79 93 13 33 5 7 58 35 +Card 33: 34 69 25 16 38 4 48 28 39 80 | 90 71 48 27 46 54 19 16 69 12 6 59 25 17 10 81 47 30 28 13 66 38 58 4 80 +Card 34: 65 48 49 80 28 9 22 57 47 95 | 28 59 79 2 4 89 64 98 14 90 18 22 92 52 3 37 95 87 74 54 43 26 51 42 88 +Card 35: 60 8 75 58 47 63 90 71 93 50 | 60 9 24 63 98 66 39 91 46 34 86 67 16 95 53 73 48 87 75 96 44 90 68 26 93 +Card 36: 31 61 33 38 70 46 2 81 73 58 | 49 67 79 3 20 64 96 62 81 82 54 57 70 30 43 56 71 86 6 19 48 93 58 15 27 +Card 37: 86 62 46 70 33 84 90 66 89 96 | 56 39 63 53 45 80 49 61 52 64 12 69 74 26 44 86 96 62 27 31 78 2 28 21 16 +Card 38: 95 40 44 15 99 76 85 20 38 11 | 57 22 23 29 69 90 48 51 66 24 11 32 33 25 92 94 70 88 78 39 28 60 77 55 31 +Card 39: 67 40 10 87 93 47 23 98 96 91 | 14 30 78 72 70 99 52 65 84 12 18 75 59 85 83 89 55 11 82 34 63 10 97 54 69 +Card 40: 95 51 94 2 36 99 98 46 87 82 | 1 40 18 73 50 82 66 14 65 85 83 45 89 58 79 55 84 80 90 72 22 5 38 44 69 +Card 41: 68 75 93 29 66 95 27 46 23 82 | 8 60 39 33 41 36 25 73 94 89 50 71 85 19 51 30 53 45 9 31 83 99 5 32 52 +Card 42: 73 48 37 23 32 19 72 52 58 91 | 35 19 55 9 23 79 62 87 72 58 95 68 20 38 5 48 60 37 73 46 91 12 74 52 32 +Card 43: 42 39 19 59 11 50 88 31 10 9 | 77 11 39 56 42 67 22 12 88 57 75 79 80 6 92 86 99 33 59 90 89 93 68 70 61 +Card 44: 86 12 3 41 71 82 6 48 97 93 | 49 75 31 45 41 83 10 86 8 91 9 70 97 69 52 77 51 36 34 14 81 28 2 40 64 +Card 45: 51 9 72 44 18 14 40 97 2 25 | 83 80 62 22 7 34 88 33 17 23 38 81 70 89 26 35 57 78 46 76 4 61 56 98 55 +Card 46: 22 59 61 94 67 87 21 18 12 69 | 50 22 60 21 67 26 59 94 28 33 30 12 16 69 4 27 95 18 61 53 56 47 85 88 87 +Card 47: 91 58 84 29 4 60 77 41 83 97 | 70 35 40 17 62 41 9 59 26 76 78 16 25 92 91 95 71 77 63 21 6 67 54 46 49 +Card 48: 90 56 13 75 73 2 8 62 21 88 | 38 88 76 75 8 2 82 77 56 73 28 18 59 21 65 90 23 94 5 13 15 79 26 1 36 +Card 49: 84 14 99 51 58 28 63 36 48 91 | 94 46 6 61 2 9 40 38 64 63 91 16 49 81 70 48 80 36 51 58 84 98 96 34 60 +Card 50: 79 98 99 11 7 34 38 52 74 27 | 21 57 11 19 89 94 72 52 81 62 92 79 32 77 28 74 84 86 80 69 83 38 98 3 34 +Card 51: 58 60 15 93 24 72 94 29 59 12 | 71 72 7 86 23 39 65 87 76 22 6 74 69 94 46 52 91 60 96 24 93 47 4 15 59 +Card 52: 6 92 21 7 9 55 17 33 23 16 | 28 69 86 94 34 21 95 51 22 41 99 87 46 1 49 36 90 76 35 30 64 5 44 93 58 +Card 53: 57 10 81 4 93 79 51 87 28 50 | 38 34 97 15 49 89 59 37 25 48 70 41 98 33 78 87 95 85 35 71 32 30 96 67 36 +Card 54: 25 41 26 14 99 98 71 83 31 54 | 68 17 28 80 79 10 31 99 54 83 27 14 25 32 26 85 42 76 33 49 8 24 67 71 41 +Card 55: 38 26 25 70 78 37 13 76 31 73 | 82 10 2 51 13 8 98 12 19 77 84 89 93 22 54 35 23 31 69 42 43 25 39 57 94 +Card 56: 31 25 88 98 23 3 2 58 99 67 | 46 27 75 97 84 53 9 47 64 49 23 92 15 74 44 78 58 56 83 30 31 7 5 2 94 +Card 57: 50 61 25 29 59 1 47 72 65 84 | 72 74 97 28 30 75 56 61 44 40 62 95 4 8 64 22 34 25 14 16 50 92 65 39 13 +Card 58: 73 65 94 47 90 35 95 12 81 78 | 86 87 24 11 1 81 96 33 12 18 74 41 9 22 5 44 48 82 68 67 88 94 20 59 90 +Card 59: 41 27 3 55 16 83 49 75 51 88 | 33 66 74 58 60 72 75 67 78 55 68 95 81 3 39 86 69 94 92 4 5 44 57 26 56 +Card 60: 33 93 56 90 16 46 65 78 13 6 | 55 41 70 6 63 69 90 82 22 17 66 2 53 79 49 25 10 34 47 54 43 58 59 81 68 +Card 61: 72 45 87 76 64 80 96 22 67 98 | 69 25 90 48 67 88 30 34 38 98 19 73 86 8 99 35 44 95 91 36 63 37 2 13 66 +Card 62: 96 68 19 52 97 83 60 67 20 35 | 21 96 30 58 10 7 40 25 92 33 15 69 61 34 6 81 87 75 41 16 51 27 8 4 86 +Card 63: 17 1 45 26 82 78 85 15 89 8 | 49 38 16 22 71 50 81 74 87 61 14 19 64 93 96 23 59 56 76 86 53 6 7 80 41 +Card 64: 3 17 22 94 37 39 67 73 27 4 | 8 27 22 5 28 53 47 52 94 25 29 54 1 59 98 16 78 9 65 91 61 74 73 60 37 +Card 65: 80 48 70 23 99 11 20 31 54 94 | 73 69 21 10 66 90 80 29 55 67 92 20 96 94 79 93 31 30 17 14 27 75 13 95 71 +Card 66: 14 79 31 27 89 95 69 63 12 67 | 36 85 67 24 87 72 89 26 17 31 27 55 10 32 14 63 71 79 13 12 81 69 28 95 30 +Card 67: 87 44 51 53 37 69 39 96 90 16 | 22 63 83 31 32 76 66 68 29 30 53 48 4 72 82 46 95 80 17 21 56 51 89 12 77 +Card 68: 39 27 17 15 50 65 38 94 84 42 | 42 84 17 50 52 47 67 93 13 35 7 26 23 95 39 81 94 15 78 27 43 21 38 55 86 +Card 69: 13 22 8 54 61 77 75 31 1 67 | 68 54 15 23 40 58 67 3 71 78 90 33 44 22 57 19 8 30 74 38 48 41 9 25 65 +Card 70: 10 43 33 21 31 6 94 46 82 83 | 48 62 6 19 67 72 46 81 75 5 54 8 56 92 37 76 96 71 32 36 26 14 30 79 9 +Card 71: 91 9 15 33 37 22 61 74 14 70 | 79 31 18 42 43 40 26 56 95 45 86 76 65 23 3 94 24 35 4 2 68 51 25 12 80 +Card 72: 30 79 24 55 42 8 13 90 68 73 | 37 61 34 94 51 30 3 10 26 19 50 42 40 31 80 86 66 27 83 90 73 79 99 14 76 +Card 73: 25 88 63 85 56 49 30 46 10 99 | 46 68 67 60 11 78 6 85 12 97 91 21 27 81 39 48 69 44 25 63 22 10 3 61 79 +Card 74: 21 3 32 71 98 69 44 78 34 11 | 83 56 29 18 34 9 63 92 53 22 61 45 41 38 82 27 49 5 32 99 69 17 55 66 96 +Card 75: 68 92 32 65 49 38 3 56 17 44 | 47 68 6 1 10 24 66 84 60 2 48 56 57 61 51 35 28 17 82 52 98 81 23 75 38 +Card 76: 30 57 5 8 10 95 45 85 54 3 | 53 2 54 34 23 12 48 16 37 92 85 27 83 8 21 44 81 26 49 67 36 25 52 47 68 +Card 77: 31 84 72 26 83 55 20 42 65 61 | 53 96 17 18 59 21 23 77 78 15 43 58 66 3 60 55 38 45 6 72 44 94 11 79 19 +Card 78: 62 77 52 72 13 24 31 60 29 26 | 74 51 46 67 97 14 71 70 55 94 6 16 65 85 66 80 60 27 32 39 73 61 34 91 69 +Card 79: 69 74 82 58 44 37 86 51 75 20 | 93 70 2 35 30 79 45 56 65 59 22 64 89 36 66 5 34 13 49 43 97 74 7 26 83 +Card 80: 84 16 89 49 81 1 79 44 93 25 | 2 35 29 8 87 21 22 57 9 73 67 82 54 45 71 72 59 5 4 97 70 60 91 7 92 +Card 81: 25 44 10 12 23 79 60 45 96 90 | 62 23 25 40 12 90 42 10 79 45 69 46 9 27 73 59 34 44 29 94 95 86 66 1 58 +Card 82: 42 43 37 18 40 64 75 76 99 3 | 67 42 11 18 91 99 14 90 3 23 73 82 76 40 37 44 28 64 96 16 74 75 55 61 15 +Card 83: 38 89 77 47 66 22 87 59 7 43 | 59 46 7 73 79 23 96 22 28 87 66 32 77 89 98 19 38 18 43 56 15 47 74 95 99 +Card 84: 86 13 97 81 46 12 88 34 92 52 | 88 69 8 2 76 63 95 27 46 31 81 48 75 92 60 33 36 22 34 13 57 30 21 42 98 +Card 85: 57 71 21 43 41 23 18 15 59 93 | 40 8 21 25 19 57 52 71 75 45 16 18 89 99 43 20 27 4 53 98 80 22 7 29 41 +Card 86: 84 43 50 94 92 31 48 8 6 91 | 92 53 6 94 25 41 74 54 62 43 95 79 16 31 8 89 84 30 50 91 58 47 17 96 46 +Card 87: 45 96 17 51 25 40 39 13 78 82 | 66 61 23 13 59 10 1 86 30 62 74 41 34 45 8 65 36 16 78 93 20 92 35 82 90 +Card 88: 29 89 14 85 93 19 56 36 99 15 | 91 14 94 89 96 19 85 71 23 46 21 75 92 7 6 33 60 8 72 81 99 36 29 56 22 +Card 89: 77 79 82 96 75 63 72 59 37 11 | 43 97 11 61 80 68 22 19 71 63 16 18 56 49 9 79 45 36 37 89 1 8 48 4 40 +Card 90: 2 81 33 10 60 57 38 99 95 65 | 3 98 33 80 32 65 45 96 99 61 25 73 74 37 91 6 2 79 38 34 97 89 36 11 5 +Card 91: 31 62 73 12 53 51 64 55 9 20 | 45 76 95 42 81 56 32 62 11 48 93 9 69 79 84 28 46 82 88 96 31 91 13 98 92 +Card 92: 64 5 81 2 59 24 40 74 84 58 | 93 43 67 70 53 20 91 18 49 4 14 52 74 19 79 85 61 86 82 57 38 44 34 9 83 +Card 93: 6 94 85 43 15 67 68 79 81 65 | 15 35 14 78 21 68 86 9 97 99 75 87 23 46 70 30 41 27 18 84 3 50 53 63 79 +Card 94: 61 34 62 94 50 23 69 98 78 60 | 43 9 90 28 49 36 19 97 56 75 62 15 79 70 40 78 24 94 48 88 45 91 66 4 34 +Card 95: 73 26 99 83 45 46 9 50 38 14 | 98 81 63 27 55 28 32 82 92 41 87 60 49 50 99 95 11 89 4 78 17 47 20 15 96 +Card 96: 52 80 3 67 69 57 16 34 40 77 | 70 35 97 2 71 25 1 15 54 26 19 5 83 20 4 99 56 38 51 87 53 47 30 13 96 +Card 97: 54 41 65 23 52 82 81 22 28 47 | 27 90 3 24 15 85 36 88 97 37 4 18 42 50 99 35 83 78 79 46 40 63 92 34 67 +Card 98: 47 56 85 60 12 1 35 88 30 86 | 75 83 15 97 66 74 55 62 9 58 19 82 51 54 61 68 47 7 17 10 39 44 20 96 34 +Card 99: 52 25 39 18 92 17 93 29 6 9 | 22 83 86 51 5 43 20 73 13 66 6 82 24 8 2 11 87 79 57 50 19 35 45 62 49 +Card 100: 27 91 93 24 17 47 80 13 51 8 | 59 78 63 74 81 26 98 64 97 79 6 77 54 83 9 86 69 31 12 10 5 56 34 33 60 +Card 101: 8 45 53 15 57 36 69 47 13 1 | 15 13 79 47 69 36 99 57 25 91 1 8 39 73 90 24 84 93 60 40 53 55 3 45 87 +Card 102: 45 76 11 54 1 15 24 60 20 29 | 25 32 88 5 66 40 16 58 24 70 79 36 29 53 54 86 60 15 78 57 27 92 99 33 30 +Card 103: 46 15 97 62 94 19 99 76 42 93 | 65 19 5 58 3 10 12 24 50 64 54 22 85 31 44 93 30 47 14 21 97 78 2 15 81 +Card 104: 61 83 16 66 81 55 52 36 76 95 | 28 51 36 20 11 6 27 33 92 57 94 96 45 9 15 2 63 72 58 44 5 81 43 1 66 +Card 105: 44 12 34 11 26 72 57 55 38 69 | 41 57 62 26 14 72 89 99 34 69 28 10 68 70 2 50 98 37 12 38 44 71 11 80 55 +Card 106: 43 33 65 67 24 17 58 16 94 9 | 51 54 71 14 95 18 42 45 73 97 24 25 92 49 29 83 38 10 30 61 22 79 43 60 65 +Card 107: 74 9 87 65 8 71 6 51 47 79 | 74 5 6 71 65 82 57 88 66 76 70 8 51 87 54 81 96 79 7 9 47 12 24 52 50 +Card 108: 32 87 49 10 41 34 68 79 33 23 | 16 67 63 69 60 37 8 2 47 78 5 9 34 61 10 42 36 95 68 24 75 77 85 56 18 +Card 109: 98 95 89 44 76 63 83 99 71 79 | 49 64 88 18 67 48 23 37 32 99 65 14 1 63 80 84 60 5 87 94 70 8 96 16 35 +Card 110: 73 30 38 99 23 57 68 39 20 45 | 74 9 1 8 35 42 23 24 83 66 76 90 30 56 82 15 6 49 88 45 96 62 43 27 16 +Card 111: 48 62 64 91 57 12 68 30 25 18 | 78 3 21 29 20 77 91 74 72 1 18 28 19 25 44 52 34 12 64 17 6 7 57 5 14 +Card 112: 62 10 63 18 34 55 72 86 12 45 | 82 7 27 95 76 64 11 31 42 38 75 15 69 29 79 20 17 8 16 39 60 24 87 81 9 +Card 113: 91 58 97 55 46 75 74 53 72 2 | 82 7 17 38 89 81 14 24 33 13 11 91 79 93 96 18 2 35 80 15 45 63 41 46 37 +Card 114: 76 22 44 83 99 59 21 67 12 17 | 78 68 63 53 16 29 31 90 70 18 69 9 40 38 32 8 27 85 67 26 62 56 97 35 94 +Card 115: 11 49 95 65 18 67 29 91 45 25 | 37 44 78 20 88 35 32 60 90 40 26 5 68 53 70 31 74 63 21 4 87 46 12 92 91 +Card 116: 50 25 19 90 91 8 80 44 9 38 | 40 47 45 53 99 1 74 65 49 67 16 29 81 70 78 89 42 80 97 76 66 21 24 95 83 +Card 117: 38 7 34 3 57 30 29 44 52 21 | 5 48 70 24 26 50 32 27 1 4 25 96 54 16 90 61 33 67 89 78 83 22 72 6 47 +Card 118: 35 25 23 73 66 57 86 21 27 8 | 9 98 50 78 75 99 83 10 70 97 49 85 14 73 46 29 16 5 60 82 15 45 62 37 3 +Card 119: 51 84 3 55 90 61 93 18 38 35 | 63 50 60 78 87 74 95 58 26 27 34 11 81 30 28 99 94 89 64 1 96 65 72 56 76 +Card 120: 17 74 98 56 54 31 10 26 60 45 | 20 90 98 46 31 15 89 10 94 26 35 69 79 60 58 11 74 77 50 30 64 56 9 45 12 +Card 121: 27 43 12 84 96 70 61 19 92 46 | 59 18 91 25 23 97 32 72 4 21 95 93 85 60 81 9 58 30 53 94 90 69 48 89 2 +Card 122: 88 85 3 82 19 98 72 38 87 93 | 60 3 31 93 51 81 82 23 69 14 72 21 95 45 76 59 86 53 85 73 19 56 61 39 35 +Card 123: 22 6 50 96 91 15 33 7 29 57 | 72 67 62 78 91 96 23 7 17 69 26 29 75 2 57 20 43 74 82 68 56 92 54 66 48 +Card 124: 73 15 66 38 69 4 83 45 70 95 | 19 71 6 5 15 17 95 1 34 3 68 70 42 75 12 46 38 8 83 39 2 16 74 79 36 +Card 125: 32 86 2 71 72 53 73 67 12 85 | 60 31 70 99 33 45 95 22 79 41 25 3 46 5 20 75 37 55 35 18 36 59 8 63 80 +Card 126: 44 96 40 68 25 34 13 72 2 80 | 47 18 77 23 63 80 17 73 3 79 21 15 11 58 54 96 95 62 51 41 75 44 40 24 97 +Card 127: 4 34 21 87 85 1 44 72 71 24 | 72 46 83 10 50 77 87 49 91 85 1 42 66 38 54 89 35 86 59 65 71 15 34 4 99 +Card 128: 24 86 90 74 48 83 88 13 2 38 | 8 16 10 92 76 44 1 59 34 37 80 52 27 70 66 26 22 43 6 84 30 21 60 77 74 +Card 129: 28 71 81 50 31 13 6 63 58 51 | 5 35 62 15 72 47 76 44 32 34 2 14 50 45 77 18 24 81 78 59 48 40 9 7 26 +Card 130: 19 68 83 40 64 99 55 45 17 9 | 22 77 99 80 90 13 88 44 57 26 85 81 15 56 30 54 18 95 6 83 51 55 94 93 73 +Card 131: 47 44 33 5 59 74 1 21 46 3 | 4 14 87 41 82 63 31 45 47 23 55 94 89 39 86 20 52 66 10 59 48 34 68 21 12 +Card 132: 78 15 99 9 40 5 34 75 3 79 | 70 30 80 23 95 66 85 7 43 27 12 83 22 44 21 10 31 14 26 45 68 57 49 94 53 +Card 133: 54 14 80 44 33 11 53 69 1 71 | 64 2 56 28 84 76 26 32 92 3 39 47 69 9 6 75 50 99 95 30 35 73 98 13 59 +Card 134: 58 85 26 9 2 94 59 23 57 52 | 21 39 80 34 50 27 45 76 16 75 54 92 8 66 53 32 17 74 83 13 1 93 99 88 46 +Card 135: 43 81 39 26 61 75 13 40 72 48 | 9 87 61 99 51 81 59 55 19 13 35 74 60 45 39 40 65 33 78 46 26 8 71 7 44 +Card 136: 76 86 15 32 6 81 29 16 22 92 | 88 73 92 50 75 79 82 61 86 41 30 69 18 76 45 15 67 16 29 81 93 65 32 14 6 +Card 137: 37 65 99 6 61 45 27 86 68 84 | 6 7 61 67 65 33 86 64 59 90 96 54 99 23 85 68 18 55 40 4 10 37 97 77 73 +Card 138: 39 80 50 4 53 73 48 54 12 60 | 63 50 72 33 17 11 24 18 54 58 68 7 30 75 22 85 87 40 19 44 69 90 97 43 36 +Card 139: 8 86 87 39 58 56 80 34 85 81 | 25 9 2 26 19 61 96 72 36 45 6 21 91 7 34 89 59 56 87 8 49 98 85 74 97 +Card 140: 19 21 14 84 81 4 62 24 71 77 | 96 14 77 71 38 24 45 51 40 81 5 19 99 57 48 65 72 4 60 62 41 79 87 49 2 +Card 141: 87 32 58 9 88 63 22 71 83 18 | 37 26 51 34 44 22 84 48 58 65 3 62 45 90 60 70 74 81 57 68 18 47 85 73 40 +Card 142: 17 56 69 87 23 26 25 32 49 47 | 65 83 15 63 73 30 93 85 45 27 84 14 58 76 38 33 8 94 61 74 37 36 52 41 78 +Card 143: 52 86 94 23 28 58 81 71 30 21 | 23 96 75 87 55 50 21 76 9 80 97 69 35 33 27 71 86 94 30 42 84 10 3 14 62 +Card 144: 80 8 67 32 42 49 76 93 41 90 | 21 59 34 80 71 37 28 33 9 68 95 31 26 47 73 94 41 13 48 27 96 7 85 17 62 +Card 145: 22 13 74 92 75 17 19 48 58 55 | 36 31 20 92 11 76 23 51 71 84 59 88 89 38 1 90 97 46 30 41 77 6 17 64 2 +Card 146: 51 81 54 87 95 28 30 44 88 85 | 96 1 35 64 45 97 54 84 4 86 40 49 15 28 19 75 10 2 68 60 66 59 12 18 63 +Card 147: 44 45 70 23 71 37 17 59 97 53 | 88 9 26 22 62 68 6 96 77 31 95 50 54 42 14 5 30 24 48 3 67 75 56 49 7 +Card 148: 38 54 1 75 6 24 70 82 74 94 | 23 34 92 5 14 83 45 88 81 21 43 78 87 56 63 36 48 4 51 60 42 25 18 2 35 +Card 149: 11 87 55 57 8 27 48 67 12 45 | 3 37 54 81 2 15 92 30 5 10 38 98 64 93 99 68 36 50 88 97 35 29 79 46 58 +Card 150: 65 89 66 91 37 3 49 19 29 17 | 24 34 69 99 15 58 56 28 90 7 73 75 72 66 77 49 8 17 21 74 84 67 19 29 54 +Card 151: 86 4 93 67 52 14 43 99 9 38 | 34 60 72 47 24 76 38 67 48 85 14 43 93 92 49 45 18 25 86 9 31 99 63 41 4 +Card 152: 79 39 53 12 11 17 27 51 92 5 | 12 79 51 75 92 2 56 39 81 67 17 5 53 55 72 48 60 11 18 27 98 77 6 66 86 +Card 153: 22 95 26 5 32 14 7 66 8 35 | 60 32 96 25 8 57 73 95 74 27 66 26 7 1 14 5 12 34 21 35 22 87 77 24 85 +Card 154: 79 4 94 63 9 96 21 86 59 46 | 52 76 55 94 57 74 46 15 38 83 32 4 9 73 62 43 36 98 89 18 96 45 79 25 35 +Card 155: 53 58 97 98 67 5 8 46 31 54 | 76 5 46 80 30 54 31 33 51 97 47 67 8 83 10 58 60 73 98 71 62 82 48 95 77 +Card 156: 3 1 23 18 71 21 8 79 84 2 | 59 8 18 87 29 14 46 99 61 90 66 21 68 62 2 86 31 88 23 74 38 10 73 7 84 +Card 157: 24 3 22 90 56 15 78 61 1 81 | 33 70 73 5 71 93 30 67 53 18 62 7 19 85 47 65 43 82 69 75 57 46 44 99 50 +Card 158: 2 8 21 71 24 82 47 53 11 25 | 27 25 35 20 3 53 73 96 38 7 65 89 16 78 97 85 74 18 56 49 32 88 59 42 33 +Card 159: 69 81 74 51 35 90 33 58 97 22 | 89 45 91 1 77 10 72 35 31 42 28 71 97 80 87 22 64 33 95 3 68 56 69 82 67 +Card 160: 99 34 53 3 6 48 93 1 42 13 | 50 35 79 89 26 5 91 10 57 63 30 72 64 17 37 40 90 88 78 18 25 95 67 58 14 +Card 161: 41 39 34 75 50 52 94 71 82 13 | 26 8 87 95 20 91 49 96 65 36 51 24 46 69 83 52 47 41 79 11 50 73 89 70 44 +Card 162: 48 87 68 57 81 52 49 60 28 15 | 92 11 94 54 45 39 7 84 93 67 42 64 26 90 6 79 4 3 23 96 41 37 97 24 50 +Card 163: 67 41 11 38 81 56 45 4 76 70 | 32 87 62 51 58 27 91 37 29 90 22 43 77 97 35 46 93 88 23 31 99 21 79 18 47 +Card 164: 2 79 35 21 96 29 22 10 69 99 | 47 91 17 60 20 31 37 81 53 84 16 77 4 46 75 26 78 93 32 76 52 8 27 59 10 +Card 165: 32 37 54 95 66 64 59 19 28 44 | 96 49 3 75 94 63 98 65 4 7 2 73 50 24 78 31 21 42 82 25 70 79 35 38 1 +Card 166: 24 61 72 44 27 38 81 59 69 89 | 85 29 98 3 73 63 25 1 16 96 57 8 78 92 82 20 79 94 71 62 2 49 97 93 99 +Card 167: 55 22 60 95 80 25 28 56 69 18 | 22 38 29 46 90 41 59 93 94 57 74 43 97 49 27 34 19 64 55 81 33 37 13 15 89 +Card 168: 90 51 39 37 67 12 65 14 6 4 | 64 70 6 37 25 26 4 48 43 91 28 90 27 41 87 74 14 39 56 51 9 67 12 65 34 +Card 169: 57 11 25 88 28 82 60 95 27 26 | 42 82 35 47 87 14 11 88 63 96 65 43 95 25 99 5 26 20 28 57 60 40 76 27 7 +Card 170: 31 34 19 29 1 55 20 61 10 94 | 48 77 3 87 91 37 38 57 75 53 12 60 76 45 4 68 13 73 35 7 30 20 6 14 69 +Card 171: 67 10 59 89 52 53 40 17 64 29 | 88 27 59 1 75 10 95 67 34 40 83 4 82 64 2 52 89 29 53 33 8 71 91 85 17 +Card 172: 87 63 66 32 37 96 3 29 88 90 | 96 18 87 17 14 69 58 65 52 31 1 44 37 60 5 32 41 90 7 49 29 66 35 77 82 +Card 173: 70 84 52 81 63 32 61 94 38 97 | 24 34 63 52 81 99 8 57 66 50 94 84 70 38 61 86 15 32 47 78 45 77 95 76 97 +Card 174: 4 74 29 30 24 87 91 92 5 2 | 55 86 5 70 12 94 96 89 58 29 14 62 4 99 48 81 91 45 27 54 31 22 68 43 76 +Card 175: 91 78 3 20 86 98 89 82 13 57 | 24 76 59 66 73 1 5 82 45 6 92 3 33 43 17 83 12 14 91 71 19 46 54 96 25 +Card 176: 12 55 93 3 43 81 28 59 72 76 | 4 90 55 84 69 74 46 45 65 17 26 71 70 21 29 23 61 99 92 44 40 41 51 8 57 +Card 177: 56 5 89 93 62 17 2 6 50 40 | 35 60 5 47 76 92 15 2 34 28 69 29 19 9 27 49 1 88 57 48 84 8 26 59 91 +Card 178: 1 93 34 57 67 58 84 37 42 91 | 42 69 41 34 91 28 75 70 1 93 4 49 66 6 37 38 32 89 46 44 62 81 9 22 73 +Card 179: 90 95 7 29 42 51 22 39 84 75 | 75 25 80 96 55 41 73 43 26 42 46 7 86 22 84 1 39 50 90 12 3 29 51 95 81 +Card 180: 72 76 4 68 9 41 16 44 61 13 | 63 92 39 68 5 13 11 65 50 25 76 55 71 29 82 31 53 59 2 99 74 16 1 90 41 +Card 181: 29 63 61 82 33 94 51 32 50 84 | 80 85 7 8 54 30 87 56 90 75 69 60 25 43 53 47 72 81 1 59 97 28 52 46 10 +Card 182: 98 45 44 32 19 6 51 49 64 84 | 64 20 90 6 4 54 19 80 51 72 69 99 29 44 45 46 84 65 43 53 74 23 42 66 49 +Card 183: 23 35 4 50 88 87 38 7 19 2 | 76 79 80 5 66 30 74 29 37 94 11 50 1 67 13 27 90 40 70 91 71 12 81 9 33 +Card 184: 55 74 2 73 75 22 32 71 67 27 | 92 19 9 24 74 73 8 67 30 18 14 71 77 45 85 72 15 69 13 27 94 63 98 40 93 +Card 185: 14 73 72 38 16 40 83 28 37 96 | 19 74 49 96 90 48 26 1 95 54 3 82 50 41 43 64 69 80 77 97 52 16 23 25 31 +Card 186: 24 91 35 21 16 71 94 95 25 53 | 60 5 17 58 82 35 45 80 28 16 13 53 68 97 86 8 52 61 65 1 27 67 91 43 3 +Card 187: 96 39 77 52 97 33 80 99 18 15 | 48 8 85 79 81 33 43 90 62 14 36 65 2 32 82 15 91 23 34 68 56 87 11 57 73 +Card 188: 8 35 86 95 94 65 26 11 96 31 | 2 98 50 33 59 93 28 49 87 29 79 8 23 6 54 16 82 96 83 61 27 60 53 62 30 +Card 189: 60 27 78 55 84 1 36 28 20 77 | 45 85 75 8 54 74 58 73 17 68 13 53 47 79 7 65 35 40 51 87 18 37 71 72 21 +Card 190: 41 31 39 33 54 42 71 47 59 24 | 21 96 85 12 81 83 64 87 93 77 92 38 25 52 20 88 65 10 29 16 95 98 22 37 15 diff --git a/2023/day04_2/src/main/resources/small_input b/2023/day04_2/src/main/resources/small_input new file mode 100644 index 0000000..71f208a --- /dev/null +++ b/2023/day04_2/src/main/resources/small_input @@ -0,0 +1,6 @@ +Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 +Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 +Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 +Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 +Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 +Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11 \ No newline at end of file diff --git a/2023/day05_1/.idea/.gitignore b/2023/day05_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2023/day05_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2023/day05_1/.idea/inspectionProfiles/Project_Default.xml b/2023/day05_1/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2023/day05_1/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2023/day05_1/.idea/kotlinc.xml b/2023/day05_1/.idea/kotlinc.xml new file mode 100644 index 0000000..5cba058 --- /dev/null +++ b/2023/day05_1/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2023/day05_1/.idea/libraries/KotlinJavaRuntime.xml b/2023/day05_1/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..b6883db --- /dev/null +++ b/2023/day05_1/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day05_1/.idea/misc.xml b/2023/day05_1/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2023/day05_1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day05_1/.idea/modules.xml b/2023/day05_1/.idea/modules.xml new file mode 100644 index 0000000..15b7871 --- /dev/null +++ b/2023/day05_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2023/day05_1/.idea/sonarlint/issuestore/index.pb b/2023/day05_1/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..b3ff4b6 --- /dev/null +++ b/2023/day05_1/.idea/sonarlint/issuestore/index.pb @@ -0,0 +1,13 @@ + +G +src/main/kotlin/Main.kt,d/8/d83ae3847b7d408136086cc5e9e95f5f7c126ed5 +S +#.idea/sonarlint/issuestore/index.pb,9/f/9fe84ebb15faf917b7def6236dba604453cc61e0 +\ +,.idea/inspectionProfiles/Project_Default.xml,4/9/496a238a6afa168dbaf6efd37bb459331589579c +] +-.idea/sonarlint/securityhotspotstore/index.pb,8/8/88a9255124c95bdc913197c120a8d560edc59c8e +U +%.idea/libraries/KotlinJavaRuntime.xml,0/2/02ddf5725f2ec9b67991423205d2b1a2009ccd06 +; + day05_1.iml,b/2/b2c639b00e5fc9973b52e30e3d0e60184b14598c \ No newline at end of file diff --git a/2023/day05_1/.idea/sonarlint/securityhotspotstore/index.pb b/2023/day05_1/.idea/sonarlint/securityhotspotstore/index.pb new file mode 100644 index 0000000..b3ff4b6 --- /dev/null +++ b/2023/day05_1/.idea/sonarlint/securityhotspotstore/index.pb @@ -0,0 +1,13 @@ + +G +src/main/kotlin/Main.kt,d/8/d83ae3847b7d408136086cc5e9e95f5f7c126ed5 +S +#.idea/sonarlint/issuestore/index.pb,9/f/9fe84ebb15faf917b7def6236dba604453cc61e0 +\ +,.idea/inspectionProfiles/Project_Default.xml,4/9/496a238a6afa168dbaf6efd37bb459331589579c +] +-.idea/sonarlint/securityhotspotstore/index.pb,8/8/88a9255124c95bdc913197c120a8d560edc59c8e +U +%.idea/libraries/KotlinJavaRuntime.xml,0/2/02ddf5725f2ec9b67991423205d2b1a2009ccd06 +; + day05_1.iml,b/2/b2c639b00e5fc9973b52e30e3d0e60184b14598c \ No newline at end of file diff --git a/2023/day05_1/.idea/vcs.xml b/2023/day05_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2023/day05_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day05_1/day05_1.iml b/2023/day05_1/day05_1.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day05_1/day05_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day05_1/src/main/kotlin/Main.kt b/2023/day05_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..45ab772 --- /dev/null +++ b/2023/day05_1/src/main/kotlin/Main.kt @@ -0,0 +1,190 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 5, Part 1 starting!!!") + + File(args[0]).forEachLine { + parseLine(it) + } + + println("Seeds: ${allSeeds.seeds}") + println("Seeds To Soil count : ${allSeedToSoil.sourceToDestination.size}") + println("Soil to Fertilizer count : ${allSoilToFertilizer.sourceToDestination.size}") + println("Fertilizer to Water count : ${allFertilizerToWater.sourceToDestination.size}") + println("Water to Light count : ${allWaterToLight.sourceToDestination.size}") + println("Light to Temperature count : ${allLightToTemperature.sourceToDestination.size}") + println("Temperature to Humidity count : ${allTemperatureToHumidity.sourceToDestination.size}") + println("Humidity to Location count : ${allHumidityToLocation.sourceToDestination.size}") + + var finalAnswer = 0L + for(seed in allSeeds.seeds) { + val answer = calculateAnswer(seed) + + if((finalAnswer == 0L) || (answer < finalAnswer)) { + finalAnswer = answer + } + } + + println("Final answer: $finalAnswer") + + println("AOC 2023, Day 5, Part 1 completed!!!") +} + +fun calculateAnswer(seed:Long):Long { + return allHumidityToLocation.getMap( + allTemperatureToHumidity.getMap( + allLightToTemperature.getMap( + allWaterToLight.getMap( + allFertilizerToWater.getMap( + allSoilToFertilizer.getMap( + allSeedToSoil.getMap(seed) + ) + ) + ) + ) + ) + ) +} + +var lastMatch:String = String() + +enum class PlantingOptions(val theName:String) { + SEEDS("seeds:"), + SEED_TO_SOIL_MAP("seed-to-soil map:"), + SOIL_TO_FERTILIZER_MAP("soil-to-fertilizer map:"), + FERTILIZER_TO_WATER_MAP("fertilizer-to-water map:"), + WATER_TO_LIGHT_MAP("water-to-light map:"), + LIGHT_TO_TEMPERATURE_MAP("light-to-temperature map:"), + TEMPERATURE_TO_HUMIDITY_MAP("temperature-to-humidity map:"), + HUMIDITY_TO_LOCATION_MAP("humidity-to-location map:") +} + +class Seeds { + val seeds:ArrayList = ArrayList() +} + +data class InfoDataSet(val destinationRange:Long, val sourceRange:Long, val range:Long) + +open class MyDataSet { + val sourceToDestination = ArrayList() + + fun getMap(v: Long): Long { + for(sToD in sourceToDestination) { + if ((v > sToD.sourceRange) && (v <= (sToD.sourceRange + sToD.range - 1))) { + val offset = v - sToD.sourceRange + return sToD.destinationRange + offset + } + } + + return v + } +} + +class SeedToSoil : MyDataSet() + +class SoilToFertilizer : MyDataSet() + +class FertilizerToWater : MyDataSet() + +class WaterToLight : MyDataSet() + +class LightToTemperature : MyDataSet() + +class TemperatureToHumidity : MyDataSet() + +class HumidityToLocation : MyDataSet() + + +val allSeeds = Seeds() +val allSeedToSoil = SeedToSoil() +val allSoilToFertilizer = SoilToFertilizer() +val allFertilizerToWater = FertilizerToWater() +val allWaterToLight = WaterToLight() +val allLightToTemperature = LightToTemperature() +val allTemperatureToHumidity = TemperatureToHumidity() +val allHumidityToLocation = HumidityToLocation() + +fun parseLine(line:String) { + if(line.isEmpty()) { + // if line is blank, skip + lastMatch = String() + return + } + + if((lastMatch.compareTo(PlantingOptions.SEEDS.theName) == 0) || (line.substring(0, 6).compareTo(PlantingOptions.SEEDS.theName) == 0)) { + lastMatch = PlantingOptions.SEEDS.theName + for(c in line.split(' ')) { + if(c.compareTo(PlantingOptions.SEEDS.theName) == 0) { + continue + } + allSeeds.seeds.add(c.toLong()) + } + return + } + + if((lastMatch.compareTo(PlantingOptions.SEED_TO_SOIL_MAP.theName) == 0) || (line.compareTo(PlantingOptions.SEED_TO_SOIL_MAP.theName) == 0)) { + if (lastMatch.isEmpty()) { + lastMatch = PlantingOptions.SEED_TO_SOIL_MAP.theName + return + } + val split = line.split(' ') + allSeedToSoil.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + return + } + + if((lastMatch.compareTo(PlantingOptions.SOIL_TO_FERTILIZER_MAP.theName) == 0) || (line.compareTo(PlantingOptions.SOIL_TO_FERTILIZER_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.SOIL_TO_FERTILIZER_MAP.theName + } else { + val split = line.split(' ') + allSoilToFertilizer.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + } + } else if ((lastMatch.compareTo(PlantingOptions.FERTILIZER_TO_WATER_MAP.theName) == 0) || (line.compareTo(PlantingOptions.FERTILIZER_TO_WATER_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.FERTILIZER_TO_WATER_MAP.theName + } else { + val split = line.split(' ') + allFertilizerToWater.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + } + } + + if ((lastMatch.compareTo(PlantingOptions.WATER_TO_LIGHT_MAP.theName) == 0) || (line.compareTo(PlantingOptions.WATER_TO_LIGHT_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.WATER_TO_LIGHT_MAP.theName + return + } + val split = line.split(' ') + allWaterToLight.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + return + } + + if((lastMatch.compareTo(PlantingOptions.LIGHT_TO_TEMPERATURE_MAP.theName) == 0) || (line.compareTo(PlantingOptions.LIGHT_TO_TEMPERATURE_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.LIGHT_TO_TEMPERATURE_MAP.theName + return + } + val split = line.split(' ') + allLightToTemperature.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + return + } + + if((lastMatch.compareTo(PlantingOptions.TEMPERATURE_TO_HUMIDITY_MAP.theName) == 0) || (line.compareTo(PlantingOptions.TEMPERATURE_TO_HUMIDITY_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.TEMPERATURE_TO_HUMIDITY_MAP.theName + return + } + val split = line.split(' ') + allTemperatureToHumidity.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + return + } + + if((lastMatch.compareTo(PlantingOptions.HUMIDITY_TO_LOCATION_MAP.theName) == 0) || (line.compareTo(PlantingOptions.HUMIDITY_TO_LOCATION_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.HUMIDITY_TO_LOCATION_MAP.theName + return + } + val split = line.split(' ') + allHumidityToLocation.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + return + } +} \ No newline at end of file diff --git a/2023/day05_1/src/main/resources/input b/2023/day05_1/src/main/resources/input new file mode 100644 index 0000000..33e6aa3 --- /dev/null +++ b/2023/day05_1/src/main/resources/input @@ -0,0 +1,197 @@ +seeds: 432563865 39236501 1476854973 326201032 1004521373 221995697 2457503679 46909145 603710475 11439698 1242281714 12935671 2569215463 456738587 3859706369 129955069 3210146725 618372750 601583464 1413192 + +seed-to-soil map: +2824905526 2969131334 898611144 +0 322319732 9776277 +379216444 692683038 140400417 +3723516670 1559827635 9493936 +637824014 332096009 211964909 +929691047 1569321571 35824014 +965515061 1605145585 1281263183 +621118546 833083455 16705468 +9776277 0 322319732 +332096009 544060918 47120435 +3733010606 1319171816 134731872 +2329500810 1453903688 72388062 +2401888872 1526291750 33535885 +2246778244 2886408768 82722566 +2435424757 929691047 389480769 +519616861 591181353 101501685 + +soil-to-fertilizer map: +2819195624 2690204780 252557843 +1098298904 1339121422 10546957 +499510245 852292683 97183057 +4225167944 2372810194 69799352 +887408376 1808006977 56225538 +3071753467 4058417302 4632491 +2455749676 3452467754 363445948 +2243979338 3846646964 211770338 +3076385958 4063049793 231917503 +3860856553 2269547568 103262626 +943633914 21067281 39980869 +1388096097 1584043708 223963269 +3493291351 2442609546 247595234 +1801722612 949475740 41203502 +264653767 678191385 102026845 +3740886585 2942762623 89236706 +1152866424 310132079 235229673 +3830123291 3815913702 30733262 +249083929 1568473870 15569838 +1612059366 1506703078 61770792 +366680612 545361752 132829633 +1108845861 1992124969 44020563 +596693302 1048406348 290715074 +3467723121 2243979338 25568230 +1879110833 1349668379 157034699 +1858043552 0 21067281 +3308303461 3293048094 159419660 +3964119179 3031999329 261048765 +983614783 780218230 72074453 +1055689236 1005796680 42609668 +1673830158 1864232515 127892454 +1842926114 990679242 15117438 +0 61048150 249083929 + +fertilizer-to-water map: +0 434502471 470583313 +1739362496 1919893972 48874906 +2735409723 1968768878 16148586 +3324522082 1858151799 61742173 +4137416965 1984917464 25502361 +470583313 2971682591 186824423 +2751558309 2532295557 111781313 +3664705516 1340674299 435773845 +1851374390 3898529330 80666020 +857422234 2010419825 207606184 +1788237402 2418040507 63136988 +1065028418 0 434502471 +1499530889 2481177495 4578648 +4162919326 2916167530 55515061 +1670138099 3158507014 69224397 +3386264255 905085784 278441261 +2496170686 3979195350 239239037 +4100479361 2879229926 36937604 +1504109537 3227731411 166028562 +657407736 2218026009 200014498 +2909879036 3393759973 257495792 +1932040410 2644076870 235153056 +2167193466 3651255765 247273565 +2863339622 2485756143 46539414 +3167374828 1183527045 157147254 +2414467031 1776448144 81703655 + +water-to-light map: +894548549 593866955 6252040 +3168871398 327816880 11668092 +3549766643 2935057349 16258370 +1070236274 1304104659 106353135 +900800589 723222576 35881223 +2175309976 2744985745 82677694 +3969615926 3819543751 36919401 +4086160816 4015453657 208806480 +0 360262147 233604808 +3566025013 1514177176 87956572 +3440195928 1874477761 44575925 +1851853101 948479332 113304167 +2969520516 3389635913 199350882 +1504406289 1061783499 137386237 +623007058 1630426233 244051528 +1749186436 620555911 102666665 +2154532801 339484972 20777175 +1965157268 759103799 189375533 +4007153882 3758595179 60948572 +3180539490 2951315719 231363953 +233604808 1471149229 43027947 +276632755 1919053686 114911374 +1176589409 0 327816880 +867058586 1410457794 27489963 +391544129 1199169736 4581933 +603082303 600118995 19924755 +4068102454 4276290379 18058362 +3810625421 3856463152 158990505 +2969008355 620043750 512161 +3758595179 4224260137 52030242 +396126062 3182679672 206956241 +4006535327 4294348741 618555 +3484771853 3588986795 64994790 +2257987670 2033965060 711020685 +1641792526 2827663439 107393910 +3411903443 1602133748 28292485 +1037034802 1437947757 33201472 +936681812 1203751669 100352990 + +light-to-temperature map: +1726863959 864157287 834947717 +263199301 190436173 53620398 +1393417259 1699105004 333446700 +2783912856 244056571 155961192 +2939874048 400017763 299945457 +671449939 2517852185 721967320 +2561811676 2295751005 222101180 +0 2032551704 263199301 +481013766 0 190436173 +316819699 699963220 164194067 + +temperature-to-humidity map: +603287260 3766826980 8741130 +572607531 3684982838 30679729 +2084038135 1101548002 100083930 +655933651 3228345771 56278566 +1881393627 553997241 168332584 +553997241 2882185871 18610290 +627184746 1072799097 28748905 +612028390 3397056204 15156356 +1693489030 1430646491 187904597 +3039118107 1734352525 2023479 +220345266 0 43042720 +840454312 3775568110 147781659 +2184122065 3715662567 51164413 +317040325 171240045 2422893 +3245373536 4158663426 136303870 +145773749 385599932 74571517 +0 43042720 128197325 +1490020808 4094893831 63769595 +319463218 173662938 140708231 +712212217 1821839294 128242095 +128197325 314371169 17576424 +2474405575 3923349769 171544062 +2352890439 3105028111 121515136 +3467140696 3318936261 78119943 +2235286478 3226543247 1802524 +4084196651 722329825 210770645 +1553790403 933100470 139698627 +1261006249 1201631932 229014559 +263387986 331947593 53652339 +3137034338 2900796161 108339198 +988235971 3412212560 272770278 +2237089002 1618551088 115801437 +3381677406 1736376004 85463290 +3545260639 1950081389 538936012 +2049726211 3284624337 34311924 +2645949637 2489017401 393168470 +3041141586 3009135359 95892752 + +humidity-to-location map: +596652260 530461632 95173962 +3845096173 1731990943 158117085 +2243878974 1890108028 393769632 +0 625635594 63651375 +1920725725 753532949 155684321 +63651375 329652856 200808776 +264460151 0 60175490 +1381444473 2283877660 346420873 +4003213258 3594530530 47694548 +548036821 60175490 46076186 +4100105147 1678246429 53744514 +2637648606 3642225078 292412911 +324635641 106251676 223401180 +4050907806 3545333189 49197341 +4153849661 909217270 141117635 +3455132509 3477799963 67533226 +594113007 689286969 2539253 +2930061517 2630298533 525070992 +753532949 1050334905 627911524 +3522665735 3155369525 322430438 +2076410046 3934637989 167468928 +1727865346 4102106917 192860379 diff --git a/2023/day05_1/src/main/resources/small_input b/2023/day05_1/src/main/resources/small_input new file mode 100644 index 0000000..f756727 --- /dev/null +++ b/2023/day05_1/src/main/resources/small_input @@ -0,0 +1,33 @@ +seeds: 79 14 55 13 + +seed-to-soil map: +50 98 2 +52 50 48 + +soil-to-fertilizer map: +0 15 37 +37 52 2 +39 0 15 + +fertilizer-to-water map: +49 53 8 +0 11 42 +42 0 7 +57 7 4 + +water-to-light map: +88 18 7 +18 25 70 + +light-to-temperature map: +45 77 23 +81 45 19 +68 64 13 + +temperature-to-humidity map: +0 69 1 +1 0 69 + +humidity-to-location map: +60 56 37 +56 93 4 diff --git a/2023/day05_2/.gitignore b/2023/day05_2/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/2023/day05_2/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/2023/day05_2/.idea/.gitignore b/2023/day05_2/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2023/day05_2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2023/day05_2/.idea/inspectionProfiles/Project_Default.xml b/2023/day05_2/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2023/day05_2/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2023/day05_2/.idea/kotlinc.xml b/2023/day05_2/.idea/kotlinc.xml new file mode 100644 index 0000000..5cba058 --- /dev/null +++ b/2023/day05_2/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2023/day05_2/.idea/libraries/KotlinJavaRuntime.xml b/2023/day05_2/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..b6883db --- /dev/null +++ b/2023/day05_2/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day05_2/.idea/misc.xml b/2023/day05_2/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2023/day05_2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day05_2/.idea/modules.xml b/2023/day05_2/.idea/modules.xml new file mode 100644 index 0000000..282d2d7 --- /dev/null +++ b/2023/day05_2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2023/day05_2/.idea/vcs.xml b/2023/day05_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2023/day05_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day05_2/day05_2.iml b/2023/day05_2/day05_2.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day05_2/day05_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day05_2/src/main/kotlin/Main.kt b/2023/day05_2/src/main/kotlin/Main.kt new file mode 100644 index 0000000..99804b5 --- /dev/null +++ b/2023/day05_2/src/main/kotlin/Main.kt @@ -0,0 +1,202 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 5, Part 2 starting!!!") + + File(args[0]).forEachLine { + parseLine(it) + } + + println("Seeds: ${allSeeds.seeds}") + println("Seeds To Soil count : ${allSeedToSoil.sourceToDestination.size}") + println("Soil to Fertilizer count : ${allSoilToFertilizer.sourceToDestination.size}") + println("Fertilizer to Water count : ${allFertilizerToWater.sourceToDestination.size}") + println("Water to Light count : ${allWaterToLight.sourceToDestination.size}") + println("Light to Temperature count : ${allLightToTemperature.sourceToDestination.size}") + println("Temperature to Humidity count : ${allTemperatureToHumidity.sourceToDestination.size}") + println("Humidity to Location count : ${allHumidityToLocation.sourceToDestination.size}") + + var finalAnswer = 0L + for(seed in allSeeds.seeds) { + for(s in seed.start.. = HashSet() +} + +data class InfoDataSet(val destinationRange:Long, val sourceRange:Long, val range:Long) + +open class MyDataSet { + val sourceToDestination = ArrayList() + + fun getMap(v: Long): Long { + for(sToD in sourceToDestination) { + if ((v >= sToD.sourceRange) && (v <= (sToD.sourceRange + sToD.range - 1))) { + val offset = v - sToD.sourceRange + return sToD.destinationRange + offset + } + } + + return v + } +} + +class SeedToSoil : MyDataSet() + +class SoilToFertilizer : MyDataSet() + +class FertilizerToWater : MyDataSet() + +class WaterToLight : MyDataSet() + +class LightToTemperature : MyDataSet() + +class TemperatureToHumidity : MyDataSet() + +class HumidityToLocation : MyDataSet() + + +val allSeeds = Seeds() +val allSeedToSoil = SeedToSoil() +val allSoilToFertilizer = SoilToFertilizer() +val allFertilizerToWater = FertilizerToWater() +val allWaterToLight = WaterToLight() +val allLightToTemperature = LightToTemperature() +val allTemperatureToHumidity = TemperatureToHumidity() +val allHumidityToLocation = HumidityToLocation() + +fun parseLine(line:String) { + if(line.isEmpty()) { + // if line is blank, skip + lastMatch = String() + return + } + + if((lastMatch.compareTo(PlantingOptions.SEEDS.theName) == 0) || (line.substring(0, 6).compareTo(PlantingOptions.SEEDS.theName) == 0)) { + lastMatch = PlantingOptions.SEEDS.theName + var seedPosition = 0L + var seedRange = 0L + for(c in line.split(' ')) { + if(c.compareTo(PlantingOptions.SEEDS.theName) == 0) { + continue + } + + if(seedPosition == 0L) { + seedPosition = c.toLong() + // continue to read range value + continue + } + + seedRange = c.toLong() + + allSeeds.seeds.add(DupleLong(seedPosition, seedRange)) + +// for(seed in seedPosition ..< (seedPosition + seedRange)) { +// allSeeds.seeds.add(seed) +// } + // reset for next parsing + seedPosition = 0L + } + return + } + + if((lastMatch.compareTo(PlantingOptions.SEED_TO_SOIL_MAP.theName) == 0) || (line.compareTo(PlantingOptions.SEED_TO_SOIL_MAP.theName) == 0)) { + if (lastMatch.isEmpty()) { + lastMatch = PlantingOptions.SEED_TO_SOIL_MAP.theName + return + } + val split = line.split(' ') + allSeedToSoil.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + return + } + + if((lastMatch.compareTo(PlantingOptions.SOIL_TO_FERTILIZER_MAP.theName) == 0) || (line.compareTo(PlantingOptions.SOIL_TO_FERTILIZER_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.SOIL_TO_FERTILIZER_MAP.theName + } else { + val split = line.split(' ') + allSoilToFertilizer.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + } + } else if ((lastMatch.compareTo(PlantingOptions.FERTILIZER_TO_WATER_MAP.theName) == 0) || (line.compareTo(PlantingOptions.FERTILIZER_TO_WATER_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.FERTILIZER_TO_WATER_MAP.theName + } else { + val split = line.split(' ') + allFertilizerToWater.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + } + } else if ((lastMatch.compareTo(PlantingOptions.WATER_TO_LIGHT_MAP.theName) == 0) || (line.compareTo(PlantingOptions.WATER_TO_LIGHT_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.WATER_TO_LIGHT_MAP.theName + return + } + val split = line.split(' ') + allWaterToLight.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + return + } else if((lastMatch.compareTo(PlantingOptions.LIGHT_TO_TEMPERATURE_MAP.theName) == 0) || (line.compareTo(PlantingOptions.LIGHT_TO_TEMPERATURE_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.LIGHT_TO_TEMPERATURE_MAP.theName + return + } + val split = line.split(' ') + allLightToTemperature.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + return + } else if((lastMatch.compareTo(PlantingOptions.TEMPERATURE_TO_HUMIDITY_MAP.theName) == 0) || (line.compareTo(PlantingOptions.TEMPERATURE_TO_HUMIDITY_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.TEMPERATURE_TO_HUMIDITY_MAP.theName + return + } + val split = line.split(' ') + allTemperatureToHumidity.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + return + } else if((lastMatch.compareTo(PlantingOptions.HUMIDITY_TO_LOCATION_MAP.theName) == 0) || (line.compareTo(PlantingOptions.HUMIDITY_TO_LOCATION_MAP.theName) == 0)) { + if(lastMatch.isEmpty()) { + lastMatch = PlantingOptions.HUMIDITY_TO_LOCATION_MAP.theName + return + } + val split = line.split(' ') + allHumidityToLocation.sourceToDestination.add(InfoDataSet(split[0].toLong(), split[1].toLong(), split[2].toLong())) + return + } +} \ No newline at end of file diff --git a/2023/day05_2/src/main/resources/input b/2023/day05_2/src/main/resources/input new file mode 100644 index 0000000..33e6aa3 --- /dev/null +++ b/2023/day05_2/src/main/resources/input @@ -0,0 +1,197 @@ +seeds: 432563865 39236501 1476854973 326201032 1004521373 221995697 2457503679 46909145 603710475 11439698 1242281714 12935671 2569215463 456738587 3859706369 129955069 3210146725 618372750 601583464 1413192 + +seed-to-soil map: +2824905526 2969131334 898611144 +0 322319732 9776277 +379216444 692683038 140400417 +3723516670 1559827635 9493936 +637824014 332096009 211964909 +929691047 1569321571 35824014 +965515061 1605145585 1281263183 +621118546 833083455 16705468 +9776277 0 322319732 +332096009 544060918 47120435 +3733010606 1319171816 134731872 +2329500810 1453903688 72388062 +2401888872 1526291750 33535885 +2246778244 2886408768 82722566 +2435424757 929691047 389480769 +519616861 591181353 101501685 + +soil-to-fertilizer map: +2819195624 2690204780 252557843 +1098298904 1339121422 10546957 +499510245 852292683 97183057 +4225167944 2372810194 69799352 +887408376 1808006977 56225538 +3071753467 4058417302 4632491 +2455749676 3452467754 363445948 +2243979338 3846646964 211770338 +3076385958 4063049793 231917503 +3860856553 2269547568 103262626 +943633914 21067281 39980869 +1388096097 1584043708 223963269 +3493291351 2442609546 247595234 +1801722612 949475740 41203502 +264653767 678191385 102026845 +3740886585 2942762623 89236706 +1152866424 310132079 235229673 +3830123291 3815913702 30733262 +249083929 1568473870 15569838 +1612059366 1506703078 61770792 +366680612 545361752 132829633 +1108845861 1992124969 44020563 +596693302 1048406348 290715074 +3467723121 2243979338 25568230 +1879110833 1349668379 157034699 +1858043552 0 21067281 +3308303461 3293048094 159419660 +3964119179 3031999329 261048765 +983614783 780218230 72074453 +1055689236 1005796680 42609668 +1673830158 1864232515 127892454 +1842926114 990679242 15117438 +0 61048150 249083929 + +fertilizer-to-water map: +0 434502471 470583313 +1739362496 1919893972 48874906 +2735409723 1968768878 16148586 +3324522082 1858151799 61742173 +4137416965 1984917464 25502361 +470583313 2971682591 186824423 +2751558309 2532295557 111781313 +3664705516 1340674299 435773845 +1851374390 3898529330 80666020 +857422234 2010419825 207606184 +1788237402 2418040507 63136988 +1065028418 0 434502471 +1499530889 2481177495 4578648 +4162919326 2916167530 55515061 +1670138099 3158507014 69224397 +3386264255 905085784 278441261 +2496170686 3979195350 239239037 +4100479361 2879229926 36937604 +1504109537 3227731411 166028562 +657407736 2218026009 200014498 +2909879036 3393759973 257495792 +1932040410 2644076870 235153056 +2167193466 3651255765 247273565 +2863339622 2485756143 46539414 +3167374828 1183527045 157147254 +2414467031 1776448144 81703655 + +water-to-light map: +894548549 593866955 6252040 +3168871398 327816880 11668092 +3549766643 2935057349 16258370 +1070236274 1304104659 106353135 +900800589 723222576 35881223 +2175309976 2744985745 82677694 +3969615926 3819543751 36919401 +4086160816 4015453657 208806480 +0 360262147 233604808 +3566025013 1514177176 87956572 +3440195928 1874477761 44575925 +1851853101 948479332 113304167 +2969520516 3389635913 199350882 +1504406289 1061783499 137386237 +623007058 1630426233 244051528 +1749186436 620555911 102666665 +2154532801 339484972 20777175 +1965157268 759103799 189375533 +4007153882 3758595179 60948572 +3180539490 2951315719 231363953 +233604808 1471149229 43027947 +276632755 1919053686 114911374 +1176589409 0 327816880 +867058586 1410457794 27489963 +391544129 1199169736 4581933 +603082303 600118995 19924755 +4068102454 4276290379 18058362 +3810625421 3856463152 158990505 +2969008355 620043750 512161 +3758595179 4224260137 52030242 +396126062 3182679672 206956241 +4006535327 4294348741 618555 +3484771853 3588986795 64994790 +2257987670 2033965060 711020685 +1641792526 2827663439 107393910 +3411903443 1602133748 28292485 +1037034802 1437947757 33201472 +936681812 1203751669 100352990 + +light-to-temperature map: +1726863959 864157287 834947717 +263199301 190436173 53620398 +1393417259 1699105004 333446700 +2783912856 244056571 155961192 +2939874048 400017763 299945457 +671449939 2517852185 721967320 +2561811676 2295751005 222101180 +0 2032551704 263199301 +481013766 0 190436173 +316819699 699963220 164194067 + +temperature-to-humidity map: +603287260 3766826980 8741130 +572607531 3684982838 30679729 +2084038135 1101548002 100083930 +655933651 3228345771 56278566 +1881393627 553997241 168332584 +553997241 2882185871 18610290 +627184746 1072799097 28748905 +612028390 3397056204 15156356 +1693489030 1430646491 187904597 +3039118107 1734352525 2023479 +220345266 0 43042720 +840454312 3775568110 147781659 +2184122065 3715662567 51164413 +317040325 171240045 2422893 +3245373536 4158663426 136303870 +145773749 385599932 74571517 +0 43042720 128197325 +1490020808 4094893831 63769595 +319463218 173662938 140708231 +712212217 1821839294 128242095 +128197325 314371169 17576424 +2474405575 3923349769 171544062 +2352890439 3105028111 121515136 +3467140696 3318936261 78119943 +2235286478 3226543247 1802524 +4084196651 722329825 210770645 +1553790403 933100470 139698627 +1261006249 1201631932 229014559 +263387986 331947593 53652339 +3137034338 2900796161 108339198 +988235971 3412212560 272770278 +2237089002 1618551088 115801437 +3381677406 1736376004 85463290 +3545260639 1950081389 538936012 +2049726211 3284624337 34311924 +2645949637 2489017401 393168470 +3041141586 3009135359 95892752 + +humidity-to-location map: +596652260 530461632 95173962 +3845096173 1731990943 158117085 +2243878974 1890108028 393769632 +0 625635594 63651375 +1920725725 753532949 155684321 +63651375 329652856 200808776 +264460151 0 60175490 +1381444473 2283877660 346420873 +4003213258 3594530530 47694548 +548036821 60175490 46076186 +4100105147 1678246429 53744514 +2637648606 3642225078 292412911 +324635641 106251676 223401180 +4050907806 3545333189 49197341 +4153849661 909217270 141117635 +3455132509 3477799963 67533226 +594113007 689286969 2539253 +2930061517 2630298533 525070992 +753532949 1050334905 627911524 +3522665735 3155369525 322430438 +2076410046 3934637989 167468928 +1727865346 4102106917 192860379 diff --git a/2023/day05_2/src/main/resources/small_input b/2023/day05_2/src/main/resources/small_input new file mode 100644 index 0000000..f756727 --- /dev/null +++ b/2023/day05_2/src/main/resources/small_input @@ -0,0 +1,33 @@ +seeds: 79 14 55 13 + +seed-to-soil map: +50 98 2 +52 50 48 + +soil-to-fertilizer map: +0 15 37 +37 52 2 +39 0 15 + +fertilizer-to-water map: +49 53 8 +0 11 42 +42 0 7 +57 7 4 + +water-to-light map: +88 18 7 +18 25 70 + +light-to-temperature map: +45 77 23 +81 45 19 +68 64 13 + +temperature-to-humidity map: +0 69 1 +1 0 69 + +humidity-to-location map: +60 56 37 +56 93 4 diff --git a/2023/day06_1/day06_1.iml b/2023/day06_1/day06_1.iml new file mode 100644 index 0000000..4eba30b --- /dev/null +++ b/2023/day06_1/day06_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day06_1/src/main/kotlin/Main.kt b/2023/day06_1/src/main/kotlin/Main.kt new file mode 100644 index 0000000..6a636d6 --- /dev/null +++ b/2023/day06_1/src/main/kotlin/Main.kt @@ -0,0 +1,66 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 6, Part 1 starting!!!") + + val time = Time() + val distance = Distance() + File(args[0]).forEachLine { + println("Data read-- $it") + val theSplit = it.split("""\W+""".toRegex()) + + if(theSplit.first() == "Time") { + for(split in theSplit) { + if(split == theSplit.first()) { + // skip the first since it is "Time" + continue + } + time.raceTimes.add(split.toInt()) + } + } else { + for(split in theSplit) { + if(split == theSplit.first()) { + continue + } + distance.raceDistances.add(split.toInt()) + } + } + } + val timeDistance = TimeDistance(time, distance) + + val answer = timeDistance.calculateWaysToBeat() + + println("The answer: $answer") + + println("AOC 2023, Day 6, Part 1 completed!!!") +} + +class Time { + val raceTimes = ArrayList() +} + +class Distance { + val raceDistances = ArrayList() +} + +class TimeDistance(private val time: Time, private val distance: Distance) { + fun calculateWaysToBeat():Long { + var winCount = 1L + for(i in 0.. raceDistance) { + winCount++ + } + } + return winCount + } +} diff --git a/2023/day06_1/src/main/resources/input b/2023/day06_1/src/main/resources/input new file mode 100644 index 0000000..e26400a --- /dev/null +++ b/2023/day06_1/src/main/resources/input @@ -0,0 +1,2 @@ +Time: 54 70 82 75 +Distance: 239 1142 1295 1253 \ No newline at end of file diff --git a/2023/day06_1/src/main/resources/small_input b/2023/day06_1/src/main/resources/small_input new file mode 100644 index 0000000..b39f49d --- /dev/null +++ b/2023/day06_1/src/main/resources/small_input @@ -0,0 +1,2 @@ +Time: 7 15 30 +Distance: 9 40 200 \ No newline at end of file diff --git a/2023/day06_2/day06_2.iml b/2023/day06_2/day06_2.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2023/day06_2/day06_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day06_2/main/resources/input b/2023/day06_2/main/resources/input new file mode 100644 index 0000000..e26400a --- /dev/null +++ b/2023/day06_2/main/resources/input @@ -0,0 +1,2 @@ +Time: 54 70 82 75 +Distance: 239 1142 1295 1253 \ No newline at end of file diff --git a/2023/day06_2/main/resources/small_input b/2023/day06_2/main/resources/small_input new file mode 100644 index 0000000..b39f49d --- /dev/null +++ b/2023/day06_2/main/resources/small_input @@ -0,0 +1,2 @@ +Time: 7 15 30 +Distance: 9 40 200 \ No newline at end of file diff --git a/2023/day06_2/src/Main.kt b/2023/day06_2/src/Main.kt new file mode 100644 index 0000000..51f08dc --- /dev/null +++ b/2023/day06_2/src/Main.kt @@ -0,0 +1,76 @@ +import java.io.File +import java.math.BigInteger + +fun main(args: Array) { + println("AOC 2023, Day 6, Part 2 starting!!!!") + + val time = Time() + val distance = Distance() + File(args[0]).forEachLine { + println("Data read-- $it") + val theSplit = it.split("""\W+""".toRegex()) + + if(theSplit.first() == "Time") { + val rebuildTime = ArrayList() + + for(split in theSplit) { + if(split == theSplit.first()) { + // skip the first since it is "Time" + continue + } + rebuildTime.add(split.toInt()) + } + time.raceTime = rebuildValue(rebuildTime) + } else { + val rebuildDistance = ArrayList() + for(split in theSplit) { + if(split == theSplit.first()) { + // skp the "Distance" + continue + } + rebuildDistance.add(split.toInt()) + } + distance.raceDistance = rebuildValue(rebuildDistance) + } + } + val timeDistance = TimeDistance(time, distance) + + val answer = timeDistance.calculateWaysToBeat() + + println("The answer: $answer") + + println("AOC 2023, Day 6, Part 2 completed!!!") +} + +fun rebuildValue(stringValues:ArrayList):BigInteger { + val theString:StringBuilder = StringBuilder() + stringValues.forEach { theString.append(it) } + return theString.toString().toBigInteger() +} + +class Time { + var raceTime:BigInteger = BigInteger.valueOf(0L) +} + +class Distance { + var raceDistance:BigInteger = BigInteger.valueOf(0L) +} + +class TimeDistance(private val time: Time, private val distance: Distance) { + fun calculateWaysToBeat():BigInteger { + return runRace(time.raceTime, distance.raceDistance) + } + + private fun runRace(raceTime: BigInteger, raceDistance: BigInteger):BigInteger { + var winCount = BigInteger.valueOf(0L) + for(t:Long in 1.. raceTime.toLong()) { + val runTime = raceTime.minus(BigInteger.valueOf(t)) + //val calculatedDistance = t * runTime + val calculatedDistance = BigInteger.valueOf(t).multiply(runTime) + if(calculatedDistance > raceDistance) { + winCount++ + } + } + return winCount + } +} diff --git a/2023/day07_1/.idea/.gitignore b/2023/day07_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/2023/day07_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/2023/day07_1/.idea/inspectionProfiles/Project_Default.xml b/2023/day07_1/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2023/day07_1/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2023/day07_1/.idea/kotlinc.xml b/2023/day07_1/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2023/day07_1/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2023/day07_1/.idea/libraries/KotlinJavaRuntime.xml b/2023/day07_1/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d39de76 --- /dev/null +++ b/2023/day07_1/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day07_1/.idea/misc.xml b/2023/day07_1/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2023/day07_1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day07_1/.idea/modules.xml b/2023/day07_1/.idea/modules.xml new file mode 100644 index 0000000..7cc42f2 --- /dev/null +++ b/2023/day07_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2023/day07_1/.idea/vcs.xml b/2023/day07_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2023/day07_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day07_1/day07_1.iml b/2023/day07_1/day07_1.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2023/day07_1/day07_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day07_1/src/Main.kt b/2023/day07_1/src/Main.kt new file mode 100644 index 0000000..33c1eb0 --- /dev/null +++ b/2023/day07_1/src/Main.kt @@ -0,0 +1,117 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 7, Part 1 starting!!!!") + + val hands = ArrayList() + File(args[0]).forEachLine { + val split = it.split(' ') + hands.add(CamelCardHand(split[0], split[1].toInt())) + } + + val sortedHands = hands.stream().sorted { o1, o2 -> o1.compareTo(o2) } + + var answer = 0L + var rank = 1L + sortedHands.forEach { + answer += it.bid * rank + rank++ + } + + println("Total Winnings: $answer") + + println("AOC 2023, Day 7, Part 1 completed!!!") +} + +class CamelCardHand (private val hand:String, val bid:Int) { + fun compareTo(otherHand:CamelCardHand):Int { + val leftType = calculateType() + val rightType = otherHand.calculateType() + if(leftType == rightType) { + // if there are both the same type, check hand rank + return compareByRank(otherHand) + } + if(leftType > rightType) return 1 + return -1 + } + + private fun compareByRank(otherHand:CamelCardHand):Int { + for(i in 0..5) { + val leftChar = hand.toCharArray()[i] + val rightChar = otherHand.hand.toCharArray()[i] + if(leftChar.compareTo(rightChar) == 0) { + continue + } + if(cardValue(leftChar) > cardValue(rightChar)) { + return 1 + } + return -1 + } + // shouldn't get here but for completeness + return 0 + } + + private fun calculateType():HandType { + val matches = HashMap() + for(c in hand.toCharArray()) { + matches[c] = matches.getOrDefault(c,0) + 1 + } + + if(matches.values.stream().filter { it == 5 }.count() == 1L) { + return HandType.FIVE_KIND + } + if(matches.values.stream().filter { it == 4 }.count() == 1L) { + return HandType.FOUR_KIND + } + if((matches.values.stream().filter { it == 3 }.count() == 1L) && (matches.values.stream().filter { it == 2 }.count() == 1L)) { + return HandType.FULL_HOUSE + } + if(matches.values.stream().filter { it == 3 }.count() == 1L) { + return HandType.THREE_KIND + } + if(matches.values.stream().filter { it == 2 }.count() == 2L) { + return HandType.TWO_PAIR + } + if (matches.values.stream().filter { it == 2}.count() == 1L) { + return HandType.ONE_PAIR + } + if (matches.values.stream().filter { it == 1 }.count() == 5L) { + return HandType.HIGH_CARD + } + + return HandType.HIGH_CARD + } + + private fun cardValue(card:Char):Int { + return when(card) { + '2' -> 2 + '3' -> 3 + '4' -> 4 + '5' -> 5 + '6' -> 6 + '7' -> 7 + '8' -> 8 + '9' -> 9 + 'T' -> 10 + 'J' -> 11 + 'Q' -> 12 + 'K' -> 13 + 'A' -> 14 + else -> 0 + } + } + + enum class HandType { + HIGH_CARD, + ONE_PAIR, + TWO_PAIR, + THREE_KIND, + FULL_HOUSE, + FOUR_KIND, + FIVE_KIND + } + + override fun toString():String { + return "hand: $hand, bid $bid" + } +} diff --git a/2023/day07_1/src/resource/input b/2023/day07_1/src/resource/input new file mode 100644 index 0000000..d133395 --- /dev/null +++ b/2023/day07_1/src/resource/input @@ -0,0 +1,1000 @@ +QAAQT 665 +5K355 312 +Q5T46 440 +A3AJA 461 +QQ9KQ 825 +QJJQQ 51 +7J7A5 37 +8J887 774 +AK3K4 62 +A399A 110 +75845 946 +KAAAA 226 +J9976 869 +627Q8 917 +K2252 216 +A44AA 867 +2TT39 160 +65566 225 +K6KK6 655 +42T34 787 +T6636 347 +QTQTT 371 +83T33 878 +Q9928 742 +JQ85Q 423 +JQJQ2 654 +63TA5 645 +TQ8JQ 884 +T44T4 6 +5J523 83 +87Q42 527 +3J7A7 530 +K99KT 158 +326A7 546 +T2AQ2 8 +99JAA 464 +QQQ9T 988 +J6466 568 +4Q9Q5 182 +J89TJ 63 +66J55 870 +Q35QQ 1 +2K637 46 +T76T8 280 +9A9QA 634 +Q6AAA 486 +88986 350 +4J266 875 +JJ666 116 +38338 422 +A72KQ 799 +A26Q7 666 +33434 788 +32845 457 +9A36A 995 +328Q2 77 +KQ688 238 +5885T 455 +52822 145 +32555 125 +85557 574 +34422 790 +KJ777 428 +JJ777 122 +26852 914 +TKAQ5 819 +374QK 918 +Q365T 462 +62359 179 +J22QJ 367 +55655 641 +JTK4J 679 +K3KK5 711 +A2353 688 +5556J 40 +QQQ79 167 +8K38K 676 +KJJ6J 61 +AA5JA 544 +KKK7K 375 +3Q7QQ 775 +22K88 71 +55KKJ 101 +5J55J 982 +AJTTT 541 +T84KT 343 +T77TA 162 +AT296 31 +T7AJ7 334 +K3K44 310 +TT49A 281 +27648 18 +34449 156 +49489 763 +42924 672 +85886 118 +J6793 800 +5878K 659 +8J26J 21 +384Q3 822 +AAJJJ 949 +77262 643 +66545 411 +24J8Q 520 +TTTT9 314 +7JA7A 473 +2QQJQ 335 +J88KK 721 +32223 251 +J222Q 403 +8J8AA 277 +39QJ6 187 +3Q99J 830 +Q8TT5 240 +J22KK 519 +4J4JQ 928 +7774J 239 +85535 415 +Q38Q9 171 +T8833 588 +3367A 781 +62224 100 +3J8T8 210 +48J88 834 +6Q66Q 301 +3A6K6 586 +2A3K2 419 +83T62 712 +7JJ49 82 +JQ798 66 +97947 921 +A478A 223 +25QA7 602 +3KJ96 729 +KK33K 543 +44Q74 386 +5A635 753 +K33AK 400 +QJ666 756 +QAK7K 564 +J8AKA 682 +28A6T 887 +8AAT7 191 +T6587 612 +JJJ22 430 +55A5A 303 +TT388 976 +33A33 388 +KKAJA 933 +KK852 922 +QTTTT 333 +4T5J4 509 +T99TT 394 +977TJ 785 +88222 862 +442J2 719 +74234 138 +J5KJ8 909 +J6JAA 341 +TQQ4J 381 +55585 111 +T7Q7J 396 +53T65 562 +9K7KK 220 +57J79 356 +KA74Q 687 +JQ687 662 +62A5K 326 +9TTQ9 163 +59595 49 +JKJKK 727 +37369 539 +JAJAA 68 +9KQ43 477 +46J4J 945 +39333 701 +38J65 767 +K93JA 941 +75725 529 +97K9K 615 +26AAK 579 +6A565 420 +5T555 650 +AA788 87 +K2799 969 +TTJQT 185 +K88KK 515 +37Q87 495 +T65QQ 275 +4QQ53 638 +68662 758 +42288 731 +36Q66 789 +JAAA8 924 +J2K77 443 +82Q82 569 +66T6A 476 +TTKTK 108 +74444 993 +J5555 658 +T89J9 38 +23332 246 +K4982 279 +KK4KT 501 +44454 233 +QT398 866 +4447T 432 +4T944 939 +2T828 549 +266TT 72 +99929 814 +49632 256 +4499J 124 +Q5QJ4 573 +48664 175 +76A8J 795 +Q82TJ 245 +JQ39K 336 +57297 689 +33KJJ 959 +64T4T 534 +63636 809 +688T8 583 +84J34 35 +4TJQJ 94 +399QQ 479 +99996 577 +76633 13 +A3AK8 298 +AAA22 697 +88J8T 19 +44Q3Q 610 +99J99 315 +88843 636 +2AAAJ 953 +53535 603 +47AK6 811 +AA65A 642 +K2QA9 902 +34K8A 748 +JA738 611 +7A777 829 +Q6Q77 559 +QQJQQ 991 +23222 368 +755A5 536 +7A987 177 +Q47K8 624 +69666 705 +KK233 329 +J9J44 450 +J22J2 670 +A55JA 926 +229K2 827 +T8A36 237 +22526 490 +KKK5K 75 +9729J 693 +9K829 609 +T293Q 796 +J8A44 931 +K9J46 441 +75776 149 +6KJK2 675 +TT7QT 507 +27K2J 533 +72444 764 +4QA89 990 +A5238 754 +K5335 152 +2K372 132 +37J73 328 +A7TQ9 965 +2T22T 484 +66T4T 199 +3K333 337 +9854K 20 +TAAQ2 103 +A44T6 81 +7262J 510 +K92AJ 983 +827A5 614 +23773 980 +9Q524 166 +333JJ 463 +AA4JQ 911 +QQ282 313 +9K75A 873 +9Q484 332 +Q7J77 114 +TATKA 218 +2TTTT 798 +3Q335 966 +33QJQ 212 +4Q55A 901 +947A9 736 +92J48 465 +4TTKJ 50 +8J898 604 +2TJ52 840 +Q9JJ8 813 +7KQQ4 958 +55453 282 +4AAAJ 183 +5998J 65 +597JJ 480 +QQQQ3 207 +Q78KJ 720 +J9993 331 +K7J57 677 +J8868 597 +36238 770 +48K28 517 +K57T7 43 +7K737 305 +22J22 553 +32J22 691 +A3K86 259 +J6A6Q 135 +5QAQA 164 +A2J2A 595 +9K3Q3 557 +J3J9J 552 +83222 703 +9Q9JQ 113 +T676J 823 +K4446 85 +TQJK6 250 +T6KTQ 376 +6AKT5 294 +7AA22 243 +26QJQ 398 +K4T28 141 +T58KA 73 +J5Q4K 47 +AAA59 652 +QA4K9 622 +T888T 967 +7375J 726 +AKA5A 14 +A3A5Q 894 +88588 7 +94664 354 +T9926 29 +54JJJ 776 +AQ3K9 752 +J8TT8 105 +65TA8 421 +99966 269 +92JKT 296 +KKKK4 673 +2JQ2T 832 +KAKK9 262 +992J3 554 +66868 700 +AA2AA 351 +Q4743 851 +34394 355 +T6T69 732 +TA549 155 +QQ99Q 300 +33QKJ 555 +A4444 833 +3KJK3 563 +65A78 831 +KAKK8 744 +5QQKQ 985 +5754J 769 +666JA 414 +TKKKK 23 +93K5J 837 +85558 78 +K6286 663 +T8K58 735 +56JAA 224 +4T94T 345 +63333 172 +58356 853 +666TK 30 +A77AQ 896 +68QA8 174 +924KA 292 +92TJ2 898 +J5859 230 +QTTT6 319 +AAJAA 860 +28A4Q 714 +K274T 671 +73337 28 +979JT 899 +8KKKK 740 +4Q99Q 944 +KKKJ7 718 +Q7JQQ 438 +73K3T 999 +5J25J 379 +5999A 416 +T9922 265 +7K485 648 +3A57K 686 +777J8 695 +KT999 274 +2554Q 500 +T2226 284 +Q8QQQ 302 +KJK9K 556 +53A99 52 +768K3 488 +55JA5 115 +K3K77 986 +77KJK 804 +86585 390 +39699 469 +TTT53 859 +26266 628 +87858 200 +J9Q7K 359 +J8AQ4 377 +3998Q 76 +99994 161 +3587J 728 +K9K33 816 +J8Q8J 456 +894J9 733 +T4J65 514 +72767 613 +5T8K2 370 +KAKA6 855 +A3QJ3 738 +JQ537 504 +83323 271 +KK667 558 +QKQ8Q 908 +4TAAA 34 +35Q95 625 +T9777 323 +66664 9 +99A66 631 +888JA 244 +J745Q 635 +ATJ4T 107 +49KQ7 757 +95999 242 +4A422 560 +6QJ2A 854 +77288 646 +6TTJ6 989 +T777T 524 +34A34 22 +3A362 295 +66967 528 +J77K3 297 +22T7K 485 +33J34 904 +83J38 287 +98KA2 372 +74Q6A 221 +KKK55 348 +QQ222 838 +7TTQ5 342 +KKK9K 640 +22922 405 +QQQTQ 633 +98T87 912 +55357 449 +92333 198 +76777 470 +48JTK 849 +J9779 321 +95557 64 +J9299 605 +2JQK2 578 +36634 44 +TTKKJ 90 +T4666 190 +TA7K4 364 +8T85A 330 +J92J2 717 +22945 606 +756K6 561 +8632K 452 +747KK 365 +T68J6 195 +JA454 587 +QK849 793 +594J8 812 +92559 970 +89829 130 +Q6849 571 +4TA4T 996 +TQ24Q 846 +T8T3T 792 +AA5A7 338 +553A8 325 +KK95J 566 +Q4443 734 +T923K 512 +939Q9 716 +K3TJ3 864 +5T9J2 590 +22522 644 +88444 778 +97779 475 +5AJK5 548 +344A4 618 +TT252 508 +6T359 466 +2AA2Q 446 +TAATA 916 +6K6KJ 954 +4AAK5 255 +T433T 952 +299K6 389 +33343 399 +QJAAA 98 +JQ3Q9 601 +39999 521 +8A3J3 847 +99339 791 +JTJTT 661 +9AKQT 451 +5Q5K5 651 +42242 955 +Q2266 794 +5JJK7 227 +QQKJ6 454 +TJ9T9 15 +K4K46 254 +Q9KKK 213 +Q8844 786 +8922K 998 +J877J 617 +77929 412 +J8A66 531 +555TT 513 +K6Q49 268 +64464 801 +99JJ9 523 +626A7 709 +7AQQQ 835 +66AA6 938 +88T56 667 +KKKJ4 960 +48999 503 +4494J 496 +K883J 391 +2KK99 119 +7737A 270 +KQJ69 550 +33KA8 723 +T3JT9 893 +99899 444 +T847J 134 +J9694 616 +55AAQ 1000 +3742T 660 +44QK4 940 +7777K 773 +TTT5T 923 +JKJKJ 150 +9KK99 649 +AJ546 2 +A999A 694 +KA4A6 828 +9AJA4 168 +555Q5 353 +64J46 426 +55KTA 327 +86688 747 +J8883 905 +2JQ2Q 460 +59826 120 +T843K 600 +52252 32 +Q62J9 576 +38777 684 +3T433 418 +4J4AA 772 +QQKJJ 621 +A9637 815 +99JK3 74 +35J99 349 +98334 402 +86K42 215 +T8J3A 930 +89A38 627 +8JJ87 730 +T6256 664 +68445 264 +47673 858 +AT28A 803 +8KQ28 392 +33JK3 425 +53999 11 +68TJ8 59 +7K7K7 241 +64379 383 +K3TQ4 581 +T5Q88 593 +77474 60 +887JA 252 +44446 852 +J9393 971 +8A633 492 +74479 589 +2Q555 565 +8J888 407 +97Q5A 178 +48632 16 +4K6QT 805 +3Q333 106 +T36J3 17 +AAKKK 981 +AAJQQ 194 +9Q393 584 +JTKK9 505 +J986K 3 +55KJ5 285 +8K882 920 +8KA82 232 +9AAA9 656 +22J92 630 +QQQQA 522 +7A652 25 +T4665 591 +T7TAT 447 +87KK7 762 +QT967 493 +Q3QJ6 580 +A8T6T 180 +88J58 843 +KKKTQ 957 +45K2K 380 +22343 749 +K8T88 963 +3T4QJ 48 +T59AQ 136 +QKKQJ 487 +353J5 283 +4J8Q5 936 +7747A 844 +52562 992 +6JJ64 888 +8Q33J 102 +K86A4 373 +747A9 572 +JA22Q 184 +79333 236 +9Q65K 532 +4J677 234 +A2J74 154 +92339 4 +J3337 751 +67A5T 248 +A8AAA 339 +37K3K 413 +43337 678 +93QQ3 69 +5KQJK 346 +T9T99 324 +66T66 802 +3T792 79 +57575 231 +J47JT 715 +62666 657 +997K9 128 +32TK7 253 +96294 877 +63666 5 +KK397 408 +4A4J4 97 +Q4265 146 +AKJAA 948 +J5Q94 263 +ATTTT 575 +4827T 133 +47AK9 683 +68T47 567 +2QK28 445 +T22JT 607 +662QQ 181 +QQ6QQ 153 +92292 582 +96K9J 173 +2J299 404 +T333T 273 +25J55 362 +6AJ2T 929 +5K323 710 +9944K 453 +A9Q49 755 +TTQ5T 962 +444Q4 311 +76666 176 +9946K 690 +KK3QJ 471 +ATTT6 247 +2A2K8 112 +A4T9Q 692 +777J7 839 +595J4 206 +TAATT 629 +53333 883 +A59T6 707 +44525 906 +Q8J8Q 137 +T3J93 696 +47464 340 +J2822 907 +JJ559 196 +55343 653 +9K9Q9 674 +8TQQQ 211 +7J275 70 +22Q5J 276 +66564 129 +TJTJJ 489 +KK6KK 409 +5Q98A 157 +78777 857 +67667 807 +5QK98 39 +K35J6 592 +96KT2 109 +4KK44 127 +T6253 768 +85989 836 +55445 299 +T9736 121 +A696A 950 +T48QT 668 +644K6 518 +JJJJJ 876 +TQ6AT 759 +KK83K 260 +73777 214 +6K66Q 598 +5K39A 169 +64T7T 219 +238J2 442 +4J22Q 203 +Q9TA6 291 +5T86J 26 +T439K 272 +44244 817 +K8844 459 +K5KK7 975 +A666Q 842 +8T6Q7 434 +63Q4J 42 +966J9 637 +JA6KA 863 +A5555 972 +T2222 745 +AAA7A 499 +Q359T 436 +A2A5A 879 +QQQQ5 623 +K4T5T 724 +A888A 987 +5J535 201 +5A9K6 123 +4QJ43 431 +75J4J 491 +283J8 698 +T7T8T 448 +33J76 197 +47QJA 24 +2T272 951 +A7A87 142 +J3TT3 540 +4JJ44 961 +KJJ63 478 +92QQ9 278 +TJTTT 192 +TJK68 307 +37773 290 +QQQT6 126 +QJQ9Q 401 +24K3A 186 +8443Q 820 +33592 56 +87923 497 +TTJ8Q 632 +J4544 934 +6K666 474 +68566 739 +A4AAA 669 +89899 139 +842K3 596 +K5AA5 429 +85885 599 +59779 437 +A336J 779 +TT3A3 366 +97Q7A 261 +83393 545 +Q6Q6T 974 +37T2J 890 +38333 58 +28227 363 +TTT66 33 +32333 468 +A8T55 824 +88889 435 +KQQ3Q 385 +T6685 318 +5K76J 202 +75777 99 +53566 55 +TTKJT 481 +875J9 551 +447A7 947 +T2TT7 147 +T2726 810 +TT6TT 856 +QK9JQ 27 +A786Q 897 +44J44 542 +98QJ3 189 +J4448 89 +Q8Q8Q 417 +59473 57 +99K99 148 +662AJ 361 +7TTTT 994 +26T97 36 +7A69T 746 +95JA5 516 +J9J8K 886 +57333 358 +4TJQA 881 +T5628 151 +72A59 205 +QK777 249 +84649 397 +T7T96 761 +4TAQQ 378 +24274 494 +KJ3KK 845 +TT77T 384 +8J88J 722 +A25T4 880 +88868 861 +Q5QK2 502 +35344 267 +K99AA 777 +2T375 903 +4484Q 891 +J8AQA 67 +QJ578 935 +T72T7 482 +5AQK8 973 +T3AA9 848 +8TJJ7 165 +88J75 322 +T8T8A 54 +93524 956 +29T9Q 458 +66272 647 +TQTQQ 681 +629J4 483 +6676T 708 +9QT99 704 +67977 942 +737J7 808 +T785K 865 +7AAA4 943 +88Q8J 619 +QK663 91 +9734J 818 +J4TTT 895 +5A585 80 +8JJJJ 159 +7T298 170 +8998A 140 +TT5T2 266 +44443 53 +57565 439 +T579A 317 +A5QAA 235 +A665A 84 +223J3 766 +T63AJ 741 +62K97 760 +Q8Q33 538 +A5955 293 +JKKKK 86 +88228 10 +376J7 93 +7343T 535 +KQK44 882 +KKK76 395 +9229K 526 +J63J8 320 +ATKKK 104 +T4JT4 850 +79A9A 780 +AA6A3 387 +6A542 889 +45242 228 +KJ75Q 369 +52T29 41 +A9924 309 +A7838 925 +2738J 229 +22262 782 +A55AA 144 +77727 88 +86556 188 +46443 997 +666J6 900 +99968 12 +9AA49 927 +68666 467 +52K68 750 +3J339 498 +43634 304 +TJK46 585 +43533 511 +55245 537 +39K3J 765 +65J54 937 +5T684 594 +22Q74 868 +25255 871 +5TTJ5 797 +93J7A 784 +AAAQ8 357 +7J727 968 +44T44 821 +77533 608 +KQQ83 547 +72222 680 +44A4A 406 +8932K 222 +KK59K 874 +774K4 92 +29992 570 +3333J 620 +39393 506 +74773 892 +T79Q8 208 +TTT3T 885 +QQQ8A 374 +99979 360 +2965T 872 +AA6AJ 96 +383K9 826 +7TK7K 685 +6J755 979 +2QQQ2 706 +TTT4T 525 +3K767 699 +75J8J 639 +KTJK3 743 +7972T 308 +77573 143 +J253K 286 +TQK85 316 +6235A 193 +338TT 393 +JT8T5 352 +JA4JA 984 +JAQ86 737 +9T589 306 +KJQQQ 424 +JJKTK 964 +QTJTQ 783 +6J626 289 +24Q22 131 +QAT5A 919 +6486K 702 +QT464 288 +A6972 841 +Q99Q9 977 +4JJ43 209 +66AA8 910 +Q34QT 806 +Q8J4Q 472 +979TT 932 +A8A8A 204 +9A34Q 382 +QT89A 713 +JQJJQ 427 +8338K 978 +99T99 913 +6A444 257 +4K5KK 45 +55K55 217 +K8866 915 +42577 771 +45564 725 +Q2TAQ 433 +Q9AA6 258 +867A3 117 +A9799 95 +74778 344 +A2727 410 +78888 626 diff --git a/2023/day07_1/src/resource/small_input b/2023/day07_1/src/resource/small_input new file mode 100644 index 0000000..bf2815e --- /dev/null +++ b/2023/day07_1/src/resource/small_input @@ -0,0 +1,5 @@ +32T3K 765 +T55J5 684 +KK677 28 +KTJJT 220 +QQQJA 483 \ No newline at end of file diff --git a/2023/day07_2/.idea/inspectionProfiles/Project_Default.xml b/2023/day07_2/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2023/day07_2/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2023/day07_2/.idea/kotlinc.xml b/2023/day07_2/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2023/day07_2/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2023/day07_2/.idea/libraries/KotlinJavaRuntime.xml b/2023/day07_2/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d39de76 --- /dev/null +++ b/2023/day07_2/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day07_2/.idea/misc.xml b/2023/day07_2/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2023/day07_2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day07_2/.idea/modules.xml b/2023/day07_2/.idea/modules.xml new file mode 100644 index 0000000..b9eba0a --- /dev/null +++ b/2023/day07_2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2023/day07_2/.idea/vcs.xml b/2023/day07_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2023/day07_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day07_2/day07_2.iml b/2023/day07_2/day07_2.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2023/day07_2/day07_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day07_2/resource/input b/2023/day07_2/resource/input new file mode 100644 index 0000000..d133395 --- /dev/null +++ b/2023/day07_2/resource/input @@ -0,0 +1,1000 @@ +QAAQT 665 +5K355 312 +Q5T46 440 +A3AJA 461 +QQ9KQ 825 +QJJQQ 51 +7J7A5 37 +8J887 774 +AK3K4 62 +A399A 110 +75845 946 +KAAAA 226 +J9976 869 +627Q8 917 +K2252 216 +A44AA 867 +2TT39 160 +65566 225 +K6KK6 655 +42T34 787 +T6636 347 +QTQTT 371 +83T33 878 +Q9928 742 +JQ85Q 423 +JQJQ2 654 +63TA5 645 +TQ8JQ 884 +T44T4 6 +5J523 83 +87Q42 527 +3J7A7 530 +K99KT 158 +326A7 546 +T2AQ2 8 +99JAA 464 +QQQ9T 988 +J6466 568 +4Q9Q5 182 +J89TJ 63 +66J55 870 +Q35QQ 1 +2K637 46 +T76T8 280 +9A9QA 634 +Q6AAA 486 +88986 350 +4J266 875 +JJ666 116 +38338 422 +A72KQ 799 +A26Q7 666 +33434 788 +32845 457 +9A36A 995 +328Q2 77 +KQ688 238 +5885T 455 +52822 145 +32555 125 +85557 574 +34422 790 +KJ777 428 +JJ777 122 +26852 914 +TKAQ5 819 +374QK 918 +Q365T 462 +62359 179 +J22QJ 367 +55655 641 +JTK4J 679 +K3KK5 711 +A2353 688 +5556J 40 +QQQ79 167 +8K38K 676 +KJJ6J 61 +AA5JA 544 +KKK7K 375 +3Q7QQ 775 +22K88 71 +55KKJ 101 +5J55J 982 +AJTTT 541 +T84KT 343 +T77TA 162 +AT296 31 +T7AJ7 334 +K3K44 310 +TT49A 281 +27648 18 +34449 156 +49489 763 +42924 672 +85886 118 +J6793 800 +5878K 659 +8J26J 21 +384Q3 822 +AAJJJ 949 +77262 643 +66545 411 +24J8Q 520 +TTTT9 314 +7JA7A 473 +2QQJQ 335 +J88KK 721 +32223 251 +J222Q 403 +8J8AA 277 +39QJ6 187 +3Q99J 830 +Q8TT5 240 +J22KK 519 +4J4JQ 928 +7774J 239 +85535 415 +Q38Q9 171 +T8833 588 +3367A 781 +62224 100 +3J8T8 210 +48J88 834 +6Q66Q 301 +3A6K6 586 +2A3K2 419 +83T62 712 +7JJ49 82 +JQ798 66 +97947 921 +A478A 223 +25QA7 602 +3KJ96 729 +KK33K 543 +44Q74 386 +5A635 753 +K33AK 400 +QJ666 756 +QAK7K 564 +J8AKA 682 +28A6T 887 +8AAT7 191 +T6587 612 +JJJ22 430 +55A5A 303 +TT388 976 +33A33 388 +KKAJA 933 +KK852 922 +QTTTT 333 +4T5J4 509 +T99TT 394 +977TJ 785 +88222 862 +442J2 719 +74234 138 +J5KJ8 909 +J6JAA 341 +TQQ4J 381 +55585 111 +T7Q7J 396 +53T65 562 +9K7KK 220 +57J79 356 +KA74Q 687 +JQ687 662 +62A5K 326 +9TTQ9 163 +59595 49 +JKJKK 727 +37369 539 +JAJAA 68 +9KQ43 477 +46J4J 945 +39333 701 +38J65 767 +K93JA 941 +75725 529 +97K9K 615 +26AAK 579 +6A565 420 +5T555 650 +AA788 87 +K2799 969 +TTJQT 185 +K88KK 515 +37Q87 495 +T65QQ 275 +4QQ53 638 +68662 758 +42288 731 +36Q66 789 +JAAA8 924 +J2K77 443 +82Q82 569 +66T6A 476 +TTKTK 108 +74444 993 +J5555 658 +T89J9 38 +23332 246 +K4982 279 +KK4KT 501 +44454 233 +QT398 866 +4447T 432 +4T944 939 +2T828 549 +266TT 72 +99929 814 +49632 256 +4499J 124 +Q5QJ4 573 +48664 175 +76A8J 795 +Q82TJ 245 +JQ39K 336 +57297 689 +33KJJ 959 +64T4T 534 +63636 809 +688T8 583 +84J34 35 +4TJQJ 94 +399QQ 479 +99996 577 +76633 13 +A3AK8 298 +AAA22 697 +88J8T 19 +44Q3Q 610 +99J99 315 +88843 636 +2AAAJ 953 +53535 603 +47AK6 811 +AA65A 642 +K2QA9 902 +34K8A 748 +JA738 611 +7A777 829 +Q6Q77 559 +QQJQQ 991 +23222 368 +755A5 536 +7A987 177 +Q47K8 624 +69666 705 +KK233 329 +J9J44 450 +J22J2 670 +A55JA 926 +229K2 827 +T8A36 237 +22526 490 +KKK5K 75 +9729J 693 +9K829 609 +T293Q 796 +J8A44 931 +K9J46 441 +75776 149 +6KJK2 675 +TT7QT 507 +27K2J 533 +72444 764 +4QA89 990 +A5238 754 +K5335 152 +2K372 132 +37J73 328 +A7TQ9 965 +2T22T 484 +66T4T 199 +3K333 337 +9854K 20 +TAAQ2 103 +A44T6 81 +7262J 510 +K92AJ 983 +827A5 614 +23773 980 +9Q524 166 +333JJ 463 +AA4JQ 911 +QQ282 313 +9K75A 873 +9Q484 332 +Q7J77 114 +TATKA 218 +2TTTT 798 +3Q335 966 +33QJQ 212 +4Q55A 901 +947A9 736 +92J48 465 +4TTKJ 50 +8J898 604 +2TJ52 840 +Q9JJ8 813 +7KQQ4 958 +55453 282 +4AAAJ 183 +5998J 65 +597JJ 480 +QQQQ3 207 +Q78KJ 720 +J9993 331 +K7J57 677 +J8868 597 +36238 770 +48K28 517 +K57T7 43 +7K737 305 +22J22 553 +32J22 691 +A3K86 259 +J6A6Q 135 +5QAQA 164 +A2J2A 595 +9K3Q3 557 +J3J9J 552 +83222 703 +9Q9JQ 113 +T676J 823 +K4446 85 +TQJK6 250 +T6KTQ 376 +6AKT5 294 +7AA22 243 +26QJQ 398 +K4T28 141 +T58KA 73 +J5Q4K 47 +AAA59 652 +QA4K9 622 +T888T 967 +7375J 726 +AKA5A 14 +A3A5Q 894 +88588 7 +94664 354 +T9926 29 +54JJJ 776 +AQ3K9 752 +J8TT8 105 +65TA8 421 +99966 269 +92JKT 296 +KKKK4 673 +2JQ2T 832 +KAKK9 262 +992J3 554 +66868 700 +AA2AA 351 +Q4743 851 +34394 355 +T6T69 732 +TA549 155 +QQ99Q 300 +33QKJ 555 +A4444 833 +3KJK3 563 +65A78 831 +KAKK8 744 +5QQKQ 985 +5754J 769 +666JA 414 +TKKKK 23 +93K5J 837 +85558 78 +K6286 663 +T8K58 735 +56JAA 224 +4T94T 345 +63333 172 +58356 853 +666TK 30 +A77AQ 896 +68QA8 174 +924KA 292 +92TJ2 898 +J5859 230 +QTTT6 319 +AAJAA 860 +28A4Q 714 +K274T 671 +73337 28 +979JT 899 +8KKKK 740 +4Q99Q 944 +KKKJ7 718 +Q7JQQ 438 +73K3T 999 +5J25J 379 +5999A 416 +T9922 265 +7K485 648 +3A57K 686 +777J8 695 +KT999 274 +2554Q 500 +T2226 284 +Q8QQQ 302 +KJK9K 556 +53A99 52 +768K3 488 +55JA5 115 +K3K77 986 +77KJK 804 +86585 390 +39699 469 +TTT53 859 +26266 628 +87858 200 +J9Q7K 359 +J8AQ4 377 +3998Q 76 +99994 161 +3587J 728 +K9K33 816 +J8Q8J 456 +894J9 733 +T4J65 514 +72767 613 +5T8K2 370 +KAKA6 855 +A3QJ3 738 +JQ537 504 +83323 271 +KK667 558 +QKQ8Q 908 +4TAAA 34 +35Q95 625 +T9777 323 +66664 9 +99A66 631 +888JA 244 +J745Q 635 +ATJ4T 107 +49KQ7 757 +95999 242 +4A422 560 +6QJ2A 854 +77288 646 +6TTJ6 989 +T777T 524 +34A34 22 +3A362 295 +66967 528 +J77K3 297 +22T7K 485 +33J34 904 +83J38 287 +98KA2 372 +74Q6A 221 +KKK55 348 +QQ222 838 +7TTQ5 342 +KKK9K 640 +22922 405 +QQQTQ 633 +98T87 912 +55357 449 +92333 198 +76777 470 +48JTK 849 +J9779 321 +95557 64 +J9299 605 +2JQK2 578 +36634 44 +TTKKJ 90 +T4666 190 +TA7K4 364 +8T85A 330 +J92J2 717 +22945 606 +756K6 561 +8632K 452 +747KK 365 +T68J6 195 +JA454 587 +QK849 793 +594J8 812 +92559 970 +89829 130 +Q6849 571 +4TA4T 996 +TQ24Q 846 +T8T3T 792 +AA5A7 338 +553A8 325 +KK95J 566 +Q4443 734 +T923K 512 +939Q9 716 +K3TJ3 864 +5T9J2 590 +22522 644 +88444 778 +97779 475 +5AJK5 548 +344A4 618 +TT252 508 +6T359 466 +2AA2Q 446 +TAATA 916 +6K6KJ 954 +4AAK5 255 +T433T 952 +299K6 389 +33343 399 +QJAAA 98 +JQ3Q9 601 +39999 521 +8A3J3 847 +99339 791 +JTJTT 661 +9AKQT 451 +5Q5K5 651 +42242 955 +Q2266 794 +5JJK7 227 +QQKJ6 454 +TJ9T9 15 +K4K46 254 +Q9KKK 213 +Q8844 786 +8922K 998 +J877J 617 +77929 412 +J8A66 531 +555TT 513 +K6Q49 268 +64464 801 +99JJ9 523 +626A7 709 +7AQQQ 835 +66AA6 938 +88T56 667 +KKKJ4 960 +48999 503 +4494J 496 +K883J 391 +2KK99 119 +7737A 270 +KQJ69 550 +33KA8 723 +T3JT9 893 +99899 444 +T847J 134 +J9694 616 +55AAQ 1000 +3742T 660 +44QK4 940 +7777K 773 +TTT5T 923 +JKJKJ 150 +9KK99 649 +AJ546 2 +A999A 694 +KA4A6 828 +9AJA4 168 +555Q5 353 +64J46 426 +55KTA 327 +86688 747 +J8883 905 +2JQ2Q 460 +59826 120 +T843K 600 +52252 32 +Q62J9 576 +38777 684 +3T433 418 +4J4AA 772 +QQKJJ 621 +A9637 815 +99JK3 74 +35J99 349 +98334 402 +86K42 215 +T8J3A 930 +89A38 627 +8JJ87 730 +T6256 664 +68445 264 +47673 858 +AT28A 803 +8KQ28 392 +33JK3 425 +53999 11 +68TJ8 59 +7K7K7 241 +64379 383 +K3TQ4 581 +T5Q88 593 +77474 60 +887JA 252 +44446 852 +J9393 971 +8A633 492 +74479 589 +2Q555 565 +8J888 407 +97Q5A 178 +48632 16 +4K6QT 805 +3Q333 106 +T36J3 17 +AAKKK 981 +AAJQQ 194 +9Q393 584 +JTKK9 505 +J986K 3 +55KJ5 285 +8K882 920 +8KA82 232 +9AAA9 656 +22J92 630 +QQQQA 522 +7A652 25 +T4665 591 +T7TAT 447 +87KK7 762 +QT967 493 +Q3QJ6 580 +A8T6T 180 +88J58 843 +KKKTQ 957 +45K2K 380 +22343 749 +K8T88 963 +3T4QJ 48 +T59AQ 136 +QKKQJ 487 +353J5 283 +4J8Q5 936 +7747A 844 +52562 992 +6JJ64 888 +8Q33J 102 +K86A4 373 +747A9 572 +JA22Q 184 +79333 236 +9Q65K 532 +4J677 234 +A2J74 154 +92339 4 +J3337 751 +67A5T 248 +A8AAA 339 +37K3K 413 +43337 678 +93QQ3 69 +5KQJK 346 +T9T99 324 +66T66 802 +3T792 79 +57575 231 +J47JT 715 +62666 657 +997K9 128 +32TK7 253 +96294 877 +63666 5 +KK397 408 +4A4J4 97 +Q4265 146 +AKJAA 948 +J5Q94 263 +ATTTT 575 +4827T 133 +47AK9 683 +68T47 567 +2QK28 445 +T22JT 607 +662QQ 181 +QQ6QQ 153 +92292 582 +96K9J 173 +2J299 404 +T333T 273 +25J55 362 +6AJ2T 929 +5K323 710 +9944K 453 +A9Q49 755 +TTQ5T 962 +444Q4 311 +76666 176 +9946K 690 +KK3QJ 471 +ATTT6 247 +2A2K8 112 +A4T9Q 692 +777J7 839 +595J4 206 +TAATT 629 +53333 883 +A59T6 707 +44525 906 +Q8J8Q 137 +T3J93 696 +47464 340 +J2822 907 +JJ559 196 +55343 653 +9K9Q9 674 +8TQQQ 211 +7J275 70 +22Q5J 276 +66564 129 +TJTJJ 489 +KK6KK 409 +5Q98A 157 +78777 857 +67667 807 +5QK98 39 +K35J6 592 +96KT2 109 +4KK44 127 +T6253 768 +85989 836 +55445 299 +T9736 121 +A696A 950 +T48QT 668 +644K6 518 +JJJJJ 876 +TQ6AT 759 +KK83K 260 +73777 214 +6K66Q 598 +5K39A 169 +64T7T 219 +238J2 442 +4J22Q 203 +Q9TA6 291 +5T86J 26 +T439K 272 +44244 817 +K8844 459 +K5KK7 975 +A666Q 842 +8T6Q7 434 +63Q4J 42 +966J9 637 +JA6KA 863 +A5555 972 +T2222 745 +AAA7A 499 +Q359T 436 +A2A5A 879 +QQQQ5 623 +K4T5T 724 +A888A 987 +5J535 201 +5A9K6 123 +4QJ43 431 +75J4J 491 +283J8 698 +T7T8T 448 +33J76 197 +47QJA 24 +2T272 951 +A7A87 142 +J3TT3 540 +4JJ44 961 +KJJ63 478 +92QQ9 278 +TJTTT 192 +TJK68 307 +37773 290 +QQQT6 126 +QJQ9Q 401 +24K3A 186 +8443Q 820 +33592 56 +87923 497 +TTJ8Q 632 +J4544 934 +6K666 474 +68566 739 +A4AAA 669 +89899 139 +842K3 596 +K5AA5 429 +85885 599 +59779 437 +A336J 779 +TT3A3 366 +97Q7A 261 +83393 545 +Q6Q6T 974 +37T2J 890 +38333 58 +28227 363 +TTT66 33 +32333 468 +A8T55 824 +88889 435 +KQQ3Q 385 +T6685 318 +5K76J 202 +75777 99 +53566 55 +TTKJT 481 +875J9 551 +447A7 947 +T2TT7 147 +T2726 810 +TT6TT 856 +QK9JQ 27 +A786Q 897 +44J44 542 +98QJ3 189 +J4448 89 +Q8Q8Q 417 +59473 57 +99K99 148 +662AJ 361 +7TTTT 994 +26T97 36 +7A69T 746 +95JA5 516 +J9J8K 886 +57333 358 +4TJQA 881 +T5628 151 +72A59 205 +QK777 249 +84649 397 +T7T96 761 +4TAQQ 378 +24274 494 +KJ3KK 845 +TT77T 384 +8J88J 722 +A25T4 880 +88868 861 +Q5QK2 502 +35344 267 +K99AA 777 +2T375 903 +4484Q 891 +J8AQA 67 +QJ578 935 +T72T7 482 +5AQK8 973 +T3AA9 848 +8TJJ7 165 +88J75 322 +T8T8A 54 +93524 956 +29T9Q 458 +66272 647 +TQTQQ 681 +629J4 483 +6676T 708 +9QT99 704 +67977 942 +737J7 808 +T785K 865 +7AAA4 943 +88Q8J 619 +QK663 91 +9734J 818 +J4TTT 895 +5A585 80 +8JJJJ 159 +7T298 170 +8998A 140 +TT5T2 266 +44443 53 +57565 439 +T579A 317 +A5QAA 235 +A665A 84 +223J3 766 +T63AJ 741 +62K97 760 +Q8Q33 538 +A5955 293 +JKKKK 86 +88228 10 +376J7 93 +7343T 535 +KQK44 882 +KKK76 395 +9229K 526 +J63J8 320 +ATKKK 104 +T4JT4 850 +79A9A 780 +AA6A3 387 +6A542 889 +45242 228 +KJ75Q 369 +52T29 41 +A9924 309 +A7838 925 +2738J 229 +22262 782 +A55AA 144 +77727 88 +86556 188 +46443 997 +666J6 900 +99968 12 +9AA49 927 +68666 467 +52K68 750 +3J339 498 +43634 304 +TJK46 585 +43533 511 +55245 537 +39K3J 765 +65J54 937 +5T684 594 +22Q74 868 +25255 871 +5TTJ5 797 +93J7A 784 +AAAQ8 357 +7J727 968 +44T44 821 +77533 608 +KQQ83 547 +72222 680 +44A4A 406 +8932K 222 +KK59K 874 +774K4 92 +29992 570 +3333J 620 +39393 506 +74773 892 +T79Q8 208 +TTT3T 885 +QQQ8A 374 +99979 360 +2965T 872 +AA6AJ 96 +383K9 826 +7TK7K 685 +6J755 979 +2QQQ2 706 +TTT4T 525 +3K767 699 +75J8J 639 +KTJK3 743 +7972T 308 +77573 143 +J253K 286 +TQK85 316 +6235A 193 +338TT 393 +JT8T5 352 +JA4JA 984 +JAQ86 737 +9T589 306 +KJQQQ 424 +JJKTK 964 +QTJTQ 783 +6J626 289 +24Q22 131 +QAT5A 919 +6486K 702 +QT464 288 +A6972 841 +Q99Q9 977 +4JJ43 209 +66AA8 910 +Q34QT 806 +Q8J4Q 472 +979TT 932 +A8A8A 204 +9A34Q 382 +QT89A 713 +JQJJQ 427 +8338K 978 +99T99 913 +6A444 257 +4K5KK 45 +55K55 217 +K8866 915 +42577 771 +45564 725 +Q2TAQ 433 +Q9AA6 258 +867A3 117 +A9799 95 +74778 344 +A2727 410 +78888 626 diff --git a/2023/day07_2/resource/small_input b/2023/day07_2/resource/small_input new file mode 100644 index 0000000..bf2815e --- /dev/null +++ b/2023/day07_2/resource/small_input @@ -0,0 +1,5 @@ +32T3K 765 +T55J5 684 +KK677 28 +KTJJT 220 +QQQJA 483 \ No newline at end of file diff --git a/2023/day07_2/resource/small_input2 b/2023/day07_2/resource/small_input2 new file mode 100644 index 0000000..232bb67 --- /dev/null +++ b/2023/day07_2/resource/small_input2 @@ -0,0 +1,7 @@ +2JJJ3 820 +JKKK2 821 +QQQQ2 822 +JJJJJ 823 +TTTTT 72 +22222 824 +TTTJT 772 \ No newline at end of file diff --git a/2023/day07_2/src/Main.kt b/2023/day07_2/src/Main.kt new file mode 100644 index 0000000..38c9dfb --- /dev/null +++ b/2023/day07_2/src/Main.kt @@ -0,0 +1,140 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 7, Part 2 starting!!!!") + + val hands = ArrayList() + File(args[0]).forEachLine { + val split = it.split(' ') + hands.add(CamelCardHand(split[0], split[1].toInt())) + } + + val sortedHands = hands.stream().sorted { o1, o2 -> o1.compareTo(o2) } + + var answer = 0L + var rank = 1L + sortedHands.forEach { + answer += it.bid * rank + rank++ + } + + println("Total Winnings: $answer") + + println("AOC 2023, Day 7, Part 2 completed!!!") +} + +class CamelCardHand (private val hand:String, val bid:Int) { + fun compareTo(otherHand:CamelCardHand):Int { + val leftType = calculateType() + val rightType = otherHand.calculateType() + if(leftType == rightType) { + // if there are both the same type, check hand rank + return compareByRank(otherHand) + } + if(leftType > rightType) return 1 + return -1 + } + + private fun compareByRank(otherHand:CamelCardHand):Int { + for(i in 0..5) { + val leftChar = hand.toCharArray()[i] + val rightChar = otherHand.hand.toCharArray()[i] + if(leftChar.compareTo(rightChar) == 0) { + continue + } + if(cardValue(leftChar) > cardValue(rightChar)) { + return 1 + } + return -1 + } + // shouldn't get here but for completeness + return 0 + } + + private fun calculateType():HandType { + val matches = HashMap() + for(c in hand.toCharArray()) { + matches[c] = matches.getOrDefault(c,0) + 1 + } + // Calculate J/Wildcards + val jokerCount: Int + if(matches.keys.contains('J')) { + jokerCount = matches.getOrDefault('J', 1) + // Skip the case where hand is JJJJJ + if(jokerCount != 5) { + val maxEntry = findMaxEntry(matches) + if (matches.values.count { it == 1 } == 5) { + val maxCard = matches.entries.maxBy { cardValue(it.key) }.key + matches[maxCard] = maxEntry.value + jokerCount + } else { + matches[maxEntry.key] = maxEntry.value + jokerCount + } + + matches.remove('J') + } + } + + if(matches.values.stream().filter { it == 5 }.count() == 1L) { + return HandType.FIVE_KIND + } + if(matches.values.stream().filter { it == 4 }.count() == 1L) { + return HandType.FOUR_KIND + } + if((matches.values.stream().filter { it == 3 }.count() == 1L) && (matches.values.stream().filter { it == 2 }.count() == 1L)) { + return HandType.FULL_HOUSE + } + if(matches.values.stream().filter { it == 3 }.count() == 1L) { + return HandType.THREE_KIND + } + if(matches.values.stream().filter { it == 2 }.count() == 2L) { + return HandType.TWO_PAIR + } + if (matches.values.stream().filter { it == 2}.count() == 1L) { + return HandType.ONE_PAIR + } + if (matches.values.stream().filter { it == 1 }.count() == 5L) { + return HandType.HIGH_CARD + } + + return HandType.HIGH_CARD + } + + private fun findMaxEntry(matches:HashMap):Map.Entry { + val maxByValue = matches.entries.filter { it.key.compareTo('J') != 0 }.maxBy { it.value } + val maxByCard = matches.entries.filter { it.value == maxByValue.value }.maxBy { cardValue(it.key) } + return maxByCard + } + + private fun cardValue(card:Char):Int { + return when(card) { + 'J' -> 1 + '2' -> 2 + '3' -> 3 + '4' -> 4 + '5' -> 5 + '6' -> 6 + '7' -> 7 + '8' -> 8 + '9' -> 9 + 'T' -> 10 + 'Q' -> 12 + 'K' -> 13 + 'A' -> 14 + else -> 0 + } + } + + enum class HandType { + HIGH_CARD, + ONE_PAIR, + TWO_PAIR, + THREE_KIND, + FULL_HOUSE, + FOUR_KIND, + FIVE_KIND + } + + override fun toString():String { + return "hand: $hand, bid $bid" + } +} diff --git a/2023/day08_1/.idea/inspectionProfiles/Project_Default.xml b/2023/day08_1/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2023/day08_1/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2023/day08_1/.idea/kotlinc.xml b/2023/day08_1/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2023/day08_1/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2023/day08_1/.idea/libraries/KotlinJavaRuntime.xml b/2023/day08_1/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d39de76 --- /dev/null +++ b/2023/day08_1/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day08_1/.idea/misc.xml b/2023/day08_1/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2023/day08_1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day08_1/.idea/modules.xml b/2023/day08_1/.idea/modules.xml new file mode 100644 index 0000000..ba10969 --- /dev/null +++ b/2023/day08_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2023/day08_1/.idea/vcs.xml b/2023/day08_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2023/day08_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day08_1/day08_1.iml b/2023/day08_1/day08_1.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2023/day08_1/day08_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day08_1/resources/input b/2023/day08_1/resources/input new file mode 100644 index 0000000..821448b --- /dev/null +++ b/2023/day08_1/resources/input @@ -0,0 +1,732 @@ +LLLLLLLRRRLRRRLRLRLRLRRLLRRRLRLLRRRLLRRLRRLRRLRLRRLRLRRRLRRLRLRRRLRRLRRLRLRRLLRLLRLRRRLRRLRLLLLRRLLLLRLRLRLRRRLRLRLLLRLRRRLRRRLRRRLRLRRLRRRLRLLLRLLRRLRRRLRRLRRLRRLRLRRRLRLRLRLLRRRLRRRLRRLRRRLLLRRLRRLRRRLRLRRRLRRRLRLRRLRRRLRLRRLRLRRLRRRLRLRRLRLLRRRLLRLRRLRRRLLLRLRRLRRRR + +DGK = (KVQ, XHR) +KTC = (TVB, MTH) +CGR = (VVK, BKP) +LCG = (FQC, KHX) +PSZ = (FSF, QSM) +FBJ = (FHP, SPX) +KJD = (NRQ, VDH) +NCM = (JPJ, KNG) +TXH = (HNK, VHQ) +NND = (TRC, DFM) +JQN = (CNX, XLD) +RHB = (CDG, GBT) +JBN = (PXV, GVN) +DFC = (JRN, TXH) +TXG = (CHT, VBL) +XXQ = (JDC, JGV) +SVF = (FVD, LHQ) +FVK = (LCG, RNB) +XKT = (MPF, XJJ) +MHB = (JSJ, VQM) +FVC = (HXF, VVN) +JJR = (VNS, SLM) +RMT = (GDS, XHP) +CHT = (PXS, VLF) +SFJ = (XGC, LPM) +BJL = (XDN, VXN) +PQK = (NHS, DVB) +PDB = (JPQ, TVJ) +RGL = (DNN, NCN) +KRN = (SBL, PHL) +MTF = (PJL, KQR) +BTL = (CCF, LDP) +NLV = (CPM, HVL) +GCQ = (QMF, JVH) +KVH = (VKD, PQG) +RLB = (GSS, JVP) +QRB = (TNL, DKN) +JFV = (RDR, NSB) +BFC = (LGH, XLX) +HGQ = (SLM, VNS) +FQC = (VFQ, BXC) +DDS = (XHR, KVQ) +VQV = (SFT, BFQ) +XFD = (HVV, FLH) +TVP = (XQF, KSS) +GBH = (NPX, LDB) +KHL = (MGS, MMD) +NPX = (BJL, SFF) +VMG = (DHX, GVC) +RTJ = (XRF, BPK) +TLM = (NCG, QBB) +LXS = (TVB, MTH) +XNM = (QFL, KQK) +KQR = (QRD, JBN) +JQD = (DNN, NCN) +QCF = (MXL, MXL) +QMH = (NKG, SDJ) +NKK = (MCB, RLB) +MPJ = (BTL, JTF) +TLS = (VPJ, LMD) +XJB = (LML, TKZ) +HGF = (HBF, QHB) +KNJ = (QKM, XLR) +XCF = (QCJ, HTN) +HFS = (NKC, JFV) +QLS = (QBB, NCG) +QFL = (NXQ, QBN) +MTH = (FLN, LQR) +VND = (KMM, MQH) +NQQ = (VVH, NDL) +BTV = (QSM, FSF) +SLT = (NRQ, VDH) +NKG = (TBV, XCV) +SLM = (LBN, HPK) +CMQ = (KKS, VBH) +JTF = (LDP, CCF) +VFC = (GKH, KPS) +KCC = (JVM, MTF) +KFP = (MVX, NMX) +NQF = (QSK, KCC) +GGC = (VBV, TJR) +QQS = (NKK, NQC) +LXK = (FXC, QBC) +DVQ = (TFF, LKB) +PBL = (BGQ, FHQ) +KHV = (BVJ, XSD) +LDB = (SFF, BJL) +RJG = (LJB, CJM) +RCX = (QTB, PPL) +FLH = (HSX, KVX) +XTV = (HST, VCC) +GDC = (CMH, NCT) +RDP = (FKR, GHJ) +NXM = (PVV, KRX) +SCQ = (MFN, GRB) +MRT = (XGT, VLK) +DHJ = (XHP, GDS) +XFL = (TJK, QMH) +XQF = (CCQ, RPH) +CLV = (CKD, CCD) +CMT = (NCD, XDM) +NCT = (SXG, CLF) +JSS = (GMJ, LJC) +TLQ = (CRC, DXQ) +DMJ = (HHB, DRV) +JBH = (FVC, HDX) +QXK = (QSB, JBH) +DQN = (QMD, GDN) +SDH = (PRH, BCX) +QSB = (HDX, FVC) +MTP = (VVG, SPN) +CTM = (MFG, GGJ) +HND = (MNV, TXG) +MJS = (DMJ, QQG) +JNL = (LKB, TFF) +QLL = (FKM, HNH) +PNM = (PQR, NRL) +VSF = (LPM, XGC) +QBC = (QQS, MVF) +BFM = (FBP, BQJ) +KNG = (RTJ, CXN) +VFQ = (HFS, LBS) +LKB = (QVB, TXF) +KQD = (CDJ, CDJ) +ZZZ = (DHJ, RMT) +XKX = (HVP, NJF) +GSL = (QMS, DHM) +PNT = (CDJ, GJZ) +KBN = (CMQ, JBG) +DNX = (SFM, GFJ) +NMX = (XRR, LKL) +VPJ = (PSK, GQL) +XQD = (QCF, QCF) +HRM = (RHB, XXJ) +LCL = (MRT, FMB) +DRG = (RNB, LCG) +BKP = (QLL, MMQ) +FSF = (SLR, XGV) +KHX = (BXC, VFQ) +SXG = (NHL, KGK) +MJD = (TDH, RFP) +NRL = (CSG, MPT) +FBP = (QGC, GXH) +HDT = (LHQ, FVD) +BMP = (RMG, JXM) +NCN = (SLT, KJD) +NXQ = (JPP, QQL) +NGV = (HNJ, VVQ) +NPN = (MXL, NJK) +FVD = (XBQ, NKF) +GQM = (QCG, GGC) +QBP = (XML, HND) +VQT = (BTL, JTF) +HKP = (CMH, NCT) +JHP = (NDL, VVH) +FRL = (SHD, FNH) +FLN = (NVL, HGF) +MXH = (QSD, KKR) +BGL = (XCX, RFC) +RSQ = (MKH, TLS) +VML = (RJM, CXK) +XHP = (MJS, DNP) +GRV = (XRN, TVQ) +GKH = (BCF, VSD) +SPH = (MVX, NMX) +TLD = (LFR, GFQ) +LML = (QKS, NND) +PKT = (VXC, CMF) +LLQ = (THT, GRV) +CKD = (SPB, QDV) +KRM = (JQV, JNG) +RNS = (HJJ, MLV) +FKR = (FKK, BHN) +XNH = (SCQ, KLF) +GDN = (LBL, FHT) +CRB = (NHQ, QRB) +JKQ = (DPT, KBN) +NJF = (RJG, NGF) +NRT = (NSK, CSL) +LJR = (VTT, HCQ) +HLK = (DFC, DPV) +PQR = (MPT, CSG) +DNF = (NJF, HVP) +MPV = (HJD, XSF) +TBV = (XTJ, SVH) +LKX = (XFJ, HBM) +KTP = (CGR, RVR) +HVL = (BJH, QXK) +GJD = (XJJ, MPF) +HLC = (VVQ, HNJ) +JTX = (NCD, XDM) +CSG = (MFF, RKT) +PCH = (PGJ, GQM) +SFF = (VXN, XDN) +TCF = (KNG, JPJ) +LDP = (XFD, SBS) +XCR = (GJD, XKT) +QBM = (GFB, LRH) +CLP = (RJM, CXK) +MTT = (HST, VCC) +TQL = (BPM, GGT) +LFR = (HNF, RDP) +JHN = (CMT, JTX) +XCX = (CHG, CHG) +XGT = (HLK, QJF) +TQS = (TKL, MNF) +KFL = (HGQ, JJR) +LHQ = (XBQ, NKF) +CCQ = (DBP, HHC) +TKL = (VDN, PBP) +LBX = (BXM, SDH) +XLX = (NGJ, LHJ) +GVN = (BPG, TNK) +CCX = (HCQ, VTT) +KQK = (QBN, NXQ) +NQC = (MCB, RLB) +MPF = (DFT, SBG) +BNH = (MLV, HJJ) +CJM = (LBH, TNM) +CND = (VKB, PGQ) +HXM = (GMJ, LJC) +TKZ = (NND, QKS) +RKT = (LNQ, KFL) +GXH = (RQP, LBX) +TFF = (QVB, TXF) +LNK = (FDC, MXH) +KPK = (BNH, RNS) +QQG = (HHB, DRV) +MFP = (PQK, NBF) +VVK = (QLL, MMQ) +GFB = (RHN, LCN) +PPD = (QCJ, HTN) +FXV = (BPM, GGT) +KSS = (CCQ, RPH) +KCM = (LTB, PCH) +RHN = (FXV, TQL) +LFV = (DDJ, NQF) +JKG = (BGQ, FHQ) +MBS = (RQJ, LDQ) +HHC = (NGV, HLC) +CCD = (QDV, SPB) +RFM = (FTB, HSB) +QCG = (VBV, TJR) +GRH = (LXK, LGQ) +CDJ = (QQJ, BFC) +THT = (TVQ, XRN) +QRD = (PXV, GVN) +VHQ = (SXV, GJL) +MLV = (VRM, MCP) +XRR = (CLV, PBJ) +NMS = (DGK, DDS) +JPS = (JKT, KHL) +DJJ = (QMS, DHM) +MFG = (TLQ, VQD) +GPQ = (SHL, BNR) +QVB = (GDC, HKP) +LNN = (CMF, VXC) +VBQ = (LNN, PKT) +MMS = (SVV, HRM) +BGJ = (HXM, JSS) +QCK = (JSJ, VQM) +PKB = (XNH, JQH) +BCF = (TQR, TLL) +JRN = (VHQ, HNK) +SHL = (DMK, JBX) +LRG = (NSK, CSL) +NJV = (FJH, TXC) +GHQ = (FSB, HFX) +LHN = (TLS, MKH) +HBF = (BMP, GLM) +DTP = (DVQ, JNL) +FXR = (FTB, HSB) +PDS = (XLD, CNX) +SXV = (CPC, JNF) +QMF = (GGF, JDP) +JVP = (GPC, DNX) +RMG = (HRF, PKB) +LRH = (LCN, RHN) +HVP = (RJG, NGF) +TRC = (VKX, RQL) +PJL = (QRD, JBN) +HNK = (GJL, SXV) +CHM = (NBF, PQK) +PGH = (KMM, MQH) +SDN = (MFP, CHM) +DMK = (VRP, NNX) +MRR = (NGK, SMQ) +QDV = (NDM, JPT) +PGJ = (QCG, GGC) +BVJ = (NLV, HBR) +PGQ = (BGK, GBH) +LKL = (CLV, PBJ) +FDC = (KKR, QSD) +JDP = (PDB, PTX) +NJJ = (HSJ, GRH) +TVJ = (HDT, SVF) +NJK = (RBV, ZZZ) +HHN = (DPP, TLD) +QMS = (BLS, TQS) +QVR = (CVB, BNJ) +FFQ = (RMJ, HGZ) +LGQ = (QBC, FXC) +JPP = (RSG, KTG) +DPV = (TXH, JRN) +HBR = (CPM, HVL) +NSK = (JQN, PDS) +SBS = (HVV, FLH) +BFQ = (VBQ, JPB) +LBN = (LXJ, CCR) +RBD = (KRM, PNX) +NQX = (LML, LML) +XSA = (QKS, NND) +NDB = (HFX, FSB) +QMD = (LBL, FHT) +XTJ = (JDT, JDT) +GLH = (SHL, BNR) +FXC = (MVF, QQS) +HSX = (NFN, LVG) +JNF = (JJH, FNR) +CXK = (SPC, TVP) +GGF = (PDB, PTX) +XBQ = (QNX, JCQ) +LJC = (SFJ, VSF) +MMD = (XLK, CND) +HFG = (JKT, KHL) +NHQ = (TNL, DKN) +JVM = (KQR, PJL) +CGH = (RTC, VFC) +HNF = (GHJ, FKR) +TMF = (NMS, GJH) +NGJ = (NXM, BDB) +MRM = (JKQ, MPS) +QTC = (JSS, HXM) +TNM = (JFF, QXR) +DHK = (LJR, CCX) +XSB = (MRR, CXC) +XRN = (XDP, QBP) +XCV = (XTJ, SVH) +VVA = (QSM, FSF) +NKC = (RDR, NSB) +MXL = (RBV, RBV) +PTX = (TVJ, JPQ) +VRL = (NQX, XJB) +RQK = (MPS, JKQ) +PBJ = (CKD, CCD) +VRP = (DQN, QLC) +KLF = (MFN, GRB) +XXJ = (GBT, CDG) +HST = (QHV, MMS) +SFT = (JPB, VBQ) +NRR = (LCL, MQR) +CSL = (JQN, PDS) +LHJ = (BDB, NXM) +TXK = (DHK, KLC) +CDK = (XCX, XCX) +FHT = (NGQ, JHN) +QQJ = (LGH, XLX) +BQJ = (GXH, QGC) +TTA = (QKM, XLR) +TVB = (FLN, LQR) +PPL = (FRL, NCX) +SPS = (XFJ, HBM) +SVH = (JDT, VRL) +QBB = (PXG, MTP) +JSJ = (VVB, NRR) +KKS = (RGL, JQD) +JDT = (NQX, NQX) +GKQ = (LLT, JRH) +VVH = (BPT, KRN) +JCQ = (CRB, PBS) +QXR = (BTV, PSZ) +VQR = (RCX, KKP) +QSM = (SLR, XGV) +JKD = (JDC, JGV) +XLD = (LFS, QVR) +TJK = (NKG, SDJ) +PVV = (HDK, VQV) +BDB = (PVV, KRX) +MPS = (KBN, DPT) +FHP = (PPD, XCF) +HTN = (KCM, PXC) +GHJ = (BHN, FKK) +JCC = (LQM, KVH) +LQR = (HGF, NVL) +LGM = (DDJ, NQF) +NJN = (QCF, NPN) +PRH = (DFF, DFF) +XDM = (FBJ, PJM) +HFN = (KRS, XSB) +GLM = (JXM, RMG) +RQP = (BXM, SDH) +BPG = (QJT, KTP) +JPB = (LNN, PKT) +DKN = (CJD, BGR) +CDG = (GSL, DJJ) +XDN = (CGM, VMG) +NQP = (SKT, JCC) +DNP = (QQG, DMJ) +NNX = (DQN, QLC) +FTB = (JFL, VJJ) +FHQ = (SMJ, XFK) +GGT = (KPK, LNT) +NGF = (LJB, CJM) +QFX = (KCN, TMF) +NKF = (JCQ, QNX) +DBP = (NGV, HLC) +RBV = (RMT, DHJ) +NML = (MBV, VCG) +KXJ = (MXH, FDC) +GFQ = (RDP, HNF) +SHD = (CMG, CTM) +GTX = (LNK, KXJ) +HXF = (KTC, LXS) +CMM = (NQP, SBR) +SDJ = (TBV, XCV) +CHG = (RMJ, RMJ) +DPT = (CMQ, JBG) +BGR = (RLM, NML) +THM = (XQD, NJN) +HJJ = (MCP, VRM) +NRQ = (JHR, GCQ) +KKR = (HSN, NJJ) +KVX = (LVG, NFN) +LTT = (TLD, DPP) +NVL = (QHB, HBF) +CXN = (XRF, BPK) +KLC = (CCX, LJR) +JDC = (DNF, XKX) +MGS = (XLK, CND) +RLM = (VCG, MBV) +VDN = (NMQ, TPR) +HSB = (JFL, VJJ) +HDS = (KLC, DHK) +XSD = (NLV, HBR) +HJD = (NJQ, PBQ) +CGM = (DHX, GVC) +LDQ = (PBL, JKG) +RDR = (XHQ, MGQ) +GPC = (GFJ, SFM) +NQT = (KRS, XSB) +TDH = (RBD, XLP) +QJF = (DFC, DPV) +VNS = (HPK, LBN) +QSD = (NJJ, HSN) +JHR = (QMF, JVH) +SMQ = (FXR, RFM) +CMG = (MFG, GGJ) +NKQ = (VFC, RTC) +VXC = (LHN, RSQ) +DHX = (LCT, XNM) +TCX = (NQT, HFN) +DRV = (TFN, QBM) +JPT = (GQX, XCR) +HRF = (JQH, XNH) +MCS = (BGJ, QTC) +PQG = (NCM, TCF) +XHR = (PJK, VPN) +MLX = (PGH, VND) +MKH = (VPJ, LMD) +TJR = (VQT, MPJ) +VLF = (GLG, QFX) +JNG = (KLR, MPV) +HDK = (BFQ, SFT) +HFX = (MLX, SPL) +BXC = (HFS, LBS) +CCT = (GTX, HPT) +VLK = (HLK, QJF) +NCD = (PJM, FBJ) +VGT = (JNL, DVQ) +LMD = (PSK, GQL) +KRX = (HDK, VQV) +QNX = (CRB, PBS) +NJQ = (GHQ, NDB) +TNV = (FBP, BQJ) +GNR = (XQD, NJN) +KKP = (QTB, PPL) +DBX = (KCQ, CPS) +VRM = (TLM, QLS) +LVG = (BRP, NJV) +NHL = (SPS, LKX) +MNV = (VBL, CHT) +PJK = (HHN, LTT) +VBH = (JQD, RGL) +GRB = (NKQ, CGH) +SKT = (KVH, LQM) +TPR = (RXR, KHV) +VVB = (LCL, MQR) +VKX = (MRM, RQK) +LTB = (PGJ, GQM) +QCJ = (KCM, PXC) +BGQ = (SMJ, SMJ) +RCV = (NQQ, JHP) +DHM = (TQS, BLS) +KRS = (CXC, MRR) +JFL = (BLT, PNM) +TXC = (NRT, LRG) +MVX = (LKL, XRR) +QSK = (JVM, MTF) +BGK = (LDB, NPX) +GJZ = (BFC, QQJ) +PXC = (LTB, PCH) +HMQ = (BGJ, QTC) +RXR = (BVJ, XSD) +BXM = (PRH, BCX) +FJH = (LRG, NRT) +GJH = (DGK, DDS) +BPT = (SBL, PHL) +RQL = (RQK, MRM) +SJB = (RQJ, LDQ) +NFN = (NJV, BRP) +MND = (NQQ, JHP) +NMQ = (KHV, RXR) +XGV = (TXK, HDS) +SPC = (KSS, XQF) +RMJ = (SMR, QRS) +CNX = (LFS, QVR) +KLR = (HJD, XSF) +XLP = (KRM, PNX) +LPM = (CMM, PHF) +FNR = (CCT, VTP) +NGQ = (CMT, JTX) +CCR = (BFM, TNV) +LCN = (FXV, TQL) +HVV = (HSX, KVX) +FSB = (MLX, SPL) +GGJ = (TLQ, VQD) +NHS = (DRG, FVK) +RQJ = (PBL, JKG) +VCC = (MMS, QHV) +HDX = (VVN, HXF) +VQM = (NRR, VVB) +TFN = (GFB, LRH) +QRS = (VQR, MDS) +HBM = (VTQ, SDN) +CCF = (SBS, XFD) +VCG = (HMQ, MCS) +NBF = (DVB, NHS) +DVB = (FVK, DRG) +PGB = (TDH, RFP) +XRF = (KFP, SPH) +KMM = (PDJ, GQN) +KTG = (GGQ, HNR) +BJH = (JBH, QSB) +JJH = (CCT, VTP) +LBH = (JFF, JFF) +GLG = (TMF, KCN) +TQR = (THM, GNR) +MQH = (GQN, PDJ) +MQR = (FMB, MRT) +FNH = (CTM, CMG) +SMR = (VQR, MDS) +GDS = (DNP, MJS) +LCT = (KQK, QFL) +VKB = (GBH, BGK) +VTQ = (CHM, MFP) +TNK = (QJT, KTP) +HNJ = (VVS, GCX) +JKT = (MMD, MGS) +PBP = (TPR, NMQ) +CPS = (KNJ, RFZ) +RNB = (KHX, FQC) +CMF = (LHN, RSQ) +HPK = (CCR, LXJ) +MFN = (NKQ, CGH) +HHB = (QBM, TFN) +DDJ = (QSK, KCC) +DFM = (RQL, VKX) +FKM = (GKQ, VJG) +HSJ = (LGQ, LXK) +HPT = (KXJ, LNK) +BNR = (JBX, DMK) +GJL = (CPC, JNF) +DFF = (KCQ, KCQ) +MCB = (GSS, JVP) +CPC = (JJH, FNR) +XLR = (MJK, DSM) +SBG = (JDG, XFL) +XSF = (NJQ, PBQ) +NGK = (RFM, FXR) +HSN = (GRH, HSJ) +LQM = (PQG, VKD) +VXN = (VMG, CGM) +PSK = (VGT, DTP) +JQH = (KLF, SCQ) +RJM = (SPC, TVP) +VSD = (TLL, TQR) +KCN = (GJH, NMS) +QHB = (GLM, BMP) +FMB = (VLK, XGT) +GBT = (DJJ, GSL) +LGH = (NGJ, LHJ) +SLR = (HDS, TXK) +VVQ = (GCX, VVS) +MDS = (RCX, KKP) +KVQ = (VPN, PJK) +CLF = (NHL, KGK) +XFK = (KQD, PNT) +CJD = (NML, RLM) +MCP = (TLM, QLS) +SPL = (PGH, VND) +GSS = (GPC, DNX) +RPH = (DBP, HHC) +HNR = (XXQ, JKD) +VBV = (VQT, MPJ) +PHF = (NQP, SBR) +BRP = (FJH, TXC) +AAA = (RMT, DHJ) +PBQ = (GHQ, NDB) +PXG = (VVG, SPN) +PNX = (JQV, JNG) +XHQ = (SJB, MBS) +VBL = (VLF, PXS) +VVG = (MTT, XTV) +PXS = (GLG, QFX) +MMQ = (FKM, HNH) +PHG = (HFN, NQT) +MFF = (KFL, LNQ) +PJM = (FHP, SPX) +SMJ = (KQD, KQD) +XGC = (CMM, PHF) +PDJ = (QCK, MHB) +SPN = (MTT, XTV) +BPK = (KFP, SPH) +MVF = (NQC, NKK) +LJB = (LBH, LBH) +GQN = (QCK, MHB) +NCG = (MTP, PXG) +GQL = (VGT, DTP) +NCX = (FNH, SHD) +HGZ = (QRS, SMR) +GMJ = (VSF, SFJ) +RFP = (XLP, RBD) +TXF = (GDC, HKP) +NBA = (SMR, QRS) +QTB = (FRL, NCX) +QLC = (GDN, QMD) +QHV = (SVV, HRM) +XTM = (GRV, THT) +VPN = (HHN, LTT) +RFZ = (XLR, QKM) +CMH = (SXG, CLF) +GFJ = (TCX, PHG) +VTT = (LGM, LFV) +RTC = (GKH, KPS) +XFJ = (VTQ, SDN) +GCX = (PGB, MJD) +MJK = (CLP, VML) +QQL = (RSG, KTG) +NSB = (XHQ, MGQ) +HCQ = (LGM, LFV) +GQX = (GJD, XKT) +RVR = (VVK, BKP) +JBG = (KKS, VBH) +JFF = (BTV, BTV) +BPM = (LNT, KPK) +LNQ = (JJR, HGQ) +FKK = (GLH, GPQ) +SBL = (CDK, BGL) +LNT = (BNH, RNS) +JRH = (JPS, HFG) +VVS = (MJD, PGB) +DPP = (LFR, GFQ) +MNF = (PBP, VDN) +QKM = (DSM, MJK) +JPJ = (CXN, RTJ) +QGC = (RQP, LBX) +CVB = (MND, RCV) +RFC = (CHG, FFQ) +KPS = (BCF, VSD) +XML = (MNV, TXG) +JVH = (JDP, GGF) +CRC = (XTM, LLQ) +VJG = (JRH, LLT) +SPB = (JPT, NDM) +JGV = (XKX, DNF) +GGQ = (XXQ, JKD) +XLK = (PGQ, VKB) +JBX = (NNX, VRP) +RSG = (HNR, GGQ) +GVC = (LCT, XNM) +XDP = (XML, HND) +CXC = (SMQ, NGK) +PXV = (TNK, BPG) +NDM = (XCR, GQX) +CPM = (BJH, QXK) +KGK = (LKX, SPS) +BLT = (NRL, PQR) +BHN = (GLH, GPQ) +BLS = (TKL, MNF) +PHL = (CDK, BGL) +BCX = (DFF, DBX) +HNH = (GKQ, VJG) +VKD = (NCM, TCF) +DSM = (VML, CLP) +DNN = (SLT, KJD) +SBR = (SKT, JCC) +TNL = (BGR, CJD) +DFT = (XFL, JDG) +MPT = (RKT, MFF) +TVQ = (XDP, QBP) +LLT = (JPS, HFG) +DXQ = (XTM, LLQ) +SFM = (PHG, TCX) +BNJ = (MND, RCV) +PBS = (NHQ, QRB) +JXM = (HRF, PKB) +VTP = (HPT, GTX) +SVV = (XXJ, RHB) +MHA = (QQJ, BFC) +MBV = (HMQ, MCS) +VJJ = (BLT, PNM) +QJT = (RVR, CGR) +VVN = (LXS, KTC) +QKS = (TRC, DFM) +MGQ = (MBS, SJB) +NDL = (BPT, KRN) +JPQ = (SVF, HDT) +VDH = (JHR, GCQ) +KCQ = (KNJ, KNJ) +XJJ = (DFT, SBG) +JQV = (MPV, KLR) +VQD = (DXQ, CRC) +JDG = (TJK, QMH) +SPX = (XCF, PPD) +LXJ = (TNV, BFM) +LBL = (NGQ, JHN) +QBN = (QQL, JPP) +LFS = (CVB, BNJ) +LBS = (JFV, NKC) +TLL = (THM, GNR) diff --git a/2023/day08_1/resources/small_input b/2023/day08_1/resources/small_input new file mode 100644 index 0000000..59e2d47 --- /dev/null +++ b/2023/day08_1/resources/small_input @@ -0,0 +1,9 @@ +RL + +AAA = (BBB, CCC) +BBB = (DDD, EEE) +CCC = (ZZZ, GGG) +DDD = (DDD, DDD) +EEE = (EEE, EEE) +GGG = (GGG, GGG) +ZZZ = (ZZZ, ZZZ) \ No newline at end of file diff --git a/2023/day08_1/resources/small_input2 b/2023/day08_1/resources/small_input2 new file mode 100644 index 0000000..34ffa8a --- /dev/null +++ b/2023/day08_1/resources/small_input2 @@ -0,0 +1,5 @@ +LLR + +AAA = (BBB, BBB) +BBB = (AAA, ZZZ) +ZZZ = (ZZZ, ZZZ) \ No newline at end of file diff --git a/2023/day08_1/resources/small_input3 b/2023/day08_1/resources/small_input3 new file mode 100644 index 0000000..c5354af --- /dev/null +++ b/2023/day08_1/resources/small_input3 @@ -0,0 +1,6 @@ +RRLLLRL + +AAA = (BBB, BBB) +BBB = (AAA, CCC) +CCC = (BBB, AAA) +ZZZ = (ZZZ, ZZZ) \ No newline at end of file diff --git a/2023/day08_1/src/Main.kt b/2023/day08_1/src/Main.kt new file mode 100644 index 0000000..4d40ee9 --- /dev/null +++ b/2023/day08_1/src/Main.kt @@ -0,0 +1,55 @@ +import java.io.File + +fun main(args: Array) { + println("AOC 2023, Day 8, Part 1 starting!!!!") + + var firstLine = false + var directions = "None" + val allNodes = ArrayList() + File(args[0]).forEachLine { + if(!firstLine) { + directions = it + firstLine = true + } else if(it.isNotEmpty()) { + val nodeName = it.substring(0..2) + val connectionLeft = it.substring(7..9) + val connectionRight = it.substring(12..14) + allNodes.add(Node(nodeName, connectionLeft, connectionRight)) + } + } + + println("Total Nodes: ${allNodes.count()}") + + val stepsIter = traverseNodesIterative(directions, allNodes) + + println("Steps taken to traverse to ZZZ: $stepsIter") + + println("AOC 2023, Day 8, Part 1 completed!!!") +} + +fun traverseNodesIterative(directions: String, nodes:ArrayList):Long { + var nextStep = 0 + var totalSteps = 0L + var currentNode = nodes.find { it.nodeName.compareTo("AAA") == 0 }!! + var nextNode:Node + while(currentNode.nodeName.compareTo("ZZZ") != 0) { + val leftOrRight = directions[nextStep] + nextNode = if(leftOrRight.compareTo('L') == 0) { + nodes.find { it.nodeName == currentNode.connectionLeft }!! + } else { + nodes.find { it.nodeName == currentNode.connectionRight }!! + } + currentNode = nextNode + + nextStep++ + totalSteps++ + if(nextStep >= directions.length) { + nextStep = 0 + } + + } + + return totalSteps +} + +data class Node (val nodeName:String, val connectionLeft:String, val connectionRight:String) \ No newline at end of file diff --git a/2023/day08_2/.idea/inspectionProfiles/Project_Default.xml b/2023/day08_2/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2023/day08_2/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2023/day08_2/.idea/kotlinc.xml b/2023/day08_2/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2023/day08_2/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2023/day08_2/.idea/libraries/KotlinJavaRuntime.xml b/2023/day08_2/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d39de76 --- /dev/null +++ b/2023/day08_2/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day08_2/.idea/misc.xml b/2023/day08_2/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2023/day08_2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day08_2/.idea/modules.xml b/2023/day08_2/.idea/modules.xml new file mode 100644 index 0000000..627ebb3 --- /dev/null +++ b/2023/day08_2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2023/day08_2/.idea/vcs.xml b/2023/day08_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2023/day08_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2023/day08_2/day08_2.iml b/2023/day08_2/day08_2.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2023/day08_2/day08_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2023/day08_2/src/Main.kt b/2023/day08_2/src/Main.kt new file mode 100644 index 0000000..6007911 --- /dev/null +++ b/2023/day08_2/src/Main.kt @@ -0,0 +1,94 @@ +import java.io.File +import java.util.* +import kotlin.collections.ArrayList + +fun main(args: Array) { + println("AOC 2023, Day 8, Part 2 starting!!!!") + + var firstLine = false + var directions = "None" + val allNodes = ArrayList() + File(args[0]).forEachLine { + if(!firstLine) { + directions = it + firstLine = true + } else if(it.isNotEmpty()) { + val nodeName = it.substring(0..2) + val connectionLeft = it.substring(7..9) + val connectionRight = it.substring(12..14) + allNodes.add(Node(nodeName, connectionLeft, connectionRight)) + } + } + + println("Total Nodes: ${allNodes.count()}") + val nodesEndWithA = findNodesEndsWithA(allNodes) + println("Finding nodes that end with A: $nodesEndWithA") + val nodesEndWithZ = findNodesEndsWithZ(allNodes) + println("Finding nodes that end with Z: $nodesEndWithZ") + + val foundCount = Stack() + nodesEndWithA.forEach { + println("Starting search starting with $it") + foundCount.push(traverseNodeIterative(directions, allNodes, it)) + println("found it! Path took ${foundCount.peek()} steps.") + } + + println("Final path count results: $foundCount") + + var stepsStack = foundCount.pop() + while(!foundCount.empty()) { + stepsStack = lcm(stepsStack, foundCount.pop()) + } + + println("Steps taken to traverse to all nodes end with Z: $stepsStack") + + println("AOC 2023, Day 8, Part 2 completed!!!") +} + +fun lcm(a: Long, b: Long): Long { + return (a / gcd(a, b)) * b +} + +fun gcd(a: Long, b: Long): Long { + if (a == 0L) return b + return gcd(b % a, a) +} + + +fun findNodesEndsWithA(nodes: ArrayList):ArrayList { + val nodesEndsWithA = ArrayList() + nodes.filter { it.nodeName.last() == 'A' }.toCollection(nodesEndsWithA) + return nodesEndsWithA +} + +fun findNodesEndsWithZ(nodes: ArrayList):ArrayList { + val nodesEndsWithZ = ArrayList() + nodes.filter { it.nodeName.last() == 'Z' }.toCollection(nodesEndsWithZ) + return nodesEndsWithZ +} + +fun traverseNodeIterative(directions: String, nodes: ArrayList, startNode: Node): Long { + var totalSteps = 0L + var nextStep = 0 + var currentNode = Node(startNode.nodeName, startNode.connectionLeft, startNode.connectionRight) + var nextNode:Node + while(currentNode.nodeName.last() != 'Z') { + val leftOrRight = directions[nextStep] + nextNode = if(leftOrRight.compareTo('L') == 0) { + nodes.find { it.nodeName == currentNode.connectionLeft }!! + } else { + nodes.find { it.nodeName == currentNode.connectionRight }!! + } + currentNode = nextNode + + nextStep++ + totalSteps++ + if(nextStep >= directions.length) { + nextStep = 0 + } + } + + return totalSteps +} + +data class Node (val nodeName:String, val connectionLeft:String, val connectionRight:String) \ No newline at end of file diff --git a/2023/day08_2/src/resources/input b/2023/day08_2/src/resources/input new file mode 100644 index 0000000..821448b --- /dev/null +++ b/2023/day08_2/src/resources/input @@ -0,0 +1,732 @@ +LLLLLLLRRRLRRRLRLRLRLRRLLRRRLRLLRRRLLRRLRRLRRLRLRRLRLRRRLRRLRLRRRLRRLRRLRLRRLLRLLRLRRRLRRLRLLLLRRLLLLRLRLRLRRRLRLRLLLRLRRRLRRRLRRRLRLRRLRRRLRLLLRLLRRLRRRLRRLRRLRRLRLRRRLRLRLRLLRRRLRRRLRRLRRRLLLRRLRRLRRRLRLRRRLRRRLRLRRLRRRLRLRRLRLRRLRRRLRLRRLRLLRRRLLRLRRLRRRLLLRLRRLRRRR + +DGK = (KVQ, XHR) +KTC = (TVB, MTH) +CGR = (VVK, BKP) +LCG = (FQC, KHX) +PSZ = (FSF, QSM) +FBJ = (FHP, SPX) +KJD = (NRQ, VDH) +NCM = (JPJ, KNG) +TXH = (HNK, VHQ) +NND = (TRC, DFM) +JQN = (CNX, XLD) +RHB = (CDG, GBT) +JBN = (PXV, GVN) +DFC = (JRN, TXH) +TXG = (CHT, VBL) +XXQ = (JDC, JGV) +SVF = (FVD, LHQ) +FVK = (LCG, RNB) +XKT = (MPF, XJJ) +MHB = (JSJ, VQM) +FVC = (HXF, VVN) +JJR = (VNS, SLM) +RMT = (GDS, XHP) +CHT = (PXS, VLF) +SFJ = (XGC, LPM) +BJL = (XDN, VXN) +PQK = (NHS, DVB) +PDB = (JPQ, TVJ) +RGL = (DNN, NCN) +KRN = (SBL, PHL) +MTF = (PJL, KQR) +BTL = (CCF, LDP) +NLV = (CPM, HVL) +GCQ = (QMF, JVH) +KVH = (VKD, PQG) +RLB = (GSS, JVP) +QRB = (TNL, DKN) +JFV = (RDR, NSB) +BFC = (LGH, XLX) +HGQ = (SLM, VNS) +FQC = (VFQ, BXC) +DDS = (XHR, KVQ) +VQV = (SFT, BFQ) +XFD = (HVV, FLH) +TVP = (XQF, KSS) +GBH = (NPX, LDB) +KHL = (MGS, MMD) +NPX = (BJL, SFF) +VMG = (DHX, GVC) +RTJ = (XRF, BPK) +TLM = (NCG, QBB) +LXS = (TVB, MTH) +XNM = (QFL, KQK) +KQR = (QRD, JBN) +JQD = (DNN, NCN) +QCF = (MXL, MXL) +QMH = (NKG, SDJ) +NKK = (MCB, RLB) +MPJ = (BTL, JTF) +TLS = (VPJ, LMD) +XJB = (LML, TKZ) +HGF = (HBF, QHB) +KNJ = (QKM, XLR) +XCF = (QCJ, HTN) +HFS = (NKC, JFV) +QLS = (QBB, NCG) +QFL = (NXQ, QBN) +MTH = (FLN, LQR) +VND = (KMM, MQH) +NQQ = (VVH, NDL) +BTV = (QSM, FSF) +SLT = (NRQ, VDH) +NKG = (TBV, XCV) +SLM = (LBN, HPK) +CMQ = (KKS, VBH) +JTF = (LDP, CCF) +VFC = (GKH, KPS) +KCC = (JVM, MTF) +KFP = (MVX, NMX) +NQF = (QSK, KCC) +GGC = (VBV, TJR) +QQS = (NKK, NQC) +LXK = (FXC, QBC) +DVQ = (TFF, LKB) +PBL = (BGQ, FHQ) +KHV = (BVJ, XSD) +LDB = (SFF, BJL) +RJG = (LJB, CJM) +RCX = (QTB, PPL) +FLH = (HSX, KVX) +XTV = (HST, VCC) +GDC = (CMH, NCT) +RDP = (FKR, GHJ) +NXM = (PVV, KRX) +SCQ = (MFN, GRB) +MRT = (XGT, VLK) +DHJ = (XHP, GDS) +XFL = (TJK, QMH) +XQF = (CCQ, RPH) +CLV = (CKD, CCD) +CMT = (NCD, XDM) +NCT = (SXG, CLF) +JSS = (GMJ, LJC) +TLQ = (CRC, DXQ) +DMJ = (HHB, DRV) +JBH = (FVC, HDX) +QXK = (QSB, JBH) +DQN = (QMD, GDN) +SDH = (PRH, BCX) +QSB = (HDX, FVC) +MTP = (VVG, SPN) +CTM = (MFG, GGJ) +HND = (MNV, TXG) +MJS = (DMJ, QQG) +JNL = (LKB, TFF) +QLL = (FKM, HNH) +PNM = (PQR, NRL) +VSF = (LPM, XGC) +QBC = (QQS, MVF) +BFM = (FBP, BQJ) +KNG = (RTJ, CXN) +VFQ = (HFS, LBS) +LKB = (QVB, TXF) +KQD = (CDJ, CDJ) +ZZZ = (DHJ, RMT) +XKX = (HVP, NJF) +GSL = (QMS, DHM) +PNT = (CDJ, GJZ) +KBN = (CMQ, JBG) +DNX = (SFM, GFJ) +NMX = (XRR, LKL) +VPJ = (PSK, GQL) +XQD = (QCF, QCF) +HRM = (RHB, XXJ) +LCL = (MRT, FMB) +DRG = (RNB, LCG) +BKP = (QLL, MMQ) +FSF = (SLR, XGV) +KHX = (BXC, VFQ) +SXG = (NHL, KGK) +MJD = (TDH, RFP) +NRL = (CSG, MPT) +FBP = (QGC, GXH) +HDT = (LHQ, FVD) +BMP = (RMG, JXM) +NCN = (SLT, KJD) +NXQ = (JPP, QQL) +NGV = (HNJ, VVQ) +NPN = (MXL, NJK) +FVD = (XBQ, NKF) +GQM = (QCG, GGC) +QBP = (XML, HND) +VQT = (BTL, JTF) +HKP = (CMH, NCT) +JHP = (NDL, VVH) +FRL = (SHD, FNH) +FLN = (NVL, HGF) +MXH = (QSD, KKR) +BGL = (XCX, RFC) +RSQ = (MKH, TLS) +VML = (RJM, CXK) +XHP = (MJS, DNP) +GRV = (XRN, TVQ) +GKH = (BCF, VSD) +SPH = (MVX, NMX) +TLD = (LFR, GFQ) +LML = (QKS, NND) +PKT = (VXC, CMF) +LLQ = (THT, GRV) +CKD = (SPB, QDV) +KRM = (JQV, JNG) +RNS = (HJJ, MLV) +FKR = (FKK, BHN) +XNH = (SCQ, KLF) +GDN = (LBL, FHT) +CRB = (NHQ, QRB) +JKQ = (DPT, KBN) +NJF = (RJG, NGF) +NRT = (NSK, CSL) +LJR = (VTT, HCQ) +HLK = (DFC, DPV) +PQR = (MPT, CSG) +DNF = (NJF, HVP) +MPV = (HJD, XSF) +TBV = (XTJ, SVH) +LKX = (XFJ, HBM) +KTP = (CGR, RVR) +HVL = (BJH, QXK) +GJD = (XJJ, MPF) +HLC = (VVQ, HNJ) +JTX = (NCD, XDM) +CSG = (MFF, RKT) +PCH = (PGJ, GQM) +SFF = (VXN, XDN) +TCF = (KNG, JPJ) +LDP = (XFD, SBS) +XCR = (GJD, XKT) +QBM = (GFB, LRH) +CLP = (RJM, CXK) +MTT = (HST, VCC) +TQL = (BPM, GGT) +LFR = (HNF, RDP) +JHN = (CMT, JTX) +XCX = (CHG, CHG) +XGT = (HLK, QJF) +TQS = (TKL, MNF) +KFL = (HGQ, JJR) +LHQ = (XBQ, NKF) +CCQ = (DBP, HHC) +TKL = (VDN, PBP) +LBX = (BXM, SDH) +XLX = (NGJ, LHJ) +GVN = (BPG, TNK) +CCX = (HCQ, VTT) +KQK = (QBN, NXQ) +NQC = (MCB, RLB) +MPF = (DFT, SBG) +BNH = (MLV, HJJ) +CJM = (LBH, TNM) +CND = (VKB, PGQ) +HXM = (GMJ, LJC) +TKZ = (NND, QKS) +RKT = (LNQ, KFL) +GXH = (RQP, LBX) +TFF = (QVB, TXF) +LNK = (FDC, MXH) +KPK = (BNH, RNS) +QQG = (HHB, DRV) +MFP = (PQK, NBF) +VVK = (QLL, MMQ) +GFB = (RHN, LCN) +PPD = (QCJ, HTN) +FXV = (BPM, GGT) +KSS = (CCQ, RPH) +KCM = (LTB, PCH) +RHN = (FXV, TQL) +LFV = (DDJ, NQF) +JKG = (BGQ, FHQ) +MBS = (RQJ, LDQ) +HHC = (NGV, HLC) +CCD = (QDV, SPB) +RFM = (FTB, HSB) +QCG = (VBV, TJR) +GRH = (LXK, LGQ) +CDJ = (QQJ, BFC) +THT = (TVQ, XRN) +QRD = (PXV, GVN) +VHQ = (SXV, GJL) +MLV = (VRM, MCP) +XRR = (CLV, PBJ) +NMS = (DGK, DDS) +JPS = (JKT, KHL) +DJJ = (QMS, DHM) +MFG = (TLQ, VQD) +GPQ = (SHL, BNR) +QVB = (GDC, HKP) +LNN = (CMF, VXC) +VBQ = (LNN, PKT) +MMS = (SVV, HRM) +BGJ = (HXM, JSS) +QCK = (JSJ, VQM) +PKB = (XNH, JQH) +BCF = (TQR, TLL) +JRN = (VHQ, HNK) +SHL = (DMK, JBX) +LRG = (NSK, CSL) +NJV = (FJH, TXC) +GHQ = (FSB, HFX) +LHN = (TLS, MKH) +HBF = (BMP, GLM) +DTP = (DVQ, JNL) +FXR = (FTB, HSB) +PDS = (XLD, CNX) +SXV = (CPC, JNF) +QMF = (GGF, JDP) +JVP = (GPC, DNX) +RMG = (HRF, PKB) +LRH = (LCN, RHN) +HVP = (RJG, NGF) +TRC = (VKX, RQL) +PJL = (QRD, JBN) +HNK = (GJL, SXV) +CHM = (NBF, PQK) +PGH = (KMM, MQH) +SDN = (MFP, CHM) +DMK = (VRP, NNX) +MRR = (NGK, SMQ) +QDV = (NDM, JPT) +PGJ = (QCG, GGC) +BVJ = (NLV, HBR) +PGQ = (BGK, GBH) +LKL = (CLV, PBJ) +FDC = (KKR, QSD) +JDP = (PDB, PTX) +NJJ = (HSJ, GRH) +TVJ = (HDT, SVF) +NJK = (RBV, ZZZ) +HHN = (DPP, TLD) +QMS = (BLS, TQS) +QVR = (CVB, BNJ) +FFQ = (RMJ, HGZ) +LGQ = (QBC, FXC) +JPP = (RSG, KTG) +DPV = (TXH, JRN) +HBR = (CPM, HVL) +NSK = (JQN, PDS) +SBS = (HVV, FLH) +BFQ = (VBQ, JPB) +LBN = (LXJ, CCR) +RBD = (KRM, PNX) +NQX = (LML, LML) +XSA = (QKS, NND) +NDB = (HFX, FSB) +QMD = (LBL, FHT) +XTJ = (JDT, JDT) +GLH = (SHL, BNR) +FXC = (MVF, QQS) +HSX = (NFN, LVG) +JNF = (JJH, FNR) +CXK = (SPC, TVP) +GGF = (PDB, PTX) +XBQ = (QNX, JCQ) +LJC = (SFJ, VSF) +MMD = (XLK, CND) +HFG = (JKT, KHL) +NHQ = (TNL, DKN) +JVM = (KQR, PJL) +CGH = (RTC, VFC) +HNF = (GHJ, FKR) +TMF = (NMS, GJH) +NGJ = (NXM, BDB) +MRM = (JKQ, MPS) +QTC = (JSS, HXM) +TNM = (JFF, QXR) +DHK = (LJR, CCX) +XSB = (MRR, CXC) +XRN = (XDP, QBP) +XCV = (XTJ, SVH) +VVA = (QSM, FSF) +NKC = (RDR, NSB) +MXL = (RBV, RBV) +PTX = (TVJ, JPQ) +VRL = (NQX, XJB) +RQK = (MPS, JKQ) +PBJ = (CKD, CCD) +VRP = (DQN, QLC) +KLF = (MFN, GRB) +XXJ = (GBT, CDG) +HST = (QHV, MMS) +SFT = (JPB, VBQ) +NRR = (LCL, MQR) +CSL = (JQN, PDS) +LHJ = (BDB, NXM) +TXK = (DHK, KLC) +CDK = (XCX, XCX) +FHT = (NGQ, JHN) +QQJ = (LGH, XLX) +BQJ = (GXH, QGC) +TTA = (QKM, XLR) +TVB = (FLN, LQR) +PPL = (FRL, NCX) +SPS = (XFJ, HBM) +SVH = (JDT, VRL) +QBB = (PXG, MTP) +JSJ = (VVB, NRR) +KKS = (RGL, JQD) +JDT = (NQX, NQX) +GKQ = (LLT, JRH) +VVH = (BPT, KRN) +JCQ = (CRB, PBS) +QXR = (BTV, PSZ) +VQR = (RCX, KKP) +QSM = (SLR, XGV) +JKD = (JDC, JGV) +XLD = (LFS, QVR) +TJK = (NKG, SDJ) +PVV = (HDK, VQV) +BDB = (PVV, KRX) +MPS = (KBN, DPT) +FHP = (PPD, XCF) +HTN = (KCM, PXC) +GHJ = (BHN, FKK) +JCC = (LQM, KVH) +LQR = (HGF, NVL) +LGM = (DDJ, NQF) +NJN = (QCF, NPN) +PRH = (DFF, DFF) +XDM = (FBJ, PJM) +HFN = (KRS, XSB) +GLM = (JXM, RMG) +RQP = (BXM, SDH) +BPG = (QJT, KTP) +JPB = (LNN, PKT) +DKN = (CJD, BGR) +CDG = (GSL, DJJ) +XDN = (CGM, VMG) +NQP = (SKT, JCC) +DNP = (QQG, DMJ) +NNX = (DQN, QLC) +FTB = (JFL, VJJ) +FHQ = (SMJ, XFK) +GGT = (KPK, LNT) +NGF = (LJB, CJM) +QFX = (KCN, TMF) +NKF = (JCQ, QNX) +DBP = (NGV, HLC) +RBV = (RMT, DHJ) +NML = (MBV, VCG) +KXJ = (MXH, FDC) +GFQ = (RDP, HNF) +SHD = (CMG, CTM) +GTX = (LNK, KXJ) +HXF = (KTC, LXS) +CMM = (NQP, SBR) +SDJ = (TBV, XCV) +CHG = (RMJ, RMJ) +DPT = (CMQ, JBG) +BGR = (RLM, NML) +THM = (XQD, NJN) +HJJ = (MCP, VRM) +NRQ = (JHR, GCQ) +KKR = (HSN, NJJ) +KVX = (LVG, NFN) +LTT = (TLD, DPP) +NVL = (QHB, HBF) +CXN = (XRF, BPK) +KLC = (CCX, LJR) +JDC = (DNF, XKX) +MGS = (XLK, CND) +RLM = (VCG, MBV) +VDN = (NMQ, TPR) +HSB = (JFL, VJJ) +HDS = (KLC, DHK) +XSD = (NLV, HBR) +HJD = (NJQ, PBQ) +CGM = (DHX, GVC) +LDQ = (PBL, JKG) +RDR = (XHQ, MGQ) +GPC = (GFJ, SFM) +NQT = (KRS, XSB) +TDH = (RBD, XLP) +QJF = (DFC, DPV) +VNS = (HPK, LBN) +QSD = (NJJ, HSN) +JHR = (QMF, JVH) +SMQ = (FXR, RFM) +CMG = (MFG, GGJ) +NKQ = (VFC, RTC) +VXC = (LHN, RSQ) +DHX = (LCT, XNM) +TCX = (NQT, HFN) +DRV = (TFN, QBM) +JPT = (GQX, XCR) +HRF = (JQH, XNH) +MCS = (BGJ, QTC) +PQG = (NCM, TCF) +XHR = (PJK, VPN) +MLX = (PGH, VND) +MKH = (VPJ, LMD) +TJR = (VQT, MPJ) +VLF = (GLG, QFX) +JNG = (KLR, MPV) +HDK = (BFQ, SFT) +HFX = (MLX, SPL) +BXC = (HFS, LBS) +CCT = (GTX, HPT) +VLK = (HLK, QJF) +NCD = (PJM, FBJ) +VGT = (JNL, DVQ) +LMD = (PSK, GQL) +KRX = (HDK, VQV) +QNX = (CRB, PBS) +NJQ = (GHQ, NDB) +TNV = (FBP, BQJ) +GNR = (XQD, NJN) +KKP = (QTB, PPL) +DBX = (KCQ, CPS) +VRM = (TLM, QLS) +LVG = (BRP, NJV) +NHL = (SPS, LKX) +MNV = (VBL, CHT) +PJK = (HHN, LTT) +VBH = (JQD, RGL) +GRB = (NKQ, CGH) +SKT = (KVH, LQM) +TPR = (RXR, KHV) +VVB = (LCL, MQR) +VKX = (MRM, RQK) +LTB = (PGJ, GQM) +QCJ = (KCM, PXC) +BGQ = (SMJ, SMJ) +RCV = (NQQ, JHP) +DHM = (TQS, BLS) +KRS = (CXC, MRR) +JFL = (BLT, PNM) +TXC = (NRT, LRG) +MVX = (LKL, XRR) +QSK = (JVM, MTF) +BGK = (LDB, NPX) +GJZ = (BFC, QQJ) +PXC = (LTB, PCH) +HMQ = (BGJ, QTC) +RXR = (BVJ, XSD) +BXM = (PRH, BCX) +FJH = (LRG, NRT) +GJH = (DGK, DDS) +BPT = (SBL, PHL) +RQL = (RQK, MRM) +SJB = (RQJ, LDQ) +NFN = (NJV, BRP) +MND = (NQQ, JHP) +NMQ = (KHV, RXR) +XGV = (TXK, HDS) +SPC = (KSS, XQF) +RMJ = (SMR, QRS) +CNX = (LFS, QVR) +KLR = (HJD, XSF) +XLP = (KRM, PNX) +LPM = (CMM, PHF) +FNR = (CCT, VTP) +NGQ = (CMT, JTX) +CCR = (BFM, TNV) +LCN = (FXV, TQL) +HVV = (HSX, KVX) +FSB = (MLX, SPL) +GGJ = (TLQ, VQD) +NHS = (DRG, FVK) +RQJ = (PBL, JKG) +VCC = (MMS, QHV) +HDX = (VVN, HXF) +VQM = (NRR, VVB) +TFN = (GFB, LRH) +QRS = (VQR, MDS) +HBM = (VTQ, SDN) +CCF = (SBS, XFD) +VCG = (HMQ, MCS) +NBF = (DVB, NHS) +DVB = (FVK, DRG) +PGB = (TDH, RFP) +XRF = (KFP, SPH) +KMM = (PDJ, GQN) +KTG = (GGQ, HNR) +BJH = (JBH, QSB) +JJH = (CCT, VTP) +LBH = (JFF, JFF) +GLG = (TMF, KCN) +TQR = (THM, GNR) +MQH = (GQN, PDJ) +MQR = (FMB, MRT) +FNH = (CTM, CMG) +SMR = (VQR, MDS) +GDS = (DNP, MJS) +LCT = (KQK, QFL) +VKB = (GBH, BGK) +VTQ = (CHM, MFP) +TNK = (QJT, KTP) +HNJ = (VVS, GCX) +JKT = (MMD, MGS) +PBP = (TPR, NMQ) +CPS = (KNJ, RFZ) +RNB = (KHX, FQC) +CMF = (LHN, RSQ) +HPK = (CCR, LXJ) +MFN = (NKQ, CGH) +HHB = (QBM, TFN) +DDJ = (QSK, KCC) +DFM = (RQL, VKX) +FKM = (GKQ, VJG) +HSJ = (LGQ, LXK) +HPT = (KXJ, LNK) +BNR = (JBX, DMK) +GJL = (CPC, JNF) +DFF = (KCQ, KCQ) +MCB = (GSS, JVP) +CPC = (JJH, FNR) +XLR = (MJK, DSM) +SBG = (JDG, XFL) +XSF = (NJQ, PBQ) +NGK = (RFM, FXR) +HSN = (GRH, HSJ) +LQM = (PQG, VKD) +VXN = (VMG, CGM) +PSK = (VGT, DTP) +JQH = (KLF, SCQ) +RJM = (SPC, TVP) +VSD = (TLL, TQR) +KCN = (GJH, NMS) +QHB = (GLM, BMP) +FMB = (VLK, XGT) +GBT = (DJJ, GSL) +LGH = (NGJ, LHJ) +SLR = (HDS, TXK) +VVQ = (GCX, VVS) +MDS = (RCX, KKP) +KVQ = (VPN, PJK) +CLF = (NHL, KGK) +XFK = (KQD, PNT) +CJD = (NML, RLM) +MCP = (TLM, QLS) +SPL = (PGH, VND) +GSS = (GPC, DNX) +RPH = (DBP, HHC) +HNR = (XXQ, JKD) +VBV = (VQT, MPJ) +PHF = (NQP, SBR) +BRP = (FJH, TXC) +AAA = (RMT, DHJ) +PBQ = (GHQ, NDB) +PXG = (VVG, SPN) +PNX = (JQV, JNG) +XHQ = (SJB, MBS) +VBL = (VLF, PXS) +VVG = (MTT, XTV) +PXS = (GLG, QFX) +MMQ = (FKM, HNH) +PHG = (HFN, NQT) +MFF = (KFL, LNQ) +PJM = (FHP, SPX) +SMJ = (KQD, KQD) +XGC = (CMM, PHF) +PDJ = (QCK, MHB) +SPN = (MTT, XTV) +BPK = (KFP, SPH) +MVF = (NQC, NKK) +LJB = (LBH, LBH) +GQN = (QCK, MHB) +NCG = (MTP, PXG) +GQL = (VGT, DTP) +NCX = (FNH, SHD) +HGZ = (QRS, SMR) +GMJ = (VSF, SFJ) +RFP = (XLP, RBD) +TXF = (GDC, HKP) +NBA = (SMR, QRS) +QTB = (FRL, NCX) +QLC = (GDN, QMD) +QHV = (SVV, HRM) +XTM = (GRV, THT) +VPN = (HHN, LTT) +RFZ = (XLR, QKM) +CMH = (SXG, CLF) +GFJ = (TCX, PHG) +VTT = (LGM, LFV) +RTC = (GKH, KPS) +XFJ = (VTQ, SDN) +GCX = (PGB, MJD) +MJK = (CLP, VML) +QQL = (RSG, KTG) +NSB = (XHQ, MGQ) +HCQ = (LGM, LFV) +GQX = (GJD, XKT) +RVR = (VVK, BKP) +JBG = (KKS, VBH) +JFF = (BTV, BTV) +BPM = (LNT, KPK) +LNQ = (JJR, HGQ) +FKK = (GLH, GPQ) +SBL = (CDK, BGL) +LNT = (BNH, RNS) +JRH = (JPS, HFG) +VVS = (MJD, PGB) +DPP = (LFR, GFQ) +MNF = (PBP, VDN) +QKM = (DSM, MJK) +JPJ = (CXN, RTJ) +QGC = (RQP, LBX) +CVB = (MND, RCV) +RFC = (CHG, FFQ) +KPS = (BCF, VSD) +XML = (MNV, TXG) +JVH = (JDP, GGF) +CRC = (XTM, LLQ) +VJG = (JRH, LLT) +SPB = (JPT, NDM) +JGV = (XKX, DNF) +GGQ = (XXQ, JKD) +XLK = (PGQ, VKB) +JBX = (NNX, VRP) +RSG = (HNR, GGQ) +GVC = (LCT, XNM) +XDP = (XML, HND) +CXC = (SMQ, NGK) +PXV = (TNK, BPG) +NDM = (XCR, GQX) +CPM = (BJH, QXK) +KGK = (LKX, SPS) +BLT = (NRL, PQR) +BHN = (GLH, GPQ) +BLS = (TKL, MNF) +PHL = (CDK, BGL) +BCX = (DFF, DBX) +HNH = (GKQ, VJG) +VKD = (NCM, TCF) +DSM = (VML, CLP) +DNN = (SLT, KJD) +SBR = (SKT, JCC) +TNL = (BGR, CJD) +DFT = (XFL, JDG) +MPT = (RKT, MFF) +TVQ = (XDP, QBP) +LLT = (JPS, HFG) +DXQ = (XTM, LLQ) +SFM = (PHG, TCX) +BNJ = (MND, RCV) +PBS = (NHQ, QRB) +JXM = (HRF, PKB) +VTP = (HPT, GTX) +SVV = (XXJ, RHB) +MHA = (QQJ, BFC) +MBV = (HMQ, MCS) +VJJ = (BLT, PNM) +QJT = (RVR, CGR) +VVN = (LXS, KTC) +QKS = (TRC, DFM) +MGQ = (MBS, SJB) +NDL = (BPT, KRN) +JPQ = (SVF, HDT) +VDH = (JHR, GCQ) +KCQ = (KNJ, KNJ) +XJJ = (DFT, SBG) +JQV = (MPV, KLR) +VQD = (DXQ, CRC) +JDG = (TJK, QMH) +SPX = (XCF, PPD) +LXJ = (TNV, BFM) +LBL = (NGQ, JHN) +QBN = (QQL, JPP) +LFS = (CVB, BNJ) +LBS = (JFV, NKC) +TLL = (THM, GNR) diff --git a/2023/day08_2/src/resources/small_input b/2023/day08_2/src/resources/small_input new file mode 100644 index 0000000..59e2d47 --- /dev/null +++ b/2023/day08_2/src/resources/small_input @@ -0,0 +1,9 @@ +RL + +AAA = (BBB, CCC) +BBB = (DDD, EEE) +CCC = (ZZZ, GGG) +DDD = (DDD, DDD) +EEE = (EEE, EEE) +GGG = (GGG, GGG) +ZZZ = (ZZZ, ZZZ) \ No newline at end of file diff --git a/2023/day08_2/src/resources/small_input2 b/2023/day08_2/src/resources/small_input2 new file mode 100644 index 0000000..34ffa8a --- /dev/null +++ b/2023/day08_2/src/resources/small_input2 @@ -0,0 +1,5 @@ +LLR + +AAA = (BBB, BBB) +BBB = (AAA, ZZZ) +ZZZ = (ZZZ, ZZZ) \ No newline at end of file diff --git a/2023/day08_2/src/resources/small_input3 b/2023/day08_2/src/resources/small_input3 new file mode 100644 index 0000000..87a68f1 --- /dev/null +++ b/2023/day08_2/src/resources/small_input3 @@ -0,0 +1,12 @@ +LR + +33B = (XXX, 22B) +11B = (XXX, 11Z) +11Z = (11B, XXX) +22A = (22B, XXX) +22B = (22C, 22C) +22C = (22Z, 22Z) +22Z = (22B, 22B) +XXX = (XXX, XXX) +11A = (11B, XXX) +33A = (33B, XXX) \ No newline at end of file diff --git a/2023/day08_2/src/resources/small_input4 b/2023/day08_2/src/resources/small_input4 new file mode 100644 index 0000000..a8e2c98 --- /dev/null +++ b/2023/day08_2/src/resources/small_input4 @@ -0,0 +1,10 @@ +LR + +11A = (11B, XXX) +11B = (XXX, 11Z) +11Z = (11B, XXX) +22A = (22B, XXX) +22B = (22C, 22C) +22C = (22Z, 22Z) +22Z = (22B, 22B) +XXX = (XXX, XXX) \ No newline at end of file diff --git a/2023/day09_1/day09_1.iml b/2023/day09_1/day09_1.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2023/day09_1/day09_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day01_1/day01_1.iml b/2024/day01_1/day01_1.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2024/day01_1/day01_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day01_1/resources/small_input b/2024/day01_1/resources/small_input new file mode 100644 index 0000000..dfca0b1 --- /dev/null +++ b/2024/day01_1/resources/small_input @@ -0,0 +1,6 @@ +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 \ No newline at end of file diff --git a/2024/day01_1/src/Main.kt b/2024/day01_1/src/Main.kt new file mode 100644 index 0000000..e41af49 --- /dev/null +++ b/2024/day01_1/src/Main.kt @@ -0,0 +1,40 @@ +import java.io.File +import kotlin.math.abs + +fun main(args: Array) { + println("AOC 2024, Day 1, Part 1 starting!!!!") + + val dualList = DualList() + + File(args[0]).forEachLine { + val theSplit = it.split(" ") + dualList.leftList.add(theSplit[0].toLong()) + dualList.rightList.add(theSplit[1].toLong()) + } + + dualList.orderLists() + val answer = dualList.calculateTotalDistance() + + println("The total distance between left/right lists is: $answer") + + println("AOC 2024, Day 1, Part 1 completed!!!") +} + +class DualList { + val leftList = ArrayList() + val rightList = ArrayList() + + fun orderLists() { + leftList.sort() + rightList.sort() + } + + fun calculateTotalDistance():Long { + var totalDistance = 0L + for(index in 0..< leftList.size) { + totalDistance += abs(leftList[index] - rightList[index]) + } + + return totalDistance + } +} \ No newline at end of file diff --git a/2024/day01_2/.idea/inspectionProfiles/Project_Default.xml b/2024/day01_2/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2024/day01_2/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2024/day01_2/.idea/kotlinc.xml b/2024/day01_2/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2024/day01_2/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2024/day01_2/.idea/libraries/KotlinJavaRuntime.xml b/2024/day01_2/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d39de76 --- /dev/null +++ b/2024/day01_2/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day01_2/.idea/misc.xml b/2024/day01_2/.idea/misc.xml new file mode 100644 index 0000000..cc6eae0 --- /dev/null +++ b/2024/day01_2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day01_2/.idea/modules.xml b/2024/day01_2/.idea/modules.xml new file mode 100644 index 0000000..69f99b5 --- /dev/null +++ b/2024/day01_2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2024/day01_2/.idea/vcs.xml b/2024/day01_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2024/day01_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day01_2/day01_2.iml b/2024/day01_2/day01_2.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2024/day01_2/day01_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day01_2/resources/small_input b/2024/day01_2/resources/small_input new file mode 100644 index 0000000..dfca0b1 --- /dev/null +++ b/2024/day01_2/resources/small_input @@ -0,0 +1,6 @@ +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 \ No newline at end of file diff --git a/2024/day02_1/.idea/kotlinc.xml b/2024/day02_1/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2024/day02_1/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2024/day02_1/.idea/libraries/KotlinJavaRuntime.xml b/2024/day02_1/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..409da39 --- /dev/null +++ b/2024/day02_1/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day02_1/.idea/misc.xml b/2024/day02_1/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2024/day02_1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day02_1/.idea/modules.xml b/2024/day02_1/.idea/modules.xml new file mode 100644 index 0000000..431cb2d --- /dev/null +++ b/2024/day02_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2024/day02_1/.idea/vcs.xml b/2024/day02_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2024/day02_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day02_1/day02_1.iml b/2024/day02_1/day02_1.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2024/day02_1/day02_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day02_1/resources/small_input b/2024/day02_1/resources/small_input new file mode 100644 index 0000000..82cd679 --- /dev/null +++ b/2024/day02_1/resources/small_input @@ -0,0 +1,6 @@ +7 6 4 2 1 +1 2 7 8 9 +9 7 6 2 1 +1 3 2 4 5 +8 6 4 4 1 +1 3 6 7 9 \ No newline at end of file diff --git a/2024/day02_2/.idea/kotlinc.xml b/2024/day02_2/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2024/day02_2/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2024/day02_2/.idea/libraries/KotlinJavaRuntime.xml b/2024/day02_2/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d39de76 --- /dev/null +++ b/2024/day02_2/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day02_2/.idea/misc.xml b/2024/day02_2/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2024/day02_2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day02_2/.idea/modules.xml b/2024/day02_2/.idea/modules.xml new file mode 100644 index 0000000..579e076 --- /dev/null +++ b/2024/day02_2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2024/day02_2/.idea/vcs.xml b/2024/day02_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2024/day02_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day02_2/day02_2.iml b/2024/day02_2/day02_2.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2024/day02_2/day02_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day02_2/src/Main.kt b/2024/day02_2/src/Main.kt new file mode 100644 index 0000000..1ea0407 --- /dev/null +++ b/2024/day02_2/src/Main.kt @@ -0,0 +1,89 @@ +import java.io.File +import kotlin.math.abs + +fun main(args: Array) { + println("AOC 2024, Day 2, Part 2 starting!!!!") + + val allReports = AllReports() + + File(args[0]).forEachLine { + val newReport = Report() + for (s in it.split(' ')) { + newReport.levels.add(s.toInt()) + } + allReports.reports.add(newReport) + } + + val safeCount = allReports.calculateSafeReports() + + println("Safe reports: $safeCount") + + + println("AOC 2024, Day 2, Part 2 completed!!!") +} + +class AllReports { + val reports = ArrayList() + + fun calculateSafeReports():Int { + return reports.count { it.safeLevels(it.levels, false) } + } +} + +class Report { + val levels = ArrayList() + + fun safeLevels(lvl:ArrayList, triggered:Boolean):Boolean { + var previousLevel = lvl.first() + var alwaysDecreasing = false + var alwaysIncreasing = false + var unsafeTrigger = false + val unsafeLevels = ArrayList() + + for(l in lvl.drop(1)) { + if(l == previousLevel) { + // the levels aren't increasing or decreasing, break and return false + unsafeTrigger = true + } + + if(l < previousLevel) { + alwaysDecreasing = true + } + if(l > previousLevel) { + alwaysIncreasing = true + } + + // If any time it these are both true, then break and return false. + if(alwaysDecreasing && alwaysIncreasing) { + unsafeTrigger = true + } + + // If increasing or decreasing more than 3, record it + if(abs(l - previousLevel) > 3) { + unsafeTrigger = true + } + + if(unsafeTrigger) { + unsafeLevels.add(l) + } + + previousLevel = l + } + + + if(unsafeLevels.isEmpty()) { + return true + } else if(unsafeTrigger && !triggered) { + for(i in 0..(lvl) + shrunkLevel.removeAt(i) + if(safeLevels(shrunkLevel, true)) { + return true + } + } + } + + // if executed to here, return false/unsafe. + return false + } +} \ No newline at end of file diff --git a/2024/day03_1/.idea/inspectionProfiles/Project_Default.xml b/2024/day03_1/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2024/day03_1/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2024/day03_1/.idea/kotlinc.xml b/2024/day03_1/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2024/day03_1/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2024/day03_1/.idea/libraries/KotlinJavaRuntime.xml b/2024/day03_1/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d39de76 --- /dev/null +++ b/2024/day03_1/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day03_1/.idea/misc.xml b/2024/day03_1/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2024/day03_1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day03_1/.idea/modules.xml b/2024/day03_1/.idea/modules.xml new file mode 100644 index 0000000..d9d9e9b --- /dev/null +++ b/2024/day03_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2024/day03_1/.idea/vcs.xml b/2024/day03_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2024/day03_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day03_1/day03_1.iml b/2024/day03_1/day03_1.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2024/day03_1/day03_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day03_1/src/Main.kt b/2024/day03_1/src/Main.kt new file mode 100644 index 0000000..7dd4ba6 --- /dev/null +++ b/2024/day03_1/src/Main.kt @@ -0,0 +1,33 @@ +import java.io.File + +// important note: RegEx that handles the problem: mul\(\d{1,3},\d{1,3}\) +fun main(args: Array) { + println("AOC 2024, Day 3, Part 1 starting!!!!") + + val theOperations = MulOperations() + val theRegex = "mul\\(\\d{1,3},\\d{1,3}\\)".toRegex() + File(args[0]).forEachLine { + val theMatches = theRegex.findAll(it) + for(match in theMatches) { + theOperations.dataList.add(match.value) + } + } + + println("The answer: ${theOperations.results()}") + + println("AOC 2024, Day 3, Part 1 completed!!!") +} + +class MulOperations { + val dataList = ArrayList() + + fun results():Long { + var theResult = 0L + val regex = "(\\d{1,3})".toRegex() + for(d in dataList) { + val theMatches = regex.findAll(d) + theResult += (theMatches.first().value.toLong() * theMatches.last().value.toLong()) + } + return theResult + } +} \ No newline at end of file diff --git a/2024/day03_2/.idea/inspectionProfiles/Project_Default.xml b/2024/day03_2/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2024/day03_2/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2024/day03_2/.idea/kotlinc.xml b/2024/day03_2/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2024/day03_2/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2024/day03_2/.idea/libraries/KotlinJavaRuntime.xml b/2024/day03_2/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d39de76 --- /dev/null +++ b/2024/day03_2/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day03_2/.idea/misc.xml b/2024/day03_2/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2024/day03_2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day03_2/.idea/modules.xml b/2024/day03_2/.idea/modules.xml new file mode 100644 index 0000000..d910da0 --- /dev/null +++ b/2024/day03_2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2024/day03_2/.idea/vcs.xml b/2024/day03_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2024/day03_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day03_2/day03_2.iml b/2024/day03_2/day03_2.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2024/day03_2/day03_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day03_2/src/Main.kt b/2024/day03_2/src/Main.kt new file mode 100644 index 0000000..2162c14 --- /dev/null +++ b/2024/day03_2/src/Main.kt @@ -0,0 +1,44 @@ +import java.io.File + +// important note: RegEx that handles the problem: mul\(\d{1,3},\d{1,3}\)|do\(\)|don\'t\(\) +fun main(args: Array) { + println("AOC 2024, Day 3, Part 2 starting!!!!") + + val theOperations = MulOperations() + val theRegex = "mul\\(\\d{1,3},\\d{1,3}\\)|do\\(\\)|don\'t\\(\\)".toRegex() + var enableMul = true + File(args[0]).forEachLine { + val theMatches = theRegex.findAll(it) + for(match in theMatches) { + if(match.value == "don't()") { + enableMul = false + continue + } + if(match.value == "do()") { + enableMul = true + continue + } + if(enableMul) { + theOperations.dataList.add(match.value) + } + } + } + + println("The answer: ${theOperations.results()}") + + println("AOC 2024, Day 3, Part 2 completed!!!") +} + +class MulOperations { + val dataList = ArrayList() + + fun results():Long { + var theResult = 0L + val regex = "(\\d{1,3})".toRegex() + for(d in dataList) { + val theMatches = regex.findAll(d) + theResult += (theMatches.first().value.toLong() * theMatches.last().value.toLong()) + } + return theResult + } +} \ No newline at end of file diff --git a/2024/day04_1/.idea/inspectionProfiles/Project_Default.xml b/2024/day04_1/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2024/day04_1/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2024/day04_1/.idea/kotlinc.xml b/2024/day04_1/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2024/day04_1/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2024/day04_1/.idea/libraries/KotlinJavaRuntime.xml b/2024/day04_1/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d39de76 --- /dev/null +++ b/2024/day04_1/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day04_1/.idea/misc.xml b/2024/day04_1/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2024/day04_1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day04_1/.idea/modules.xml b/2024/day04_1/.idea/modules.xml new file mode 100644 index 0000000..6abc551 --- /dev/null +++ b/2024/day04_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2024/day04_1/.idea/vcs.xml b/2024/day04_1/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2024/day04_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day04_1/day04_1.iml b/2024/day04_1/day04_1.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2024/day04_1/day04_1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day04_1/src/Main.kt b/2024/day04_1/src/Main.kt new file mode 100644 index 0000000..e5874fa --- /dev/null +++ b/2024/day04_1/src/Main.kt @@ -0,0 +1,134 @@ +import java.io.File +import kotlin.math.max + +fun main(args: Array) { + println("AOC 2024, Day 4, Part 1 starting!!!!") + + val theData = WordSearchData() + var yPosition = 0 + File(args[0]).forEachLine { + var xPosition = 0 + for(c in it.toCharArray()) { + val newWordSearchCharacter = WordSearchCharacter(c, xPosition, yPosition) + theData.characters.add(newWordSearchCharacter) + xPosition++ + } + theData.maxX = xPosition + yPosition++ + } + theData.maxY = yPosition + + val answer = theData.searchForXmas() + + println("Word search grid: ${theData.maxX} x ${theData.maxY}") + println("Number of matches: $answer") + + println("AOC 2024, Day 4, Part 1 completed!!!") +} + +class WordSearchData { + val characters = ArrayList() + + var maxX:Int = 0 + set(value) { + field = max(field, value) + } + var maxY:Int = 0 + set(value) { + field = max(field, value) + } + + enum class Direction { + UP_LEFT, UP, UP_RIGHT, LEFT, RIGHT, DOWN_LEFT, DOWN, DOWN_RIGHT, NONE + } + + fun searchForXmas():Int { + var matches = 0 + // All characters in word search space + for(wordSearchCharacter in characters) { + // Look for matches to on characters XMAS + + for (direction in WordSearchData.Direction.entries) { + if (wordSearchCharacter.theChar == 'X' && + searchForXmas(wordSearchCharacter, 'M', direction, 1) && + searchForXmas(wordSearchCharacter, 'A', direction, 2) && + searchForXmas(wordSearchCharacter, 'S', direction, 3) + ) { + println("Found XMAS at ${wordSearchCharacter.xPosition}, ${wordSearchCharacter.yPosition} in direction $direction") + matches++ + } + } + } + + return matches + } + + private fun searchForXmas(character: WordSearchCharacter, lookFor:Char, direction:Direction, step:Int):Boolean { + if(direction == Direction.NONE) { + return false + } + + var nextX = character.xPosition + var nextY = character.yPosition + when (direction) { + // search up left : x - 1, y - 1 + Direction.UP_LEFT -> { + nextX -= step + nextY -= step + } + // search up : x, y - 1 + Direction.UP -> { + nextY -= step + } + // search up right : x + 1, y - 1 + Direction.UP_RIGHT -> { + nextX += step + nextY -= step + } + // search left : x - 1, y + Direction.LEFT -> { + nextX -= step + } + // search right : x + 1, y + Direction.RIGHT -> { + nextX += step + } + // search down left : x - 1, y + 1 + Direction.DOWN_LEFT -> { + nextX -= step + nextY += step + } + // search down : x, y + 1 + Direction.DOWN -> { + nextY += step + } + // search down right: x + 1, y + 1 + Direction.DOWN_RIGHT -> { + nextX += step + nextY += step + } + else -> { + // do nothing + } + } + if (positionCheck(nextX, nextY)) { + val nextChar = characters.find { allCharacters -> allCharacters.xPosition == nextX && allCharacters.yPosition == nextY } + return nextChar?.theChar == lookFor + } + + // If code arrives here, then false + return false + } + + private fun positionCheck(x:Int, y:Int):Boolean { + if((x < 0) || (y < 0)) return false + + if((x > maxX) || (y > maxY)) return false + + return true + } +} + + + +data class WordSearchCharacter (val theChar:Char, val xPosition:Int, val yPosition:Int) diff --git a/2024/day04_2/.idea/inspectionProfiles/Project_Default.xml b/2024/day04_2/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/2024/day04_2/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2024/day04_2/.idea/kotlinc.xml b/2024/day04_2/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/2024/day04_2/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/2024/day04_2/.idea/libraries/KotlinJavaRuntime.xml b/2024/day04_2/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d39de76 --- /dev/null +++ b/2024/day04_2/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day04_2/.idea/misc.xml b/2024/day04_2/.idea/misc.xml new file mode 100644 index 0000000..97a68f6 --- /dev/null +++ b/2024/day04_2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day04_2/.idea/modules.xml b/2024/day04_2/.idea/modules.xml new file mode 100644 index 0000000..25e2d60 --- /dev/null +++ b/2024/day04_2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2024/day04_2/.idea/vcs.xml b/2024/day04_2/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/2024/day04_2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2024/day04_2/day04_2.iml b/2024/day04_2/day04_2.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/2024/day04_2/day04_2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2024/day04_2/src/Main.kt b/2024/day04_2/src/Main.kt new file mode 100644 index 0000000..7c325b8 --- /dev/null +++ b/2024/day04_2/src/Main.kt @@ -0,0 +1,173 @@ +import java.io.File +import kotlin.math.max + + +fun main(args: Array) { + println("AOC 2024, Day 4, Part 2 starting!!!!") + + val theData = WordSearchData() + var yPosition = 0 + File(args[0]).forEachLine { + var xPosition = 0 + for(c in it.toCharArray()) { + val newWordSearchCharacter = WordSearchCharacter(c, xPosition, yPosition) + theData.characters.add(newWordSearchCharacter) + xPosition++ + } + theData.maxX = xPosition + yPosition++ + } + theData.maxY = yPosition + + val answer = theData.searchForXmas() + + println("Word search grid: ${theData.maxX} x ${theData.maxY}") + println("Number of matches: $answer") + + println("AOC 2024, Day 4, Part 2 completed!!!") +} + +class WordSearchData { + val characters = ArrayList() + + var maxX: Int = 0 + set(value) { + field = max(field, value) + } + var maxY: Int = 0 + set(value) { + field = max(field, value) + } + + enum class Direction { + UP_LEFT, UP, UP_RIGHT, LEFT, RIGHT, DOWN_LEFT, DOWN, DOWN_RIGHT + } + + fun searchForXmas(): Int { + var matches = 0 + // All characters in word search space + for (wordSearchCharacter in characters) { + // Look for matches to on characters XMAS + + if ((wordSearchCharacter.theChar == 'A') && searchForXMAS(wordSearchCharacter)) { + println("Found X of MAS at ${wordSearchCharacter.xPosition}, ${wordSearchCharacter.yPosition}") + matches++ + } + } + + return matches + } + + + private fun searchForXMAS(character: WordSearchCharacter): Boolean { + + return checkPattern1(character) || checkPattern2(character) || checkPattern3(character) || checkPattern4(character) + } + + // Pattern 1 + // M . M + // . A . + // S . S + private fun checkPattern1(character: WordSearchCharacter):Boolean { + return searchForMAS(character, 'M', Direction.UP_LEFT, 1) && + searchForMAS(character, 'M', Direction.UP_RIGHT, 1) && + searchForMAS(character, 'S', Direction.DOWN_LEFT, 1) && + searchForMAS(character, 'S', Direction.DOWN_RIGHT, 1) + } + + // Pattern 2 + // M . S + // . A . + // M . S + private fun checkPattern2(character: WordSearchCharacter):Boolean { + return searchForMAS(character, 'M', Direction.UP_LEFT, 1) && + searchForMAS(character, 'S', Direction.UP_RIGHT, 1) && + searchForMAS(character, 'M', Direction.DOWN_LEFT, 1) && + searchForMAS(character, 'S', Direction.DOWN_RIGHT, 1) + } + + // Pattern 3 + // S . S + // . A . + // M . M + private fun checkPattern3(character: WordSearchCharacter):Boolean { + return searchForMAS(character, 'S', Direction.UP_LEFT, 1) && + searchForMAS(character, 'S', Direction.UP_RIGHT, 1) && + searchForMAS(character, 'M', Direction.DOWN_LEFT, 1) && + searchForMAS(character, 'M', Direction.DOWN_RIGHT, 1) + } + + // Pattern 4 + // S . M + // . A . + // S . M + private fun checkPattern4(character: WordSearchCharacter):Boolean { + return searchForMAS(character, 'S', Direction.UP_LEFT, 1) && + searchForMAS(character, 'M', Direction.UP_RIGHT, 1) && + searchForMAS(character, 'S', Direction.DOWN_LEFT, 1) && + searchForMAS(character, 'M', Direction.DOWN_RIGHT, 1) + } + + private fun searchForMAS(character: WordSearchCharacter, lookFor: Char, direction: Direction, step: Int): Boolean { + + + var nextX = character.xPosition + var nextY = character.yPosition + when (direction) { + // search up left : x - 1, y - 1 + Direction.UP_LEFT -> { + nextX -= step + nextY -= step + } + // search up : x, y - 1 + Direction.UP -> { + nextY -= step + } + // search up right : x + 1, y - 1 + Direction.UP_RIGHT -> { + nextX += step + nextY -= step + } + // search left : x - 1, y + Direction.LEFT -> { + nextX -= step + } + // search right : x + 1, y + Direction.RIGHT -> { + nextX += step + } + // search down left : x - 1, y + 1 + Direction.DOWN_LEFT -> { + nextX -= step + nextY += step + } + // search down : x, y + 1 + Direction.DOWN -> { + nextY += step + } + // search down right: x + 1, y + 1 + Direction.DOWN_RIGHT -> { + nextX += step + nextY += step + } + } + if (positionCheck(nextX, nextY)) { + val nextChar = + characters.find { allCharacters -> allCharacters.xPosition == nextX && allCharacters.yPosition == nextY } + return nextChar?.theChar == lookFor + } + + // If code arrives here, then false + return false + } + + private fun positionCheck(x: Int, y: Int): Boolean { + if ((x < 0) || (y < 0)) return false + + if ((x > maxX) || (y > maxY)) return false + + return true + } +} + +data class WordSearchCharacter (val theChar:Char, val xPosition:Int, val yPosition:Int) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This 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.