-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor_a_few_billion.html
More file actions
43 lines (36 loc) · 1.18 KB
/
for_a_few_billion.html
File metadata and controls
43 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
There is an old tale about a king who offered a servant $10,000 as a reward. The servant instead asked that for 30 days he be given an amount that would double, starting with a penny. (1 penny for the first day, 2 for the second, 4 for the third, then 8, 16, 32 pennies, and so on).
Use for loops to answer the following:
How much was the reward after 30 days?
remember, a penny isn't 1, but 0.01
Bonus (Only If You Have Time):
How many days would it take the servant to make $10,000?
How about 1 billion?
In JavaScript, there is a value Infinity . How many days until the servant has infinite money?
<!DOCTYPE html>
<html>
<script>
// amount after 30 days
var amt =.01;
var days = 30;
for (var day = 2; day <= days; day++){
amt = amt*2;
}
amt
// days to specified amt
var amt = 1000000000;
var days = 0;
while (amt >= .01) {
amt = amt /2;
days ++;
}
days
//days to Infinity
var amt = .01;
var days = 1;
while (amt< Infinity) {
amt = amt*2;
days ++;
}
days
</script>
</html>