;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname l07-list-functions) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor mixed-fraction #f #t none #f () #t)))
;; (add-replace lst-nums) replaces the first two numbers in the list
;; with their sum.
;; Examples:
(check-expect (add-replace (cons 1 (cons 3 (cons 5 empty)))) (cons 4 (cons 5 empty)))
;; add-replace: (listof Nums) -> (listof Nums)
;; Requires: (length lst-nums) >= 2
(define (add-replace lst-nums)
(cons (+ (first lst-nums)
(first (rest lst-nums)))
(rest (rest lst-nums))))
(check-expect (add-replace (cons 10 (cons 13 (cons 5 (cons 6 empty)))))
(cons 23 (cons 5 (cons 6 empty))))
;; (first-two-equal? los) determines if first two strings are the
;; same; produces false if there are fewer than two strings.
;; Examples
(check-expect (first-two-equal? empty) false)
(check-expect (first-two-equal? (cons "hello" empty)) false)
(check-expect (first-two-equal? (cons "cs135" (cons "rocks!" empty))) false)
(check-expect (first-two-equal? (cons "cs135" (cons "cs135" empty))) true)
;; first-two-equal? (listof Str) -> Bool
(define (first-two-equal? los)
(and (not (empty? los))
(not (empty? (rest los)))
(string=? (first los) (first (rest los)))))