It is not the shorter way: Step by step: 1) convert to string ": ": 12341 12341 (string of characters)
2) self classify = = ": 12341 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 3) add on row +/"1 +/"1 = ": 12341 2 1 1 1 4) check if one number is >1 1 < +/"1 = ": 12341 1 0 0 0 5) OR the result 0: if all digits are different 1: otherwise +./ 1 < +/"1 = ": 12341 1 +./ 1 < +/"1 = ": 0123456789 0 Make a verb: vv vv =: 13 : '+./ 1 < +/"1 = ": y' Test the verb: vv 1234 0 vv 11333222 1 vv"0 (1231 1234) 1 0 On Wed, Aug 17, 2011 at 12:55 PM, Alex Giannakopoulos < [email protected]> wrote: > Hi > > I am trying to write a verb that will tell me if the digits in a number are > distinct, > e.g. return 1 for 1234 but return 0 for 1231 > > So far I have the following, but I feel it could be tidied up a bit. > Any suggestions welcome > > filter =: 1 : #~ x > digits =: 10&#.^:_1 > distinct =: [: *./ "1 [: ~:"1 digits > distinct filter 100 101 102 103 > 102 103 > > It seems to work OK (I appreciate that number lengths must all be the same > to avoid padded zero problems), but are there any ways to tidy it up, > especially re the "1 directives? > > Many Thanks > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > -- Daniel Durieu Rue du Grand Coron, 28 B-7034-Obourg Tél: 065/ 72 32 14 e-mail: [email protected] ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
