From be0d323f5bbf2dee749358f1c1424f2594900faf Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Mon, 13 Jul 2020 21:39:19 -0400 Subject: net: fortytwo.scm: Add adjoin-position * net/ricketyspace/sicp/two/fortytwo.scm (adjoin-position): New function. Mostly done. --- net/ricketyspace/sicp/two/fortytwo.scm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'net/ricketyspace') diff --git a/net/ricketyspace/sicp/two/fortytwo.scm b/net/ricketyspace/sicp/two/fortytwo.scm index 7ccf00e..e284591 100644 --- a/net/ricketyspace/sicp/two/fortytwo.scm +++ b/net/ricketyspace/sicp/two/fortytwo.scm @@ -3,7 +3,8 @@ ;;;; (define-module (net ricketyspace sicp two fortytwo) - #:export (safe?)) + #:export (safe? + adjoin-position)) (define (accumulate op initial sequence) (if (null? sequence) @@ -52,3 +53,8 @@ positions))) (if (null? in-same-diag) #f #t))) (not (or (same-row?) (same-diagonal?)))) + + +(define (adjoin-position new-row k rest-of-queens) + (let ((queen-at-k (cons new-row k))) + (append rest-of-queens (list queen-at-k)))) -- cgit v1.2.3