ABC problem: Difference between revisions
Content added Content deleted
m (Adjust formatting) |
(→{{header|J}}: Add J) |
||
Line 48: | Line 48: | ||
True |
True |
||
</lang> |
</lang> |
||
=={{header|J}}== |
|||
'''Solution:''' |
|||
<lang j>can_make_word=: #/.~@] *./@:<: #/.~@[ {~ ~.@[ i.&(tolower@~.) ]</lang> |
|||
'''Examples''' |
|||
<lang j>Blocks=: , ];._2 noun define |
|||
BO |
|||
XK |
|||
DQ |
|||
CP |
|||
NA |
|||
GT |
|||
RE |
|||
TG |
|||
QD |
|||
FS |
|||
JW |
|||
HU |
|||
VI |
|||
AN |
|||
OB |
|||
ER |
|||
FS |
|||
LY |
|||
PC |
|||
ZM |
|||
) |
|||
ExampleWords=: a: , ;:'A BARK BOOK TREAT COMMON SQUAD' |
|||
Blocks&can_make_word &> ExampleWords |
|||
1 1 1 1 1 0 1</lang> |
Revision as of 20:01, 8 January 2014
ABC problem is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
You are given a set of ABC blocks. Just like the ones you had when you were a kid. There are twenty blocks with two letters on each block. You are guaranteed to have a complete alphabet amongst all sides of the blocks. The sample blocks are:
- ((B O)
- (X K)
- (D Q)
- (C P)
- (N A)
- (G T)
- (R E)
- (T G)
- (Q D)
- (F S)
- (J W)
- (H U)
- (V I)
- (A N)
- (O B)
- (E R)
- (F S)
- (L Y)
- (P C)
- (Z M))
The goal of this task is to write a function that takes a string and can determine whether you can spell the word with the given set of blocks. The rules are simple:
- Once a letter on a block is used that block cannot be used again
- The function should be case-insensitive
- Example
<lang python>
>>> can_make_word("") False >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True
</lang>
J
Solution: <lang j>can_make_word=: #/.~@] *./@:<: #/.~@[ {~ ~.@[ i.&(tolower@~.) ]</lang>
Examples <lang j>Blocks=: , ];._2 noun define BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM )
ExampleWords=: a: , ;:'A BARK BOOK TREAT COMMON SQUAD'
Blocks&can_make_word &> ExampleWords
1 1 1 1 1 0 1</lang>