-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.rkt
More file actions
executable file
·28 lines (23 loc) · 793 Bytes
/
Copy pathmatrix.rkt
File metadata and controls
executable file
·28 lines (23 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#lang racket
(define (nth-col n matrix)
(if (= n 0)
(map (lambda (row) (car row)) matrix)
(nth-col (- n 1) (map (lambda (row) (cdr row)) matrix))))
(define (mult row col)
(if (null? (cdr row))
(* (car row) (car col))
(+ (* (car row)
(car col)) (mult (cdr row) (cdr col)))))
(define (lst-len lst)
(if(null? lst)
0
(+ 1 (lst-len (cdr lst)))))
(define (cnt-row-in row mat mat-width init)
(if (= init mat-width)
(cons (mult row (nth-col init mat)) null)
(cons (mult row (nth-col init mat)) (cnt-row-in row mat mat-width (+ 1 init)))))
(define (cnt-row row mat)
(let ([mat-width (- (lst-len (car mat)) 1)])
(cnt-row-in row mat mat-width 0)))
(define (matrix-mul mat1 mat2)
(map (lambda (row) (cnt-row row mat2)) mat1))