Last active
December 2, 2015 17:37
-
-
Save kiasaki/18ea329b62203c5b8712 to your computer and use it in GitHub Desktop.
Advent of Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import chicken scheme) | |
(use utils) | |
(define *input* (read-all (current-input-port))) | |
(define (main) | |
(let loop ((input (string->list *input*)) | |
(i 1)) | |
(cond ((null? input) i) | |
(else (case (car input) | |
((#\() (loop (cdr input) (+ i 1))) | |
((#\)) (loop (cdr input) (- i 1)))))))) | |
(print (main)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import chicken scheme) | |
(use utils) | |
(define *input* (read-all (current-input-port))) | |
(define (main) | |
(let loop ((input (string->list *input*)) | |
(index 1) | |
(flor 0)) | |
(cond ((null? input) 0) | |
((eq? flor -1) (- index 1)) | |
(else (case (car input) | |
((#\() (loop (cdr input) (+ index 1) (+ flor 1))) | |
((#\)) (loop (cdr input) (+ index 1) (- flor 1)))))))) | |
(print (main)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import chicken scheme) | |
(use utils srfi-1) | |
(define *input* (read-all (current-input-port))) | |
(define (gifts-from-input input) | |
(string-split (string-trim-right input #\newline) "\n" #t)) | |
(define (gift-parse gift) | |
(string-split gift "x")) | |
(define (gift-total l w h) | |
(let ((side1 (* l w)) | |
(side2 (* w h)) | |
(side3 (* h l))) | |
(+ (* side1 2) (* side2 2) (* side3 2) (min side1 (min side2 side3))))) | |
(define (gift-total* gift) | |
(gift-total | |
(string->number (first gift)) | |
(string->number (second gift)) | |
(string->number (third gift)))) | |
(define (gift-list-total gifts) | |
(apply + (map gift-total* gifts))) | |
(define (main) | |
(print (gift-list-total (map gift-parse (gifts-from-input *input*))))) | |
(main) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import chicken scheme) | |
(use utils srfi-1) | |
(define *input* (read-all (current-input-port))) | |
(define (gifts-from-input input) | |
(string-split (string-trim-right input #\newline) "\n" #t)) | |
(define (gift-parse gift) | |
(string-split gift "x")) | |
(define (gift-total l w h) | |
(let* ((sides (sort (list l w h) <)) | |
(x (first sides)) | |
(y (second sides))) | |
(+ x x y y (* l w h)))) | |
(define (gift-total* gift) | |
(gift-total | |
(string->number (first gift)) | |
(string->number (second gift)) | |
(string->number (third gift)))) | |
(define (gift-list-total gifts) | |
(apply + (map gift-total* gifts))) | |
(define (main) | |
(print (gift-list-total (map gift-parse (gifts-from-input *input*))))) | |
(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment