+ 2
Challenge::: Return the combination of all substring from a string.
The program takes a string as input and returns all possible substrings without repeat. So, abc, bac, cba are all same. Input - - - - > abc Output - - -> ab, bc, ac, a, b, c Input - - - - > abcd Output - - ->abc, bcd, ab, bc, cd, ac, ad, bd, a, b, c, d Remember not repeatation and maintain order of main string.
5 Respuestas
+ 3
Okay it's a cheap shot, but Haskell has that built in!
import Data.List
main = interact $ show . subsequences
https://tio.run/##BcG7DYAwDAXAPlO8gjob0FGyhBMsxSIfiB0xvrkrpDfX6i7tGdNwkFE8RS2ERtKxQ7rxpGzYoGV8iNCVlN/FPbO6U8rXDw
0
Vinay, your code doesn't run and i think it just outputs random string.
0
My response in Ruby:
https://code.sololearn.com/cJ1l7GvN1VI4/?ref=app
Nice challenge - finding the different combinations is straightforward enough, only returning the unique ones is a nice addition, but what I like about this challenge is the requirement that substring characters be returned in the order they occur in the original word, that made it a little trickier.
0
Also, shouldn't the output for 'abcd' in the original question also include abd and acd? Otherwise it's not returning combinations, just sections of the input, and 'abc' output wouldn't include ac like in the original post.
- 2
##python
import string
import random
string.letters
'abc'
random.choice(string.letters)