M Mahares Expert Licensed User Longtime User Dec 13, 2017 #1 An old professor asked me this question at the gym today: If I give you 1 US penny (1/100th of a dollar) today and you double the result every day for 30 days only, how much money will you end up with at the end of the 30 days? I answered: I have no idea, but I will write a little B4A code after the workout and get back to you tomorrow with the result. I wrote these few lines of code and to my astonishment it is over $10,000,000. If you disagree or have a better way to achieve the result, please post it: Code: Dim x As Long =1 For i= 0 To 30-1 x=x*2 Next Dim y As String = NumberFormat2(x/100,1,0,0,True) LogColor(y, Colors.Red) 'displays: 10,737,418
An old professor asked me this question at the gym today: If I give you 1 US penny (1/100th of a dollar) today and you double the result every day for 30 days only, how much money will you end up with at the end of the 30 days? I answered: I have no idea, but I will write a little B4A code after the workout and get back to you tomorrow with the result. I wrote these few lines of code and to my astonishment it is over $10,000,000. If you disagree or have a better way to achieve the result, please post it: Code: Dim x As Long =1 For i= 0 To 30-1 x=x*2 Next Dim y As String = NumberFormat2(x/100,1,0,0,True) LogColor(y, Colors.Red) 'displays: 10,737,418
Lee Gillie CCP Active Member Licensed User Longtime User Dec 13, 2017 #2 (2 ^ 30)/100 = 10,737,418.24 Upvote 0
M Mahares Expert Licensed User Longtime User Dec 13, 2017 #3 Lee Gillie CCP said: (2 ^ 30)/100 = 10,737,418.24 Click to expand... Lee: Your post would yield some code like this which is more elegant than mine: Code: Dim x As Long x=Power(2,30) Dim y As String = NumberFormat2(x/100,1,0,0,True) LogColor(y, Colors.Red) 'displays: 10,737,418 Upvote 0
Lee Gillie CCP said: (2 ^ 30)/100 = 10,737,418.24 Click to expand... Lee: Your post would yield some code like this which is more elegant than mine: Code: Dim x As Long x=Power(2,30) Dim y As String = NumberFormat2(x/100,1,0,0,True) LogColor(y, Colors.Red) 'displays: 10,737,418
NJDude Expert Licensed User Longtime User Dec 13, 2017 #4 That question is based on the old Chessboard problem. Just an FYI. Upvote 0
tigrot Well-Known Member Licensed User Longtime User Dec 13, 2017 #5 NJDude said: That question is based on the old Chessboard problem. Click to expand... My father used to tell me this novel, when I was a boy... Upvote 0
NJDude said: That question is based on the old Chessboard problem. Click to expand... My father used to tell me this novel, when I was a boy...
M Mahares Expert Licensed User Longtime User Dec 13, 2017 #6 based on the formula in @NJDude 's link, the equivalent B4A code would be: Code: Dim x As Long Dim a As Int =1 'the first term Dim r As Int=2 'multiplier Dim n As Int=30 'number of days x=a*(1-Power(r,n))/(1-r) Dim y As String = NumberFormat2(x/100,1,0,0,True) LogColor(y, Colors.Red) 'displays: 10,737,418 Upvote 0
based on the formula in @NJDude 's link, the equivalent B4A code would be: Code: Dim x As Long Dim a As Int =1 'the first term Dim r As Int=2 'multiplier Dim n As Int=30 'number of days x=a*(1-Power(r,n))/(1-r) Dim y As String = NumberFormat2(x/100,1,0,0,True) LogColor(y, Colors.Red) 'displays: 10,737,418
LucaMs Expert Licensed User Longtime User Dec 14, 2017 #7 You have a share capital worth $ 1,000. Its value increases today by 1%. The following day it decreases by 1%. The two events above are repeated for 15 times (30 days). How much is your capital at the end? [Some news programs say things like: "Today the stock market has risen by 2%, recovering 2% lost yesterday"] Last edited: Dec 14, 2017 Upvote 0
You have a share capital worth $ 1,000. Its value increases today by 1%. The following day it decreases by 1%. The two events above are repeated for 15 times (30 days). How much is your capital at the end? [Some news programs say things like: "Today the stock market has risen by 2%, recovering 2% lost yesterday"]
MaFu Well-Known Member Licensed User Longtime User Dec 14, 2017 #8 LucaMs said: You have a share capital worth $ 1,000. Its value increases today by 1%. The following day it decreases by 1%. The two events above are repeated for 15 times (30 days). How much is your capital at the end? [Some news programs say things like: "Today the stock market has risen by 2%, recovering 2% lost yesterday"] Click to expand... $ 998,50 And after 115124 cycles (230248 days) you have 1 cent. But you're to old to spend it. Upvote 0
LucaMs said: You have a share capital worth $ 1,000. Its value increases today by 1%. The following day it decreases by 1%. The two events above are repeated for 15 times (30 days). How much is your capital at the end? [Some news programs say things like: "Today the stock market has risen by 2%, recovering 2% lost yesterday"] Click to expand... $ 998,50 And after 115124 cycles (230248 days) you have 1 cent. But you're to old to spend it.
tigrot Well-Known Member Licensed User Longtime User Dec 14, 2017 #9 Back to the primary school! All together! Upvote 0
MaFu Well-Known Member Licensed User Longtime User Dec 14, 2017 #10 tigrot said: Back to the primary school! All together! Click to expand... ??? Upvote 0
M Mahares Expert Licensed User Longtime User Dec 14, 2017 #11 LucaMs said: You have a share capital worth $ 1,000. Its value increases today by 1%. The following day it decreases by 1%. The two events above are repeated for 15 times (30 days). How much is your capital at the end? Click to expand... Professor and Father @LucaMs , is this the correct B4A code needed. I like your blessing. If different, please enlighten me: Code: LogColor(Compound(1000,30),Colors.Green) 'displays 998.50 Sub Compound(x As Double, days As Int) As String For i= 0 To days-1 If i Mod 2 =0 Then x=x*(1+.01) Else x=x*(1-.01) End If Next Return NumberFormat2(x,1,2,2,True) End Sub Upvote 0
LucaMs said: You have a share capital worth $ 1,000. Its value increases today by 1%. The following day it decreases by 1%. The two events above are repeated for 15 times (30 days). How much is your capital at the end? Click to expand... Professor and Father @LucaMs , is this the correct B4A code needed. I like your blessing. If different, please enlighten me: Code: LogColor(Compound(1000,30),Colors.Green) 'displays 998.50 Sub Compound(x As Double, days As Int) As String For i= 0 To days-1 If i Mod 2 =0 Then x=x*(1+.01) Else x=x*(1-.01) End If Next Return NumberFormat2(x,1,2,2,True) End Sub
LucaMs Expert Licensed User Longtime User Dec 14, 2017 #12 Mahares said: Professor and Father @LucaMs , is this the correct B4A code needed. I like your blessing. If different, please enlighten me: Code: LogColor(Compound(1000,30),Colors.Green) 'displays 998.50 Sub Compound(x As Double, days As Int) As String For i= 0 To days-1 If i Mod 2 =0 Then x=x*(1+.01) Else x=x*(1-.01) End If Next Return NumberFormat2(x,1,2,2,True) End Sub Click to expand... What is surely incorrect is this: Mahares said: Professor and Father @LucaMs Click to expand... Your routine is correct... although not very useful. My example was used only to point out how journalists understand well the percentages when they refer to stocks (and also to the GDP of the state - PIL in italian). [Your function should return x as double or float, not a string, anyway] Upvote 0
Mahares said: Professor and Father @LucaMs , is this the correct B4A code needed. I like your blessing. If different, please enlighten me: Code: LogColor(Compound(1000,30),Colors.Green) 'displays 998.50 Sub Compound(x As Double, days As Int) As String For i= 0 To days-1 If i Mod 2 =0 Then x=x*(1+.01) Else x=x*(1-.01) End If Next Return NumberFormat2(x,1,2,2,True) End Sub Click to expand... What is surely incorrect is this: Mahares said: Professor and Father @LucaMs Click to expand... Your routine is correct... although not very useful. My example was used only to point out how journalists understand well the percentages when they refer to stocks (and also to the GDP of the state - PIL in italian). [Your function should return x as double or float, not a string, anyway]
mrred128 Active Member Licensed User Longtime User Dec 17, 2017 #13 LucaMs said: You have a share capital worth $ 1,000. Its value increases today by 1%. The following day it decreases by 1%. The two events above are repeated for 15 times (30 days). How much is your capital at the end? [Some news programs say things like: "Today the stock market has risen by 2%, recovering 2% lost yesterday"] Click to expand... You have asked more than 1 quedtion / thread. Taxes = %90. Upvote 0
LucaMs said: You have a share capital worth $ 1,000. Its value increases today by 1%. The following day it decreases by 1%. The two events above are repeated for 15 times (30 days). How much is your capital at the end? [Some news programs say things like: "Today the stock market has risen by 2%, recovering 2% lost yesterday"] Click to expand... You have asked more than 1 quedtion / thread. Taxes = %90.
Widget Well-Known Member Licensed User Longtime User Dec 17, 2017 #14 LucaMs said: What is surely incorrect is this: Your routine is correct... although not very useful. My example was used only to point out how journalists understand well the percentages when they refer to stocks (and also to the GDP of the state - PIL in italian). [Your function should return x as double or float, not a string, anyway] Click to expand... The U.S. is now adding research and development to the GDP. So the more money that is spent on R&D, the higher the GDP regardless of producing any results. I'm not making this up. I wish I was. This has motivated me into getting a $100,000 GofundMe campaign to contemplate my navel for all of 2018. But I can't do it alone. If each of us did this with their own navel, we could have 8% GDP growth in no time, and much cleaner navels. I'm even thinking of getting a government grant. We must do our best to get our governments out of a recession. Who's with me on this? Upvote 0
LucaMs said: What is surely incorrect is this: Your routine is correct... although not very useful. My example was used only to point out how journalists understand well the percentages when they refer to stocks (and also to the GDP of the state - PIL in italian). [Your function should return x as double or float, not a string, anyway] Click to expand... The U.S. is now adding research and development to the GDP. So the more money that is spent on R&D, the higher the GDP regardless of producing any results. I'm not making this up. I wish I was. This has motivated me into getting a $100,000 GofundMe campaign to contemplate my navel for all of 2018. But I can't do it alone. If each of us did this with their own navel, we could have 8% GDP growth in no time, and much cleaner navels. I'm even thinking of getting a government grant. We must do our best to get our governments out of a recession. Who's with me on this?