online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#this version is a model of 3d growth in a mold, telling you if your mycelium will fill the mold/how much mycelium you can grow in a given time. #author: Arvind Veluvali import random import math init = float(input("In square meters--what is the area of your original sample? ")) x=float(input("In meters--what is the thickness of your original sample? ")) #x represents the initial thickness of a mycelium sample/sheet. This was estimated in the lab as being around a millimeter, but is an input variable depending on whether we want to play with thickness. growperiod = int(input("To the nearest integer--how many full days of growth will your sample have? ")) base = float(input("In square meters--what is the area of the base of your mold? ")) height = float(input("In meters--what is the height of your mold? ")) initvol=x*init if init > base: print("Try again with an initial sample smaller than the base of your mold.") import sys sys.exit() if x > height: print("Try again with an initial sample shorter than the height of your mold.") import sys sys.exit() #initialize s = (0,0) grown = [] growthsites = [] grown.append(s) for mcs in range(growperiod): for n in range(len(grown)): i = random.randrange(0,len(grown), 1) s = grown[i] r = random.randrange(0,3,1) if r == 0: target = (s[0],s[1]-1) elif r == 1: target = (s[0],s[1]+1) elif r == 2: target = (s[0]-1,s[1]) elif r == 3: target = (s[0]+1,s[1]) #these statements give options of where the spore can grow next: up, down, left, right. if ((target not in grown) and (target not in growthsites)) and (len(grown) < base): growthsites.append(target) #this is the period in which the mycelia is filling the base of the mold, spreading outward but not upward. if ((len(grown) >= base) and (target in grown)) and (target not in growthsites): growthsites.append(target) #this is the period of "double growth"--when new hyphae can only grow on, and are growing on top of, already-established hyphae--hence why target must be in "grown." From what we've observed in the lab, mycelia will fill the base of the mold before it begins growing upward. #still, competition between hyphae still prevails--hence why target cannot be in growthsites. #in addition, mycelia grow more quickly outward than they do upward--hence why upward growth is subject to randomization, and isn't a sure thing (continuous upward growth doesn't really occur--this is likely a result of substrate channeling against the force of gravity). grown.extend(growthsites) #this represents a "growth period" in which growthsites are converted into mycelia. #these sites are fully integrated members of the grown list--hence the use of the extend function. growthsites = [] #print growth stats data fin = (len(grown))*init finvol = fin*x moldvol = math.ceil(base*height) #this is the volume of the mold, rounded up to the nearest integer. This will make it possible to find the convergence of this with len(grown) #the grown list contains a list of points. Each point corresponds to a square occupied by mycelia in the list. Thus, counting the points, subtracting one (for the initial sample) and multiplying that number by the size of the original sample will give you the final sample size. print(" ") #this puts in a line break between the inputs and the output if finvol < moldvol and len(grown) < base: print("After growing your initial sample of", init*x, "cubic meters for a period of", growperiod, "days, you will have grown", finvol, "cubic meters of mycelium.") print("Your mycelium will not have filled your mold in the allotted time.") print("However, your mycelium has grown from an area of", init, "square meters to an area of", fin, "square meters.") #the mycelium will only grow upward once it's filled the base area. Thus, if base area isn't filled, you're ok using fin, which would otherwise include 3d growth. if finvol < moldvol and len(grown) >= base: print("After growing your initial sample of", init*x, "cubic meters for a period of", growperiod, "days, you will have grown", finvol, "cubic meters of mycelium.") print("Your mycelium will not have filled your mold in the allotted time.") print("However, your mycelium has grown from an area of", init, "square meters to an area of", base, "square meters, completely covering the base of your mold.") if finvol >= moldvol: print("After growing your initial sample of", init*x, "cubic meters for a period of", growperiod, "days, you will have grown", moldvol, "cubic meters of mycelium.") #this statement serves to constrain the growth of the mycelium to the mold--you won't ever have more cubic meters of mycelium than your mold can contain. print("Your mycelium has completely filled your mold and will not grow further unless removed from the mold.") mcsAsString = str(mcs) usefultime = "It took you " + mcsAsString + " days to fill the mold." #this will tell you how much of your growth time was actually utilized by your mycelium--how long it took you to fill the mold. print(usefultime) #CITE: This review paper on Eden growth models was an influence on this model. The link can be found here: http://www.jfgouyet.fr/fractal/fractauk/chapter4.pdf. #This code was written by Arvind Veluvali. For questions, contact [email protected].

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue