How to resolve the algorithm ABC problem step by step in the Transd programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm ABC problem step by step in the Transd 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 Transd programming language

Source code in the transd programming language

#lang transd

MainModule: {
    blocks: ["BO", "XK", "DQ", "CP", "NA", "GT", "RE", "TG", "QD", "FS", 
		"JW", "HU", "VI", "AN", "OB", "ER", "FS", "LY", "PC", "ZM"],
    words: ["A","BARK","BOOK","TREAT","COMMON","SQUAD","CONFUSE"],

    testMake: Lambda Bool>(λ 
        w String() v Vector() 
        locals: c (toupper (subn w 0))
        (for bl in v do
            (if (contains bl c)
                (if (== (size w) 1) (ret true))
                (if (exec testMake (sub w 1) (erase (cp v) @idx)) 
                    (ret true)))
        )
        (ret false)
    ),
	_start: (lambda
        (for word in words do
            (lout :boolalpha word " : "
                (exec testMake word blocks))
        )
    )
}

  

You may also check:How to resolve the algorithm Sum of squares step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Solve a Holy Knight's tour step by step in the Python programming language
You may also check:How to resolve the algorithm Compound data type step by step in the BASIC programming language
You may also check:How to resolve the algorithm Input loop step by step in the NodeJS programming language
You may also check:How to resolve the algorithm Color of a screen pixel step by step in the Smalltalk programming language