User:Roelroscama/trim2/protoyping2/collatz: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "=== Collatz Pattern Script === http://pzwart3.wdka.hro.nl/~rroscam/collatz_pattern_documentation.ogv")
 
 
Line 2: Line 2:


http://pzwart3.wdka.hro.nl/~rroscam/collatz_pattern_documentation.ogv
http://pzwart3.wdka.hro.nl/~rroscam/collatz_pattern_documentation.ogv
<source lang="python">
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import os, sys
#import time
def collatz(n):
        #print(n)
        while n != 1:
                if    n%2 == 0:
                        n = n/2
                else:
                        n = 3*n +1
                ConvertInt(n)
                #print n
        return n
                #time.sleep(0.02)
try:
        n = int(sys.argv[1])
except IndexError:
        n = 100
except ValueError:
        print "Please type a number"
        sys.exit()
def ConvertInt(integ):
        ding = ""
        number_string = str(integ)
        for ch in str(number_string):
                if int(ch)%2 == 0:
                        ding+="‚ñÜ"
                elif int(ch)%2 != 0:
                        ding+=" "
        print unicode(ding, "utf-8")
collatz(n)
</source>

Latest revision as of 00:13, 23 January 2013

Collatz Pattern Script

http://pzwart3.wdka.hro.nl/~rroscam/collatz_pattern_documentation.ogv


#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import os, sys
#import time

def collatz(n):
        #print(n)
        while n != 1:
                if    n%2 == 0:
                        n = n/2
                else:
                        n = 3*n +1
                ConvertInt(n)
                #print n
        return n
                #time.sleep(0.02)

try:
        n = int(sys.argv[1])
except IndexError:
        n = 100
except ValueError:
        print "Please type a number"
        sys.exit()

def ConvertInt(integ):
        ding = ""
        number_string = str(integ)
        for ch in str(number_string):
                if int(ch)%2 == 0:
                        ding+="▆"
                elif int(ch)%2 != 0:
                        ding+=" "
        print unicode(ding, "utf-8")

collatz(n)