Skip to main content
deleted 3 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
f1 = FoldList[Plus, #, 3 Mod[Range[0, 2 (# - 2)], 2] - 2] &

f1 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f1 @ 4
{4, 2, 3, 1, 2, 0}

Also

f2 = Accumulate[Prepend[#]@{-2,Accumulate 1}@ Prepend[#] @ (3 Mod[Range[0, 2 (# - 2)], 2] - 2) &;

f2 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f2  @ 4
{4, 2, 3, 1, 2, 0}
f1 = FoldList[Plus, #, 3 Mod[Range[0, 2 (# - 2)], 2] - 2] &

f1 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f1 @ 4
{4, 2, 3, 1, 2, 0}

Also

f2 = Accumulate[Prepend[#]@{-2, 1}(3 Mod[Range[0, 2 (# - 2)], 2] - 2) &;

f2 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f2  @ 4
{4, 2, 3, 1, 2, 0}
f1 = FoldList[Plus, #, 3 Mod[Range[0, 2 (# - 2)], 2] - 2] &

f1 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f1 @ 4
{4, 2, 3, 1, 2, 0}

Also

f2 = Accumulate @ Prepend[#] @ (3 Mod[Range[0, 2 (# - 2)], 2] - 2) &;

f2 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f2  @ 4
{4, 2, 3, 1, 2, 0}
added 1 character in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
f1 = FoldList[Plus, #, {-23 Mod[Range[0, 1}[[Mod[Range[22 (# - 3], 2)], 1]]]]2] - 2] &

f1 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f1 @ 4
{4, 2, 3, 1, 2, 0}

Also

f2 = Accumulate[Prepend[#]@{-2, 1}[[Mod[Range[2(3 Mod[Range[0, 2 (# - 3], 2)], 1]]]]2] - 2) &;

f2 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f2  @ 4
{4, 2, 3, 1, 2, 0}
f1 = FoldList[Plus, #, {-2, 1}[[Mod[Range[2 # - 3], 2, 1]]]] &

f1 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f1 @ 4
{4, 2, 3, 1, 2, 0}

Also

f2 = Accumulate[Prepend[#]@{-2, 1}[[Mod[Range[2  # - 3], 2, 1]]]] &;

f2 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f2  @ 4
{4, 2, 3, 1, 2, 0}
f1 = FoldList[Plus, #, 3 Mod[Range[0, 2 (# - 2)], 2] - 2] &

f1 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f1 @ 4
{4, 2, 3, 1, 2, 0}

Also

f2 = Accumulate[Prepend[#]@{-2, 1}(3 Mod[Range[0, 2 (# - 2)], 2] - 2) &;

f2 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f2  @ 4
{4, 2, 3, 1, 2, 0}
added 187 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
ff1 = FoldList[Plus, #, {-2, 1}[[Mod[Range[2 # - 3], 2, 1]]]] &

ff1 @ 5

{5, 3, 4, 2, 3, 1, 2, 0}

{5, 3, 4, 2, 3, 1, 2, 0}
ff1 @ 4

{4, 2, 3, 1, 2, 0}

{4, 2, 3, 1, 2, 0}

Also

f2 = Accumulate[Prepend[#]@{-2, 1}[[Mod[Range[2  # - 3], 2, 1]]]] &;

f2 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f2  @ 4
{4, 2, 3, 1, 2, 0}
f = FoldList[Plus, #, {-2, 1}[[Mod[Range[2 # - 3], 2, 1]]]] &

f @ 5

{5, 3, 4, 2, 3, 1, 2, 0}

f @ 4

{4, 2, 3, 1, 2, 0}

f1 = FoldList[Plus, #, {-2, 1}[[Mod[Range[2 # - 3], 2, 1]]]] &

f1 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f1 @ 4
{4, 2, 3, 1, 2, 0}

Also

f2 = Accumulate[Prepend[#]@{-2, 1}[[Mod[Range[2  # - 3], 2, 1]]]] &;

f2 @ 5
{5, 3, 4, 2, 3, 1, 2, 0}
f2  @ 4
{4, 2, 3, 1, 2, 0}
deleted 22 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading