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

added 411 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Try it online! Try it online! (footer joins with spaces to avoid full-program's implicit smashing)
Note: I added three edge cases to the string in the OP - unfrackled and nofracfracheremate to the beginning, which should not output and fracfracit to the end which should output fracit.

Incoming


previous 11 byter:

Ḳs€L}Ḣ=\ƇẎ€

Also a dyadic link as above.

Try it online!

How?

Ḳs€L}Ḣ=\ƇẎ€Ḳœṣ€ḢÐḟj€ - Link: text, prefix - split (text) at spaces -> list of words
 } e.g. "fracfracit unfracked", "frac"
Ḳ - use right argument...
 - Lsplit (text) at spaces -> list of words - get the length
 ["fracfracit", "unfracked"]
  - for each (word):
 s  œṣ - split intoaround chunkssublists (ofequal L)to (e.g.prefix) "foobarspam"s3 -> ["foo","bar" ["","spa""","m"])
 "it"] ["un","ked"]
 ƇÐḟ - filter keepdiscard items for which this is truthy:
  \ - head
  - last-- twoCrucially linksthis asmodifies athe dyadlist: i.e. f(word ["","it"] prefix): ["ked"]
  -  -- and yields the popped item: head
 - "" -- Crucially this modifies the list so ["foo","bar","spam","m"]
 "un"
 - - -- becomesand ["bar","spam","m"]only whilenon-empty yieldinglists "foo"
are truthy: = kept discarded
  - equal (to ...so we end up with the prefix)?
list:  [["","it"]]
 € - for each (remaining, "decapitated"list wordof lists of characters):
 j - - join with tightenthe (e.g.prefix ["bar","spam","m"] "fracit"  -> "barspam") ["fracit"]

previous 11 byter:

Ḳs€L}Ḣ=\ƇẎ€

Also a dyadic link as above.

Try it online!

Try it online! (footer joins with spaces to avoid full-program's implicit smashing)
Note: I added three edge cases to the string in the OP - unfrackled and nofracfracheremate to the beginning, which should not output and fracfracit to the end which should output fracit.

Incoming


previous 11 byter:

Ḳs€L}Ḣ=\ƇẎ€

Also a dyadic link as above.

Try it online!

How?

Ḳs€L}Ḣ=\ƇẎ€ - Link: text, prefix - split (text) at spaces -> list of words
 } - use right argument...
 L - get the length
  - for each (word):
 s  - split into chunks (of L) (e.g. "foobarspam"s3 -> ["foo","bar","spa","m"])
  Ƈ - filter keep items for which this is truthy:
 \ - last two links as a dyad i.e. f(word, prefix):
  - head
 - -- Crucially this modifies the list so ["foo","bar","spam","m"]
 - -- becomes ["bar","spam","m"] while yielding "foo"
 = - equal (to the prefix)?
 € - for each (remaining, "decapitated" word):
  - tighten (e.g. ["bar","spam","m"] -> "barspam")

Try it online! (footer joins with spaces to avoid full-program's implicit smashing)
Note: I added three edge cases to the string in the OP - unfrackled and nofracfracheremate to the beginning, which should not output and fracfracit to the end which should output fracit.

Ḳœṣ€ḢÐḟj€ - Link: text, prefix  e.g. "fracfracit unfracked", "frac"
Ḳ - split (text) at spaces -> list of words ["fracfracit", "unfracked"]
  - for each (word):
 œṣ - split around sublists equal to (prefix)  ["","","it"] ["un","ked"]
 Ðḟ - filter discard items for which this is truthy:
   - head
  - -- Crucially this modifies the list:  ["","it"]  ["ked"]
 -  -- and yields the popped item: "" "un"
 - -- and only non-empty lists are truthy:  kept discarded
  -  ...so we end up with the list:  [["","it"]]
 € - for each (remaining list of lists of characters):
 j - join with the prefix  "fracit"  -  ["fracit"]

previous 11 byter:

Ḳs€L}Ḣ=\ƇẎ€

Also a dyadic link as above.

Try it online!

added 411 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Jelly, 11(削除) 11 (削除ここまで) 9 bytes

Ḳs€L}Ḣ=\ƇẎ€Ḳœṣ€ḢÐḟj€

A dyadic link accepting the text (a list of characters) on the left and the prefix (a list of characters) on the right which yields a list of lists of characters (the resulting suffixes).

Try it online! Try it online! (footer joins with spaces to avoid full-program's implicit smashing)
Note: I added three edge cases to the string in the OP - unfrackled and nofracfracheremate to the beginning, which should not output and fracfracit to the end which should output fracit.

How?

Incoming


previous 11 byter:

Ḳs€L}Ḣ=\ƇẎ€

Also a dyadic link as above.

Try it online!

How?

Ḳs€L}Ḣ=\ƇẎ€ - Link: text, prefix
Ḳ - split (text) at spaces -> list of words
 } - use right argument...
 L - get the length
 € - for each (word):
 s - split into chunks (of L) (e.g. "foobarspam"s3 -> ["foo","bar","spa","m"])
 Ƈ - filter keep items for which this is truthy:
 \ - last two links as a dyad i.e. f(word, prefix):
 Ḣ - head
 - -- Crucially this modifies the list so ["foo","bar","spam","m"]
 - -- becomes ["bar","spam","m"] while yielding "foo"
 = - equal (to the prefix)?
 € - for each (remaining, "decapitated" word):
 Ẏ - tighten (e.g. ["bar","spam","m"] -> "barspam")

Jelly, 11 bytes

Ḳs€L}Ḣ=\ƇẎ€

A dyadic link accepting the text (a list of characters) on the left and the prefix (a list of characters) on the right which yields a list of lists of characters (the resulting suffixes).

Try it online! (footer joins with spaces to avoid full-program's implicit smashing)
Note: I added three edge cases to the string in the OP - unfrackled and nofracfracheremate to the beginning, which should not output and fracfracit to the end which should output fracit.

How?

Ḳs€L}Ḣ=\ƇẎ€ - Link: text, prefix
Ḳ - split (text) at spaces -> list of words
 } - use right argument...
 L - get the length
 € - for each (word):
 s - split into chunks (of L) (e.g. "foobarspam"s3 -> ["foo","bar","spa","m"])
 Ƈ - filter keep items for which this is truthy:
 \ - last two links as a dyad i.e. f(word, prefix):
 Ḣ - head
 - -- Crucially this modifies the list so ["foo","bar","spam","m"]
 - -- becomes ["bar","spam","m"] while yielding "foo"
 = - equal (to the prefix)?
 € - for each (remaining, "decapitated" word):
 Ẏ - tighten (e.g. ["bar","spam","m"] -> "barspam")

Jelly, (削除) 11 (削除ここまで) 9 bytes

Ḳœṣ€ḢÐḟj€

A dyadic link accepting the text (a list of characters) on the left and the prefix (a list of characters) on the right which yields a list of lists of characters (the resulting suffixes).

Try it online! (footer joins with spaces to avoid full-program's implicit smashing)
Note: I added three edge cases to the string in the OP - unfrackled and nofracfracheremate to the beginning, which should not output and fracfracit to the end which should output fracit.

How?

Incoming


previous 11 byter:

Ḳs€L}Ḣ=\ƇẎ€

Also a dyadic link as above.

Try it online!

How?

Ḳs€L}Ḣ=\ƇẎ€ - Link: text, prefix
Ḳ - split (text) at spaces -> list of words
 } - use right argument...
 L - get the length
 € - for each (word):
 s - split into chunks (of L) (e.g. "foobarspam"s3 -> ["foo","bar","spa","m"])
 Ƈ - filter keep items for which this is truthy:
 \ - last two links as a dyad i.e. f(word, prefix):
 Ḣ - head
 - -- Crucially this modifies the list so ["foo","bar","spam","m"]
 - -- becomes ["bar","spam","m"] while yielding "foo"
 = - equal (to the prefix)?
 € - for each (remaining, "decapitated" word):
 Ẏ - tighten (e.g. ["bar","spam","m"] -> "barspam")
added 815 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Jelly, 11 bytes

Ḳs€L}Ḣ=\ƇẎ€

A dyadic link accepting the text (a list of characters) on the left and the prefix (a list of characters) on the right which yields a list of lists of characters (the resulting suffixes).

Try it online! (footer joins with spaces to avoid full-program's implicit smashing)
Note: I added three edge cases to the string in the OP - unfrackled and nofracfracheremate to the beginning, which should not output and fracfracit to the end which should output fracit.

How?

Ḳs€L}Ḣ=\ƇẎ€ - Link: text, prefix
Ḳ - split (text) at spaces -> list of words
 } - use right argument...
 L - get the length
 € - for each (word):
 s - split into chunks (of L) (e.g. "foobarspam"s3 -> ["foo","bar","spa","m"])
 Ƈ - filter keep items for which this is truthy:
 \ - last two links as a dyad i.e. f(word, prefix):
 Ḣ - head
 - -- Crucially this modifies the list so ["foo","bar","spam","m"]
 - -- becomes ["bar","spam","m"] while yielding "foo"
 = - equal (to the prefix)?
 € - for each (remaining, "decapitated" word):
 Ẏ - tighten (e.g. ["bar","spam","m"] -> "barspam")

Jelly, 11 bytes

Ḳs€L}Ḣ=\ƇẎ€

A dyadic link accepting the text (a list of characters) on the left and the prefix (a list of characters) on the right which yields a list of lists of characters (the resulting suffixes).

Try it online! (footer joins with spaces to avoid full-program's implicit smashing)
Note: I added three edge cases to the string in the OP - unfrackled and nofracfracheremate to the beginning, which should not output and fracfracit to the end which should output fracit.

Jelly, 11 bytes

Ḳs€L}Ḣ=\ƇẎ€

A dyadic link accepting the text (a list of characters) on the left and the prefix (a list of characters) on the right which yields a list of lists of characters (the resulting suffixes).

Try it online! (footer joins with spaces to avoid full-program's implicit smashing)
Note: I added three edge cases to the string in the OP - unfrackled and nofracfracheremate to the beginning, which should not output and fracfracit to the end which should output fracit.

How?

Ḳs€L}Ḣ=\ƇẎ€ - Link: text, prefix
Ḳ - split (text) at spaces -> list of words
 } - use right argument...
 L - get the length
 € - for each (word):
 s - split into chunks (of L) (e.g. "foobarspam"s3 -> ["foo","bar","spa","m"])
 Ƈ - filter keep items for which this is truthy:
 \ - last two links as a dyad i.e. f(word, prefix):
 Ḣ - head
 - -- Crucially this modifies the list so ["foo","bar","spam","m"]
 - -- becomes ["bar","spam","m"] while yielding "foo"
 = - equal (to the prefix)?
 € - for each (remaining, "decapitated" word):
 Ẏ - tighten (e.g. ["bar","spam","m"] -> "barspam")
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading

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