This year I decided I'd learn the Kotlin language while working on solutions for Advent of Code. 😅 Hopefully I can get past the day 10 hump without life getting in the way this year, but should be a fun learning experience nonetheless.
The solutions that are provided here are probably not the "best way" of doing things. I'm looking forward to learning along the way and figuring out different ways to accomplish these problems with Kotlin 🙌.
If you'd like to follow along, I'll provide the steps below that I took to get this all up and running. This should allow you to go from Fresh Windows install to running the code in this repository.
First we'll start by installing the JDK.
- Click the link above to go to the JDK download page.
Note: Currently I've installed the Java 19 JDK. - Choose the Windows tab and download the x64 installer.
- Run the installer and let it take all the default options.
Next we'll install the Kotlin Command-Line Compiler.
- Download the
kotlin-compiler-[version].zip
file from the link above. - Extract the zip file into a folder at
c:\Program Files\kotlinc
.
- Open your start menu and type in
environment variables
, then clickEdit the system environment variables
. - Click the button at the bottom labeled
Environment Variables
. - Under the section labeled
User variables for ...
click the New Button. - Enter a Variable Name of
JAVA_HOME
and a Variable Value ofc:\Program Files\Java\jdk-19
(note: this assumes you installed version 19). - Click OK
- Under the section labeled
System Variables
, find the variable namedPath
, select it, and clickEdit...
. - Click the New button and add
C:\Program Files\kotlinc\bin
. (Make sure that this is the path that contains the kotlinc app). - Click the New button again and add
C:\Program Files\Java\jdk-19\bin
. (This again assumes the Java 19 version) - Click OK.
- Click OK again.
You'll need to have git installed locally for all this to work. You can download it and install it here.
This is just the easiest way to make sure your path is updated, it's probably enough to restart any open terminals that you have, but this guarantees that it works well.
Next, we'll make sure that your java and kotlin compiler are both installed properly. Open the start menu and type Terminal and open windows terminal. Run the following two commands and you should see similar output to the below:
javac -version
# javac 19.0.1
kotlinc -version
# info: kotlinc-jvm 1.7.21 (JRE 19.0.1+10-21)
As long as you see the above, you should be in good shape.
While we're here, let's run the following code to pull this repository and get it ready to run:
mkdir gitroot
cd gitroot
git clone https://github.com/joshpierce/advent-of-code-22
Now you should have the repository locally to tinker with.
Next, we'll download and install Visual Studio (VS) Code. This should be pretty self explanatory.
Open up a new Windows Terminal window like above, and run the following commands:
cd gitroot
cd advent-of-code-22
code .
This is shorthand to open VS Code with the scope of whatever folder you're in, it's handy.
- Code Runner - This we'll use to run our Kotlin code in VS Code.
- Kotlin Language - This will help us with syntax highlighting and code completion.
- Extension Pack for Java - I don't know if this is needed, but might be nice for Java development. Remember, I'm new here too. 🙃
- vscode-icons - Because they're awesome. ❤️
Inside VS Code, you should now be able to navigate to the src/DayXX.kt files, and right click on them and choose Run Code
. Any output from the files should be placed in the output window at the bottom of VS Code. You will need to add the associated day's input file from Advent of Code alongside the DayXX.kt files. For instance, you can copy and paste your input file from AOC into Day01.txt right next to Day01.kt to run the Day 1 solution.
I'm sorry 😞 Send me a message and I'd be happy to help if possible.
If you're stuck with Kotlin-specific questions or anything related to this template, check out the following resources:
- Kotlin docs
- Kotlin Slack
- Template issue tracker