Alex Giannakopoulos 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
>
>
diffdig =: *./@~:@(#.^:_1)
10 diffdig"0 ] 01234509 123 1001
1 1 0
--
View this message in context:
http://old.nabble.com/Finding-numbers-with-_distinct_-digits-tp32278688s24193p32278751.html
Sent from the J Programming mailing list archive at Nabble.com.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm