Skip to main content
-2
Source Link
Adám
  • 31.1k
  • 3
  • 124
  • 287

APL (Dyalog Unicode), 24 24 22 bytesSBCS

Anonymous tacit prefix function.

⊂∊1↓⍳∘≢{⍺/⍵/⍨(≢⍵)⍴⍺↑1⍴⍺↑⍺}¨⊂

Try it online!

 enclose the string to treat map using the entire string
e.g. "aaabbb"

⍳∘≢{ for each of the ɩndices 1 through the tally of characters in the string:
e.g. 3

⍺↑1⍺↑⍺ take the current number of elements from 1the current number, padding with 0s
e.g. [1[3,0,0]

(≢⍵)⍴ cyclically reshape into the shape of the tally of characters in the string
e.g. [1[3,0,0,13,0,0]

⍵/⍨ use that to filter (lit. replicate) the string's characters
"ab"

⍺/ replicate the characters per the current number
e.g. "aaabbb"

1↓ drop the first one (n = 1)

⊂∊ is the the entire string a member of that list?

APL (Dyalog Unicode), 24 bytesSBCS

Anonymous tacit prefix function.

⊂∊1↓⍳∘≢{⍺/⍵/⍨(≢⍵)⍴⍺↑1}¨⊂

Try it online!

 enclose the string to treat map using the entire string
e.g. "aaabbb"

⍳∘≢{ for each of the ɩndices 1 through the tally of characters in the string:
e.g. 3

⍺↑1 take the current number of elements from 1, padding with 0s
e.g. [1,0,0]

(≢⍵)⍴ cyclically reshape into the shape of the tally of characters in the string
e.g. [1,0,0,1,0,0]

⍵/⍨ use that to filter (lit. replicate) the string's characters
"ab"

⍺/ replicate the characters per the current number
e.g. "aaabbb"

1↓ drop the first one (n = 1)

⊂∊ is the the entire string a member of that list?

APL (Dyalog Unicode), 24 22 bytesSBCS

Anonymous tacit prefix function.

⊂∊1↓⍳∘≢{⍵/⍨(≢⍵)⍴⍺↑⍺}¨⊂

Try it online!

 enclose the string to treat map using the entire string
e.g. "aaabbb"

⍳∘≢{ for each of the ɩndices 1 through the tally of characters in the string:
e.g. 3

⍺↑⍺ take the current number of elements from the current number, padding with 0s
e.g. [3,0,0]

(≢⍵)⍴ cyclically reshape into the shape of the tally of characters in the string
e.g. [3,0,0,3,0,0]

⍵/⍨ use that to replicate the string's characters
"aaabbb"

1↓ drop the first one (n = 1)

⊂∊ is the the entire string a member of that list?

explanation
Source Link
Adám
  • 31.1k
  • 3
  • 124
  • 287

APL (Dyalog Unicode), 24 bytesSBCS

Anonymous tacit prefix function.

⊂∊1↓⍳∘≢{⍺/⍵/⍨(≢⍵)⍴⍺↑1}¨⊂

Try it online!

 enclose the string to treat map using the entire string
e.g. "aaabbb"

⍳∘≢{ for each of the ɩndices 1 through the tally of characters in the string:
e.g. 3

⍺↑1 take the current number of elements from 1, padding with 0s
e.g. [1,0,0]

(≢⍵)⍴ cyclically reshape into the shape of the tally of characters in the string
e.g. [1,0,0,1,0,0]

⍵/⍨ use that to filter (lit. replicate) the string's characters
"ab"

⍺/ replicate the characters per the current number
e.g. "aaabbb"

1↓ drop the first one (n = 1)

⊂∊ is the the entire string a member of that list?

APL (Dyalog Unicode), 24 bytesSBCS

Anonymous tacit prefix function.

⊂∊1↓⍳∘≢{⍺/⍵/⍨(≢⍵)⍴⍺↑1}¨⊂

Try it online!

APL (Dyalog Unicode), 24 bytesSBCS

Anonymous tacit prefix function.

⊂∊1↓⍳∘≢{⍺/⍵/⍨(≢⍵)⍴⍺↑1}¨⊂

Try it online!

 enclose the string to treat map using the entire string
e.g. "aaabbb"

⍳∘≢{ for each of the ɩndices 1 through the tally of characters in the string:
e.g. 3

⍺↑1 take the current number of elements from 1, padding with 0s
e.g. [1,0,0]

(≢⍵)⍴ cyclically reshape into the shape of the tally of characters in the string
e.g. [1,0,0,1,0,0]

⍵/⍨ use that to filter (lit. replicate) the string's characters
"ab"

⍺/ replicate the characters per the current number
e.g. "aaabbb"

1↓ drop the first one (n = 1)

⊂∊ is the the entire string a member of that list?

Source Link
Adám
  • 31.1k
  • 3
  • 124
  • 287

APL (Dyalog Unicode), 24 bytesSBCS

Anonymous tacit prefix function.

⊂∊1↓⍳∘≢{⍺/⍵/⍨(≢⍵)⍴⍺↑1}¨⊂

Try it online!