#Rebol, 136 bytes
Rebol, 136 bytes
f: func[s][repeat n length? b: copy s[unless empty? x: collect[forall s[unless find next find b t: copy/part s n t[keep t]]][return x]]]
Ungolfed:
f: func [s] [
repeat n length? b: copy s [
unless empty? x: collect [
forall s [
unless find next find b t: copy/part s n t [keep t]
]
][return x]
]
]
Usage example:
>> f ""
== none
>> f "abcaa"
== ["b" "c"]
>> f "rererere"
== ["ererer"]
>> f "asdfasdfd"
== ["fa" "fd"]
>> f "ffffhhhhfffffhhhhhfffhhh"
== ["hffff" "fffff" "hhhhh" "hfffh"]
>> f "asdfdfasddfdfaddsasadsasadsddsddfdsasdf"
== ["fas" "fad" "add" "fds"]
NB. I suppose the heart of the code is how the find
part is working. Hopefully this will help explain...
>> find "asdfasdfd" "df"
== "dfasdfd"
>> next find "asdfasdfd" "df"
== "fasdfd"
>> find next find "asdfasdfd" "df" "df"
== "dfd"
>> ;; so above shows that "df" is present more than once - so not unique
>> ;; whereas below returns NONE because "fa" found only once - ie. bingo!
>> find next find "asdfasdfd" "fa" "fa"
== none