Git Product home page Git Product logo

aoc-2023-roc's Introduction

Advent of Code Template

A template for AoC using Roc ๐Ÿค˜

Roc is a fast, friendly, and functional language which makes it ideal for AoC.

All you need to get started is the roc executable. Installing it doesn't take long, and it ships with testing (roc test) and code formatting (roc format) already included.

The simplest setup is to make each day its own .roc file.

For example, here's all you need for day1.

day1.roc

app "AoC"
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br",
    }
    imports [pf.Stdout, pf.Task.{Task}, "day-1-input.txt" as input : Str]
    provides [main] to pf

main : Task {} *
main = Stdout.line part1

part1 : Str
part1 =
    elfCalories
    |> List.map List.sum
    |> List.sortDesc
    |> List.first
    |> Result.map \highestCals -> "The Elf with the highest calories has \(Num.toStr highestCals) kCal"
    |> Result.withDefault "Ooops there are no rucksacks to count"

elfCalories : List (List U64)
elfCalories = parse input

parse : Str -> List (List U64)
parse = \str ->
    inventory <- str |> Str.split "\n\n" |> List.map

    inventory |> Str.split "\n" |> List.keepOks Str.toU64

You can run your solution from the terminal in the same directory as day1.roc with:

$ roc dev day1.roc

If you want to do an optimized build, run roc run --optimize day1.roc instead. This will take longer to build, but then the program will run faster.

To run tests, use:

$ roc test day1.roc 

0 failed and 1 passed in 277 ms.

This is all you need to solve AoC in Roc! ๐ŸŽ‰

Optional: AoC CLI, TUI and Web Apps

If you'd like additional features that are specific to AoC, then this repository has several to choose from:

  • A CLI App that prints the results to stdout roc run src/cli.roc -- 2022 1
  • A TUI App with a graphical menu to choose a solution to run roc src/tui.roc
  • A Web App for sharing your AoC solutions with your friends roc src/web.roc

The solutions for CLI, TUI and Web are common to all three applications. They are located in subfolders like src/S2023/D01.roc.

To add another you can copy a previous solution, and include it in the solutions variable in src/App.roc.

solutions : List AoC.Solution
solutions = 
    [
        S2022.D01.solution,
        S2022.D02.solution,
        S2022.D03.solution,
        S2023.D01.solution,
    ]
    |> List.sortWith sortByYearAndDay

aoc-2023-roc's People

Contributors

danmarcab avatar

Watchers

 avatar  avatar

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.