#!/usr/local/bin/sage # -*- python -*- # Nathaniel Shar # HW 18 # Experimental Mathematics # It is okay to link to this assignment on the course webpage. ############# # Problem 1 # ############# # This is the hardest problem of the year. I can't really think of # anything neat to write. Oh well.... def LookSay(first, n): if n <= 1: return [first] else: return LookSayOneStep(LookSay(first, n-1)) def LookSayOneStep(L): i = 0 count = 1 r = [] while i < len(L): if i == len(L) - 1: r.append(count) r.append(L[i]) elif L[i+1] == L[i]: count += 1 else: r.append(count) r.append(L[i]) count = 1 i+=1 return r def EstLookSayConst(n): return (len(LookSay(1, n))+0.0)/len(LookSay(1, n-1)) print EstLookSayConst(40) # gives 1.30423.... # The look-say sequence is neat, isn't it?