diff --git a/racket/2015/1/problem.rkt b/racket/2015/1/problem.rkt new file mode 100644 index 0000000..04cf18e --- /dev/null +++ b/racket/2015/1/problem.rkt @@ -0,0 +1,28 @@ +#lang racket + +(define input (open-input-file "../data/2015/1/input.txt")) + +(define (final-floor str current-floor) + (let ([current-char (read-string 1 str) ]) + (if (equal? current-char "(") + (final-floor str (+ current-floor 1)) + (if (equal? current-char ")") + (final-floor str (- current-floor 1)) + current-floor)))) + +(define (total-steps str current-floor current-steps) + (let ([current-char (read-string 1 str) ] + [next-steps (+ current-steps 1)]) + (if (< current-floor 0) current-steps + (if (equal? current-char "(") + (total-steps str (+ current-floor 1) next-steps) + (if (equal? current-char ")") + (total-steps str (- current-floor 1) next-steps) + current-floor))))) + +(printf "Part 1: ~a\n" (final-floor input 0)) + +(file-position input 0) + +(printf "Part 2: ~a\n" (total-steps input 0 0)) + diff --git a/racket/bin/run b/racket/bin/run new file mode 100755 index 0000000..a08f059 --- /dev/null +++ b/racket/bin/run @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +year=$1 +day=$2 + +time racket $year/$day/problem.rkt