From e4ee931c081c22b6a2e7c8818112d9414cf24813 Mon Sep 17 00:00:00 2001 From: MsK` Date: Wed, 8 Dec 2021 01:22:28 +0100 Subject: [PATCH] simplified using scheme control constructs --- 05-hydrothermal-venture/code.scm | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/05-hydrothermal-venture/code.scm b/05-hydrothermal-venture/code.scm index 9a03f32..52e486d 100644 --- a/05-hydrothermal-venture/code.scm +++ b/05-hydrothermal-venture/code.scm @@ -44,13 +44,7 @@ ; returns the largest value obtained while applying pick to each element of lst (define (get-max lst pick) - (let loop [(m 0) - (lst lst)] - (if (null? lst) - m - [loop - (max m (pick (car lst))) - (cdr lst)]))) + (apply max (map pick lst))) (define (sign value) (cond @@ -95,10 +89,10 @@ (let* [(width (+ 1 (get-max lines get-max-x))) (height (+ 1 (get-max lines get-max-y))) (image (make-image width height))] - (let loop! [(lines lines)] - (when (not (null? lines)) - (additively-rasterize-line! image (car lines) allow-diagonals) - (loop! (cdr lines)))) + (for-each + (lambda (line) + (additively-rasterize-line! image line allow-diagonals)) + lines) image)) ; count pixels with value strictly higher than 1