From 6100600fbf7d86218a71d735b2c08a61a520c02a Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 19 Nov 2022 13:00:30 -0500 Subject: add northwoods test --- .gitignore | 3 +- northwoods/.envrc | 1 + northwoods/guile.scm | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ northwoods/shell.nix | 5 +++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 northwoods/.envrc create mode 100644 northwoods/guile.scm create mode 100644 northwoods/shell.nix diff --git a/.gitignore b/.gitignore index d38ad60..545278e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ client_session_key.aes .stack-work -state/ \ No newline at end of file +state/ +.direnv diff --git a/northwoods/.envrc b/northwoods/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/northwoods/.envrc @@ -0,0 +1 @@ +use nix diff --git a/northwoods/guile.scm b/northwoods/guile.scm new file mode 100644 index 0000000..8dea315 --- /dev/null +++ b/northwoods/guile.scm @@ -0,0 +1,100 @@ +#| +Babysitter Kata + +Background +---------- +This kata simulates a babysitter working and getting paid for one night. The rules are pretty straight forward: + +The babysitter +- starts no earlier than 5:00PM +- leaves no later than 4:00AM +- gets paid $12/hour from start-time to bedtime +- gets paid $8/hour from bedtime to midnight +- gets paid $16/hour from midnight to end of job +- gets paid for full hours (no fractional hours) + + +Feature: +As a babysitter +In order to get paid for 1 night of work +I want to calculate my nightly charge +|# + +;; doing this in guile scheme because they said i could use any language, and if +;; i'm gonna be writing code on saturday morning its gonna be lisp :P + +(import (only (rnrs base) assert)) + +(define +max+ 4) ;; can't work longer than 4am +(define +start+ 5) ;; can't start before 5pm + +;; times are represented as a pair of (hours . minutes) +(define (h time) (car time)) +(define (m time) (cdr time)) + +;; if hour is > 1 && < +max+, add 12h to account for midnight rollover +;; (always call this on end time) +(define (handle-midnight time) + (if (and (>= (h time) 1) (<= (h time) +max+)) + `(,(+ 12 (h time)) . ,(m time)) + time)) + +;; round-* functions return just the hour for simplicity, but ideally these +;; would operate on a