Giter Site home page Giter Site logo

advent's Introduction

Quickstart

To run, supply the year and day at the command prompt:

clojure -X:run :year 2021 :day 2

To test:

clojure -X:test

Introduction

Advent of Code is a yearly event--25 magical programming puzzles!

I've been doing Advent of Code somewhat halfheartedly for the past several years. In 2021 I decided to be a bit more disciplined with my code (included a "runner", a common library for "utilities", tests).

I also scooped up some of my code from previous years and jammed it into the repository. Some of it works "as-is", some might need improvement. I have aspirations to some day work my way through the "backlog" of previous years and fill in the gaps.

Selective overview: using the utility libraries

util/matrix.clj

Many Advent of Code puzzles use tables, two-dimensional data, or some other contrived data structure which can be thought of as a matrix. I've created some utilities for working with matrices, especially reading, writing, and visualizing.

(def raw-matrix-string
  " 9 15  6
   13  4 18
    4 13  7")

(require '[net.bjoc.advent.util.matrix :as mtx])

(def my-matrix
  (mtx/from-string raw-matrix-string)) ;; cool, we can automagically "read" a matrix

(mtx/dump my-matrix)                   ;; dumping it to stdout is easy

(-> my-matrix
    (mtx/rotate 2)
    mtx/dump)                          ;; string together operations before dumping

util/matrix_visualizations.clj

Beyond dumping a matrix to text, sometimes it's nice to look at a bitmap.

(require '[net.bjoc.advent.util.matrix-visualization :as vis])

;; definitely want a good color scheme
(import '[java.awt Color])
(def ocean-pallette {\O (. Color getHSBColor (/ 133 360) 0.87 0.24)
                     \. (. Color getHSBColor (/ 214 360) 0.83 0.65)
                     \# (. Color getHSBColor (/ 214 360) 0.62 0.85)})

;; write an image file
(use '[net.bjoc.advent.year-2020.day-20])
(-> "data/year_2020/day_20.input"
    file->tiles
    assemble
    mark-monsters
    (vis/write-image-file "visualizations/2020_day_20.png"
                          :img-size [800 800] :pallette ocean-pallette))

2020 Day 20 Visualization

advent's People

Contributors

bjocallaghan avatar

Watchers

 avatar  avatar

Forkers

erkankesik

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.