Skip to main content
added 13 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

A couple for fun:

lst = {a, b, c, d, e, f, g};

Partition[lst, 2, 2, 1, {}] ~Flatten~ {2}
{{a, c, e, g}, {b, d, f}}
i = 1; GatherBy[lst, i *= -1 &]
{{a, c, e, g}, {b, d, f}}

And my Golf entry:

lst[[# ;; ;; 2]] & /@ {1,2}
{{a, c, e, g}, {b, d, f}}

And here is an anti-Golf "Rube Goldberg" solution:

ReleaseHold[List @@ Dot @@ 
  PadRight[{Hold /@ lst, {}}, Automatic, #]] & /@
    {{1, 0}Permutations[Range[1, {0, 1}}-1]]
{{a, c, e, g}, {b, d, f}}

A couple for fun:

lst = {a, b, c, d, e, f, g};

Partition[lst, 2, 2, 1, {}] ~Flatten~ {2}
{{a, c, e, g}, {b, d, f}}
i = 1; GatherBy[lst, i *= -1 &]
{{a, c, e, g}, {b, d, f}}

And my Golf entry:

lst[[# ;; ;; 2]] & /@ {1,2}
{{a, c, e, g}, {b, d, f}}

And here is an anti-Golf "Rube Goldberg" solution:

ReleaseHold[List @@ Dot @@ 
  PadRight[{Hold /@ lst, {}}, Automatic, #]] & /@
    {{1, 0}, {0, 1}}
{{a, c, e, g}, {b, d, f}}

A couple for fun:

lst = {a, b, c, d, e, f, g};

Partition[lst, 2, 2, 1, {}] ~Flatten~ {2}
{{a, c, e, g}, {b, d, f}}
i = 1; GatherBy[lst, i *= -1 &]
{{a, c, e, g}, {b, d, f}}

And my Golf entry:

lst[[# ;; ;; 2]] & /@ {1,2}
{{a, c, e, g}, {b, d, f}}

And here is an anti-Golf "Rube Goldberg" solution:

ReleaseHold[List @@ Dot @@ 
  PadRight[{Hold /@ lst, {}}, Automatic, #]] & /@
    Permutations[Range[1, 0, -1]]
{{a, c, e, g}, {b, d, f}}
added 221 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

A couple for fun:

lst = {a, b, c, d, e, f, g};

Partition[lst, 2, 2, 1, {}] ~Flatten~ {2}
{{a, c, e, g}, {b, d, f}}
i = 1; GatherBy[lst, i *= -1 &]
{{a, c, e, g}, {b, d, f}}

And my Golf entry:

lst[[# ;; ;; 2]] & /@ {1,2}
{{a, c, e, g}, {b, d, f}}

And here is an anti-Golf "Rube Goldberg" solution:

ReleaseHold[List @@ Dot @@ 
  PadRight[{Hold /@ lst, {}}, Automatic, #]] & /@
    {{1, 0}, {0, 1}}
{{a, c, e, g}, {b, d, f}}

A couple for fun:

lst = {a, b, c, d, e, f, g};

Partition[lst, 2, 2, 1, {}] ~Flatten~ {2}
{{a, c, e, g}, {b, d, f}}
i = 1; GatherBy[lst, i *= -1 &]
{{a, c, e, g}, {b, d, f}}

And my Golf entry:

lst[[# ;; ;; 2]] & /@ {1,2}
{{a, c, e, g}, {b, d, f}}

A couple for fun:

lst = {a, b, c, d, e, f, g};

Partition[lst, 2, 2, 1, {}] ~Flatten~ {2}
{{a, c, e, g}, {b, d, f}}
i = 1; GatherBy[lst, i *= -1 &]
{{a, c, e, g}, {b, d, f}}

And my Golf entry:

lst[[# ;; ;; 2]] & /@ {1,2}
{{a, c, e, g}, {b, d, f}}

And here is an anti-Golf "Rube Goldberg" solution:

ReleaseHold[List @@ Dot @@ 
  PadRight[{Hold /@ lst, {}}, Automatic, #]] & /@
    {{1, 0}, {0, 1}}
{{a, c, e, g}, {b, d, f}}
deleted 1 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

A couple for fun:

lst = {a, b, c, d, e, f, g};

Partition[lst, 2, 2, 1, {}] ~Flatten~ {2}
{{a, c, e, g}, {b, d, f}}
i = 0;1; GatherBy[lst, OddQ[i++]i *= -1 &]
{{a, c, e, g}, {b, d, f}}

And my Golf entry:

lst[[# ;; ;; 2]] & ~Array~/@ {1,2}
{{a, c, e, g}, {b, d, f}}
lst = {a, b, c, d, e, f, g};

Partition[lst, 2, 2, 1, {}] ~Flatten~ {2}
{{a, c, e, g}, {b, d, f}}
i = 0; GatherBy[lst, OddQ[i++] &]
{{a, c, e, g}, {b, d, f}}

And my Golf entry:

lst[[# ;; ;; 2]] & ~Array~ 2
{{a, c, e, g}, {b, d, f}}

A couple for fun:

lst = {a, b, c, d, e, f, g};

Partition[lst, 2, 2, 1, {}] ~Flatten~ {2}
{{a, c, e, g}, {b, d, f}}
i = 1; GatherBy[lst, i *= -1 &]
{{a, c, e, g}, {b, d, f}}

And my Golf entry:

lst[[# ;; ;; 2]] & /@ {1,2}
{{a, c, e, g}, {b, d, f}}
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading