Teacup rim text: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
|||
Line 473: | Line 473: | ||
=={{header|J}}== |
=={{header|J}}== |
||
Definitions, which are developed following the solution |
|||
<lang J> |
|||
read=: CR -.~ 1!:1@boxopen NB. dang that line end! |
|||
Filter=:(#~`)(`:6) |
|||
prep=: (;~ /:~);._2 |
|||
gba=: <@:([: ,/ (>@}."1))/.~ 0&{"1 |
|||
ew=: (>:&# {.)S:_1 Filter |
|||
le=: (2 < #@{.)S:_1 Filter |
|||
ra=: a: -.~ rotations&> |
|||
NB. prep was separated for fun, not necessity |
|||
teacup=: ra@:le@:ew@:gba |
|||
rotations=: 3 :0 |
|||
subset=: 0 = #@:-. |
|||
assert. 0 1 -: 'ab'(subset~ , subset)'cabag' |
|||
N=. # {. y |
|||
for_word. y do. |
|||
a=. N ]\ (, (<: N)&{.) word |
|||
if. a subset y do. word return. end. |
|||
end. |
|||
'' |
|||
) |
|||
</lang> |
|||
Solution finds "apt", "arc", and "ate". |
|||
<lang J> |
|||
NB. D includes the ordered anagram |
|||
D=: prep read'd:\tmp\dict' |
|||
NB. transposed samples of the input to teacup |
|||
|: ({~ (7 ?@$ #)) D |
|||
┌──────────┬────────────┬───────┬──────────┬──────┬────────┬────────┐ |
|||
│ aaegnprty│ aadeiloprtz│ gmpsuy│ eimnnptuu│ aipst│ agggint│ effoprr│ |
|||
├──────────┼────────────┼───────┼──────────┼──────┼────────┼────────┤ |
|||
│pageantry │trapezoidal │gypsum │neptunium │tapis │tagging │proffer │ |
|||
└──────────┴────────────┴───────┴──────────┴──────┴────────┴────────┘ |
|||
teacup D |
|||
┌───┬───┬───┐ |
|||
│apt│arc│ate│ |
|||
└───┴───┴───┘ |
|||
</lang> |
|||
The action of the individual verbs shown here along with intermediate pronouns having such descriptive names as to describe the proverbial names demonstrates the construction of teacup. |
|||
<lang J> |
|||
TEST_DICTIONARY=: 'abc ah ate bac bca blort cab eat ha rat tar tea tra ' |
|||
TEST=: prep TEST_DICTIONARY |
|||
] GROUPS_BY_ANAGRAM=: gba TEST |
|||
┌───┬──┬───┬─────┬───┐ |
|||
│abc│ah│ate│blort│rat│ |
|||
│bac│ha│eat│ │tar│ |
|||
│bca│ │tea│ │tra│ |
|||
│cab│ │ │ │ │ |
|||
└───┴──┴───┴─────┴───┘ |
|||
] ENOUGH_WORDS=: ew GROUPS_BY_ANAGRAM |
|||
┌───┬──┬───┬───┐ |
|||
│abc│ah│ate│rat│ |
|||
│bac│ha│eat│tar│ |
|||
│bca│ │tea│tra│ |
|||
│cab│ │ │ │ |
|||
└───┴──┴───┴───┘ |
|||
] LONG_ENOUGH=: le ENOUGH_WORDS |
|||
┌───┬───┬───┐ |
|||
│abc│ate│rat│ |
|||
│bac│eat│tar│ |
|||
│bca│tea│tra│ |
|||
│cab│ │ │ |
|||
└───┴───┴───┘ |
|||
] SOLUTION=: ROTATIONS_ACCEPTABLE=: ra LONG_ENOUGH |
|||
┌───┬───┐ |
|||
│abc│ate│ |
|||
└───┴───┘ |
|||
</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|C++}} |
{{trans|C++}} |