+ 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.

8th Oct 2017, 3:45 PM
AlphaCoder
AlphaCoder - avatar
5 Antworten
+ 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
8th Oct 2017, 4:23 PM
Schindlabua
Schindlabua - avatar
0
Vinay, your code doesn't run and i think it just outputs random string.
8th Oct 2017, 4:09 PM
AlphaCoder
AlphaCoder - avatar
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.
10th Oct 2017, 8:23 PM
André
André - avatar
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.
10th Oct 2017, 8:26 PM
André
André - avatar
- 2
##python import string import random string.letters 'abc' random.choice(string.letters)
8th Oct 2017, 3:57 PM
Vinay bhor
Vinay bhor - avatar