Kip, This is impressive!

If I had ever learned how to write formal proofs, I think there must be one
lurking in here somewhere:

    collatz =: ([:$: (] , -:@{:)`(] , 1 + 3 * {:)@.(2&|@{:))`]@.(1= {:)
   
Your definition (slight style modification)
   
   Ckm=: ([:$: (] , [:-:{:)`(] , 1 + 3 * {:)@.(2|{:))`]@.(1= {:)
   
   collatz 23
23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1
   Ckm 23
23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1

Primes under 100   
   p0=: i.&.(p:^:_1)
   p0 100
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
   
All prime that appeared in  Ckm 97
   ((Ckm 97) e.p0 100)#Ckm 97
97 73 83 47 71 61 23 53 5 2
   
  
   |.C 97
1 2 4 8 16 5 10 20 40 80 160 53 106 35 70 23 46 92 184 61 122 244 488 976
325 650 1300 433 866 1732 577 1154 2308 4616 9232 3077 6154 2051 4102 1367
2734 911 1822 3644 7288 2429 4858 1619 3238 1079 2158 719 1438 479 958 319
638 1276 425 850 283 566 1132 37...
  
   |.C 83
1 2 4 8 16 5 10 20 40 80 160 53 106 35 70 23 46 92 184 61 122 244 488 976
325 650 1300 433 866 1732 577 1154 2308 4616 9232 3077 6154 2051 4102 1367
2734 911 1822 3644 7288 2429 4858 1619 3238 1079 2158 719 1438 479 958 319
638 1276 425 850 283 566 1132 37...
  
   C 97
97 292 146 73 220 110 55 166 83 250 125 376 188 94 47 142 71 214 107 322 161
484 242 121 364 182 91 274 137 412 206 103 310 155 466 233 700 350 175 526
263 790 395 1186 593 1780 890 445 1336 668 334 167 502 251 754 377 1132 566
283 850 425 1276 638 319 958...
   C 73
73 220 110 55 166 83 250 125 376 188 94 47 142 71 214 107 322 161 484 242
121 364 182 91 274 137 412 206 103 310 155 466 233 700 350 175 526 263 790
395 1186 593d 1780 890 445 1336 668 334 167 502 251 754 377 1132 566 283 850
425 1276 638 319 958 479 1438 7...
   
When you reverse the sequence you can see that somewhere they began to match
first at 73 and then in successive primes earlier in the list of primes in
Ckm .

Linda

-----Original Message-----
From: programming-boun...@forums.jsoftware.com [mailto:programing-Sent:
Thursday, October 25, 2012 7:23 AMc
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Collatz and stuff
i
   collatz =: ([: $: (] , -:@{:)`(] , 1 + 3 * {:)@.(2&|@{:))`]@.(1 = {:)
   collatz 1
1
   collatz 2
2 1
   collatz 3
3 10 5 16 8 4 2 1
   collatz 4
4 2 1
   collatz 5
5 16 8 4 2 1
   collatz 6
6 3 10 5 16 8 4 2 1

Above uses Agenda @. and Self-Reference $: and test for oddness 2&| borrowed
from Phrases. The assumed right argument is the initial part of a Collatz
sequence.  Tail {: provides the tail (last term) of a sequence.

Kip Murray

Sent from my iPad


On Oct 25, 2012, at 4:44 AM, Brian Schott <schott.br...@gmail.com> wrote:

> http://www.jsoftware.com/jwiki/Essays/Collatz%20Conjecture
> 
> On Thu, Oct 25, 2012 at 5:12 AM, Stefan Stankovic 
> <anonimnist...@gmail.com> wrote:
>> I have just started learning J and I think the language is wonderful. 
>> It is breathtaking.
>> 
>> I have a question about a basic thing-how can I create a monad 
>> (preferably
>> tacit) which will, given input x,provide a list of numbers which 
>> contains the Collatz seqyence for the given x? Thanks in advance.
> ----------------------------------------------------------------------
> 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