Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (define (interleave list1 list2)
- (if (null? list1) ; If list1 is empty, just return list2
- list2
- (cons (car list1) ; Otherwise, add the first element of list1 to a recursive call:
- (interleave list2 (cdr list1)); pass in list2 as the first list, this way we alternate between the lists. Then pass in the rest of list1.
- )
- )
- )
- (define (key-store list1 key)
- (if (null? list1) ; If we never found the key, return an empty list
- '()
- (cond
- [(equal? (car (car list1)) key) ; If the key of the first element is equal to the serach key
- (car (cdr (car list1))) ; Return the second element of the first list in list1
- ]
- [else
- (key-store (cdr list1) key) ; Otherwise, recursively call the function, passing in the next elements of the list
- ]
- )
- )
- )
- ;TODO
- (define (list-replace list1 key value)
- (if (null? list1)
- '()
- (cond
- [(equal? (car list1) key)
- (cons value (cdr list1)) ; possibly change to (member ...)
- ]
- [(list? (car list1))
- (list-replace (car list1) key value) ; Issue is that this is an if/else, not an if.
- ]
- [else
- (list-replace (cdr list1) key value)
- ]
- )
- )
- )
- (define (first-n list1 num)
- (if (<= num 0) ; base case
- '()
- (if (>= num (length list1))
- list1
- (cons (car list1) (first-n (cdr list1) (- num 1)))
- )
- )
- )
- ;TODO
- (define (key-store-increment list1 key)
- (if (null? list1)
- (append (list key) (list 1))
- (cond
- [(equal? (car (car list1)) key)
- (append (list (car (car list1))) (list (+ (car (cdr (car list1))) 1)))
- ][else
- (key-store-increment (cdr list1) key) ])))
- (define (indices list1 x)
- (indices-helper list1 x 0))
- (define (indices-helper list1 x counter)
- (if (null? list1) ;base case
- '()
- (cond
- [(equal? (car list1) x) ; If we found a value equal to x
- (cons counter (indices-helper (cdr list1) x (+ counter 1)))] ;add the current index to a recursive-call(pass in the next part of the list, and an incremented counter)
- [else
- (indices-helper (cdr list1) x (+ counter 1))] ; recursively call, passing in the next part of the list and incrementing counter
- )
- )
- )
- (define (join-together list1 list2)
- (if (null? list1)
- list2
- (if (null? list2)
- list1
- (if (< (car list1) (car list2))
- (cons (car list1) (join-together (cdr list1) list2))
- (cons (car list2) (join-together list1 (cdr list2)))
- )
- )
- )
- )
- (define (merge-sorter list1)
- (if (null? list1)
- '() ; If empty
- (if (null? (cdr list1))
- list1 ; If one element
- (merge (merge-sorter(car (split list1)))
- (merge-sorter(car (cdr list1))))
- )
- )
- )
- (define (split-list list1)
- (cons (even-indices list1) (list (odd-indices list1))))
- ; Return each even-index as a list
- (define (even-indices list1)
- (if (null? list1)
- '()
- (if (null? (cdr list1))
- '()
- (odd-indices (cdr list1)))))
- ; Return each odd-index as a list
- (define (odd-indices list1)
- (if (null? list1)
- '()
- (if (null? (cdr list1))
- (list (car list1))
- (cons (car list1) (odd-indices (cdr (cdr list1)))))))
- ;; Exp. (merge '(1 3 5 7 8 9 10) '(2 4 6)) ==> (1 2 3 4 5 6 7 8 9 10)
- (define (merge L M)
- (if (null? L) M
- (if (null? M) L
- (if (< (car L) (car M))
- (cons (car L) (merge (cdr L) M))
- (cons (car M) (merge (cdr M) L))))))
- ;; split helper functions
- (define (odd L)
- (if (null? L) '()
- (if (null? (cdr L)) (list (car L))
- (cons (car L) (odd (cddr L))))))
- (define (even L)
- (if (null? L) '()
- (if (null? (cdr L)) '()
- (cons (cadr L) (even (cddr L))))))
- ;; Exp. (split '(a b c d e f g h i)) ==> ((a c e g i)(b d f h))
- (define (split L)
- (cons (odd L) (cons (even L) `())))
- ;; Exp. (mergesort '(8 1 3 9 6 5 7 2 4 10)) ==> (1 2 3 4 5 6 7 8 9 10)
- (define (mergesort L)
- (if (null? L) L
- (if (null? (cdr L)) L
- (merge
- (mergesort (car (split L)))
- (mergesort (cadr (split L)))))))
- For
- For each emotion in my emotions:
- If emotion is frustration:
- Print "I'm frustrated because…"
- Printing…
- What are you talking about?
- If emotion is confusion:
- Print "I'm confused because you said…"
- Printing…
- What the hell do you mean?
- If emotion is anger:
- Print "I'm angry because you said I didn't listen…"
- Printing…
- What the fuck? I never did that?
- If emotion is sadness:
- Print "I'm sad because you said I didn't listen when you were telling me about…"
- Printing…
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement