Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Evaluation order of an APL n-train

Haskell, 52 48 45 42 bytes Caught mistake thanks to rak1507 Saved 3 bytes thanks to Hakerh400 f n=n:g[n-1,n-2..1] g(b:c:t)=c:b:g t g t=t Try it online! g takes the rest of the trains. -...

posted 3y ago by user‭  ·  edited 3y ago by user‭

Answer
#7: Post edited by user avatar user‭ · 2021-06-09T22:39:47Z (over 3 years ago)
  • # [Haskell], <s>52</s> <s>48</s> 45 bytes
  • Caught mistake thanks to rak1507
  • <!-- language-all: lang-hs -->
  • f n=n:g[n-1,n-2..1]
  • g(b:c:t)=[c,b]++g t
  • g t=t
  • [Try it online!][TIO-kpop5lec]
  • [Haskell]: https://www.haskell.org/
  • [TIO-kpop5lec]: https://tio.run/##y0gszk7Nyfn/P00hzzbPKj06T9dQJ0/XSE/PMJYrXSPJKtmqRNM2OlknKVZbO12hhAuIbUv@5yZm5ilYWSl4@itoaHKBebYKKflcCgq5iQW@8QoFRZl5JQoqIJ5CmkK0IdA4g9j/AA "Haskell – Try It Online"
  • `g` takes the rest of the trains.
  • ```
  • -- This is a fork, so append c (monad) and b (dyad)
  • -- and continue with the rest of the train
  • g(b:c:t)#=[c,b]++g t
  • -- t is either empty or a single monad, so finish it off
  • g t=t
  • ```
  • `f` simply starts it off with the last function `n` and the other trains `1..n-1` (in reverse).
  • ```
  • f n=n:g[n-1,n-2..1]
  • ```
  • # [Haskell], <s>52</s> <s>48</s> <s>45</s> 42 bytes
  • Caught mistake thanks to rak1507
  • Saved 3 bytes thanks to Hakerh400
  • <!-- language-all: lang-hs -->
  • f n=n:g[n-1,n-2..1]
  • g(b:c:t)=c:b:g t
  • g t=t
  • [Try it online!][TIO-kpq203v9]
  • [Haskell]: https://www.haskell.org/
  • [TIO-kpq203v9]: https://tio.run/##y0gszk7Nyfn/P00hzzbPKj06T9dQJ0/XSE/PMJYrXSPJKtmqRNM22SrJKl2hhAuIbUv@5yZm5ilYWSl4@itoaHKBebYKKflcCgq5iQW@8QoFRZl5JQoqIJ5CmkK0IdAsg9j/AA "Haskell – Try It Online"
  • `g` takes the rest of the trains.
  • ```
  • -- This is a fork, so append c (monad) and b (dyad)
  • -- and continue with the rest of the train
  • g(b:c:t)#=[c,b]++g t
  • -- t is either empty or a single monad, so finish it off
  • g t=t
  • ```
  • `f` simply starts it off with the last function `n` and the other trains `1..n-1` (in reverse).
  • ```
  • f n=n:g[n-1,n-2..1]
  • ```
#6: Post edited by user avatar user‭ · 2021-06-08T23:51:56Z (over 3 years ago)
  • # [Haskell], <s>52</s> 48 bytes
  • Caught mistake thanks to rak1507
  • <!-- language-all: lang-hs -->
  • f n=[n]++g[n-1,n-2..1]
  • g(b:c:t)=[c,b]++g t
  • g t=t
  • [Try it online!][TIO-kpo1lt1b]
  • [Haskell]: https://www.haskell.org/
  • [TIO-kpo1lt1b]: https://tio.run/##HYw5CoAwFAX7nOIVFgkuGMtADmAhHiAEibuoX9HcPy7FFMPAzO5eh20LYQRpQzaOJ0OpTCgtskxaNvFWdcoLbbqk/So8e9E@7G4hKIWyBhfsN43@YMDuzqrBeS3kEX2GEUa@u9yGBw "Haskell – Try It Online"
  • `g` takes the rest of the trains.
  • ```
  • -- This is a fork, so append c (monad) and b (dyad)
  • -- and continue with the rest of the train
  • g(b:c:t)#=[c,b]++g t
  • -- t is either empty or a single monad, so finish it off
  • g t=t
  • ```
  • `f` simply starts it off with the last function `n` and the other trains `1..n-1` (in reverse).
  • ```
  • f n=[n]++g[n-1,n-2..1]
  • ```
  • # [Haskell], <s>52</s> <s>48</s> 45 bytes
  • Caught mistake thanks to rak1507
  • <!-- language-all: lang-hs -->
  • f n=n:g[n-1,n-2..1]
  • g(b:c:t)=[c,b]++g t
  • g t=t
  • [Try it online!][TIO-kpop5lec]
  • [Haskell]: https://www.haskell.org/
  • [TIO-kpop5lec]: https://tio.run/##y0gszk7Nyfn/P00hzzbPKj06T9dQJ0/XSE/PMJYrXSPJKtmqRNM2OlknKVZbO12hhAuIbUv@5yZm5ilYWSl4@itoaHKBebYKKflcCgq5iQW@8QoFRZl5JQoqIJ5CmkK0IdA4g9j/AA "Haskell – Try It Online"
  • `g` takes the rest of the trains.
  • ```
  • -- This is a fork, so append c (monad) and b (dyad)
  • -- and continue with the rest of the train
  • g(b:c:t)#=[c,b]++g t
  • -- t is either empty or a single monad, so finish it off
  • g t=t
  • ```
  • `f` simply starts it off with the last function `n` and the other trains `1..n-1` (in reverse).
  • ```
  • f n=n:g[n-1,n-2..1]
  • ```
#5: Post edited by user avatar user‭ · 2021-06-08T12:57:29Z (over 3 years ago)
  • # [Haskell], <s>52</s> 48 bytes
  • Caught mistake thanks to rak1507
  • <!-- language-all: lang-hs -->
  • f n=[n]++g[n-1,n-2..1]
  • g(b:c:t)=[c,b]++g t
  • g t=t
  • [Try it online!][TIO-kpo1lt1b]
  • [Haskell]: https://www.haskell.org/
  • [TIO-kpo1lt1b]: https://tio.run/##HYw5CoAwFAX7nOIVFgkuGMtADmAhHiAEibuoX9HcPy7FFMPAzO5eh20LYQRpQzaOJ0OpTCgtskxaNvFWdcoLbbqk/So8e9E@7G4hKIWyBhfsN43@YMDuzqrBeS3kEX2GEUa@u9yGBw "Haskell – Try It Online"
  • `g` takes the rest of the trains.
  • ```
  • --- This is a dyadic train, so append c (monad) and b (dyad)
  • -- and continue with the rest of the train
  • g(b:c:t)#=[c,b]++g t
  • -- t is either empty or a single monad, so finish it off
  • g t=t
  • ```
  • `f` simply starts it off with the last function `n` and the other trains `1..n-1` (in reverse).
  • ```
  • f n=[n]++g[n-1,n-2..1]
  • ```
  • # [Haskell], <s>52</s> 48 bytes
  • Caught mistake thanks to rak1507
  • <!-- language-all: lang-hs -->
  • f n=[n]++g[n-1,n-2..1]
  • g(b:c:t)=[c,b]++g t
  • g t=t
  • [Try it online!][TIO-kpo1lt1b]
  • [Haskell]: https://www.haskell.org/
  • [TIO-kpo1lt1b]: https://tio.run/##HYw5CoAwFAX7nOIVFgkuGMtADmAhHiAEibuoX9HcPy7FFMPAzO5eh20LYQRpQzaOJ0OpTCgtskxaNvFWdcoLbbqk/So8e9E@7G4hKIWyBhfsN43@YMDuzqrBeS3kEX2GEUa@u9yGBw "Haskell – Try It Online"
  • `g` takes the rest of the trains.
  • ```
  • --- This is a dyadic train, so append c (monad) and b (dyad)
  • -- This is a fork, so append c (monad) and b (dyad)
  • -- and continue with the rest of the train
  • g(b:c:t)#=[c,b]++g t
  • -- t is either empty or a single monad, so finish it off
  • g t=t
  • ```
  • `f` simply starts it off with the last function `n` and the other trains `1..n-1` (in reverse).
  • ```
  • f n=[n]++g[n-1,n-2..1]
  • ```
#4: Post edited by user avatar user‭ · 2021-06-08T12:56:13Z (over 3 years ago)
  • # [Haskell], 50 bytes
  • <!-- language-all: lang-hs -->
  • f n=[n-1,n-2..1]#[n]
  • (b:c:t)#a=t#a++[c,b]
  • t#a=a++t
  • [Try it online!][TIO-kpn9kiha]
  • [Haskell]: https://www.haskell.org/
  • [TIO-kpn9kiha]: https://tio.run/##y0gszk7Nyfn/P00hzzY6T9dQJ0/XSE/PMFY5Oi@WSyPJKtmqRFM50bZEOVFbOzpZJymWC8i0BXJK/ucmZuYpWFkpePoraGhygXm2Cin5XAoKuYkFvvEKBUWZeSUKKiCeQppCtCHQWIPY/wA "Haskell – Try It Online"
  • `#` takes a list of numbers representing a previously processed sub-train on the right, and the rest of the trains on the left.
  • ```
  • --- This is a dyadic train, so appending c (monad) and b (dyad)
  • -- and continue with the rest of the train
  • (b:c:t)#a=t#a++[c,b]
  • -- t is either empty or a single monad, so finish it off
  • t#a=a++t
  • ```
  • `f` simply starts it off with the last function `n` and the other trains `1..n-1` (in reverse).
  • ```
  • f n=[n-1,n-2..1]#[n]
  • ```
  • # [Haskell], <s>52</s> 48 bytes
  • Caught mistake thanks to rak1507
  • <!-- language-all: lang-hs -->
  • f n=[n]++g[n-1,n-2..1]
  • g(b:c:t)=[c,b]++g t
  • g t=t
  • [Try it online!][TIO-kpo1lt1b]
  • [Haskell]: https://www.haskell.org/
  • [TIO-kpo1lt1b]: https://tio.run/##HYw5CoAwFAX7nOIVFgkuGMtADmAhHiAEibuoX9HcPy7FFMPAzO5eh20LYQRpQzaOJ0OpTCgtskxaNvFWdcoLbbqk/So8e9E@7G4hKIWyBhfsN43@YMDuzqrBeS3kEX2GEUa@u9yGBw "Haskell – Try It Online"
  • `g` takes the rest of the trains.
  • ```
  • --- This is a dyadic train, so appending c (monad) and b (dyad)
  • -- This is a dyadic train, so append c (monad) and b (dyad)
  • -- and continue with the rest of the train
  • g(b:c:t)#=[c,b]++g t
  • -- t is either empty or a single monad, so finish it off
  • g t=t
  • ```
  • `f` simply starts it off with the last function `n` and the other trains `1..n-1` (in reverse).
  • ```
  • f n=[n]++g[n-1,n-2..1]
  • ```
#3: Post edited by user avatar user‭ · 2021-06-07T23:51:52Z (over 3 years ago)
  • # [Haskell], 50 bytes
  • <!-- language-all: lang-hs -->
  • f n=[n-1,n-2..1]#[n]
  • (b:c:t)#a=t#a++[c,b]
  • t#a=a++t
  • [Try it online!][TIO-kpn9kiha]
  • [Haskell]: https://www.haskell.org/
  • [TIO-kpn9kiha]: https://tio.run/##y0gszk7Nyfn/P00hzzY6T9dQJ0/XSE/PMFY5Oi@WSyPJKtmqRFM50bZEOVFbOzpZJymWC8i0BXJK/ucmZuYpWFkpePoraGhygXm2Cin5XAoKuYkFvvEKBUWZeSUKKiCeQppCtCHQWIPY/wA "Haskell – Try It Online"
  • # [Haskell], 50 bytes
  • <!-- language-all: lang-hs -->
  • f n=[n-1,n-2..1]#[n]
  • (b:c:t)#a=t#a++[c,b]
  • t#a=a++t
  • [Try it online!][TIO-kpn9kiha]
  • [Haskell]: https://www.haskell.org/
  • [TIO-kpn9kiha]: https://tio.run/##y0gszk7Nyfn/P00hzzY6T9dQJ0/XSE/PMFY5Oi@WSyPJKtmqRFM50bZEOVFbOzpZJymWC8i0BXJK/ucmZuYpWFkpePoraGhygXm2Cin5XAoKuYkFvvEKBUWZeSUKKiCeQppCtCHQWIPY/wA "Haskell – Try It Online"
  • `#` takes a list of numbers representing a previously processed sub-train on the right, and the rest of the trains on the left.
  • ```
  • -- This is a dyadic train, so appending c (monad) and b (dyad)
  • -- and continue with the rest of the train
  • (b:c:t)#a=t#a++[c,b]
  • -- t is either empty or a single monad, so finish it off
  • t#a=a++t
  • ```
  • `f` simply starts it off with the last function `n` and the other trains `1..n-1` (in reverse).
  • ```
  • f n=[n-1,n-2..1]#[n]
  • ```
#2: Post edited by user avatar user‭ · 2021-06-07T23:48:47Z (over 3 years ago)
#1: Initial revision by user avatar user‭ · 2021-06-07T23:47:52Z (over 3 years ago)
# [Haskell], 50 bytes

<!-- language-all: lang-hs -->

    f n=[n-1,n-2..1]#[n]
    (b:c:t)#a=t#a++[c,b]
    t#a=a++t

[Try it online!][TIO-kpn9kiha]

[Haskell]: https://www.haskell.org/
[TIO-kpn9kiha]: https://tio.run/##y0gszk7Nyfn/P00hzzY6T9dQJ0/XSE/PMFY5Oi@WSyPJKtmqRFM50bZEOVFbOzpZJymWC8i0BXJK/ucmZuYpWFkpePoraGhygXm2Cin5XAoKuYkFvvEKBUWZeSUKKiCeQppCtCHQWIPY/wA "Haskell – Try It Online"