Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Better challenge

Name: Anonymous 2011-02-09 11:54

Prove that this program terminates for all positive values of n.


def sequence(n):
  while n != 1:
    print n,
    if n%2 == 0:        # n is even
      n = n/2
    else:               # n is odd
      n = n*3+1

Name: Anonymous 2011-02-09 12:02

>>1
If you going to post open mathematical problems, at least found problem that is not known to any retard.

Name: Anonymous 2011-02-09 12:14

n must be a positive natural number.
If you get any number that equal to a power of two, eventually it will get back to two and then become 1 and quit.  If you get any number that is not even, you will turn it into an even number (multiplying odd numbers always produce odd numbers) and will eventually become a power of two number.  In the following example, 3 becomes 10 becomes 5 becomes 16 which reduces to 1.
(3)*3 + 1 = 10
(10)/2 = 5
(5)+3 + 1 = 16
(16)/2 = 8
(8)/2 = 4
(4)/2 = 2
(2)/2 = 1

To further demonstrate:
[m](7)*3 + 1 = 22
(22)/2 = 11
(11)*3 + 1 = 34
(34)/2 = 17
(17)*3 + 1 = 52
(52)/2 = 26
(26)/2 = 13
(13)*3 + 1 = 40
(40)/2 = 20
(10)/2 = 5
...
(2)/2 = 1[m]
What I am not certain how to explain is how this formula is guaranteed to encounter a power of two number.

Name: Anonymous 2011-02-09 12:15

Forgot my [/m] tag.

Name: Anonymous 2011-02-09 12:31

>>1
>Prove that this program terminates for all positive values of n.
Define "all", Jew.

Name: Anonymous 2011-02-09 12:52

I never heard of it, but I was able to prove it in 3 minutes.
The proof is left as an exercise to >>9.

Name: Anonymous 2011-02-09 12:53

>>8
Hi there, Fermat.

Name: Anonymous 2011-02-09 15:25

This is a math challenge, not a PROGRAMMING one

Name: Anonymous 2011-02-10 8:34

The function is never called so the program always terminates successfully as per the Python standard.

Name: Anonymous 2011-02-10 12:05

>>14
fuck off faggot

Name: Anonymous 2011-02-10 12:10

>>13
nice

Name: Anonymous 2011-02-10 17:43

I'm working on a proof based on bit shifts but my anus hurts and it's not done yet

is there any known formal solution for this?

Name: Anonymous 2011-02-10 18:39

Name: Anonymous 2011-02-10 18:55

Name: sage 2011-02-10 21:01

>>19
Ruined it.

Don't change these.
Name: Email:
Entire Thread Thread List