Skip to content
/ llfl Public

Solution to "last letter-first letter" problem.

Notifications You must be signed in to change notification settings

MauKMu/llfl

Repository files navigation

llfl

Solution to exercise 45 from http://www.ling.gu.se/~lager/python_exercises.html, quoted below:

"""

A certain childrens game involves starting with a word in a particular category. Each participant in turn says a word, but that word must begin with the final letter of the previous word. Once a word has been given, it cannot be repeated. If an opponent cannot give a word in the category, they fall out of the game. For example, with "animals" as the category,

Child 1: dog

Child 2: goldfish

Child 1: hippopotamus

Child 2: snake ...

Your task in this exercise is as follows: Take the following selection of 70 English Pokemon names (extracted from Wikipedia's list of Pokemon) and generate the/a sequence with the highest possible number of Pokemon names where the subsequent name starts with the final letter of the preceding name. No Pokemon name is to be repeated.

audino bagon baltoy banette bidoof braviary bronzor carracosta charmeleon cresselia croagunk darmanitan deino emboar emolga exeggcute gabite girafarig gulpin haxorus heatmor heatran ivysaur jellicent jumpluff kangaskhan kricketune landorus ledyba loudred lumineon lunatone machamp magnezone mamoswine nosepass petilil pidgeotto pikachu pinsir poliwrath poochyena porygon2 porygonz registeel relicanth remoraid rufflet sableye scolipede scrafty seaking sealeo silcoon simisear snivy snorlax spoink starly tirtouga trapinch treecko tyrogue vigoroth vulpix wailord wartortle whismur wingull yamask

"""

Notes:

Takes about 5 million calls to process 70 Pokemon.

Running time for even 151 Pokemon seems to be far too much. Will look into dynamic programming/efficient longest-path algorithms to improve on this!

About

Solution to "last letter-first letter" problem.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages