User:Roelroscama/trim2/protoyping2/collatz

From XPUB & Lens-Based wiki
< User:Roelroscama‎ | trim2‎ | protoyping2
Revision as of 01:13, 23 January 2013 by Roelroscama (talk | contribs) (→‎Collatz Pattern Script)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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)