Skip to main content
Commonmark migration
Source Link

#ES6 (Javascript), 79, 67, 65 bytes#

ES6 (Javascript), 79, 67, 65 bytes

UPDATE

  • minus 2 bytes, by starting with i=2, as suggested by @ETHProductions
  • Saved 3 bytes, thanks to excellent advice from @Neil !

Golfed

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

Test

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

>S(8,[1,3])
Array [ 1, 3, 4, 12, -8, -1.5, -9.5, 14.25 ]

>S(5,[0,1])
Array [ 0, 1, 1, 1, 0 ]

>S(9,[1,0])
Array [ 1, 0, 1, 0, 1, 0, 1, 0, 1 ]

>S(25,[6,3])
Array [ 6, 3, 9, 27, -18, -1.5, -19.5, 29.25, -48.75, -0.6, ...]

#ES6 (Javascript), 79, 67, 65 bytes#

UPDATE

  • minus 2 bytes, by starting with i=2, as suggested by @ETHProductions
  • Saved 3 bytes, thanks to excellent advice from @Neil !

Golfed

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

Test

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

>S(8,[1,3])
Array [ 1, 3, 4, 12, -8, -1.5, -9.5, 14.25 ]

>S(5,[0,1])
Array [ 0, 1, 1, 1, 0 ]

>S(9,[1,0])
Array [ 1, 0, 1, 0, 1, 0, 1, 0, 1 ]

>S(25,[6,3])
Array [ 6, 3, 9, 27, -18, -1.5, -19.5, 29.25, -48.75, -0.6, ...]

ES6 (Javascript), 79, 67, 65 bytes

UPDATE

  • minus 2 bytes, by starting with i=2, as suggested by @ETHProductions
  • Saved 3 bytes, thanks to excellent advice from @Neil !

Golfed

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

Test

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

>S(8,[1,3])
Array [ 1, 3, 4, 12, -8, -1.5, -9.5, 14.25 ]

>S(5,[0,1])
Array [ 0, 1, 1, 1, 0 ]

>S(9,[1,0])
Array [ 1, 0, 1, 0, 1, 0, 1, 0, 1 ]

>S(25,[6,3])
Array [ 6, 3, 9, 27, -18, -1.5, -19.5, 29.25, -48.75, -0.6, ...]
added missing parenthesis in one of the tests
Source Link
zeppelin
  • 8.5k
  • 3
  • 21
  • 42

#ES6 (Javascript), 79, 67, 65 bytes#

UPDATE

  • minus 2 bytes, by starting with i=2, as suggested by @ETHProductions
  • Saved 3 bytes, thanks to excellent advice from @Neil !

Golfed

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

Test

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

>S(8,[1,3])
Array [ 1, 3, 4, 12, -8, -1.5, -9.5, 14.25 ]

>S(5,[0,1])
Array [ 0, 1, 1, 1, 0 ]

>S(9,[1,0])
Array [ 1, 0, 1, 0, 1, 0, 1, 0, 1 ]

>S(25,[6,3])
Array [ 6, 3, 9, 27, -18, -1.5, -19.5, 29.25, -48.75, -0.6, ...]

#ES6 (Javascript), 79, 67, 65 bytes#

UPDATE

  • minus 2 bytes, by starting with i=2, as suggested by @ETHProductions
  • Saved 3 bytes, thanks to excellent advice from @Neil !

Golfed

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

Test

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

>S(8,[1,3]
Array [ 1, 3, 4, 12, -8, -1.5, -9.5, 14.25 ]

>S(5,[0,1])
Array [ 0, 1, 1, 1, 0 ]

>S(9,[1,0])
Array [ 1, 0, 1, 0, 1, 0, 1, 0, 1 ]

>S(25,[6,3])
Array [ 6, 3, 9, 27, -18, -1.5, -19.5, 29.25, -48.75, -0.6, ...]

#ES6 (Javascript), 79, 67, 65 bytes#

UPDATE

  • minus 2 bytes, by starting with i=2, as suggested by @ETHProductions
  • Saved 3 bytes, thanks to excellent advice from @Neil !

Golfed

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

Test

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

>S(8,[1,3])
Array [ 1, 3, 4, 12, -8, -1.5, -9.5, 14.25 ]

>S(5,[0,1])
Array [ 0, 1, 1, 1, 0 ]

>S(9,[1,0])
Array [ 1, 0, 1, 0, 1, 0, 1, 0, 1 ]

>S(25,[6,3])
Array [ 6, 3, 9, 27, -18, -1.5, -19.5, 29.25, -48.75, -0.6, ...]
added 83 characters in body
Source Link
zeppelin
  • 8.5k
  • 3
  • 21
  • 42

#ES6 (Javascript), 79, 6767, 65 bytes#

UPDATE

  • minus 2 bytes, by starting with i=2, as suggested by @ETHProductions
  • Saved 3 bytes, thanks to excellent advice from @Neil !

Can certainly be golfed further.

Golfed

S=(n,a,i=0i=2)=>i<n-2?S(n,a,a.push(eval(a[i]+"+*a[i-2]+"-/"[i%4]+a[++i]+*"[i%4]+a[i-1]))-2):a

Test

S=(n,a,i=0i=2)=>i<n-2?S(n,a,a.push(eval(a[i]+"+*a[i-2]+"-/"[i%4]+a[++i]+*"[i%4]+a[i-1]))-2):a

>S(8,[1,3]
Array [ 1, 3, 4, 12, -8, -1.5, -9.5, 14.25 ]

>S(5,[0,1])
Array [ 0, 1, 1, 1, 0 ]

>S(9,[1,0])
Array [ 1, 0, 1, 0, 1, 0, 1, 0, 1 ]

>S(25,[6,3])
Array [ 6, 3, 9, 27, -18, -1.5, -19.5, 29.25, -48.75, -0.6, ...]

#ES6 (Javascript), 79, 67 bytes#

UPDATE

  • Saved 3 bytes, thanks to excellent advice from @Neil !

Can certainly be golfed further.

Golfed

S=(n,a,i=0)=>i<n-2?S(n,a,a.push(eval(a[i]+"+*-/"[i%4]+a[++i]))-2):a

Test

S=(n,a,i=0)=>i<n-2?S(n,a,a.push(eval(a[i]+"+*-/"[i%4]+a[++i]))-2):a

>S(8,[1,3]
Array [ 1, 3, 4, 12, -8, -1.5, -9.5, 14.25 ]

>S(5,[0,1])
Array [ 0, 1, 1, 1, 0 ]

>S(9,[1,0])
Array [ 1, 0, 1, 0, 1, 0, 1, 0, 1 ]

>S(25,[6,3])
Array [ 6, 3, 9, 27, -18, -1.5, -19.5, 29.25, -48.75, -0.6, ...]

#ES6 (Javascript), 79, 67, 65 bytes#

UPDATE

  • minus 2 bytes, by starting with i=2, as suggested by @ETHProductions
  • Saved 3 bytes, thanks to excellent advice from @Neil !

Golfed

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

Test

S=(n,a,i=2)=>i<n?S(n,a,a.push(eval(a[i-2]+"-/+*"[i%4]+a[i-1]))):a

>S(8,[1,3]
Array [ 1, 3, 4, 12, -8, -1.5, -9.5, 14.25 ]

>S(5,[0,1])
Array [ 0, 1, 1, 1, 0 ]

>S(9,[1,0])
Array [ 1, 0, 1, 0, 1, 0, 1, 0, 1 ]

>S(25,[6,3])
Array [ 6, 3, 9, 27, -18, -1.5, -19.5, 29.25, -48.75, -0.6, ...]
added 62 characters in body
Source Link
zeppelin
  • 8.5k
  • 3
  • 21
  • 42
Loading
added 4 characters in body
Source Link
zeppelin
  • 8.5k
  • 3
  • 21
  • 42
Loading
added 4 characters in body
Source Link
zeppelin
  • 8.5k
  • 3
  • 21
  • 42
Loading
Source Link
zeppelin
  • 8.5k
  • 3
  • 21
  • 42
Loading