ABC Blocks

Challenge: ABC Blocks

You are given a collection of blocks with two letters of the alphabet on each block. A complete alphabet is guaranteed among all sides of the blocks. You would like to check if a given word can be written with the provided set of blocks.

An example set of blocks:

 (F E)
 (A W)
 (Q V)
 (B M)
 (X H)
 (N P)
 (I Z)
 (G U)
 (S R)
 (K Y)
 (T L)
 (O C)
 (J D)
 (A N)
 (O B)
 (E R)
 (F S)
 (L Y)
 (P C)
 (Z M)

Your task for this challenge is to write a generator abc-blocks. It takes a cell of two arguments. The first argument is a (list (pair @t @t)) which represents the input set of blocks. The second argument is a @t which represents the word that you'd like to check.

Your generator should first check if the input blocks cover all letters of the alphabet. If not, the generator should fail (possibly returning an error message). It should also check if the input word only has alphabetical characters (no spaces, numbers, or special characters). Otherwise it should fail. Then, it should check whether the word can be spelled with the blocks, either returning a %.y or %.n. It should not care about case, for the blocks or for the word.

Example usage:

Unit Tests

Following a principle of test-driven development, we compose a series of tests which allow us to rigorously check for expected behavior.

Solutions

These solutions were submitted by the Urbit community as part of a competition in ~2023.6. They are made available under the MIT License and CC0. We ask you to acknowledge authorship should you utilize these elsewhere.

Solution #1

By ~dozreg-toplud. In the process, he found and fixed a bug in the implementation of +curr.

Solution #2

By ~bantus-follus

Solution #3

By ~dannul-bortux

Last updated