Instructions
Objective
Write a Scheme assignment to merge 2 lists whilst performing operation on element paris Scheme.
Requirements and Specifications
Screenshots of output
Source Code
;;; Problema 1
(define (suma_especial l a)
(truncate (/ (apply + l) a)))
;;; Problema 2
(define (merge_simple l1 l2 ops)
(if (null? l1)
'()
(let
((i (car l1))
(j (car l2))
(op (car ops)))
(cons
(cond
((char=? op #\S) (+ i j))
((char=? op #\R) (- i j))
((char=? op #\M) (* i j)))
(merge_simple (cdr l1) (cdr l2) (cdr ops))))))
(define (merge_cola l1 l2 ops)
(letrec
((merge_aux (lambda (l1_aux l2_aux ops_aux acum)
(if (null? l1_aux)
(reverse acum)
(let
((i (car l1_aux))
(j (car l2_aux))
(op (car ops_aux)))
(merge_aux
(cdr l1_aux)
(cdr l2_aux)
(cdr ops_aux)
(cons
(cond
((char=? op #\S) (+ i j))
((char=? op #\R) (- i j))
((char=? op #\M) (* i j)))
acum)))))))
(merge_aux l1 l2 ops '())))
;;; Problema 3
(define (demerge_simple l f)
(if (null? l)
(list '() '())
(let*
((num (car l))
(a (f num))
(b (- num a))
(ll (demerge_simple (cdr l) f)))
(list (cons a (car ll)) (cons b (cadr ll))))))
(define (demerge_cola l f)
(letrec
((demerge_aux (lambda (ls_aux f_aux l1 l2)
(if (null? ls_aux)
(list (reverse l1) (reverse l2))
(let*
((num (car ls_aux))
(a (f_aux num))
(b (- num a)))
(demerge_aux (cdr ls_aux) f_aux (cons a l1) (cons b l2)))))))
(demerge_aux l f '() '())))
;;; Problema 4
(define (superior l ops f num)
(let*
((merge_res (merge_cola l l ops))
(demerge_res (demerge_cola merge_res f))
(r1 (* (suma_especial l num) 2))
(r2 (+ (suma_especial (car demerge_res) num) (suma_especial (cadr demerge_res) num))))
(if (> r1 r2)
1
0)))
;;; Problema 5
(define (all_superior matriz_ls matriz_ops matriz_f matriz_nums c f)
(letrec
((superior_filas (lambda (i j m_ls m_ops m_f m_nums)
(if (< j f)
(cons
(superior_columnas i j (car m_ls) (car m_ops) (car m_f) (car m_nums))
(superior_filas i (+ j 1) (cdr m_ls) (cdr m_ops) (cdr m_f) (cdr m_nums)))
'())))
(superior_columnas (lambda (i j m_ls m_ops m_f m_nums)
(if (< i c)
(cons
(superior (car m_ls) (car m_ops) (car m_f) (car m_nums))
(superior_columnas (+ i 1) j (cdr m_ls) (cdr m_ops) (cdr m_f) (cdr m_nums)))
'()))))
(superior_filas 0 0 matriz_ls matriz_ops matriz_f matriz_nums)))
Related Samples
View our top-notch Data Structures and Algorithms Assignment Samples for comprehensive examples and solutions. Enhance your understanding of key concepts such as sorting algorithms, data structures like linked lists, and more. Explore these samples to excel in your programming assignments.
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Java
C++
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms