Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env racket
- #lang racket
- ; n=10 - размерность матрицы
- (define nth list-ref)
- (define (diag-maxs-vec matrix)
- (define (iter i vec)
- (if (= i 19)
- vec
- (iter (add1 i)
- (cons (apply max (diag matrix i)) vec))))
- (iter 0 '()))
- (define (diag matrix n)
- (let ((beg (diag-beg n))
- (end (coord-move-diag (diag-end n))))
- (define (iter p d)
- (if (equal? p end)
- d
- (iter (coord-move-diag p) (cons (matrix-elem matrix p) d))))
- (iter beg '())))
- (define (diag-beg n)
- (make-coord (max (- 9 n) 0)
- (max (- n 9) 0)))
- (define (diag-end n)
- (make-coord (min (- 18 n) 9)
- (min n 9)))
- (define (matrix-elem matrix coord)
- (nth (nth matrix
- (coord-i coord))
- (coord-j coord)))
- (define (make-coord i j)
- (cons i j))
- (define (coord-i c)
- (car c))
- (define (coord-j c)
- (cdr c))
- (define (coord-move-diag c)
- (make-coord (add1 (coord-i c)) (add1 (coord-j c))))
- (define matrix (list (list 1 2 3 4 5 6 7 8 9 10)
- (list 1 2 3 4 5 6 7 8 9 10)
- (list 1 2 3 4 5 6 7 8 9 10)
- (list 1 2 3 4 5 6 7 8 9 10)
- (list 1 2 3 4 5 6 7 8 9 10)
- (list 1 2 3 4 5 6 7 8 9 10)
- (list 1 2 3 4 5 6 7 8 9 10)
- (list 1 2 3 4 5 6 7 8 9 10)
- (list 1 2 3 4 5 6 7 8 9 10)
- (list 1 2 3 4 5 6 7 8 9 10)))
- (diag-maxs-vec matrix)
- (length (diag-maxs-vec matrix))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement