reset password
Author Message
jcalilu
Posts: 20
Posted 22:14 Dec 02, 2015 |

Regarding Lab 9, 

Flatten this list of lists. (Note that you can't use Flatten since it will flatten the lists you want to keep as lists. Since there is only one level to flatten, you can use append with either apply or a fold.) After flattening you will have:

( (0 x-accel y-accel) ; This is the acceleration on ball-0 due to ball-1.
  (1 x-accel y-accel) ; This is the acceleration on ball-1 due to ball-0.
  (0 x-accel y-accel) ; This is the acceleration on ball-0 due to ball-2.
  (2 x-accel y-accel) ; This is the acceleration on ball-2 due to ball-0.
  . . .
  (1 x-accel y-accel) ; This is the acceleration on ball-1 due to ball-2.
  (2 x-accel y-accel) ; This is the acceleration on ball-2 due to ball-1.
  (1 x-accel y-accel) ; This is the acceleration on ball-1 due to ball-3.
  (3 x-accel y-accel) ; This is the acceleration on ball-3 due to ball-1.
  . . .
)

 What does it mean to flatten a list? Is it just to make a list of lists become just one whole list?

Also would the acceleration on ball-0 due to ball-3 and the acceleration on ball-3 due to ball-0 be included in the beginning part of this list? Or would ball-3 and ball-0's interaction force be checked when we check ball-3?

For example:

( (0 x-accel y-accel) ; This is the acceleration on ball-0 due to ball-1.
  (1 x-accel y-accel) ; This is the acceleration on ball-1 due to ball-0.
  (0 x-accel y-accel) ; This is the acceleration on ball-0 due to ball-2.
  (2 x-accel y-accel) ; This is the acceleration on ball-2 due to ball-0.
  (0 x-accel y-accel) ; This is the acceleration on ball-0 due to ball-3.
  (3 x-accel y-accel) ; This is the acceleration on ball-3 due to ball-0. 
  . . .
  (1 x-accel y-accel) ; This is the acceleration on ball-1 due to ball-2.
  (2 x-accel y-accel) ; This is the acceleration on ball-2 due to ball-1.
  (1 x-accel y-accel) ; This is the acceleration on ball-1 due to ball-3.
  (3 x-accel y-accel) ; This is the acceleration on ball-3 due to ball-1.
  . . .

Thanks in advance.

Last edited by jcalilu at 22:15 Dec 02, 2015.
rabbott
Posts: 1649
Posted 22:22 Dec 02, 2015 |

The simplest way to think of flatten is to take away all the parentheses except the outermost ones that make the overall list.

(flatten '((a b) c (d (e f)))) => '(a b c d e f)

 

The interaction between balls 0 and 3 would be generated when considering ball 0. When considering ball 3 only interactions between it with higher numbered balls are generated.

Last edited by rabbott at 22:23 Dec 02, 2015.