I am working on a program that does some stuff with the collatz conjecture. I originally wrote it in Python as that is the language I am most familiar with:
n = []
mod = []
step = 0
def lstfill(nb,ne,lst):
while nb <= ne:
lst.append(nb)
nb+=1
def collatz(n, s):
for i in n:
s = 0
print "starting #", i
while i != 1:
if i%2==0:
i=i/2
s+=1
print i
mod.append(i%2)
else:
i=3*i+1
s+=1
print i
mod.append(i%2)
print "mod:", mod
print "steps:", s
lstfill(3,6,n)
collatz(n, step)
However, there are some things I need to do that I can't really do without downloading libraries and I can't do that. So I thought I'd switch to Mathematica. Except I looked at my code and realized I had no idea how to write this code in the Mathematica language. How would I manipulate lists, or create functions, or anything like that? And what is the equivalent of the modulo operator?
Any help would be appreciated. Thanks!
Mod[]
already? Have you also searched the site for "collatz"? $\endgroup$ – J. M.'s ennui♦ Oct 13 '16 at 1:54Mod[]
command! I guess I kind of wanted to be able to use my own code that I wrote in Python, just translate it, and I didn't know quite how to write a function or manipulate lists. $\endgroup$ – heather Oct 13 '16 at 1:57