;; 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-advanced-reader.ss" "lang")((modname 06-2) (read-case-sensitive #f) (teachpacks ()) (htdp-settings #(#f write mixed-fraction #t #t none #f () #f)))
(define (sum-numbers from to)
(if (< to from)
0
(+ from (sum-numbers (+ from 1) to))))
(define (sum-squares from to)
(if (< to from)
0
(+ (sqr from) (sum-squares (+ from 1) to))))
(define (sum-sequence seq from to)
(if (< to from)
0
(+ (seq from) (sum-sequence seq (+ from 1) to))))
(define (accumulate seq from to combiner null-val)
(if (< to from)
null-val
(combiner (seq from)
(accumulate seq (+ from 1) to combiner null-val))))
(define (fact n)
(accumulate identity 1 n * 1))
(define (square? n)
(= (sqr (round (sqrt n))) n))
;; Zjistí, kolik je čtverců (druhých mocnin) mezi danými dvěma čísly
(define (count-squares a b)
(accumulate (lambda (n) (if (square? n) 1 0))
a
b
+
0))