|
[Sponsors] |
Need help in Scheme Programming - Mulltiplying list elements |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
November 8, 2011, 18:17 |
Need help in Scheme Programming - Mulltiplying list elements
|
#1 |
New Member
Daniel Yacouboff
Join Date: Nov 2011
Posts: 3
Rep Power: 15 |
Hello everyone, I've ran into this site and was wondering if you can advise me something.
The program I'm trying to write called (multListsA lst1 lst2) which receives 2 lists and returns a new list in which the i'th element is the product of the two i'th elements from the 2 given lists. MOREOVER, in case that one list is shorter than the other, the shorter list should be used from the beginning again. Which means 2 things: 1) The result list should have the same length as the longer list. 2) I have to use the modulo option at some point. I'm trying to write a recursive solution to that nice program, but I can't seem to find the right formula and the right use of modulo to solve this. Can you please help me? Thanks in advance |
|
November 8, 2011, 23:55 |
|
#2 |
Member
Join Date: Apr 2009
Posts: 46
Rep Power: 17 |
What is "modulo option"?
Code:
(define (multiply la lb) (define n (max (length la) (length lb))) (let loop ((i 0) (l '()) (a la) (b lb)) (if (>= i n) l (begin (if (null? a) (set! a la) #f) (if (null? b) (set! b lb) #f) (set! l (append l (list (* (car a) (car b))))) (loop (+ i 1) l (cdr a) (cdr b)))))) Last edited by fox000002; November 9, 2011 at 00:15. |
|
November 9, 2011, 01:05 |
|
#3 |
New Member
Daniel Yacouboff
Join Date: Nov 2011
Posts: 3
Rep Power: 15 |
Modulo option (or remainder) is the way to solve this program recursively.
You're referring to the place in the list, dividing in the smaller list's length in order to stay within the list until the longer one is finished. I know my explaination is lame, may be someone understood it anyway? |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] swak4foam building problem | GGerber | OpenFOAM Community Contributions | 54 | April 24, 2015 17:02 |
OpenFOAM on MinGW crosscompiler hosted on Linux | allenzhao | OpenFOAM Installation | 127 | January 30, 2009 20:08 |
DecomposePar links against liblamso0 with OpenMPI | jens_klostermann | OpenFOAM Bugs | 11 | June 28, 2007 18:51 |
CFX4.3 -build analysis form | Chie Min | CFX | 5 | July 13, 2001 00:19 |