How to resolve the algorithm ABC problem step by step in the Common Lisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm ABC problem step by step in the Common Lisp programming language
Table of Contents
Problem Statement
You are given a collection of ABC blocks (maybe like the ones you had when you were a kid).
There are twenty blocks with two letters on each block.
A complete alphabet is guaranteed amongst all sides of the blocks.
The sample collection of blocks:
Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks.
The rules are simple:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm ABC problem step by step in the Common Lisp programming language
Source code in the common programming language
(defun word-possible-p (word blocks)
(cond
((= (length word) 0) t)
((null blocks) nil)
(t (let*
((c (aref word 0))
(bs (remove-if-not #'(lambda (b)
(find c b :test #'char-equal))
blocks)))
(some #'identity
(loop for b in bs
collect (word-possible-p
(subseq word 1)
(remove b blocks))))))))
You may also check:How to resolve the algorithm Strip control codes and extended characters from a string step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Price fraction step by step in the Pascal programming language
You may also check:How to resolve the algorithm Define a primitive data type step by step in the Pascal programming language
You may also check:How to resolve the algorithm Polynomial long division step by step in the Phix programming language
You may also check:How to resolve the algorithm Permutations by swapping step by step in the BASIC programming language