reset password
Author Message
LuisG72
Posts: 36
Posted 12:35 Apr 08, 2017 |

Has anyone figured out how to print the substrings in order by size, so far I can only print all the substrings but they are not in order. 

kknaur
Posts: 540
Posted 13:09 Apr 08, 2017 |

Email me your code.  I am curious as to how you solved the problem without printing them in order.

LuisG72
Posts: 36
Posted 13:19 Apr 08, 2017 |

I emailed you code, also where we supposed to use methods?

kknaur
Posts: 540
Posted 13:28 Apr 08, 2017 |

You can think about what methods to use.  For this problem it is ok to only have one other method. 

jgarc629
Posts: 76
Posted 20:51 Apr 09, 2017 |

I've gotten some substrings but they aren't in order either. Am I supposed to be using a nested for loop for this? Not sure if I'm doing this right. 

LuisG72
Posts: 36
Posted 20:54 Apr 09, 2017 |

I was able to do this with only two for loops, the first outer for loop controls the number of characters in the substrings, the inner loops controls the substring itself. 

Arnav98
Posts: 48
Posted 23:05 Apr 09, 2017 |

I got all the substrings within like 30 lines of codes but mine aren't in order either. Does anyone know how to arrange them in order ?

jzunig20
Posts: 38
Posted 01:17 Apr 10, 2017 |

begin with tracing the for loops. see which indices are needed for the single character substring and try to figure out how you can make the loops give the the indices in the correct order 

what i did was i wrote out a word and next to the single letters, i wrote down the indices i needed in order to print the single character substrings and then moved on to the 2 character substring and so on, 

you definitely will need nested for loops. 

i figured out how to get the substrings in the correct order without using methods then i implemented the methods maybe that will help 

 

sdo8
Posts: 54
Posted 20:11 Apr 10, 2017 |

This problem is a bit tricky. My suggestion would be to take a look at the pattern of the output. Notice how it starts off with only 1 character, then 2 characters, then 3 characters, etc. to the final substring (of itself). By taking out every possible snippet of the word, you eventually get all of the substrings. However, you have to find out a way to start out with single character strings, then two character strings, and at the same time changing the position of where your string is about to be read). I used nested loops and ended up with maybe 20~ lines of code. What I really can't find out is how to implement a method in this. Could I just take create a method and use the user-inputted word as the argument, then call that method?

kknaur
Posts: 540
Posted 20:16 Apr 10, 2017 |
sdo8 wrote:

This problem is a bit tricky. My suggestion would be to take a look at the pattern of the output. Notice how it starts off with only 1 character, then 2 characters, then 3 characters, etc. to the final substring (of itself). By taking out every possible snippet of the word, you eventually get all of the substrings. However, you have to find out a way to start out with single character strings, then two character strings, and at the same time changing the position of where your string is about to be read). I used nested loops and ended up with maybe 20~ lines of code. What I really can't find out is how to implement a method in this. Could I just take create a method and use the user-inputted word as the argument, then call that method?

Yes, and that method can generate the substrings.

sdo8
Posts: 54
Posted 12:13 Apr 11, 2017 |

Alright, great! Thank you.