Write code that outputs the percent of infected humans given an input of number of days assuming a rate of doubling of infected every day in any language you like
Write code that outputs the percent of infected humans given an input of number of days assuming a rate of doubling of...
Other urls found in this thread:
merriam-webster.com
twitter.com
Forgot, assume a population of 8 billion and 1 person initially infected
why
Do your own homework. If you cannot do this simple question, drop out. Seriously. You'll save yourself a lot of time and money.
I wrote this already dude
Yours was a question mine was not. Very different.
It's just
import sys
infected =1
input= int(sys.argv[1])
day=1
while(infected
>Reading comprehension
Not quite what the problem asked for user.
return 2^num_days
return min(100, 2^num_days)
>Everyone always gets infected in 6.6 days no matter population
Not a percentage infected.
Welp Jow Forums cannot even read directions
THE ABSOLUTE STATE OF Jow Forums
Thats why I posted it user lol. These tards think Im trying to get homework but Im actually trying to expose the face the Jow Forums cant read while claiming it s a simple problem
oh
min(100, (2^num_days / 8,000,000,000) * 100)
i mean, it is a simple problem. i half read your question and replied in a span of like 10s lol
Have prize user.
These are both me. Interesting test though.
infected = 2 ** days
if infected < 8000000000:
return infected
return 8000000000
between this and the python reply its like.. you guys know you can do more than one thing per line of code right?
oh FUG its percentage, changed to
infected = 2 ** days
if infected < 8000000000:
return (infected/8000000000) * 100
return 100
its just cleaner formatting, why does it trigger you
i guess its a preference. personally i wouldn't call it "cleaner" but just more explicit.
def infection(startPop, infeced, days):
daysIntoInfection = 0
while daysIntoInfection
Will this work?
cout humansAliveOnEarthAtBeginning;
bool checkIfLoopIsDone = false; //Checks if the loop is done
int infectedPeople = 0;
int iteratorEqualToDay = 0;
while(!checkIfLoopIsDone){
iteratorEqualToDay = iteratorEqualToDay + (int)((char)b - (char)a);
if(infectedPeople != 0)
infectedPeople = 1;
else
infectedPeople = infectedPeople + infectedPeople;
cout
What? This is calculus. You can do this by hand.
If you need calculus to do this by hand, yikers.
i can't tell if Jow Forums is seriously retarded or if this thread is just drawing a terrible cross section
Yes, you have to prove your formula is correct.
But um, it's literally multiplication and division then outputting values to a screen.
So? You a still have to prove it's correct and didn't pull it out your ass.
"I decree that my calculator is, in fact, correct, and that I give zero shits about writing an inductive proof"
There is nothing to "prove", unless you (a) believe that the operations of multiplication and division are faulty or (b) the method doesn't come produce results to be expected. U big dummy.
Heres OP's solution:
days = int(input("Enter number of days"))
def calcPercent(days):
i = 0
infected = 1
while i < days:
infected = infected * 2
i += 1
return infected
print(calcPercent(days))
You couldn't even read your post to make sure it included your full homework question, why should others?
>calcPercent
>returns the total infected count and not a percentage
user
Okay how come the formula isnt P(x) = -1 for instance?
Jesus have any of you solved a single differential equation?
save yourself trouble and go into sales
Durrrrr, what are exponents. Did you ever consider that there is a close form solution to this problem?
whoops....
More importantly, why are you guys using a signed int to hold the total infected count?
On typical machines this is limited to 2,147,483,648.
print(calcPercent(days) / 8000000000)
Python 3 unified int and long
I didnt ask for you to do by hand I asked for the code to do it.
>close form solution
ok so post it hot shot
This is what real code looks like, take notes
Little better
days = int(input("Enter number of days"))
def calcPercent(days):
i = 0
infected = 1
while i < days:
infected = infected * 2
i += 1
if infected >= 8000000000:
return 100
else:
return 100 * (infected / 8000000000)
print (calcPercent(days))
#on day 1, % infected humans = 1/8bil * 100
#on day 2, %infected humans = 2/8bil
#on day n, % infected humans = 2^(n-1)/8bil
def f(x):
return (x*100)/(8*10**9)
print f(input(x))
Well that's too bad, go fuck yourself.
>eventually your program outputs outputs more infected humans than there are actual humans
Why do you need to "write code" to answer a simple math question?
This is code monkey behavior, if you use a loop for this you have serious mental issues and I hope you never get to write a single line of code for any software I have to use.
Yikes, this is awful.
The answer is just max(1,2^n/8bil) assuming 1 person is affected on day zero, times 100 if you like.
The purpose of writing code is often to make tedious tasks easier. Yr obviously too dense to understand that.
>The purpose of writing code is often to make tedious tasks easier.
If you write more then one line of code for this you are mentally retarded.
The solution is a very simple math formula, if you want to express it in code that is trivial.
Also this is not a tedious tasks, it is a very simple one, that's why the solution "in code" is also completely trivial, but you are too dense to understand that using fucking loops to solve this is a sign of mental retardation.
The formula is trivial and after that the code is as well.
Say you wanted to estimate quickly with different populations sizes, different rates, and other variables. this simple code could easily become more complicated. Also, please post yr working code in one line in any language.
grow up
>Say you wanted to estimate quickly with different populations sizes, different rates, and other variables.
The formula is there, it's trivial to adapt.
Type it into a computer and you are done.
You are making an extremely simple thing extremely complicated, again using loops for this is mental retardation,but if you want a computer to calculate it use the trivial formula.
>Also, please post yr working code in one line in any language.
100*max([1,2^n/8000000000])
This is perfectly acceptable MATLAB or OCTAVE code.
>grow up
What?
Icm not a porgrammer but...
*Grabs calculator*
Number of infected=1×2^t
Percentage=100:8Billion×Numbers of infected
>CS brainlets will unironically write a program for this
See >tedious task
This is literally babbies first math. This is so extremely basic.. If you truly think that that is tedious, I don't even know what to tell you.
If you cannot write code that says the equivalent of 100 * (2^x/8billion), drop out, seriously.
This isn't even programming, it's basic math.
What's with the max()? 2^0=1.
So that it is limited at 100%.
200% of humanity being infected makes no sense.
>If you cannot write code that says the equivalent of 100 * (2^x/8billion), drop out, seriously.
>(2^x/8billion)
day 1 (start), x = 1
>assume a population of 8 billion and 1 person initially infected
>2^1 = 2
>drop out, seriously.
It's day 0, you mong.
>merriam-webster.com
>Definition of day one
>: the first day or very beginning of something
You see, humans start indexing from one, not zero, NPC.
>a hurfdurf i don't know basicmath
so it should be min?
>Say you wanted to estimate quickly with different populations sizes, different rates, and other variables. this simple code could easily become more complicated. Also, please post yr working code in one line in any language.
>grow up
it would still fit in one line
let x= (n, pop)=>((1
>he thinks human indexing conventions are about math
The autism is palpable.
>Python poster
>Gets the only number besides 1 wrong
>Assumes self superiority
Everything seems in order here
Oh sorry, obviously yes.
>in other language you can use bit shifting instead of power 2, which as I was told , it's CPU efficient operation i.e better than power
Firstly, it doesn't really matter on these small scales, secondly I, who knows what the interpreter does exactly?
But you are right, shifting to the right works, at least for certain data types.
what a raging retard, you sound like my retarded physics classmates that fail to understand any proof and then start claiming something isn't proved, when actually it is already by definition.
The function literally is just multiplication, and you are only taking positive values, assuming short scale: [(2^n)/(8*10^9)]*100 is the percentage.
Now you just have to make a baby's first hello world for this given an user input.
>You a still have to prove it's correct
It's literally impossible.
This is about modelling reality, mathematics can't prove a Modell. Just Like Newtons laws can not be proven mathematically.
The correctness of a model isn't a mathematical claim, it can brothers be proven not disproven.
haha
>/ 8,000,000,000 * 100
you do know algebra, right?
You know what a bracket does, right?
kek
you do realize clarity is more important than brevity, right?