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

Spaghetti Python

Name: Anonymous 2013-02-23 7:48

I'm trying to write a program in python named get_numrubix_cubes that does the following:
It calculates how many rubix cubes it takes to stack up to any height building in meters.

Assume every rubix cube you stack is 0.057 meters on each side. However, I need to take into consideration the compression factor for every cube stacked, which is the following: ((1-1/100000)^n)

So when I run the program, this would be an example of the output:
get_numrubix_cubes(42.5) = 749

How can I do this recursively? I can't think of any way to do it. I know its already possible without the use of recursion which is blowing my mind.

Name: Anonymous 2013-02-23 9:42

is 749 really the correct answer? i get 746. here is my solution (not recursive, recursive only for faggots)

#!/usr/bin/env python
# encoding: utf-8

def get_numrubix_cubes(heightower, heightcube=0.057):
    lengthtowercube = 0
    counttube = 0
    compression = lambda n: ((1-1/100000)**n)
    while lengthtowercube <= heightower:
        lengthtowercube += heightcube * compression(counttube)
        counttube += 1
    return counttube

print(get_numrubix_cubes(42.5))

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