Find words that rhyme

-1

Challenge

Joe the rapper is struggling with rhyming words in his lyrics. He needs your help.

For this situation, we will use rhymes where the last syllable in a word is the same as the other word (spelled the same).

When Joe inputs a word, the program will read a list of words from a file and output those that rhyme with Joe's word.

To show that the program works, we will only need to use a small list.

txt File:

hello
joe
crew
flow
time
apple
heart
glow
rhyme
art
jello
grew
doe
flue
blow
smart
dime
cat
slime
show
bedtime
clue
grime
toe
dart
cart
brew
snow
prime
hat
chart
lime
blue
knew
lunchtime
restart

Examples

Input: snow

Output: blow flow glow show Note- Should not output the input

Input: fart

Output: restart art dart cart chart smart heart Note- Should work for inputs not in list

Input: crime

Output: time slime prime grime dime lime bedtime lunchtime Note- Should work for all syllables

Rules

  1. Should output all words that rhyme with input

    does not need to output rhymes with different letters Ex: Crime should not output rhyme

  2. Should not output the input

  3. Should work with inputs not in the list
  4. Should work will all syllables

Shortest Bytes Wins!

JoshK

Posted 2016-05-20T04:24:24.840

Reputation: 139

Question was closed 2016-05-20T13:34:20.253

1Define "rhyme". Does "bedtime" rhyme with "clue"? – Leaky Nun – 2016-05-20T09:11:32.120

See comments on http://meta.codegolf.stackexchange.com/a/7014/194 for a suggestion as to how to make "rhyme" well-specified.

– Peter Taylor – 2016-05-20T10:30:30.837

@Peter I think JoshK is looking for something simpler than phonetic rhyming. does not need to output rhymes with differet letters and snow --> blow flow glow show (but not toe) Anyway, Josh, a proper definition is required. Given examples follow the rule of last vowel and all consonants after it (this works for chart & heart but would fail for chat & heat.) As shown by Kenny Lau's example, matching the whole of the last vowel cluster (and any following consonants) may be better but would make heart invalid. Voting to close until resolved. (personally I'd get rid of heart) – Level River St – 2016-05-20T10:52:40.750

As you haven't been here that long, I'll point out that the reason for close voting is nothing personal, it's to temporarily stop the posting of answers before the rules have been fully clarified (as is happening right now.) You could try posting your next challeng in the sandbox for feedback first before posting on the main site http://meta.codegolf.stackexchange.com/q/2140/15599

– Level River St – 2016-05-20T10:57:08.257

Do though, through, and rough rhyme? – mbomb007 – 2016-05-20T19:12:21.603

Answers

1

JavaScript (ES6), 67 bytes

(a,w)=>a.filter(s=>s!=w&s.endsWith(w.replace(/.*([aeiou].)/,"$1")))

Function that accepts an array of words and an input word as parameters. Uses the definition of rhyme as the substring of the word starting at the last vowel before the last letter.

a=
(a,w)=>a.filter(s=>s!=w&s.endsWith(w.replace(/.*([aeiou].)/,"$1")))
;
u=w=>r.value=a(f.value.split`\n`,w).join`\n`
File:
<textarea rows=5 id=f>
hello
joe
crew
flow
time
apple
heart
glow
rhyme
art
jello
grew
doe
flue
blow
smart
dime
cat
slime
show
bedtime
clue
grime
toe
dart
cart
brew
snow
prime
hat
chart
lime
blue
knew
lunchtime
restart
</textarea>
<br>
Word:
<input oninput="u(this.value)">
<br>
Rhymes:
<textarea rows=5 id=r>
</textarea>

Neil

Posted 2016-05-20T04:24:24.840

Reputation: 95 035

What is your definition of rhyme? You should state it in English (not just code) in the answer. Better still, wait for the OP to clarify the rules before posting. – Level River St – 2016-05-20T10:58:33.780

0

Ruby, 68 bytes

FGITW. Full program, takes file and word from command line: ruby script.rb words.txt "hello".

Assumes the last syllable (or rather, the section of the syllable to match against for the purposes of rhyming) is at least 2 characters long, or more if there are extra vowels before that.

f,w=$*
w=~/[aeiou]*..$/
puts open(f).map(&:chomp).grep(/#{$&}$/)-[w]

Value Ink

Posted 2016-05-20T04:24:24.840

Reputation: 10 608