aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHVukman <peterslopp@googlemail.com>2025-09-07 21:25:21 +0200
committerGitHub <noreply@github.com>2025-09-07 21:25:21 +0200
commit1bdf6d26b7bdedd19ae43ce86fd2815c542a59fe (patch)
treedff2a92d231d8cc240d0ae0f0839544a90e1f009
parent87f616b2eae70a81348e8171d057409dbb5ab0fe (diff)
downloadperlweeklychallenge-club-1bdf6d26b7bdedd19ae43ce86fd2815c542a59fe.tar.gz
perlweeklychallenge-club-1bdf6d26b7bdedd19ae43ce86fd2815c542a59fe.tar.bz2
perlweeklychallenge-club-1bdf6d26b7bdedd19ae43ce86fd2815c542a59fe.zip
Create 337_p2.rkt
-rw-r--r--challenge-337/hvukman/racket/337_p2.rkt52
1 files changed, 52 insertions, 0 deletions
diff --git a/challenge-337/hvukman/racket/337_p2.rkt b/challenge-337/hvukman/racket/337_p2.rkt
new file mode 100644
index 0000000000..2bc2e23fd0
--- /dev/null
+++ b/challenge-337/hvukman/racket/337_p2.rkt
@@ -0,0 +1,52 @@
+#lang racket
+(require racket/list)
+(require rackunit)
+
+; create list with row and columns
+(define (CreateMat row column)
+ (build-list row (lambda (x) (make-list column 0)))
+ )
+
+; increase row y
+(define (IncRow x y)
+ (list-set x y (map (lambda (z) (+ z 1) ) (list-ref x y)))
+ )
+
+; increase column y
+(define (IncCol x y)
+ (list-set x y (+ (list-ref x y) 1))
+ )
+
+; main function increases col and row
+(define (Odd z y)
+ (map (lambda (x) (IncCol x (cadr y))) (IncRow
+ z (car y)))
+
+)
+
+; if cdr Y not empty do the oddloop
+(define (Oddloop X Y)
+ (if (not (equal? Y '()))
+ (Oddloop (Odd X (car Y)) (cdr Y))
+ X
+ )
+ )
+
+; function for inputs
+(define (func X Y Z)
+(let ([row X] [col Y] [pos Z])
+ (apply + (map (lambda (x) (length x)) (map (lambda (x)
+ (filter odd? x)) (Oddloop (CreateMat row col) pos)))))
+)
+
+(check-equal? (func 2 3 '( (0 1) (1 1) )) 6)
+(check-equal? (func 2 2 '( (1 1) (0 0) )) 0)
+(check-equal? (func 3 3 '( (0 0) (1 2) (2 1) )) 0)
+(check-equal? (func 1 5 '( (0 2) (0 4) )) 2)
+(check-equal? (func 4 2 '( (1 0) (3 1) (2 0) (0 1) )) 8)
+
+(func 2 3 '( (0 1) (1 1) ))
+(func 2 2 '( (1 1) (0 0) ))
+(func 3 3 '( (0 0) (1 2) (2 1) ))
+(func 1 5 '( (0 2) (0 4) ))
+(func 4 2 '( (1 0) (3 1) (2 0) (0 1) ))