This commit is contained in:
joachimschmidt557 2019-02-23 20:59:04 +01:00
parent 9d2e745be6
commit 3ecd76609c
7 changed files with 574 additions and 0 deletions

7
Durchschnitt.rkt Executable file
View file

@ -0,0 +1,7 @@
#lang racket
(define (durchschnitt lst) (
/ (apply + lst) (length lst)
))
(durchschnitt (list 1 1 1 3 3 3))

21
GUI.rkt Executable file
View file

@ -0,0 +1,21 @@
#lang racket/gui
(require racket/gui/base)
; Make a frame by instantiating the frame% class
(define frame (new frame% [label "Example"]))
; Make a static text message in the frame
(define msg (new message% [parent frame]
[label "No events so far..."]))
; Make a button in the frame
(new button% [parent frame]
[label "Click Me"]
; Callback procedure for a button click:
[callback (lambda (button event)
(send msg set-label "Button click"))])
; Show the frame by calling its show method
(send frame show #t)

28
Halloween.rkt Executable file
View file

@ -0,0 +1,28 @@
;; 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 Halloween) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f () #f)))
;; (map (lambda (x) (+ 5 x)) (list 1 2 (3))
(define (zip list1 list2) (
map list list1 list2
))
(define (vec-mult list1 list2) (
foldr + 0 (map * list1 list2)
))
;(list "a" "b")
;(list 1 2)
(vec-mult (list 1 2 3) (list 4 5 6))
;; number -> (number -> number)
(define (z x)
;; number -> number
(lambda (y) (* x y)))
((lambda (y) (* 3 y)) 4)
((z 3) 4)
(cond [ (= 5 7) (#t) ] [ ])

3
LinkedList.rkt Executable file
View file

@ -0,0 +1,3 @@
#lang racket
(define-struct linked-list-item item next prev)

13
SelectionSort.rkt Executable file
View file

@ -0,0 +1,13 @@
#lang racket
(define (selection-sort lst) (
cond
[(empty? lst) empty]
[else (cons
(apply min lst)
(selection-sort (remove (apply min lst) lst))
)
]
))
(selection-sort (list 4 7 4 6 1 5 2 9 7))

207
test.bak Executable file
View file

@ -0,0 +1,207 @@
#lang racket
;(define (fib n) (
; if (= n 0)
; 0
; (
; if (= n 1)
; 1
; (+ (fib (- n 1)) (fib (- n 2)))
; )
;))
;
;(fib 10)
;(define (fib n) (
; (cond
; [(= n 0) 0]
; [(= n 1) 1]
; [else
; (+ (fib (- n 1)) fib (- n 2))
; ]
; )
;))
;
;(fib 10)
;(define list1 ( list 1 2 3 4 ))
;
;(define (sum list) (
; if (empty? list)
; 0
; ;else
; (
; +
; (first list)
; ( sum(rest list) )
; )
;))
;
;(sum list1)
;(define (list-with-length len) (
; if (= len 0)
; empty
; (
; cons 0 (list-with-length (- len 1) )
; )
;))
;
;(list-with-length 10)
;(filter (lambda (x) (> x 10) ) (list 0 5 10 15 20) )
;(map (lambda (x) (+ x 10)) (list 0 1 2 3) )
;(define (repeat fct times) (
;
;))
;(define-struct abc (a b))
;
;;; Type: abc -> list
;;; Returns: bla bla
;(define (foo p) (
; ;(
; if (abc? p)
; (
; if (list? (abc-b p))
; ;(
; (list (abc-a p) (abc-b p))
; ;)
; ;else
; ;(
; #f
; ;)
; )
; ; else
; #f
; ;)
;))
;
;;(define test (make-abc ("asdf" (list 1 2 3 4))))
;
;(foo (make-abc 123 (list 1 2 3 4)))
;
;(foo 123)
;
;(foo (make-abc 123 1234))
;
;(define (contains-x? liste x) (
; cond
; [(list? x) #f]
; [(not (list? liste)) #f]
; [(empty? liste) #f]
; [
; (= (first liste) x)
; #t
; ]
; [
; else
; (contains-x? (rest liste) x)
; ]
;
;))
;
;(contains-x? (list 12) (list 12 5))
;(define (contains-x? liste x) (
; cond
; [(list? x) #f]
; [(not (list? liste)) #f]
; [(empty? liste) #f]
; [
; (= (first liste) x)
; #t
; ]
; [
; else
; (contains-x? (rest liste) x)
; ]
;
;))
;
;(define (duplicate? lst) (
; cond
; [(not (list? lst)) #f]
; [(empty? lst) #f]
; [
; (contains-x? (rest lst) (first lst))
; #t
; ]
; [
; else
; (duplicate? (rest lst))
; ]
;))
;
;(duplicate? (list 1 2 3 4 5 6 7 3))
;(define (contains-x? liste x) (
; cond
; [(list? x) #f]
; [(not (list? liste)) #f]
; [(empty? liste) #f]
; [
; (= (first liste) x)
; #t
; ]
; [
; else
; (contains-x? (rest liste) x)
; ]
;
;))
;
;(define (duplicate? lst) (
; cond
; [(not (list? lst)) #f]
; [(empty? lst) #f]
; [
; (contains-x? (rest lst) (first lst))
; #t
; ]
; [
; else
; (duplicate? (rest lst))
; ]
;))
;
;(define (collect lst oracle) (
; cond
; [(empty? lst) oracle]
; [
; else
; (if (list? (first lst))
; (collect (rest lst) (collect (first lst) oracle))
; (
; collect (rest lst) (cons (first lst) oracle)
; ))
; ]
;))
;
;(collect (list 1 2 3 (list 1 4 6)) empty)
;
;;(define (duplicates-deep? deep-lst) (
;;
;;))
;
;
;;; Type: ( list of ANY ) -> number
;;; Returns: the sum of the fees of all student in the list
;( define ( sum-of-student-fees list )
;( my-fold
;( lambda ( x y ) ( + x y ) )
;0
;( my-map
;( lambda ( stud ) ( student-fee stud ) )
;( my-filter ( lambda ( x ) ( student? x ) ) list ) ) ) )
(define asdf 10)
(check-expect asdf 10)

295
test.rkt Executable file
View file

@ -0,0 +1,295 @@
;; 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 test) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f () #f)))
;#lang racket
;(define (fib n) (
; if (= n 0)
; 0
; (
; if (= n 1)
; 1
; (+ (fib (- n 1)) (fib (- n 2)))
; )
;))
;
;(fib 10)
;
;
;(define (fib n) (
; (cond
; [(= n 0) 0]
; [(= n 1) 1]
; [else
; (+ (fib (- n 1)) fib (- n 2))
; ]
; )
;))
;
;(fib 10)
;(define list1 ( list 1 2 3 4 ))
;
;(define (sum list) (
; if (empty? list)
; 0
; ;else
; (
; +
; (first list)
; ( sum(rest list) )
; )
;))
;
;(sum list1)
;(define (list-with-length len) (
; if (= len 0)
; empty
; (
; cons 0 (list-with-length (- len 1) )
; )
;))
;
;(list-with-length 10)
;(filter (lambda (x) (> x 10) ) (list 0 5 10 15 20) )
;(map (lambda (x) (+ x 10)) (list 0 1 2 3) )
;(define (repeat fct times) (
;
;))
(define-struct abc (a b))
;; Type: abc -> list
;; Returns: bla bla
(define (foo p) (
;(
if (abc? p)
(
if (list? (abc-b p))
;(
(list (abc-a p) (abc-b p))
;)
;else
;(
#f
;)
)
; else
#f
;)
))
;
;Variante 2 - mit (and ... ...)
;
;Variante 3 - mit (cond [])
;
;
;;(define test (make-abc ("asdf" (list 1 2 3 4))))
;
;(foo (make-abc 123 (list 1 2 3 4)))
;
;(foo 123)
;
;(foo (make-abc 123 1234))
;
;(define (contains-x? liste x) (
; cond
; [(list? x) #f]
; [(not (list? liste)) #f]
; [(empty? liste) #f]
; [
; (= (first liste) x)
; #t
; ]
; [
; else
; (contains-x? (rest liste) x)
; ]
;
;))
;
;(contains-x? (list 12) (list 12 5))
;(define (contains-x? liste x) (
; cond
; [(list? x) #f]
; [(not (list? liste)) #f]
; [(empty? liste) #f]
; [
; (= (first liste) x)
; #t
; ]
; [
; else
; (contains-x? (rest liste) x)
; ]
;
;))
;
;(define (duplicate? lst) (
; cond
; [(not (list? lst)) #f]
; [(empty? lst) #f]
; [
; (contains-x? (rest lst) (first lst))
; #t
; ]
; [
; else
; (duplicate? (rest lst))
; ]
;))
;
;(duplicate? (list 1 2 3 4 5 6 7 3))
;(define (contains-x? liste x) (
; cond
; [(list? x) #f]
; [(not (list? liste)) #f]
; [(empty? liste) #f]
; [
; (= (first liste) x)
; #t
; ]
; [
; else
; (contains-x? (rest liste) x)
; ]
;
;))
;
;(define (duplicate? lst) (
; cond
; [(not (list? lst)) #f]
; [(empty? lst) #f]
; [
; (contains-x? (rest lst) (first lst))
; #t
; ]
; [
; else
; (duplicate? (rest lst))
; ]
;))
;
;(define (collect lst oracle) (
; cond
; [(empty? lst) oracle]
; [
; else
; (if (list? (first lst))
; (collect (rest lst) (collect (first lst) oracle))
; (
; collect (rest lst) (cons (first lst) oracle)
; ))
; ]
;))
;
;(define (collect lst oracle) (
; cond
; [(empty? lst) oracle]
; [(list? (first lst)) (
; collect (first lst) (collect (rest list ) oracle)
; )]
; [
; else
; (collect (rest lst) (cons (first lst) oracle))
; ]
;))
;
;(define (duplicates-deep? deep-lst) (
; duplicates? (collect deep-lst '())
;))
;
;(collect (list 1 2 3 (list 1 4 6)) empty)
;
;;(define (duplicates-deep? deep-lst) (
;;
;;))
;
;
;;; Type: ( list of ANY ) -> number
;;; Returns: the sum of the fees of all student in the list
;( define ( sum-of-student-fees list )
;( my-fold
;( lambda ( x y ) ( + x y ) )
;0
;( my-map
;( lambda ( stud ) ( student-fee stud ) )
;( my-filter ( lambda ( x ) ( student? x ) ) list ) ) ) )
;(define asdf 10)
;(define aaa 20)
;
;(define (add x y) (+ x y))
;
;(check-expect (add asdf asdf) aaa)
;;; (define (euclid a b) (
;;; cond
;;; [(= b 0) a] ; Rekursionsanker
;;; [(= a 0) b]
;;; [(> a b) (
;;; euclid (- a b) b
;;; )]
;;; [else (euclid a (- b a))]
;;; ))
;;; (euclid 50 5)
;;; (and #t #t)
;(define (bar1 lst) (
; map foo (filter abc? lst)
;))
;
;(bar1 (list (make-abc 1 (list 2)) (make-abc 3 4) 1231342154))
;
;(define (cartesian-prod list1 list2) (
; map
; (lambda (y) (map (lambda (x) (list y x)) list2))
; list1
;))
;
;;(define (cartesian-prod list1 list2) (
;; cond
;; [(and (not (empty? list1)) (not (empty? list2)))
;; cons (list (first list1) (first list2))
;; ]
;;
;;))
;
;(cartesian-prod (list 1 2)(list 3 4))
;;;(define ( proof lst r g b ) (
;;; cond
;;; [(= 0 r g b) (map + (list 0 1) lst)]
;;; [(= 255 r g b) (map + (list 1 0) lst)]
;;; [else lst]
;;;))
;;;
;;;(define (count-black-white img) (
;;; (count-black-white-of-list (image->color-list img))
;;;))
;;;
;;;(define (count-black-white-of-list lst) (
;;; cond
;;; [(empty? lst) (list 0 0)]
;;;
;;;))
; TODO: use length of list
;(define (count-black-white img) (
; list
; (filter (lambda (x) (= 0 (color-red x) (color-green x) (color-blue x)))
; (image->color-list img)
; )
; ;( (image->color-list img))
;))