CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Need help in Scheme Programming - Mulltiplying list elements

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 8, 2011, 17:17
Default Need help in Scheme Programming - Mulltiplying list elements
  #1
New Member
 
Daniel Yacouboff
Join Date: Nov 2011
Posts: 3
Rep Power: 14
ydan87 is on a distinguished road
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
ydan87 is offline   Reply With Quote

Old   November 8, 2011, 22:55
Default
  #2
Member
 
fox000002's Avatar
 
Join Date: Apr 2009
Posts: 46
Rep Power: 17
fox000002 is on a distinguished road
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 8, 2011 at 23:15.
fox000002 is offline   Reply With Quote

Old   November 9, 2011, 00:05
Default
  #3
New Member
 
Daniel Yacouboff
Join Date: Nov 2011
Posts: 3
Rep Power: 14
ydan87 is on a distinguished road
Quote:
Originally Posted by fox000002 View Post
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?
ydan87 is offline   Reply With Quote

Reply


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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 16:02
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51
CFX4.3 -build analysis form Chie Min CFX 5 July 12, 2001 23:19


All times are GMT -4. The time now is 19:13.