How to resolve the algorithm Last letter-first letter step by step in the PicoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Last letter-first letter step by step in the PicoLisp programming language

Table of Contents

Problem Statement

A certain children's 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,

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.

Extra brownie points for dealing with the full list of   646   names.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Last letter-first letter step by step in the PicoLisp programming language

Source code in the picolisp programming language

(de pokemonChain (File)
   (let Names (make (in File (while (read) (link @))))
      (for Name Names
         (let C (last (chop Name))
            (set Name
               (filter '((Nm) (pre? C Nm)) Names) ) ) )
      (let Res NIL
         (for Name Names
            (let Lst NIL
               (recur (Name Lst)
                  (if (or (memq Name Lst) (not (val (push 'Lst Name))))
                     (when (> (length Lst) (length Res))
                        (setq Res Lst) )
                     (mapc recurse (val Name) (circ Lst)) ) ) ) )
         (flip Res) ) ) )

  

You may also check:How to resolve the algorithm Make directory path step by step in the Delphi programming language
You may also check:How to resolve the algorithm Knapsack problem/0-1 step by step in the C_sharp programming language
You may also check:How to resolve the algorithm Real constants and functions step by step in the Logo programming language
You may also check:How to resolve the algorithm XML/DOM serialization step by step in the Ruby programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the Liberty BASIC programming language