2
$\begingroup$

Let's say I have the following table,

y=40;
b=Flatten[Table[{i, j}, {i, 1, 2.25, 1.25}, {j, y - 5, y - 8, -3}], 1]

then c is equal to,

c = b - ConstantArray[{0, 8}, 4]

and the out put is

{{1., 27}, {1., 24}, {2.25, 27}, {2.25, 24}}

y is 27 and 24 which is fine

d equal to

d = c - ConstantArray[{0, 8}, 4]

similarly, y is >=4, which is fine,

e equal to

e = d - ConstantArray[{0, 8}, 4]

again, y is >=4, which is fine,

and f equal to

f = e - ConstantArray[{0, 8}, 4]

the output is

{{1., 3}, {1., 0}, {2.25, 3}, {2.25, 0}}

so now in f, y less than 4, so it is not fine,

How can I make a table using any iteration command such that,

y=40;
    b=Flatten[Table[{i, j}, {i, 1, 2.25, 1.25}, {j, y - 5, y - 8, -3}], 1]
  c = b - ConstantArray[{0, 8}, 4]
d = c - ConstantArray[{0, 8}, 4]
e = d - ConstantArray[{0, 8}, 4]
f = e - ConstantArray[{0, 8}, 4]

and if any of the y limits (start and end) becomes less than 4, the occurance stops.

I tired nestlist and array but can't.

$\endgroup$

1 Answer 1

4
$\begingroup$
Most @ NestWhileList[# - Threaded[{0, 8}] &, b, Min @ #[[All, 2]] >= 4 &]
 {{{1., 35}, {1., 32}, {2.25, 35}, {2.25, 32}}, 
  {{1., 27}, {1., 24}, {2.25, 27}, {2.25, 24}},
  {{1., 19}, {1., 16}, {2.25, 19}, {2.25, 16}},
  {{1., 11}, {1., 8}, {2.25, 11}, {2.25, 8}}}
{b, c, d, e} == lists
True
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.