Skip to content

Instantly share code, notes, and snippets.

@patrickdet
Created September 8, 2008 20:42
Show Gist options
  • Select an option

  • Save patrickdet/9534 to your computer and use it in GitHub Desktop.

Select an option

Save patrickdet/9534 to your computer and use it in GitHub Desktop.
undefined
(define
(container-ok? maxvolumen container)
(= (apply + container) maxvolumen))
(define
(container-zu-voll? maxvolumen container)
(> (apply + container) maxvolumen))
(define
(packecontainer stueckgutliste maxvolumen1 container1)
(cond
((container-ok? maxvolumen1 container1) container1)
((null? stueckgutliste) #f)
((container-zu-voll? maxvolumen1 container1)
(packecontainer stueckgutliste maxvolumen1 (cdr container1)))
(else
(packecontainer (cdr stueckgutliste) maxvolumen1 (cons (car stueckgutliste) container1)))))
(packecontainer '(30 30 15 10 10 5 3 2 1) 103 '()) ; sollte (3 5 10 10 15 30 30) sein
(packecontainer '(30 30 30 15 10 5 3 3 2 2 1 1) 103 '()) ; sollte (3 10 30 30 30)
(packecontainer '(30 30 30 15 30 45) 103 '()) ; sollte #f sein
(packecontainer '(30 30 30 30 45 13) 103 '()) ; (13 30 30 30)
(packecontainer '(30 30 60 30 30 15 10 5 3) 103 '())
(packecontainer '(30 30 30 103) 103 '()) ; sollte (103) sein ist aber #f !!!!
;;; dieser algorithmus tut nicht was er tun sollte. kein richtiges backtracking, da
;;; im letzten test anstelle an den anfang des baumes zu springen und die 103 einzusetzen
;;; wird #f zurück gegeben.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment