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 8:09

Damn Python.

Name: Anonymous 2013-02-23 8:30

Bump.

Name: Anonymous 2013-02-23 8:35

Don't fucking ``bump´´ or we'll sage this shit to hell

Anyway, just define an inductive definition for the problem

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))

Name: Anonymous 2013-02-23 11:54

>>5
You're only getting the wrong answer cause its not take the compression factor correctly.

Name: Anonymous 2013-02-23 16:14

>>5
>+=

Name: Anonymous 2013-02-23 18:44

>python

Name: Anonymous 2013-02-23 19:31


~normal
[spoiler]
n = [1:3]
for (iter=n)
  h += ch * (1 - 1/100000)^n
[/spoiler]

~rec
[spoiler]
n = [1:3]
for (iter=n)
  h = h * (1 - 1/100000) + ch
[/spoiler]

Name: Anonymous 2013-02-23 21:32

then guestimate_n = ceil(target_h / ch)

actually this seems like a reasonable use of recursion.. n multiplies v 2n optim.(?) / sum(1:n) basic

Name: Anonymous 2013-02-24 1:33

Wat

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