How to resolve the algorithm ABC problem step by step in the Icon and Unicon programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm ABC problem step by step in the Icon and Unicon 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 Icon and Unicon programming language
Source code in the icon programming language
procedure main(A)
blocks := ["bo","xk","dq","cp","na","gt","re","tg","qd","fs",
"jw","hu","vi","an","ob","er","fs","ly","pc","zm",&null]
every write("\"",word := !A,"\" ",checkSpell(map(word),blocks)," with blocks.")
end
procedure checkSpell(w,blocks)
blks := copy(blocks)
w ? return if canMakeWord(blks) then "can be spelled"
else "can not be spelled"
end
procedure canMakeWord(blks)
c := move(1) | return
if /blks[1] then fail
every i := 1 to *blks do {
if /blks[i] then (move(-1),fail)
if c == !blks[i] then {
blks[1] :=: blks[i]
if canMakeWord(blks[2:0]) then return
blks[1] :=: blks[i]
}
}
end
You may also check:How to resolve the algorithm Append a record to the end of a text file step by step in the COBOL programming language
You may also check:How to resolve the algorithm Archimedean spiral step by step in the Rust programming language
You may also check:How to resolve the algorithm Sorting algorithms/Pancake sort step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Include a file step by step in the Harbour programming language
You may also check:How to resolve the algorithm Shoelace formula for polygonal area step by step in the Arturo programming language