RW
Raymond West
Tue, Oct 25, 2022 1:00 PM
How can I generate a list, generally as list = 0, a, a+b, a+b+a,
a+b+a+b, a+b+a+b+a, etc.
e.g. list = 0,18,28,46,56,74, etc. where a=18, b=10
How can I generate a list, generally as list = 0, a, a+b, a+b+a,
a+b+a+b, a+b+a+b+a, etc.
e.g. list = 0,18,28,46,56,74, etc. where a=18, b=10
NH
nop head
Tue, Oct 25, 2022 1:04 PM
list = [for(i = 0 : n) each [0, a] + i * (a + b)];
I have not tried it but I think it should work.
On Tue, 25 Oct 2022 at 14:01, Raymond West raywest@raywest.com wrote:
How can I generate a list, generally as list = 0, a, a+b, a+b+a,
a+b+a+b, a+b+a+b+a, etc.
e.g. list = 0,18,28,46,56,74, etc. where a=18, b=10
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
list = [for(i = 0 : n) each [0, a] + i * (a + b)];
I have not tried it but I think it should work.
On Tue, 25 Oct 2022 at 14:01, Raymond West <raywest@raywest.com> wrote:
> How can I generate a list, generally as list = 0, a, a+b, a+b+a,
> a+b+a+b, a+b+a+b+a, etc.
>
> e.g. list = 0,18,28,46,56,74, etc. where a=18, b=10
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
SP
Sanjeev Prabhakar
Tue, Oct 25, 2022 4:05 PM
I think in this, a series cumulative addition is required
please try following code:
function sum(list)=[for(i=[0:len(list)-1])1]*list;
function cumsum(list)=[for(i=[0:len(list)-1])sum([for(j=[0:i])list[j]])];
a=18;
b=10;
n=10;
c=[for(i=[0:n])i>0?(i%2==0?b:a):0];
echo(cumsum(c));
On Tue, 25 Oct 2022 at 18:31, Raymond West raywest@raywest.com wrote:
How can I generate a list, generally as list = 0, a, a+b, a+b+a,
a+b+a+b, a+b+a+b+a, etc.
e.g. list = 0,18,28,46,56,74, etc. where a=18, b=10
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I think in this, a series cumulative addition is required
please try following code:
function sum(list)=[for(i=[0:len(list)-1])1]*list;
function cumsum(list)=[for(i=[0:len(list)-1])sum([for(j=[0:i])list[j]])];
a=18;
b=10;
n=10;
c=[for(i=[0:n])i>0?(i%2==0?b:a):0];
echo(cumsum(c));
On Tue, 25 Oct 2022 at 18:31, Raymond West <raywest@raywest.com> wrote:
> How can I generate a list, generally as list = 0, a, a+b, a+b+a,
> a+b+a+b, a+b+a+b+a, etc.
>
> e.g. list = 0,18,28,46,56,74, etc. where a=18, b=10
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
RW
Raymond West
Tue, Oct 25, 2022 7:18 PM
Thanks for your reply.
I'm initially using Nop Head's corrected solution,
a = 18;
b = 10;
n = 5;
list = [for(i = [0 : n], k = i * (a + b)) each [k, k + a]];
echo(list);
but your version works fine, too, and can have an odd number of values.
Best wishes,
Ray
On 25/10/2022 17:05, Sanjeev Prabhakar wrote:
I think in this, a series cumulative addition is required
please try following code:
function sum(list)=[for(i=[0:len(list)-1])1]*list;
function cumsum(list)=[for(i=[0:len(list)-1])sum([for(j=[0:i])list[j]])];
a=18;
b=10;
n=10;
c=[for(i=[0:n])i>0?(i%2==0?b:a):0];
echo(cumsum(c));
On Tue, 25 Oct 2022 at 18:31, Raymond West raywest@raywest.com wrote:
How can I generate a list, generally as list = 0, a, a+b, a+b+a,
a+b+a+b, a+b+a+b+a, etc.
e.g. list = 0,18,28,46,56,74, etc. where a=18, b=10
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
Thanks for your reply.
I'm initially using Nop Head's corrected solution,
a = 18;
b = 10;
n = 5;
list = [for(i = [0 : n], k = i * (a + b)) each [k, k + a]];
echo(list);
but your version works fine, too, and can have an odd number of values.
Best wishes,
Ray
On 25/10/2022 17:05, Sanjeev Prabhakar wrote:
> I think in this, a series cumulative addition is required
>
> please try following code:
>
> function sum(list)=[for(i=[0:len(list)-1])1]*list;
>
> function cumsum(list)=[for(i=[0:len(list)-1])sum([for(j=[0:i])list[j]])];
>
> a=18;
> b=10;
> n=10;
> c=[for(i=[0:n])i>0?(i%2==0?b:a):0];
> echo(cumsum(c));
>
> On Tue, 25 Oct 2022 at 18:31, Raymond West <raywest@raywest.com> wrote:
>
> How can I generate a list, generally as list = 0, a, a+b, a+b+a,
> a+b+a+b, a+b+a+b+a, etc.
>
> e.g. list = 0,18,28,46,56,74, etc. where a=18, b=10
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email todiscuss-leave@lists.openscad.org
JB
Jordan Brown
Tue, Oct 25, 2022 8:05 PM
This works to get any value in the list:
function f(a,b,i) = floor((i+1)/2)*a + floor(i/2)*b;
where i starts at zero.
It can also extend the sequence to the left, if that's helpful.
If you really need a list, you can use list comprehension to create one:
list = [ for(i=[0:5]) f(a,b,i) ];
This works to get any value in the list:
function f(a,b,i) = floor((i+1)/2)*a + floor(i/2)*b;
where i starts at zero.
It can also extend the sequence to the left, if that's helpful.
If you really need a list, you can use list comprehension to create one:
list = [ for(i=[0:5]) f(a,b,i) ];
SP
Sanjeev Prabhakar
Wed, Oct 26, 2022 12:55 AM
Thanks
It's a series which alternates between a and b like 0,a,b,a,b,a,b .......
You need a function for cumulative sum for the same
On Wed, 26 Oct, 2022, 12:49 am Raymond West, raywest@raywest.com wrote:
Thanks for your reply.
I'm initially using Nop Head's corrected solution,
a = 18;
b = 10;
n = 5;
list = [for(i = [0 : n], k = i * (a + b)) each [k, k + a]];
echo(list);
but your version works fine, too, and can have an odd number of values.
Best wishes,
Ray
On 25/10/2022 17:05, Sanjeev Prabhakar wrote:
I think in this, a series cumulative addition is required
please try following code:
function sum(list)=[for(i=[0:len(list)-1])1]*list;
function cumsum(list)=[for(i=[0:len(list)-1])sum([for(j=[0:i])list[j]])];
a=18;
b=10;
n=10;
c=[for(i=[0:n])i>0?(i%2==0?b:a):0];
echo(cumsum(c));
On Tue, 25 Oct 2022 at 18:31, Raymond West raywest@raywest.com wrote:
How can I generate a list, generally as list = 0, a, a+b, a+b+a,
a+b+a+b, a+b+a+b+a, etc.
e.g. list = 0,18,28,46,56,74, etc. where a=18, b=10
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Thanks
It's a series which alternates between a and b like 0,a,b,a,b,a,b .......
You need a function for cumulative sum for the same
On Wed, 26 Oct, 2022, 12:49 am Raymond West, <raywest@raywest.com> wrote:
> Thanks for your reply.
>
> I'm initially using Nop Head's corrected solution,
>
> a = 18;
> b = 10;
> n = 5;
>
> list = [for(i = [0 : n], k = i * (a + b)) each [k, k + a]];
>
> echo(list);
>
> but your version works fine, too, and can have an odd number of values.
>
> Best wishes,
>
> Ray
>
>
> On 25/10/2022 17:05, Sanjeev Prabhakar wrote:
>
> I think in this, a series cumulative addition is required
>
> please try following code:
>
> function sum(list)=[for(i=[0:len(list)-1])1]*list;
>
> function cumsum(list)=[for(i=[0:len(list)-1])sum([for(j=[0:i])list[j]])];
>
> a=18;
> b=10;
> n=10;
> c=[for(i=[0:n])i>0?(i%2==0?b:a):0];
> echo(cumsum(c));
>
> On Tue, 25 Oct 2022 at 18:31, Raymond West <raywest@raywest.com> wrote:
>
>> How can I generate a list, generally as list = 0, a, a+b, a+b+a,
>> a+b+a+b, a+b+a+b+a, etc.
>>
>> e.g. list = 0,18,28,46,56,74, etc. where a=18, b=10
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>>
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>