Here's the problem i was trying to solve :

The number 197 is called a circular prime because all rotations of the
digits: 197, 971, and 719, are themselves prime. There are thirteen such
primes below 100. How many circular primes are there below One million? Link
to problem on Quora.
<https://www.quora.com/Number-197-is-called-a-circular-prime-because-all-rotations-of-the-digits-197-971-and-719-are-themselves-prime-There-are-thirteen-such-primes-below-100-How-many-circular-primes-are-there-below-One-million-What-will?__nsrc__=4>

Here's my solution - thanks to ethiejiesa:

*#m=.n#~;*./ea p=.1 p: ea ~. ea 10#.ea(|.~ ,.@i.@#)&.> sep ea n=.1 to 1e6*

*55*

There are 55 circular primes in the integers from 1 to 1e6.

List them:

* m*

* 2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199 311 337 373 719 733
919 971 991 1193 1931 3119 3779 7793 7937 9311 9377 11939 19391 19937 37199
39119 71993 91193 93719 93911 99371 193939 199933 319993 331999 391939
393919 919393 933199 939193 939391 993319 999331*
Skip


On Sat, Oct 31, 2020 at 1:58 AM Skip Cave <[email protected]> wrote:

> Wow! That will take me some studying to understand, but that is exactly
> what I needed. Thanks so much!
>
> Skip
>
>
> Skip Cave
> Cave Consulting LLC
>
>
> On Sat, Oct 31, 2020 at 1:33 AM ethiejiesa via Programming <
> [email protected]> wrote:
>
>> What about something like this?
>>
>>        (|.~ ,.@i.@#)&.> n
>>     ┌─────┬─────────┬───┬───────┐
>>     │1 2 3│4 5 6 7 8│8 6│3 5 7 9│
>>     │2 3 1│5 6 7 8 4│6 8│5 7 9 3│
>>     │3 1 2│6 7 8 4 5│   │7 9 3 5│
>>     │     │7 8 4 5 6│   │9 3 5 7│
>>     │     │8 4 5 6 7│   │       │
>>     └─────┴─────────┴───┴───────┘
>>
>> Skip Cave <[email protected]> wrote:
>> > Is there a more concise way to express m rotations of each of a set of
>> > items?
>> >
>> > ]n=.1 2 3;4 5 6 7 8;8 6;3 5 7 9
>> >
>> > ┌─────┬─────────┬───┬───────┐
>> >
>> > │1 2 3│4 5 6 7 8│8 6│3 5 7 9│
>> >
>> > └─────┴─────────┴───┴───────┘
>> >
>> > m=. 0, 1, 2, 3, 4 NB. Number of rotations
>> >
>> > ea =. each
>> >
>> >
>> > n,.(1|.ea n),.(2|.ea n),.(3|.ea n),.(4|.ea n)
>> >
>> > ┌─────────┬─────────┬─────────┬─────────┬─────────┐
>> >
>> > │1 2 3 │2 3 1 │3 1 2 │1 2 3 │2 3 1 │
>> >
>> > ├─────────┼─────────┼─────────┼─────────┼─────────┤
>> >
>> > │4 5 6 7 8│5 6 7 8 4│6 7 8 4 5│7 8 4 5 6│8 4 5 6 7│
>> >
>> > ├─────────┼─────────┼─────────┼─────────┼─────────┤
>> >
>> > │8 6 │6 8 │8 6 │6 8 │8 6 │
>> >
>> > ├─────────┼─────────┼─────────┼─────────┼─────────┤
>> >
>> > │3 5 7 9 │5 7 9 3 │7 9 3 5 │9 3 5 7 │3 5 7 9 │
>> >
>> > └─────────┴─────────┴─────────┴─────────┴─────────┘
>> >
>> >
>> > Or better yet with no duplicated rotations::
>> >
>> > 2 7$~.,n,.(1|.ea n),.(2|.ea n),.(3|.ea n),.(4|.ea n)
>> >
>> > ┌─────────┬─────┬─────┬─────────┬─────────┬─────────┬─────────┐
>> >
>> > │1 2 3 │2 3 1│3 1 2│4 5 6 7 8│5 6 7 8 4│6 7 8 4 5│7 8 4 5 6│
>> >
>> > ├─────────┼─────┼─────┼─────────┼─────────┼─────────┼─────────┤
>> >
>> > │8 4 5 6 7│8 6 │6 8 │3 5 7 9 │5 7 9 3 │7 9 3 5 │9 3 5 7 │
>> >
>> > └─────────┴─────┴─────┴─────────┴─────────┴─────────┴─────────┘
>> >
>> > Can this be done using iteration rather than explicitly listing each
>> > rotation?
>> >
>> > 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
>>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to