Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.83 KB | None | 0 0
  1. (define (cuenta-atomos lista)
  2.   (cond
  3.   ((null? lista) 0)
  4.   ((list? (car lista)) (+ (cuenta-atomos (car lista)) (cuenta-atomos (cdr lista))))
  5.   (else (+ 1 (cuenta-atomos (cdr lista))))))
  6.  
  7. (define (swap-up L)
  8.   (if (null? (cdr L))
  9.     L
  10.     (if(< (car L) (cadr L))
  11.       (cons (car L) (swap-up (cdr L)))
  12.       (cons (cadr L) (swap-up (cons (car L) (cddr L)))))))
  13.  
  14. (define (bubble-aux N L)  
  15.   (cond ((= N 1) L)
  16.         (else (bubble-aux (- N 1) (swap-up L)))))
  17.  
  18. (define (bubble L)
  19.   (bubble-aux (length L) L))
  20.  
  21. (define (countM R)
  22.   (cond
  23.     ( (null? R) 0)
  24.     ((eq? (car (car R)) "m" ) (+ (countM (cdr R)) 1))
  25.     (else (countM (cdr R)  ))))
  26.  
  27. (define (countF R)
  28.   (cond
  29.     ( (null? R) 0)
  30.     ((eq? (car (car R)) "f" ) (+ (countF (cdr R)) 1))
  31.     (else (countF (cdr R)  ))))
  32.  
  33. (define (sumM R)
  34.   (cond
  35.     ( (null? R) 0)
  36.     ((eq? (car (car R)) "m" ) (+ (sumM (cdr R)) (cadar R) ))
  37.     (else (sumM (cdr R)  ))))
  38.  
  39. (define (sumF R)
  40.   (cond
  41.     ( (null? R) 0)
  42.     ((eq? (car (car R)) "f" ) (+ (sumF (cdr R)) (cadar R) ))
  43.     (else (sumF (cdr R)  ))))
  44.  
  45. (define (promM R)
  46.   (/ (sumM R) (countM R)))
  47.  
  48. (define (promF R)
  49.   (/ (sumF R) (countF R)))
  50.  
  51. (define (Promedios R)
  52.   (list (list "Masculino" (promM R)) (list "Femenino" (promF R))))
  53.  
  54. (define (build tree left right)
  55.   (list tree left right)
  56. )
  57.  
  58. (define (value tree) (car tree))
  59. (define (left tree) (cadr tree))
  60. (define (right tree) (caddr tree))
  61.  
  62. (define (insert x tree)
  63.   (cond
  64.     ((null? tree) (build x '() '()) )
  65.     ((< x (value tree))
  66.       (build (value tree) (insert x (left tree)) (right tree) ) )
  67.     ((> x (value tree))
  68.       (build (value tree) (left tree) (insert x (right tree))))))
  69.  
  70. (insert 0 '(1 () (5 (3 () ()) (6 () ()))))
  71. (Promedios '( ("m" 13) ("f" 14) ("m" 12) ))
  72. (bubble (list 10 9 1 3 7 6))
  73. (cuenta-atomos '(a (b c (d))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement