Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 74 characters in body
Source Link
ბიმო
  • 17k
  • 3
  • 43
  • 106

Haskell, 60(削除) 60 (削除ここまで) 59 bytes

(init<>reverse).(scanl(pure.(>>=?)<*>tail)
a?_=do \uu<->ua;u:[' '|' '<u]))<*>tail)

Try it online! Try it online!

Explanation / Ungolfed

Explanation

For a string (eg. "abc") we apply first

scanl (pure . (>>= \u->u:[' '|' '<u])?) <*> tail

which is the same as

\str -> scanl (const . (>>= \u->u:[' '|' '<u])?) str (tail str)

This repeatedly applies (>>= \u->u:[' '|' '<u])?) (appends a space to each character in the range [33..]) to the str until there are that many strings as str has characters: ["abc","a b c ", "a b c "]

Now we only need to concatenate the result (minus the last element) with its reversed counter part:

init<>reverse

Haskell, 60 bytes

(init<>reverse).(scanl(pure.(>>= \u->u:[' '|' '<u]))<*>tail)

Try it online!

Explanation / Ungolfed

For a string (eg. "abc") we apply first

scanl (pure . (>>= \u->u:[' '|' '<u])) <*> tail

which is the same as

\str -> scanl (const . (>>= \u->u:[' '|' '<u])) str (tail str)

This repeatedly applies (>>= \u->u:[' '|' '<u])) (appends a space to each character in the range [33..]) to the str until there are that many strings as str has characters: ["abc","a b c ", "a b c "]

Now we only need to concatenate the result (minus the last element) with its reversed counter part:

init<>reverse

Haskell, (削除) 60 (削除ここまで) 59 bytes

(init<>reverse).(scanl(?)<*>tail)
a?_=do u<-a;u:[' '|' '<u]

Try it online!

Explanation

For a string (eg. "abc") we apply first

scanl (?) <*> tail

which is the same as

\str -> scanl (?) str (tail str)

This repeatedly applies (?) (appends a space to each character in the range [33..]) to the str until there are that many strings as str has characters: ["abc","a b c ", "a b c "]

Now we only need to concatenate the result (minus the last element) with its reversed counter part:

init<>reverse
ypto
Source Link
ბიმო
  • 17k
  • 3
  • 43
  • 106

Haskell, 60 bytes

(init<>reverse).(scanl(pure.(>>= \u->u:[' '|' '<u]))<*>tail)

Try it online!

Explanation / Ungolfed

For a string (eg. "abc") we apply first

scanl (pure . (>>= \u->u:[' '|' '<u])) <*> tail

which is the same as

\str -> scanl (const . (>>= \u->u:[' '|' '<u])) str (tail str)

This repeatedly applies (>>= \u->u:[' '|' '<u])) (appends a space to each character in the range [33..]) to the str until there are that many strings as str has characters: ["abc","a b c ", "a b c "]

Now we only need to concatenate the result (minus the firstlast element) with its reversed counter part:

init<>reverse

Haskell, 60 bytes

(init<>reverse).(scanl(pure.(>>= \u->u:[' '|' '<u]))<*>tail)

Try it online!

Explanation / Ungolfed

For a string (eg. "abc") we apply first

scanl (pure . (>>= \u->u:[' '|' '<u])) <*> tail

which is the same as

\str -> scanl (const . (>>= \u->u:[' '|' '<u])) str (tail str)

This repeatedly applies (>>= \u->u:[' '|' '<u])) (appends a space to each character in the range [33..]) to the str until there are that many strings as str has characters: ["abc","a b c ", "a b c "]

Now we only need to concatenate the result (minus the first element) with its reversed counter part:

init<>reverse

Haskell, 60 bytes

(init<>reverse).(scanl(pure.(>>= \u->u:[' '|' '<u]))<*>tail)

Try it online!

Explanation / Ungolfed

For a string (eg. "abc") we apply first

scanl (pure . (>>= \u->u:[' '|' '<u])) <*> tail

which is the same as

\str -> scanl (const . (>>= \u->u:[' '|' '<u])) str (tail str)

This repeatedly applies (>>= \u->u:[' '|' '<u])) (appends a space to each character in the range [33..]) to the str until there are that many strings as str has characters: ["abc","a b c ", "a b c "]

Now we only need to concatenate the result (minus the last element) with its reversed counter part:

init<>reverse
Source Link
ბიმო
  • 17k
  • 3
  • 43
  • 106

Haskell, 60 bytes

(init<>reverse).(scanl(pure.(>>= \u->u:[' '|' '<u]))<*>tail)

Try it online!

Explanation / Ungolfed

For a string (eg. "abc") we apply first

scanl (pure . (>>= \u->u:[' '|' '<u])) <*> tail

which is the same as

\str -> scanl (const . (>>= \u->u:[' '|' '<u])) str (tail str)

This repeatedly applies (>>= \u->u:[' '|' '<u])) (appends a space to each character in the range [33..]) to the str until there are that many strings as str has characters: ["abc","a b c ", "a b c "]

Now we only need to concatenate the result (minus the first element) with its reversed counter part:

init<>reverse

AltStyle によって変換されたページ (->オリジナル) /