Guest User

Untitled

a guest
May 10th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. #lang racket
  2. (define (schet lst_int lst_func)
  3. (car (lst_schet (rec_mult lst_int (mult lst_func '() 0))
  4. (filter (λ(x) (not (eq? (eval x) *))) lst_func))))
  5. ;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  6. (define (lst_schet lst_int lst_func)
  7. (if (empty? (cdr lst_int))
  8. lst_int
  9. (lst_schet (append (list ((eval (car lst_func)) (car lst_int) (cadr lst_int))) (cddr lst_int)) (cdr lst_func))))
  10. ;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  11. (define (mult lst_func res pos) ;( pos1 pos2 ) (* * *) ( 0 1 2 )
  12. (if (empty? lst_func)
  13. res
  14. (if (eq? (eval (car lst_func)) *)
  15. (mult (cdr lst_func) (append res (list pos)) (+ pos 1))
  16. (mult (cdr lst_func) res (+ pos 1)))))
  17. ;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  18. (define (rec_mult lst_int lst_mult) ;( 1 6 4) (1)
  19. (if (empty? lst_mult)
  20. lst_int
  21. (rec_mult (append
  22. (take lst_int (car lst_mult))
  23. (list (* (list-ref lst_int (+ (car lst_mult) 1))(list-ref lst_int (car lst_mult))))
  24. (drop lst_int (+ (car lst_mult) 2)))
  25. (cdr (map (λ (x) (- x 1)) lst_mult)))))
  26.  
  27. (define (perenos lst lst2 f)
  28. (if (empty? lst)
  29. lst2
  30. (if (not f)
  31. (begin (display (append lst2 lst)) (append lst2 lst) )
  32. (cond [(eq? (eval (car lst)) *) (perenos (cdr lst) (append lst2 (list '+))
  33. (if (empty? (cdr lst))
  34. #f
  35. #t))]
  36. [(eq? (eval (car lst)) +) (perenos (cdr lst) (append lst2 (list '-)) #f)]
  37. [(eq? (eval (car lst)) -) (perenos (cdr lst) (append lst2 (list '*)) #f)]))))
  38.  
  39. (define (near_zero lst-main)
  40. (define end (build-list (- (length lst-main) 1) (λ (x) '+)))
  41. (define res (build-list (- (length lst-main) 1) (λ (x) '+)))
  42. (define (SIGN lst)
  43. (if (equal? lst end)
  44. (help '() lst)
  45. (begin (help '() lst) (SIGN (perenos lst '() #t)))))
  46. ;(define lst-main '(1 2 3 5))
  47.  
  48. (define (help fix-lst lst)
  49. (if (empty? lst)
  50. (cond [(< (abs (schet lst-main fix-lst)) (abs (schet lst-main res)))
  51. (begin (display 1)(display fix-lst)(display 2) (display res)(set! res fix-lst)(display 3)(display fix-lst)(display 4) (display res))])
  52. (for-each (λ (x) (help (cons x fix-lst) (remove x lst))) lst)))
  53. (SIGN (append (build-list (- (length lst-main) 2) (λ (x) '+)) (list '-)))
  54. res)
Advertisement
Add Comment
Please, Sign In to add comment