Need help in Scheme Programming - Mulltiplying list elements

 Register Blogs Members List Search Today's Posts Mark Forums Read

 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: 7 Sponsored Links 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: 10 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: 7
Quote:
 Originally Posted by fox000002 What is "modulo option"?
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?

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post GGerber OpenFOAM Installation 54 April 24, 2015 16:02 allenzhao OpenFOAM Installation 127 January 30, 2009 20:08 jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51 Chie Min CFX 5 July 12, 2001 23:19