You can. There's surely a more efficient way.

   3 <;._3 sep 123334
+-----+-----+-----+-----+
|1 2 3|2 3 3|3 3 3|3 3 4|
+-----+-----+-----+-----+
   3 (1=#@~.);._3 sep 123334
0 0 1 0
   triple =: [: +./ 3&((1=#@~.);._3)
   triple"1 sep 123334 122344 121212 111222 112122 555432
1 0 0 1 0 1
   (#~ triple"1) sep 123334 122344 121212 111222 112122 555432
1 2 3 3 3 4
1 1 1 2 2 2
5 5 5 4 3 2
   timex '$(#~ triple"1) sn'
0.906543

That takes about 80x as long as the attached method
using the FFI and a quick library in D.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Saturday, July 3rd, 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