aoc_omni/racket/2015/1/problem.rkt
2023-12-19 15:11:40 -05:00

29 lines
916 B
Racket

#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))