This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prep=: ranks @: makeHand | |
assert -. isAceLowStraight prep '6 D 4 H 3 C 2 S A C' | |
assert -. isAceLowStraight prep '6 H 5 D 4 H 3 C 2 S' | |
assert isAceLowStraight prep '5 D 4 H 3 C 2 S A C' | |
assert isAceLowStraight prep '5 D 4 D 3 D 2 D A D' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NB. These snippets are involved with a J implementation of RCRPG: http://rosettacode.org/wiki/Category:RCRPG | |
NB. That solution is still being written, so has not yet been posted to that website. | |
NB. The exercise of eliminating control-statements was largely inspired by the conversation on Twitter with @Huperniketes that included this comment: https://twitter.com/Huperniketes/status/240917975228637185 | |
NB. NOTE: The version posted earlier, with tacit definitions of verbs such as fail_tool, did not work. The final portion has been corrected to fix this. | |
NB. Here's the original version of the verb 'dig' (omitting definitions of included names) | |
dig=: 3 : 0 | |
if. PC_equipped includes 1 Sledge do. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NB. preparatory | |
OrFailureReport=: adverb : ' u ` asFailure @. fails ' | |
UnlessFailed=: adverb : ' u ` ] @. fails ' | |
NotingUnknownParsingError=: ::((makeFailure 'Unknown error in parsing attempt.')"_) | |
FAILMARK=: < s:'`_|_' NB. arbitrary | |
makeFailure=: [: < FAILMARK ; < :[: | |
fails=: [:+./ [:flatten (FAILMARK e. ]) L:1 | |
NB. main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'byRow byColumn'=: <"0 s:' Row Column' NB. these two names may be any two distinct values | |
nix=: 2 :' #~"(1+n=byRow) -.@ u"(1+n=byColumn) ' | |
NB. examples of use: | |
(2={.) nix byColumn i. 3 5 | |
0 1 3 4 | |
5 6 8 9 | |
10 11 13 14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
whitespace=: 9 10 32 { a. | |
vowel =: ( , toupper) 'aeiou' | |
consonant =: vowel -.~ a.{~ , 97 65 +"0 _ i.26 | |
other =: a. -. whitespace, vowel, consonant | |
kind=: whitespace; vowel; consonant; other | |
count=: ([: +/ ] e. >@[ )" _1 _ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NB. The Prime Factor Kata, in J | |
NB. -- an exercise in humor -- | |
NB. Inspired by http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata | |
NB. RED | |
testPrimeFactors =: 3 : 0 | |
assert ($0) -: primefactors 1 NB. add test of 1 | |
) | |
NB. GREEN |