﻿ Unreal Software - Thread: Do you have what it takes to be a Programmer?

# Forum

Off Topic Do you have what it takes to be a Programmer?

# Do you have what it takes to be a Programmer?

40 replies
Page
1 2 3

#### Re: Do you have what it takes to be a Programmer?

Lee
Moderator Offline

Quote
Wait, shouldn't the viruses increase by 160%?
That's viruses = viruses*2.6 or viruses = viruses + viruses * 1.6

vir_n = vir_(n-1)*1.6 - 50000

Quote
This means, the virus count only doubles every 4th hour, meaning the check for (!(virusCount < 10^12)) will only return true on a 4th hour, which means the answer has to be either 108 hours if you don't include the initial "0 hour" or 104 if you do.

You are working under the presumption that viral growth is a discrete process. As the viruses are introduced to a population of cells within varying degrees of mitotic development, we have to assume that growth is continuous. Therefore, before 4 hours have elapsed, the population of the virus will still have grown.

---------------------------------------------------------------

Now try to find the precise number of hours that it takes given the following criteria:

Instead of having 50,000 viruses eliminated every 4 hours, they are instead eliminated once every one hour. The rate of viral growth is still 1.6x every 4 hours. (Everything else are the same as the previous problem)

You can solve this either programatically or analytically.
edited 2×, last 10.02.10 03:25:30 am

#### Re: Do you have what it takes to be a Programmer?

Psytechnic
User Offline

leegao has written
once every one hour.

does this mean 50,000 is removed every hour or 25% of 50,000 is removed every hour?

#### Re: Do you have what it takes to be a Programmer?

Lee
Moderator Offline

50,000 is removed every hour. However keep in mind of the continuous nature of the viral rate of growth.

#### Re: Do you have what it takes to be a Programmer?

YellowBanana
BANNED Offline

growrate per year now is 1.6^(1/4).
1
2
3
4
5
6
7
8
9
10
11
```val = 100
set = false
hours = 0
while(set == false) do
hours = hours+1
val = val*1.12468 - 5
if(val > 1e+8) then
print(hours)
set = true
end
end
```

btw, this is lua code.

check with the previous result, which was 120 hours.
It should be almost the same, since the 50.000 is relatively small.

#### Re: Do you have what it takes to be a Programmer?

Flacko
User Offline

Banana is right (I guess)
The answer is between 120 and 124
edited 1×, last 10.02.10 04:16:59 pm

#### Re: Do you have what it takes to be a Programmer?

Crazyx
User Offline

YellowBanana has written
growrate per year now is 1.6^(1/4).
1
2
3
4
5
6
7
8
9
10
11
```val = 100
set = false
hours = 0
while(set == false) do
hours = hours+1
val = val*1.12468 - 5
if(val > 1e+8) then
print(hours)
set = true
end
end
```

The Banana man strikes again.

btw, this is lua code.

check with the previous result, which was 120 hours.
It should be almost the same, since the 50.000 is relatively small.

#### Re: Do you have what it takes to be a Programmer?

Lee
Moderator Offline

Quote

Quote
Now try to find the precise number of hours that it takes...

I'll give you one hint though, you are extremely close, and your analysis of the problem is correct

#### Re: Do you have what it takes to be a Programmer?

Flacko
User Offline

All I can say is that the answer is between 121,9 and 122.
I suck

#### Re: Do you have what it takes to be a Programmer?

Psytechnic
User Offline

I gotta say, I love this thread as it's taking me back a long time to when I was in highschool, trying to remember exactly how logarithms and such work, but I have to say, it's slightly presumptuous of you to make a thread called "Do you have what it takes to be a Programmer?" when the questions are mathematically advanced in nature. Advanced mathematics is a strong and rewarding basis for programming, but interestingly, due to the induction of very high level languages and modern integrated development environments, not to mention JIT languages that have a base API with many advanced mathematical functions already built in, this kind of mathematical understanding not always necessary.

But please! Don't stop the questions! I'm loving the challenge and I'm really enjoying having to apply high level mathematics in a high level language. It's forcing me to use low level functions for it which is new and interesting for me. So thanks for the inspiration!

#### Re: Do you have what it takes to be a Programmer?

YellowBanana
BANNED Offline

I'm sorry to say, but this really isn't high level mathematics.

122 is the precise number. Unless you want it in minutes too.

#### Re: Do you have what it takes to be a Programmer?

Psytechnic
User Offline

YellowBanana has written
I'm sorry to say, but this really isn't high level mathematics.

122 is the precise number. Unless you want it in minutes too.

I used the term, making a poor assumption that most people either forget or don't study too deeply in mathematics. You are a resounding exception. I would include myself, but even I had forgotten how logarithms work.

#### Re: Do you have what it takes to be a Programmer?

Lee
Moderator Offline

YellowBanana has written
I'm sorry to say, but this really isn't high level mathematics.

122 is the precise number. Unless you want it in minutes too.

122 is not the precise number, 122 however is the correct answer under the assumption that both growth and elimination are stepwise under a discrete condition.

(In other words, create an hourly based discrete model to estimate how long it will take for the population of the viruses to exceed 10^12, assuming that a continuous rate of growth is the most accurate estimate. It may sound confusing, but it'll seem clearer after you delve into the problem.)

#### Re: Do you have what it takes to be a Programmer?

jeepohahyo
User Offline

Couldn't you just solve (or in this case, rather approximate)

and get the exact value for continouous growth and elimination?
We did that kind of exercises in school just a year ago.

EDIT:
Yes, it seems so.
I was too lazy to solve it and my calculator failed me, but trying numbers around 120 for x and then bisecting towards 10^12 gave me ca. 117.577 hours as result (all 3 decimal places accurate)

EDIT2: I successfully convinced my calculator to do the approximation work for me and indeed it gives me x=117.5779554 (in hours) as result.
edited 5×, last 11.02.10 02:44:50 pm

#### Re: Do you have what it takes to be a Programmer?

Lee
Moderator Offline

@Dicker:

Remember that as 50,000 viral particles are eliminated per hour, the base of the exponential growth for the successive hours also change, therefore you cannot use a fixed elimination rate. The answer is larger than 117.577.

#### Re: Do you have what it takes to be a Programmer?

jeepohahyo
User Offline

That is because as I said, I provided a model for continuous growth AND elimination because I think that an immune system sitting idly for an hour and then suddenly eliminating 50000 virii in an instant is a bit unrealistic.

EDIT: Okay, now I see it, damn you're right

#### Re: Do you have what it takes to be a Programmer?

DannyDeth
User Offline

I got 106 hrs. Not sure if I"m right though, probably wrong.

#### Re: Do you have what it takes to be a Programmer?

sonnenschein
User Offline

DannyDeth has written
I got 106 hrs. Not sure if I"m right though, probably wrong.

leegao has written
The answer is larger than 117.577

Maybe 117.578?

#### Re: Do you have what it takes to be a Programmer?

Flacko
User Offline

I wrote a more complete program.

And I got this output in the last lines:
Quote
99694064.000000 121.92
99811272.000000 121.93
99928616.000000 121.94
100046096.000000 121.95
100163704.000000 121.96

I don't think that the program is very precise, but I think that I can say that the number is between 121,94 and 121,95 being closer to 121,95
Whatever

#### Re: Do you have what it takes to be a Programmer?

Lee
Moderator Offline

@Flacko: Very good, now think of the output in terms of the following.

Note: This is an attempt at a discrete analytical solution to the problem.

The virus is growing at a rate of ae^k - c where a,k are elements of Reals.

To find k, we need to assume that the virus is growing at a natural rate.

After 400 0.01 hours, the number of virus will have grown by 160% correct? Therefore

1.6 = e^(400k)
k = ln(1.6)/400

a in this case is 10^6, and c is 50,000/100 (We assume linearity of the decimating factors as the hour to hour rate is zero, therefore the rate of elimination must also be linear or constant)

If we model the discrete sets of data, we have:

1     ae^k     ae^k - c
2      (ae^k - c)e^k      (ae^k - c)e^k-c
3      ((ae^k - c)e^k-c)e^k      ((ae^k - c)e^k-c)e^k-c
n      (...((ae^k - c)e^k-c)e^k...)e^k      (...((ae^k - c)e^k-c)e^k...)e^k -c

Focusing on the n series, we see that it's geometric in nature

(((ae^k - c)e^k-c)e^k-c)...
= ((ae^2k - ce^k - c)e^k-c)...
= (ae^3k - ce^2k - ce^k -c ) ...

= (ae^nk - ce^(n-1)k - ... - ce^k - ce^0)
= ae^nk - c(e^(n-1)k + ... + e^k + 1)

Let's refactors the e^n series
h(n) = e^(n-1)k + ... + e^k + 1
(e^k)h(n) = e^nk + ... e^k
(e^k-1)h(n) = e^nk - 1
h(n) = e^(n-1)k + ... + e^k + 1 = (e^nk - 1)/(e^k-1)

Back to the original problem

= ae^nk - c(e^(n-1)k + ... + e^k + )
= ae^nk - c(e^nk - 1)/(e^k-1)

Thus P(n) = ae^nk - c(e^nk - c)/(e^k-1)
where n is the amount of time (in 0.01 hours) that it'll take to reach the number of particles that we need. So we solve for n.

P = ae^nk - c(e^nk - 1)/(e^k-1)
P = (ae^nk*(e^k-1))/(e^k-1) - c(e^nk - 1)/(e^k-1)
P = (ae^nk*(e^k-1) - ce^nk + c)/(e^k-1)
P*(e^k-1) = ae^nk*(e^k-1) - ce^nk + c
= ae^nk*e^k-ae^nk-ce^nk+c
= e^nk (ae^k-a-c)+ c
(P(e^k-1)-c)/(ae^k-a-c)= e^nk
e^nk = (P(e^k-1)-c)/(a(e^k-1)-c)
nk= ln((P(e^k-1)-c)/(a(e^k-1)-c))

n = (k^-1)*ln((P(e^k-1)-c)/(a(e^k-1)-c))

n = 12229.165266997 hours *10^-2 = 122.29165266997 Hours.

Using different step sizes give us different results

by 0.1 hours:

n = 1222.5847084475 hours * 10^-1 =
122.25847084475 hours

by hour:

n = 121.93977381663 hours

The pattern here is pretty distinct, let's try something even more extreme

1
2
3
4
5
6
```function n(a,r,c,P,step)
if not step then step = 1 end
local k = math.log(r)/(4*step)
c = c/step
return ((k^-1)*math.log((P*(e^k-1)-c)/(a*(e^k-1)-c)))/step
end
```

n(10^6,1.6,50000,10^12,1000000) yields 122.29535441805

etc.

#### Re: Do you have what it takes to be a Programmer?

Flacko
User Offline

Damn.
I think I'm not going to get very far without knowing how do logarithms work.
Hopefully I'll learn that this year in school (I guess)

But it seems like I was wrong
It was just a small programming error Dx
1 2 3