Compound Interest… with Wizard Money
$begingroup$
Gringotts isn't just a vault, but a reputable financial institution and wizards need loans too. Since you don't want to be screwed over by the Gringotts goblins, you decided it would be a good idea to write a program to calculate interest. Interest is compounded only yearly.
Your task is to calculate total owed amount after interest given the principal, interest rate, and time (whole years), operating in whole denominations of wizard money, rounding down. There are 29 Bronze Knuts in a Silver Sickle and 17 Sickles in a Gold Galleon.
Example
Loan taken out:
23 Knuts
16 Sickles
103 Galleons
@ 7.250%
For 3 years
Total owed after interest:
24 Knuts
4 Sickles
128 Galleons
Notes and Rules
- Input and output may be in any convenient format. You must take in Knuts, Sickles, Galleons, interest rate, and time. All but interest rate will be whole numbers. The interest rate is in increments of 0.125%.
- Input money is not guaranteed to be canonical (i.e. you can have 29 or more Knuts and 17 or more Sickles.)
- Output must be the canonical representation. (i.e. less than 29 Knuts and less than 17 Sickles)
- Totals owed, up to 1,000 Galleons, should be accurate to within 1 Knut per year of interest when compared with arbitrary precision calculations.
- You may round down after each year of interest or only at the end. Reference calculations can take this into account for accuracy checks.
Happy golfing!
code-golf math
$endgroup$
|
show 1 more comment
$begingroup$
Gringotts isn't just a vault, but a reputable financial institution and wizards need loans too. Since you don't want to be screwed over by the Gringotts goblins, you decided it would be a good idea to write a program to calculate interest. Interest is compounded only yearly.
Your task is to calculate total owed amount after interest given the principal, interest rate, and time (whole years), operating in whole denominations of wizard money, rounding down. There are 29 Bronze Knuts in a Silver Sickle and 17 Sickles in a Gold Galleon.
Example
Loan taken out:
23 Knuts
16 Sickles
103 Galleons
@ 7.250%
For 3 years
Total owed after interest:
24 Knuts
4 Sickles
128 Galleons
Notes and Rules
- Input and output may be in any convenient format. You must take in Knuts, Sickles, Galleons, interest rate, and time. All but interest rate will be whole numbers. The interest rate is in increments of 0.125%.
- Input money is not guaranteed to be canonical (i.e. you can have 29 or more Knuts and 17 or more Sickles.)
- Output must be the canonical representation. (i.e. less than 29 Knuts and less than 17 Sickles)
- Totals owed, up to 1,000 Galleons, should be accurate to within 1 Knut per year of interest when compared with arbitrary precision calculations.
- You may round down after each year of interest or only at the end. Reference calculations can take this into account for accuracy checks.
Happy golfing!
code-golf math
$endgroup$
4
$begingroup$
Can we take the interest rate as a decimal instead of a percentage? (e.g.,0.0725
instead of7.25
)
$endgroup$
– Shaggy
8 hours ago
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
7 hours ago
$begingroup$
If the loan is exactly 1 Knut, and the interest is 99% per year, and the term is 1 year, should the result be "1 Knut" or "2 Knuts"?
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
In other words, please clarify the mathematical meaning of the phraserounding down
$endgroup$
– senox13
4 hours ago
$begingroup$
@Shaggy: of course. It's just a different representation, which is fair game for I/O
$endgroup$
– Beefster
23 mins ago
|
show 1 more comment
$begingroup$
Gringotts isn't just a vault, but a reputable financial institution and wizards need loans too. Since you don't want to be screwed over by the Gringotts goblins, you decided it would be a good idea to write a program to calculate interest. Interest is compounded only yearly.
Your task is to calculate total owed amount after interest given the principal, interest rate, and time (whole years), operating in whole denominations of wizard money, rounding down. There are 29 Bronze Knuts in a Silver Sickle and 17 Sickles in a Gold Galleon.
Example
Loan taken out:
23 Knuts
16 Sickles
103 Galleons
@ 7.250%
For 3 years
Total owed after interest:
24 Knuts
4 Sickles
128 Galleons
Notes and Rules
- Input and output may be in any convenient format. You must take in Knuts, Sickles, Galleons, interest rate, and time. All but interest rate will be whole numbers. The interest rate is in increments of 0.125%.
- Input money is not guaranteed to be canonical (i.e. you can have 29 or more Knuts and 17 or more Sickles.)
- Output must be the canonical representation. (i.e. less than 29 Knuts and less than 17 Sickles)
- Totals owed, up to 1,000 Galleons, should be accurate to within 1 Knut per year of interest when compared with arbitrary precision calculations.
- You may round down after each year of interest or only at the end. Reference calculations can take this into account for accuracy checks.
Happy golfing!
code-golf math
$endgroup$
Gringotts isn't just a vault, but a reputable financial institution and wizards need loans too. Since you don't want to be screwed over by the Gringotts goblins, you decided it would be a good idea to write a program to calculate interest. Interest is compounded only yearly.
Your task is to calculate total owed amount after interest given the principal, interest rate, and time (whole years), operating in whole denominations of wizard money, rounding down. There are 29 Bronze Knuts in a Silver Sickle and 17 Sickles in a Gold Galleon.
Example
Loan taken out:
23 Knuts
16 Sickles
103 Galleons
@ 7.250%
For 3 years
Total owed after interest:
24 Knuts
4 Sickles
128 Galleons
Notes and Rules
- Input and output may be in any convenient format. You must take in Knuts, Sickles, Galleons, interest rate, and time. All but interest rate will be whole numbers. The interest rate is in increments of 0.125%.
- Input money is not guaranteed to be canonical (i.e. you can have 29 or more Knuts and 17 or more Sickles.)
- Output must be the canonical representation. (i.e. less than 29 Knuts and less than 17 Sickles)
- Totals owed, up to 1,000 Galleons, should be accurate to within 1 Knut per year of interest when compared with arbitrary precision calculations.
- You may round down after each year of interest or only at the end. Reference calculations can take this into account for accuracy checks.
Happy golfing!
code-golf math
code-golf math
asked 9 hours ago
BeefsterBeefster
1,906833
1,906833
4
$begingroup$
Can we take the interest rate as a decimal instead of a percentage? (e.g.,0.0725
instead of7.25
)
$endgroup$
– Shaggy
8 hours ago
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
7 hours ago
$begingroup$
If the loan is exactly 1 Knut, and the interest is 99% per year, and the term is 1 year, should the result be "1 Knut" or "2 Knuts"?
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
In other words, please clarify the mathematical meaning of the phraserounding down
$endgroup$
– senox13
4 hours ago
$begingroup$
@Shaggy: of course. It's just a different representation, which is fair game for I/O
$endgroup$
– Beefster
23 mins ago
|
show 1 more comment
4
$begingroup$
Can we take the interest rate as a decimal instead of a percentage? (e.g.,0.0725
instead of7.25
)
$endgroup$
– Shaggy
8 hours ago
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
7 hours ago
$begingroup$
If the loan is exactly 1 Knut, and the interest is 99% per year, and the term is 1 year, should the result be "1 Knut" or "2 Knuts"?
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
In other words, please clarify the mathematical meaning of the phraserounding down
$endgroup$
– senox13
4 hours ago
$begingroup$
@Shaggy: of course. It's just a different representation, which is fair game for I/O
$endgroup$
– Beefster
23 mins ago
4
4
$begingroup$
Can we take the interest rate as a decimal instead of a percentage? (e.g.,
0.0725
instead of 7.25
)$endgroup$
– Shaggy
8 hours ago
$begingroup$
Can we take the interest rate as a decimal instead of a percentage? (e.g.,
0.0725
instead of 7.25
)$endgroup$
– Shaggy
8 hours ago
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
7 hours ago
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
7 hours ago
$begingroup$
If the loan is exactly 1 Knut, and the interest is 99% per year, and the term is 1 year, should the result be "1 Knut" or "2 Knuts"?
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
If the loan is exactly 1 Knut, and the interest is 99% per year, and the term is 1 year, should the result be "1 Knut" or "2 Knuts"?
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
In other words, please clarify the mathematical meaning of the phrase
rounding down
$endgroup$
– senox13
4 hours ago
$begingroup$
In other words, please clarify the mathematical meaning of the phrase
rounding down
$endgroup$
– senox13
4 hours ago
$begingroup$
@Shaggy: of course. It's just a different representation, which is fair game for I/O
$endgroup$
– Beefster
23 mins ago
$begingroup$
@Shaggy: of course. It's just a different representation, which is fair game for I/O
$endgroup$
– Beefster
23 mins ago
|
show 1 more comment
6 Answers
6
active
oldest
votes
$begingroup$
Python 3.8 (pre-release), 75 74 71 bytes
-1 bytes thanks to @EmbodimentofIgnorance
-3 bytes thanks to @xnor
This takes Knuts, Sickles, and Galleons as ints, interest as a float (decimal, not percentage), and years as an int. It returns a tuple containing the number after interest of Knuts, Sickles, and Galleons, respectively.
lambda K,S,G,R,Y:((k:=int((K+G*493+S*29)*(1+R)**Y))%29,k//29%17,k//493)
Usage:
>>> print(I(23,16,103,0.0725,3))
(24, 4, 128)
Try it online!
$endgroup$
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
6 hours ago
$begingroup$
Easy fix, but I think you need to round to the nearest Knut - soI(1,0,0,0.99,1)
should yield2,0,0
instead of1,0,0
. (Also, for convenience on TIO you can add to theHeader
sectionI=
so you don't need to repeat the lambda in theFooter
section).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
The question saysoperating in whole denominations of wizard money, rounding down
. I tookrounding down
to meanchop off everything after the decimal point.
Using the header definitely sounds like an easier way to do things. I'll do that for future posts, thanks
$endgroup$
– senox13
5 hours ago
$begingroup$
That sounds a lot more like "truncating" than "rounding"; but I have asked the OP for clarification (because nit-picking is the name of the game here at PPCG :) ).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
I don't disagree with you, that's just the meaning I've always seen used for rounding down, because you always round to the integer below your result. Otherwise it's just normal rounding. Letting OP decide is a good idea
$endgroup$
– senox13
4 hours ago
|
show 2 more comments
$begingroup$
Jelly, 29 bytes
“¢×ø‘©×
÷ȷ2‘*⁵×÷¢S×¢d®U1¦Ṫ€Ḟ
A full program accepting arguments: rate
; [Galleons, Sickles, Knuts]
; years
.
Prints [Galleons, Sickles, Knuts]
.
Try it online!
Floors at the end of the entire term.÷ȷ2
may be removed if we may accept the rate as a ratio rather than a percentage.
How?
“¢×ø‘©× - Link 1 multipliers: no arguments
“¢×ø‘ - list of code-age indices = [1,17,29]
© - (copy this to the register for later use)
- reduce by:
× - multiplication = [1,17,483]
÷ȷ2‘*⁵×÷¢S×¢d®U1¦Ṫ€Ḟ - Main Link
ȷ2 - 10^2 = 100
÷ - divide = rate/100
‘ - increment = 1+rate/100
⁵ - 5th command line argument (3rd input) = years
* - exponentiate = (1+rate/100)^years --i.e. multiplicand
× - multiply (by the borrowed amounts)
¢ - call last Link as a nilad
÷ - divide (all amounts in Galleons)
S - sum (total Galleons owed)
¢ - call last Link as a nilad
× - multiply (total owed in each of Galleons, Sickles, Knuts)
® - recall from register = [1,17,29]
d - divmod (vectorises) = [[G/1, G%1], [S/17, S^17], [K/17, K%17]]
U1¦ - reverse first one = [[G%1, G/1], [S/17, S%17], [K/17, K%17]]
Ṫ€ - tail €ach = [G/1, S%17, K%17]
Ḟ - floor (vectorises)
$endgroup$
add a comment |
$begingroup$
K, 46 Bytes
c:1000 17 29
t:{c:{z(y*)/x}[c/:x;1+y%100;z]}
c
store the list for base-conversion
t
is the function that calculates total amount
Use example:
t[103 16 23;7.25;3]
writes (128;4;24.29209)
Explanation:
c/:x
transform the list (galleon; sickle; knuts) to kuts1+y%100
calculate rate of interest (example 1.0725 for 7.25% rate)lambda
{z(y*)x}
does the work: iterate 3 times, applying interes*main, and returns final main.c:
generates galleon, sickles, knuts from knuts
NOTE.- if you don't need a names-function, we can use a lambda, saving 2 bytes
{c:{z(y*)/x}[c/:x;1+y%100;z]}inputArgs
$endgroup$
add a comment |
$begingroup$
APL+WIN, 37 bytes
⌊n,17 29⊤493×n←(+/⎕÷1 17 493)×(1+⎕)*⎕
Try it online! Courtesy of Dyalog Classic
Explanation:
(1+⎕)*⎕ prompts for years followed by decimal interest rate and calculates
compounding multiplier
n←(+/⎕÷1 17 493) prompts for Galleons, Sickles and Knuts and converts to decimal Galleons
⌊n,17 29⊤493× converts decimal Galleons after applying compound interest,
converts back to Galleons, Sickles and Knuts and rounds down
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 86 bytes
(a,b,c)=>((k=(int)((a.a*493+a.b*29+a.c)*Math.Pow(1+b,c)))/493,(k%=493)/29,k%29);int k;
Takes inout as a named tuple with 3 values representing knuts, sickles, and galleons, and interest rate as a double (not a percentage). I really wish C# had an exponentation operator. Math.Pow is way too long :(
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 48 bytes
XÄ pY *(U*493+V*29+W)f
Uu493
[Uz493 ,Vz29 ,Vu29]
My first try at Japt, going for @Shaggy's bounty! Needless to say, this isn't very golfy :(
Try it Online!
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f180776%2fcompound-interest-with-wizard-money%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 3.8 (pre-release), 75 74 71 bytes
-1 bytes thanks to @EmbodimentofIgnorance
-3 bytes thanks to @xnor
This takes Knuts, Sickles, and Galleons as ints, interest as a float (decimal, not percentage), and years as an int. It returns a tuple containing the number after interest of Knuts, Sickles, and Galleons, respectively.
lambda K,S,G,R,Y:((k:=int((K+G*493+S*29)*(1+R)**Y))%29,k//29%17,k//493)
Usage:
>>> print(I(23,16,103,0.0725,3))
(24, 4, 128)
Try it online!
$endgroup$
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
6 hours ago
$begingroup$
Easy fix, but I think you need to round to the nearest Knut - soI(1,0,0,0.99,1)
should yield2,0,0
instead of1,0,0
. (Also, for convenience on TIO you can add to theHeader
sectionI=
so you don't need to repeat the lambda in theFooter
section).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
The question saysoperating in whole denominations of wizard money, rounding down
. I tookrounding down
to meanchop off everything after the decimal point.
Using the header definitely sounds like an easier way to do things. I'll do that for future posts, thanks
$endgroup$
– senox13
5 hours ago
$begingroup$
That sounds a lot more like "truncating" than "rounding"; but I have asked the OP for clarification (because nit-picking is the name of the game here at PPCG :) ).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
I don't disagree with you, that's just the meaning I've always seen used for rounding down, because you always round to the integer below your result. Otherwise it's just normal rounding. Letting OP decide is a good idea
$endgroup$
– senox13
4 hours ago
|
show 2 more comments
$begingroup$
Python 3.8 (pre-release), 75 74 71 bytes
-1 bytes thanks to @EmbodimentofIgnorance
-3 bytes thanks to @xnor
This takes Knuts, Sickles, and Galleons as ints, interest as a float (decimal, not percentage), and years as an int. It returns a tuple containing the number after interest of Knuts, Sickles, and Galleons, respectively.
lambda K,S,G,R,Y:((k:=int((K+G*493+S*29)*(1+R)**Y))%29,k//29%17,k//493)
Usage:
>>> print(I(23,16,103,0.0725,3))
(24, 4, 128)
Try it online!
$endgroup$
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
6 hours ago
$begingroup$
Easy fix, but I think you need to round to the nearest Knut - soI(1,0,0,0.99,1)
should yield2,0,0
instead of1,0,0
. (Also, for convenience on TIO you can add to theHeader
sectionI=
so you don't need to repeat the lambda in theFooter
section).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
The question saysoperating in whole denominations of wizard money, rounding down
. I tookrounding down
to meanchop off everything after the decimal point.
Using the header definitely sounds like an easier way to do things. I'll do that for future posts, thanks
$endgroup$
– senox13
5 hours ago
$begingroup$
That sounds a lot more like "truncating" than "rounding"; but I have asked the OP for clarification (because nit-picking is the name of the game here at PPCG :) ).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
I don't disagree with you, that's just the meaning I've always seen used for rounding down, because you always round to the integer below your result. Otherwise it's just normal rounding. Letting OP decide is a good idea
$endgroup$
– senox13
4 hours ago
|
show 2 more comments
$begingroup$
Python 3.8 (pre-release), 75 74 71 bytes
-1 bytes thanks to @EmbodimentofIgnorance
-3 bytes thanks to @xnor
This takes Knuts, Sickles, and Galleons as ints, interest as a float (decimal, not percentage), and years as an int. It returns a tuple containing the number after interest of Knuts, Sickles, and Galleons, respectively.
lambda K,S,G,R,Y:((k:=int((K+G*493+S*29)*(1+R)**Y))%29,k//29%17,k//493)
Usage:
>>> print(I(23,16,103,0.0725,3))
(24, 4, 128)
Try it online!
$endgroup$
Python 3.8 (pre-release), 75 74 71 bytes
-1 bytes thanks to @EmbodimentofIgnorance
-3 bytes thanks to @xnor
This takes Knuts, Sickles, and Galleons as ints, interest as a float (decimal, not percentage), and years as an int. It returns a tuple containing the number after interest of Knuts, Sickles, and Galleons, respectively.
lambda K,S,G,R,Y:((k:=int((K+G*493+S*29)*(1+R)**Y))%29,k//29%17,k//493)
Usage:
>>> print(I(23,16,103,0.0725,3))
(24, 4, 128)
Try it online!
edited 4 hours ago
answered 7 hours ago
senox13senox13
915
915
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
6 hours ago
$begingroup$
Easy fix, but I think you need to round to the nearest Knut - soI(1,0,0,0.99,1)
should yield2,0,0
instead of1,0,0
. (Also, for convenience on TIO you can add to theHeader
sectionI=
so you don't need to repeat the lambda in theFooter
section).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
The question saysoperating in whole denominations of wizard money, rounding down
. I tookrounding down
to meanchop off everything after the decimal point.
Using the header definitely sounds like an easier way to do things. I'll do that for future posts, thanks
$endgroup$
– senox13
5 hours ago
$begingroup$
That sounds a lot more like "truncating" than "rounding"; but I have asked the OP for clarification (because nit-picking is the name of the game here at PPCG :) ).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
I don't disagree with you, that's just the meaning I've always seen used for rounding down, because you always round to the integer below your result. Otherwise it's just normal rounding. Letting OP decide is a good idea
$endgroup$
– senox13
4 hours ago
|
show 2 more comments
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
6 hours ago
$begingroup$
Easy fix, but I think you need to round to the nearest Knut - soI(1,0,0,0.99,1)
should yield2,0,0
instead of1,0,0
. (Also, for convenience on TIO you can add to theHeader
sectionI=
so you don't need to repeat the lambda in theFooter
section).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
The question saysoperating in whole denominations of wizard money, rounding down
. I tookrounding down
to meanchop off everything after the decimal point.
Using the header definitely sounds like an easier way to do things. I'll do that for future posts, thanks
$endgroup$
– senox13
5 hours ago
$begingroup$
That sounds a lot more like "truncating" than "rounding"; but I have asked the OP for clarification (because nit-picking is the name of the game here at PPCG :) ).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
I don't disagree with you, that's just the meaning I've always seen used for rounding down, because you always round to the integer below your result. Otherwise it's just normal rounding. Letting OP decide is a good idea
$endgroup$
– senox13
4 hours ago
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
6 hours ago
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
6 hours ago
$begingroup$
Easy fix, but I think you need to round to the nearest Knut - so
I(1,0,0,0.99,1)
should yield 2,0,0
instead of 1,0,0
. (Also, for convenience on TIO you can add to the Header
section I=
so you don't need to repeat the lambda in the Footer
section).$endgroup$
– Chas Brown
5 hours ago
$begingroup$
Easy fix, but I think you need to round to the nearest Knut - so
I(1,0,0,0.99,1)
should yield 2,0,0
instead of 1,0,0
. (Also, for convenience on TIO you can add to the Header
section I=
so you don't need to repeat the lambda in the Footer
section).$endgroup$
– Chas Brown
5 hours ago
$begingroup$
The question says
operating in whole denominations of wizard money, rounding down
. I took rounding down
to mean chop off everything after the decimal point.
Using the header definitely sounds like an easier way to do things. I'll do that for future posts, thanks$endgroup$
– senox13
5 hours ago
$begingroup$
The question says
operating in whole denominations of wizard money, rounding down
. I took rounding down
to mean chop off everything after the decimal point.
Using the header definitely sounds like an easier way to do things. I'll do that for future posts, thanks$endgroup$
– senox13
5 hours ago
$begingroup$
That sounds a lot more like "truncating" than "rounding"; but I have asked the OP for clarification (because nit-picking is the name of the game here at PPCG :) ).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
That sounds a lot more like "truncating" than "rounding"; but I have asked the OP for clarification (because nit-picking is the name of the game here at PPCG :) ).
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
I don't disagree with you, that's just the meaning I've always seen used for rounding down, because you always round to the integer below your result. Otherwise it's just normal rounding. Letting OP decide is a good idea
$endgroup$
– senox13
4 hours ago
$begingroup$
I don't disagree with you, that's just the meaning I've always seen used for rounding down, because you always round to the integer below your result. Otherwise it's just normal rounding. Letting OP decide is a good idea
$endgroup$
– senox13
4 hours ago
|
show 2 more comments
$begingroup$
Jelly, 29 bytes
“¢×ø‘©×
÷ȷ2‘*⁵×÷¢S×¢d®U1¦Ṫ€Ḟ
A full program accepting arguments: rate
; [Galleons, Sickles, Knuts]
; years
.
Prints [Galleons, Sickles, Knuts]
.
Try it online!
Floors at the end of the entire term.÷ȷ2
may be removed if we may accept the rate as a ratio rather than a percentage.
How?
“¢×ø‘©× - Link 1 multipliers: no arguments
“¢×ø‘ - list of code-age indices = [1,17,29]
© - (copy this to the register for later use)
- reduce by:
× - multiplication = [1,17,483]
÷ȷ2‘*⁵×÷¢S×¢d®U1¦Ṫ€Ḟ - Main Link
ȷ2 - 10^2 = 100
÷ - divide = rate/100
‘ - increment = 1+rate/100
⁵ - 5th command line argument (3rd input) = years
* - exponentiate = (1+rate/100)^years --i.e. multiplicand
× - multiply (by the borrowed amounts)
¢ - call last Link as a nilad
÷ - divide (all amounts in Galleons)
S - sum (total Galleons owed)
¢ - call last Link as a nilad
× - multiply (total owed in each of Galleons, Sickles, Knuts)
® - recall from register = [1,17,29]
d - divmod (vectorises) = [[G/1, G%1], [S/17, S^17], [K/17, K%17]]
U1¦ - reverse first one = [[G%1, G/1], [S/17, S%17], [K/17, K%17]]
Ṫ€ - tail €ach = [G/1, S%17, K%17]
Ḟ - floor (vectorises)
$endgroup$
add a comment |
$begingroup$
Jelly, 29 bytes
“¢×ø‘©×
÷ȷ2‘*⁵×÷¢S×¢d®U1¦Ṫ€Ḟ
A full program accepting arguments: rate
; [Galleons, Sickles, Knuts]
; years
.
Prints [Galleons, Sickles, Knuts]
.
Try it online!
Floors at the end of the entire term.÷ȷ2
may be removed if we may accept the rate as a ratio rather than a percentage.
How?
“¢×ø‘©× - Link 1 multipliers: no arguments
“¢×ø‘ - list of code-age indices = [1,17,29]
© - (copy this to the register for later use)
- reduce by:
× - multiplication = [1,17,483]
÷ȷ2‘*⁵×÷¢S×¢d®U1¦Ṫ€Ḟ - Main Link
ȷ2 - 10^2 = 100
÷ - divide = rate/100
‘ - increment = 1+rate/100
⁵ - 5th command line argument (3rd input) = years
* - exponentiate = (1+rate/100)^years --i.e. multiplicand
× - multiply (by the borrowed amounts)
¢ - call last Link as a nilad
÷ - divide (all amounts in Galleons)
S - sum (total Galleons owed)
¢ - call last Link as a nilad
× - multiply (total owed in each of Galleons, Sickles, Knuts)
® - recall from register = [1,17,29]
d - divmod (vectorises) = [[G/1, G%1], [S/17, S^17], [K/17, K%17]]
U1¦ - reverse first one = [[G%1, G/1], [S/17, S%17], [K/17, K%17]]
Ṫ€ - tail €ach = [G/1, S%17, K%17]
Ḟ - floor (vectorises)
$endgroup$
add a comment |
$begingroup$
Jelly, 29 bytes
“¢×ø‘©×
÷ȷ2‘*⁵×÷¢S×¢d®U1¦Ṫ€Ḟ
A full program accepting arguments: rate
; [Galleons, Sickles, Knuts]
; years
.
Prints [Galleons, Sickles, Knuts]
.
Try it online!
Floors at the end of the entire term.÷ȷ2
may be removed if we may accept the rate as a ratio rather than a percentage.
How?
“¢×ø‘©× - Link 1 multipliers: no arguments
“¢×ø‘ - list of code-age indices = [1,17,29]
© - (copy this to the register for later use)
- reduce by:
× - multiplication = [1,17,483]
÷ȷ2‘*⁵×÷¢S×¢d®U1¦Ṫ€Ḟ - Main Link
ȷ2 - 10^2 = 100
÷ - divide = rate/100
‘ - increment = 1+rate/100
⁵ - 5th command line argument (3rd input) = years
* - exponentiate = (1+rate/100)^years --i.e. multiplicand
× - multiply (by the borrowed amounts)
¢ - call last Link as a nilad
÷ - divide (all amounts in Galleons)
S - sum (total Galleons owed)
¢ - call last Link as a nilad
× - multiply (total owed in each of Galleons, Sickles, Knuts)
® - recall from register = [1,17,29]
d - divmod (vectorises) = [[G/1, G%1], [S/17, S^17], [K/17, K%17]]
U1¦ - reverse first one = [[G%1, G/1], [S/17, S%17], [K/17, K%17]]
Ṫ€ - tail €ach = [G/1, S%17, K%17]
Ḟ - floor (vectorises)
$endgroup$
Jelly, 29 bytes
“¢×ø‘©×
÷ȷ2‘*⁵×÷¢S×¢d®U1¦Ṫ€Ḟ
A full program accepting arguments: rate
; [Galleons, Sickles, Knuts]
; years
.
Prints [Galleons, Sickles, Knuts]
.
Try it online!
Floors at the end of the entire term.÷ȷ2
may be removed if we may accept the rate as a ratio rather than a percentage.
How?
“¢×ø‘©× - Link 1 multipliers: no arguments
“¢×ø‘ - list of code-age indices = [1,17,29]
© - (copy this to the register for later use)
- reduce by:
× - multiplication = [1,17,483]
÷ȷ2‘*⁵×÷¢S×¢d®U1¦Ṫ€Ḟ - Main Link
ȷ2 - 10^2 = 100
÷ - divide = rate/100
‘ - increment = 1+rate/100
⁵ - 5th command line argument (3rd input) = years
* - exponentiate = (1+rate/100)^years --i.e. multiplicand
× - multiply (by the borrowed amounts)
¢ - call last Link as a nilad
÷ - divide (all amounts in Galleons)
S - sum (total Galleons owed)
¢ - call last Link as a nilad
× - multiply (total owed in each of Galleons, Sickles, Knuts)
® - recall from register = [1,17,29]
d - divmod (vectorises) = [[G/1, G%1], [S/17, S^17], [K/17, K%17]]
U1¦ - reverse first one = [[G%1, G/1], [S/17, S%17], [K/17, K%17]]
Ṫ€ - tail €ach = [G/1, S%17, K%17]
Ḟ - floor (vectorises)
edited 8 hours ago
answered 8 hours ago
Jonathan AllanJonathan Allan
52.4k535170
52.4k535170
add a comment |
add a comment |
$begingroup$
K, 46 Bytes
c:1000 17 29
t:{c:{z(y*)/x}[c/:x;1+y%100;z]}
c
store the list for base-conversion
t
is the function that calculates total amount
Use example:
t[103 16 23;7.25;3]
writes (128;4;24.29209)
Explanation:
c/:x
transform the list (galleon; sickle; knuts) to kuts1+y%100
calculate rate of interest (example 1.0725 for 7.25% rate)lambda
{z(y*)x}
does the work: iterate 3 times, applying interes*main, and returns final main.c:
generates galleon, sickles, knuts from knuts
NOTE.- if you don't need a names-function, we can use a lambda, saving 2 bytes
{c:{z(y*)/x}[c/:x;1+y%100;z]}inputArgs
$endgroup$
add a comment |
$begingroup$
K, 46 Bytes
c:1000 17 29
t:{c:{z(y*)/x}[c/:x;1+y%100;z]}
c
store the list for base-conversion
t
is the function that calculates total amount
Use example:
t[103 16 23;7.25;3]
writes (128;4;24.29209)
Explanation:
c/:x
transform the list (galleon; sickle; knuts) to kuts1+y%100
calculate rate of interest (example 1.0725 for 7.25% rate)lambda
{z(y*)x}
does the work: iterate 3 times, applying interes*main, and returns final main.c:
generates galleon, sickles, knuts from knuts
NOTE.- if you don't need a names-function, we can use a lambda, saving 2 bytes
{c:{z(y*)/x}[c/:x;1+y%100;z]}inputArgs
$endgroup$
add a comment |
$begingroup$
K, 46 Bytes
c:1000 17 29
t:{c:{z(y*)/x}[c/:x;1+y%100;z]}
c
store the list for base-conversion
t
is the function that calculates total amount
Use example:
t[103 16 23;7.25;3]
writes (128;4;24.29209)
Explanation:
c/:x
transform the list (galleon; sickle; knuts) to kuts1+y%100
calculate rate of interest (example 1.0725 for 7.25% rate)lambda
{z(y*)x}
does the work: iterate 3 times, applying interes*main, and returns final main.c:
generates galleon, sickles, knuts from knuts
NOTE.- if you don't need a names-function, we can use a lambda, saving 2 bytes
{c:{z(y*)/x}[c/:x;1+y%100;z]}inputArgs
$endgroup$
K, 46 Bytes
c:1000 17 29
t:{c:{z(y*)/x}[c/:x;1+y%100;z]}
c
store the list for base-conversion
t
is the function that calculates total amount
Use example:
t[103 16 23;7.25;3]
writes (128;4;24.29209)
Explanation:
c/:x
transform the list (galleon; sickle; knuts) to kuts1+y%100
calculate rate of interest (example 1.0725 for 7.25% rate)lambda
{z(y*)x}
does the work: iterate 3 times, applying interes*main, and returns final main.c:
generates galleon, sickles, knuts from knuts
NOTE.- if you don't need a names-function, we can use a lambda, saving 2 bytes
{c:{z(y*)/x}[c/:x;1+y%100;z]}inputArgs
answered 6 hours ago
J. SendraJ. Sendra
37625
37625
add a comment |
add a comment |
$begingroup$
APL+WIN, 37 bytes
⌊n,17 29⊤493×n←(+/⎕÷1 17 493)×(1+⎕)*⎕
Try it online! Courtesy of Dyalog Classic
Explanation:
(1+⎕)*⎕ prompts for years followed by decimal interest rate and calculates
compounding multiplier
n←(+/⎕÷1 17 493) prompts for Galleons, Sickles and Knuts and converts to decimal Galleons
⌊n,17 29⊤493× converts decimal Galleons after applying compound interest,
converts back to Galleons, Sickles and Knuts and rounds down
$endgroup$
add a comment |
$begingroup$
APL+WIN, 37 bytes
⌊n,17 29⊤493×n←(+/⎕÷1 17 493)×(1+⎕)*⎕
Try it online! Courtesy of Dyalog Classic
Explanation:
(1+⎕)*⎕ prompts for years followed by decimal interest rate and calculates
compounding multiplier
n←(+/⎕÷1 17 493) prompts for Galleons, Sickles and Knuts and converts to decimal Galleons
⌊n,17 29⊤493× converts decimal Galleons after applying compound interest,
converts back to Galleons, Sickles and Knuts and rounds down
$endgroup$
add a comment |
$begingroup$
APL+WIN, 37 bytes
⌊n,17 29⊤493×n←(+/⎕÷1 17 493)×(1+⎕)*⎕
Try it online! Courtesy of Dyalog Classic
Explanation:
(1+⎕)*⎕ prompts for years followed by decimal interest rate and calculates
compounding multiplier
n←(+/⎕÷1 17 493) prompts for Galleons, Sickles and Knuts and converts to decimal Galleons
⌊n,17 29⊤493× converts decimal Galleons after applying compound interest,
converts back to Galleons, Sickles and Knuts and rounds down
$endgroup$
APL+WIN, 37 bytes
⌊n,17 29⊤493×n←(+/⎕÷1 17 493)×(1+⎕)*⎕
Try it online! Courtesy of Dyalog Classic
Explanation:
(1+⎕)*⎕ prompts for years followed by decimal interest rate and calculates
compounding multiplier
n←(+/⎕÷1 17 493) prompts for Galleons, Sickles and Knuts and converts to decimal Galleons
⌊n,17 29⊤493× converts decimal Galleons after applying compound interest,
converts back to Galleons, Sickles and Knuts and rounds down
edited 5 hours ago
answered 6 hours ago
GrahamGraham
2,45678
2,45678
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 86 bytes
(a,b,c)=>((k=(int)((a.a*493+a.b*29+a.c)*Math.Pow(1+b,c)))/493,(k%=493)/29,k%29);int k;
Takes inout as a named tuple with 3 values representing knuts, sickles, and galleons, and interest rate as a double (not a percentage). I really wish C# had an exponentation operator. Math.Pow is way too long :(
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 86 bytes
(a,b,c)=>((k=(int)((a.a*493+a.b*29+a.c)*Math.Pow(1+b,c)))/493,(k%=493)/29,k%29);int k;
Takes inout as a named tuple with 3 values representing knuts, sickles, and galleons, and interest rate as a double (not a percentage). I really wish C# had an exponentation operator. Math.Pow is way too long :(
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 86 bytes
(a,b,c)=>((k=(int)((a.a*493+a.b*29+a.c)*Math.Pow(1+b,c)))/493,(k%=493)/29,k%29);int k;
Takes inout as a named tuple with 3 values representing knuts, sickles, and galleons, and interest rate as a double (not a percentage). I really wish C# had an exponentation operator. Math.Pow is way too long :(
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 86 bytes
(a,b,c)=>((k=(int)((a.a*493+a.b*29+a.c)*Math.Pow(1+b,c)))/493,(k%=493)/29,k%29);int k;
Takes inout as a named tuple with 3 values representing knuts, sickles, and galleons, and interest rate as a double (not a percentage). I really wish C# had an exponentation operator. Math.Pow is way too long :(
Try it online!
edited 2 hours ago
answered 6 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
1,378122
1,378122
add a comment |
add a comment |
$begingroup$
Japt, 48 bytes
XÄ pY *(U*493+V*29+W)f
Uu493
[Uz493 ,Vz29 ,Vu29]
My first try at Japt, going for @Shaggy's bounty! Needless to say, this isn't very golfy :(
Try it Online!
$endgroup$
add a comment |
$begingroup$
Japt, 48 bytes
XÄ pY *(U*493+V*29+W)f
Uu493
[Uz493 ,Vz29 ,Vu29]
My first try at Japt, going for @Shaggy's bounty! Needless to say, this isn't very golfy :(
Try it Online!
$endgroup$
add a comment |
$begingroup$
Japt, 48 bytes
XÄ pY *(U*493+V*29+W)f
Uu493
[Uz493 ,Vz29 ,Vu29]
My first try at Japt, going for @Shaggy's bounty! Needless to say, this isn't very golfy :(
Try it Online!
$endgroup$
Japt, 48 bytes
XÄ pY *(U*493+V*29+W)f
Uu493
[Uz493 ,Vz29 ,Vu29]
My first try at Japt, going for @Shaggy's bounty! Needless to say, this isn't very golfy :(
Try it Online!
answered 2 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
1,378122
1,378122
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f180776%2fcompound-interest-with-wizard-money%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
$begingroup$
Can we take the interest rate as a decimal instead of a percentage? (e.g.,
0.0725
instead of7.25
)$endgroup$
– Shaggy
8 hours ago
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
7 hours ago
$begingroup$
If the loan is exactly 1 Knut, and the interest is 99% per year, and the term is 1 year, should the result be "1 Knut" or "2 Knuts"?
$endgroup$
– Chas Brown
5 hours ago
$begingroup$
In other words, please clarify the mathematical meaning of the phrase
rounding down
$endgroup$
– senox13
4 hours ago
$begingroup$
@Shaggy: of course. It's just a different representation, which is fair game for I/O
$endgroup$
– Beefster
23 mins ago