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