Coder Social home page Coder Social logo

hughjdavey / aoc-kotlin-starter Goto Github PK

View Code? Open in Web Editor NEW
22.0 3.0 5.0 294 KB

Starter template for solving Advent of Code in Kotlin

License: Creative Commons Zero v1.0 Universal

Kotlin 100.00%
advent-of-code kotlin starter-template starter-project

aoc-kotlin-starter's Introduction

aoc-kotlin-starter

Screenshots

Starter template for solving Advent of Code in Kotlin

Features

  • Gradle setup so you can run a specific day or all days on the command line (see Running below)
  • Timings for each part of each day
  • Input for each day automatically exposed in String and List form
  • Junit and Hamcrest test libraries included (see Testing below)
  • Starter .gitignore

Running

Project is already setup with gradle. To run the app:

  • Navigate to top-level directory on the command line
  • Run ./gradlew run to run all days
  • Run ./gradlew run --args $DAY where $DAY is an integer to run a specific day

Testing

Project includes Junit and Hamcrest and a stub unit test to get you going. To run all tests:

  • Navigate to top-level directory on the command line
  • Run ./gradlew test
  • Add --info, --debug or --stacktrace flags for more output
Test input

By default, instantiations of Day classes in tests will use the input files in src/test/resources, not those in src/main/resources. This hopefully gives you flexibility - you could either just copy the real input into src/test/resources if you want to test the actual answers, or you could add a file of test data based on the examples given on the Advent of Code description for the day. The stub Day1Test class shows a test of the functionality of Day1 where the test input differs from the actual input.

Architecture

  • Inputs go into src/main/resources and follow the naming convention input_day_X.txt
  • Solutions go into src/main/kotlin/days and extend the Day abstract class, calling its constructor with their day number
  • Solutions follow the naming convention DayX
  • It is assumed all solutions will have two parts but share the same input
  • Input is exposed in the solution classes in two forms - inputList and inputString
  • Day 1 solution class and input file are stubbed as a guide on how to extend the project, and how you can use the inputList and inputString mentioned above
  • To get started simply replace src/main/input_day_1.txt with the real input and the solutions in Day1 with your own
  • A Day 1 test class also exists, mostly to show a few hamcrest matchers, and how test input files can differ from actual ones (see Test input section above). To get started with testing you can edit this class, and the input file at src/test/resources/input_day_1.txt

Screenshots

Screenshots show fake data (not a real advent of code year!)

Running all days

Running all days

Running a single day

Running a single day

aoc-kotlin-starter's People

Contributors

hughjdavey avatar rusticflare avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aoc-kotlin-starter's Issues

Using InputReader in Day statically

I had to put the function of InputReader in a companion object to access the functions in a "static" way.
eg:

class InputReader {

    companion object {
        fun getInputAsString(day: Int) = fromResources(day).readText()


        fun getInputAsList(day: Int) = fromResources(day).readLines()

        private fun fromResources(day: Int): File {
            return File(javaClass.classLoader.getResource("input_day_$day.txt").toURI())
        }
    }
}

alternative would be to change the access to

protected val inputList: List<String> by lazy { InputReader().getInputAsList(dayNumber) }

I've copy pasted the files instead of cloning, maybe I missed some configuration preventing this error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.