new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
17
Task/Balanced-brackets/Racket/balanced-brackets.rkt
Normal file
17
Task/Balanced-brackets/Racket/balanced-brackets.rkt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#lang racket
|
||||
|
||||
(define (generate n)
|
||||
(list->string (shuffle (append* (make-list n '(#\[ #\]))))))
|
||||
|
||||
(define (balanced? str)
|
||||
(let loop ([l (string->list str)] [n 0])
|
||||
(or (null? l)
|
||||
(if (eq? #\[ (car l))
|
||||
(loop (cdr l) (add1 n))
|
||||
(and (> n 0) (loop (cdr l) (sub1 n)))))))
|
||||
|
||||
(define (try n)
|
||||
(define s (generate n))
|
||||
(printf "~a => ~a\n" s (if (balanced? s) "OK" "NOT OK")))
|
||||
|
||||
(for ([n 10]) (try n))
|
||||
Loading…
Add table
Add a link
Reference in a new issue