You can win half of it if you replace   >#&.>~.&.>{3,\   by the equivalent   3 
#@~.\


R.E. Boss


-----Original Message-----
From: Programming <[email protected]> On Behalf Of Skip 
Cave
Sent: zondag 4 juli 2021 19:43
To: [email protected]
Subject: Re: [Jprogramming] Cut

Thanks for all the suggestions. That gave me the general idea.

My take using boxing (slower)

*sep=.10 #.^:_1 ]*

*#a=.n#~+./"1[1=>#&.>~.&.>{3,\"1 sep n=.1e5 to 999999*

*33219*


So there are 33,219 six-digit integers that have 3 or more identical 
consecutive digits.


* 30 timex '#a=.n#~+./"1[1=>#&.>~.&.>{3,\"1 sep n=.1e5 to 999999'*

*2.76304*


Not very fast.

Skip Cave
Cave Consulting LLC


On Sat, Jul 3, 2021 at 6:13 PM Skip Cave <[email protected]> wrote:

> Can I use cut to find all the 6-digit integers that have three 
> consecutive identical digits? Or is there a more efficient way?
>
> sep=:10#.^:_1] NB. Separate digits.
>
> to=:[+i.@:>:@-~ NB. Generate integer ranges.
>
>
> $ sn=.sep n=.1e5 to 999999 NB. Generate all the 6 digit integers and 
> separate their digits.
>
> 900000 6
>
> Now what? Can I apply cut to sn to find all 6-digit integers with 
> three consecutive identical digits? Or is there a better way?
>
>
> 123334 is correct
>
> 122344 is not correct
>
> 121212 is not correct
>
> 111222 is correct
>
> 112122 is not correct
>
> 555432 is correct
>
>
> NB. Test vector: tv=. 123334 122344 121212 111222 112122 555432
>
> Skip
>
>
> Skip Cave
> Cave Consulting LLC
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to