This repository was archived by the owner on Sep 7, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ #lang racket
2+
3+ (provide caesar-cypher)
4+
5+ ;; Turn plain text into cypher text with caesar cypher algorithm.
6+ ;; Numbers, symbols and whitespace are not changed.
7+ ;; args:
8+ ;; str: string to encode
9+ ;; shift: optional shift length, default is 3
10+ (define (caesar-cypher str [shift 3 ])
11+ (let* ([shift-uppercase
12+ (lambda (c)
13+ (integer->char
14+ (+ 65 (remainder (+ shift (char->integer c) -65 ) 26 ))))]
15+ [shift-lowercase
16+ (lambda (c)
17+ (integer->char
18+ (+ 97 (remainder (+ shift (char->integer c) -97 ) 26 ))))]
19+ [shift
20+ (lambda (c)
21+ (cond [(and (char-alphabetic? c)
22+ (char-upper-case? c))
23+ (shift-uppercase c)]
24+ [(and (char-alphabetic? c)
25+ (char-lower-case? c))
26+ (shift-lowercase c)]
27+ [else c]))]
28+ [char-list (string->list str)])
29+ (let loop ([acc '() ]
30+ [ls char-list])
31+ (if (null? ls)
32+ (list->string (reverse acc))
33+ (loop (cons (shift (car ls)) acc) (cdr ls))))))
34+
Original file line number Diff line number Diff line change 1+ #lang racket
2+
3+ (provide factorial)
4+
5+ (define (factorial n)
6+ (let loop ([acc 1 ]
7+ [n n])
8+ (if (zero? n)
9+ acc
10+ (loop (* acc n) (sub1 n)))))
11+
You can’t perform that action at this time.
0 commit comments