Re: [BEGINNER] reccurence! and sequence!

2017-07-06 Thread ag0aep6g via Digitalmars-d-learn
On 07/06/2017 02:21 AM, Ali Çehreli wrote: On 07/05/2017 04:38 PM, helxi wrote: [...] >> recurrence!((a, n) => a[0] + 1)(1).take(10).writeln; > 1. In the last example of reccurence, what does n in (a,n) refer to? n is "the index of the current value". Each time the lambda is called,

Re: [BEGINNER] reccurence! and sequence!

2017-07-06 Thread helxi via Digitalmars-d-learn
On Thursday, 6 July 2017 at 00:21:44 UTC, Ali Çehreli wrote: On 07/05/2017 04:38 PM, helxi wrote: >> [...] > > Oh thank you. Just 2 follow-up questions: >> [...] > 1. In the last example of reccurence, what does n in (a,n) refer to? n is "the index of the current value". Each time the lambda

Re: [BEGINNER] reccurence! and sequence!

2017-07-05 Thread Ali Çehreli via Digitalmars-d-learn
On 07/05/2017 04:38 PM, helxi wrote: >> >> sequence!((a, n) => a[0] + 1)(1).take(10).writeln; >> // [2, 2, 2, 2, 2, 2, 2, 2, 2, 2] >> // because a[0] is always 1 >> >> recurrence!((a, n) => a[0] + 1)(1).take(10).writeln; >> // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >> // because

Re: [BEGINNER] reccurence! and sequence!

2017-07-05 Thread helxi via Digitalmars-d-learn
On Monday, 26 June 2017 at 10:34:22 UTC, ag0aep6g wrote: On 06/26/2017 11:51 AM, helxi wrote: [...] `a` is a tuple of the run-time arguments you pass to `sequence`. In this example, no arguments are passed (empty parens at the end of the call), so `a` is empty. [...] a[0] = 1 a[1] = 2

Re: [BEGINNER] reccurence! and sequence!

2017-06-26 Thread ag0aep6g via Digitalmars-d-learn
On 06/26/2017 11:51 AM, helxi wrote: auto tri = sequence!((a,n) => n*(n+1)/2)(); /** okay, it's a triangular number array * I understand n is the index number, the nth term * However where does this 'a' go? */ `a` is a tuple of the run-time arguments you pass to `sequence`. In this example,

[BEGINNER] reccurence! and sequence!

2017-06-26 Thread helxi via Digitalmars-d-learn
Can someone give me a very watered-down explanation of what std.range's recurrence! and sequence! do? auto tri = sequence!((a,n) => n*(n+1)/2)(); /** okay, it's a triangular number array * I understand n is the index number, the nth term * However where does this 'a' go? */ auto odds =