Problem of the Day
A new programming or logic puzzle every Mon-Fri

Combo Word

What a glorious Monday it is!

Today's goal is to create a function that takes in a word (no spaces or dashes) and determines if that word is created from two or more smaller words. For instance the word "newspaper" is a combination of "news" and "paper". All smaller words must contain at least 2 letters, thus all words passed to this function must be 4 characters or more. Here is an English dictionary to get you started. Feel free to use any language dictionary you want though.

Permalink: http://problemotd.com/problem/combo-word/

Comments:

  • Anonymous - 8¬†years, 1¬†month ago

    inputword = raw_input("Enter a word> ")
    p = len(inputword)
    
    wordlist = []
    
    file = open('WordsEn.txt', 'r')
    for line in file:
        if len(line) <= p+2:
            wordlist.append(line[0:(len(line)-2)])
    
    pointer = 2
    
    combo = []
    
    while pointer <= (p - 2):
        a = inputword[0:pointer]
        b = inputword[pointer:p]
    
        if a in wordlist:
            if b in wordlist:
                combo.append([a,b])
    
        pointer = pointer + 1
    
    print combo
    

    Output: $ python comboword.py Enter a word> crossword [['cros', 'sword'], ['cross', 'word']]

    reply permalink

Content curated by @MaxBurstein