Created
April 4, 2024 21:16
-
-
Save vdeemann/dc4d7c856ffafa3ba758210388b05fed to your computer and use it in GitHub Desktop.
exercism Scheme exercises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require racket/trace) | |
(define (leap-year? year) | |
(if (and (and (div-by-4? year) (div-by-100? year)) (div-by-400? year)) #t | |
(if (and (div-by-4? year) (not (div-by-100? year))) #t #f))) | |
(define (div-by-4? year) | |
(if (= (modulo year 4) 0) #t #f)) | |
(define (div-by-100? year) | |
(if (= (modulo year 100) 0) #t #f)) | |
(define (div-by-400? year) | |
(if (= (modulo year 400) 0) #t #f)) | |
; modulo code found here | |
; https://stackoverflow.com/a/60892769/8706936 | |
(define (modulo a b) | |
(- a (* b (floor (/ a b))))) | |
(trace leap-year?) | |
(leap-year? 1997) | |
(leap-year? 1900) | |
(leap-year? 2000) | |
(leap-year? 1966) | |
(leap-year? 1960) | |
(leap-year? 2100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require racket/trace) | |
; helper function is used to convert dna into a list | |
(define (dna->rna dna) | |
(define dna-list (string->list dna)) | |
(define (helper dna-list) | |
(cond | |
((= (string-length dna) 0) "") | |
((eqv? dna-list '()) "") | |
((eqv? (car dna-list) #\C) (string-append "G" (helper(cdr dna-list)))) | |
((eqv? (car dna-list) #\G) (string-append "C" (helper(cdr dna-list)))) | |
((eqv? (car dna-list) #\T) (string-append "A" (helper(cdr dna-list)))) | |
((eqv? (car dna-list) #\A) (string-append "U" (helper(cdr dna-list)))) | |
(else #f)) | |
) | |
(helper dna-list) | |
) | |
(trace dna->rna) | |
(dna->rna "") | |
(dna->rna "C") | |
(dna->rna "G") | |
(dna->rna "T") | |
(dna->rna "A") | |
;UGCACCAGAAUU | |
(dna->rna "ACGTGGTCTTAA") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment