Compound Interest… with Wizard MoneySave money with price roundingPlus one sheep minus one sheepIonic...
What is the wife of a henpecked husband called?
What is better: yes / no radio, or simple checkbox?
Has the Isbell–Freyd criterion ever been used to check that a category is concretisable?
Do my Windows system binaries contain sensitive information?
Proof by Induction - New to proofs
Could be quantum mechanics necessary to analyze some biology scenarios?
Metadata API deployments are failing in Spring '19
How to prepare vegetables for a sandwich that can last for several days in a fridge?
What happens if a wizard reaches level 20 but has no 3rd-level spells that they can use with the Signature Spells feature?
Why do members of Congress in committee hearings ask witnesses the same question multiple times?
Wanted: 5.25 floppy to usb adapter
"Sheng" as a male given name
How would an AI self awareness kill switch work?
Why is working on the same position for more than 15 years not a red flag?
Where is this triangular-shaped space station from?
Quenching swords in dragon blood; why?
Does this pattern of summing polygonal numbers to get a square repeat indefinitely?
How can I improve my fireworks photography?
How to acknowledge an embarrassing job interview, now that I work directly with the interviewer?
On what did Lego base the appearance of the new Hogwarts minifigs?
Meth dealer reference in Family Guy
'A' vs 'an' in newspaper article
4 Spheres all touching each other??
How to mitigate "bandwagon attacking" from players?
Compound Interest… with Wizard Money
Save money with price roundingPlus one sheep minus one sheepIonic Compound GolfPerson of InterestBounce DynamicsInverse regex of compound interestCalculate the Trump TaxWho owes who money?Loan “generous” amounts of moneyCompound interest with additions
$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
yesterday
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
yesterday
$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
yesterday
$begingroup$
In other words, please clarify the mathematical meaning of the phraserounding down
$endgroup$
– senox13
yesterday
1
$begingroup$
@ChasBrown: 1 Knut. Truncate/floor function to the nearest whole Knut.
$endgroup$
– Beefster
21 hours 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 yesterday
BeefsterBeefster
1,921833
1,921833
4
$begingroup$
Can we take the interest rate as a decimal instead of a percentage? (e.g.,0.0725
instead of7.25
)
$endgroup$
– Shaggy
yesterday
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
yesterday
$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
yesterday
$begingroup$
In other words, please clarify the mathematical meaning of the phraserounding down
$endgroup$
– senox13
yesterday
1
$begingroup$
@ChasBrown: 1 Knut. Truncate/floor function to the nearest whole Knut.
$endgroup$
– Beefster
21 hours 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
yesterday
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
yesterday
$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
yesterday
$begingroup$
In other words, please clarify the mathematical meaning of the phraserounding down
$endgroup$
– senox13
yesterday
1
$begingroup$
@ChasBrown: 1 Knut. Truncate/floor function to the nearest whole Knut.
$endgroup$
– Beefster
21 hours 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
yesterday
$begingroup$
Can we take the interest rate as a decimal instead of a percentage? (e.g.,
0.0725
instead of 7.25
)$endgroup$
– Shaggy
yesterday
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
yesterday
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
yesterday
$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
yesterday
$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
yesterday
$begingroup$
In other words, please clarify the mathematical meaning of the phrase
rounding down
$endgroup$
– senox13
yesterday
$begingroup$
In other words, please clarify the mathematical meaning of the phrase
rounding down
$endgroup$
– senox13
yesterday
1
1
$begingroup$
@ChasBrown: 1 Knut. Truncate/floor function to the nearest whole Knut.
$endgroup$
– Beefster
21 hours ago
$begingroup$
@ChasBrown: 1 Knut. Truncate/floor function to the nearest whole Knut.
$endgroup$
– Beefster
21 hours ago
|
show 1 more comment
9 Answers
9
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
yesterday
$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
yesterday
$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
yesterday
$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
yesterday
$begingroup$
FYI, a useful trick to make anonymous functions testable on TIO is to putI=
in the header like this. Also, it looks likek//29//17
can bek//493
.
$endgroup$
– xnor
yesterday
|
show 1 more comment
$begingroup$
APL+WIN, 37 28 26 bytes
⌊a⊤((a←0 17 29)⊥⎕)×(1+⎕)*⎕
2 bytes saved thanks to lirtosiast
Try it online! Courtesy of Dyalog Classic
Explanation:
(1+⎕)*⎕ prompts for years followed by decimal interest rate and calculates
compounding multiplier
((a←0 17 29)⊥⎕) prompts for Galleons, Sickles and Knuts and converts to Knuts
⌊a⊤ converts back to Galleons, Sickles and Knuts and floor
after applying compound interest.
$endgroup$
$begingroup$
⌊a⊤(⎕⊥⍨a←0 17 29)×⎕*⍨1+⎕
for 24?
$endgroup$
– lirtosiast
19 hours ago
$begingroup$
@lirtosiast Thanks but I am afraid my ancient APL+WIN interpreter does not have the ⍨ function. By all means submit this as your own APL solution.
$endgroup$
– Graham
19 hours ago
$begingroup$
@lirtosiast Thanks again I have taken the 2 bytes resulting from the assignment to a.
$endgroup$
– Graham
18 hours ago
add a comment |
$begingroup$
R, 70 bytes
function(d,i,y,m=sum(d*(a=c(1,29,493))))(m*(1+i)^y)%/%a%%c(29,17,1e99)
Try it online!
Takes input as d: deposit in knuts, sickles, galleons; i: interest rate as decimal; y: years. Outputs final deposit in knuts, sickles, galleons. Galleons would wrap round at 1e99 which I hope is acceptable.
$endgroup$
add a comment |
$begingroup$
Perl 6, 47 bytes
((1+*)*** *(*Z*1,29,493).sum+|0).polymod(29,17)
Try it online!
I'm surprised I managed to get this into an anonymous Whatever lambda! Especially the part where it's more *
s than anything else. Takes input as interest rate (e.g. 0.0725), years, [Knuts, Sickles, Galleons]
and returns a list of currencies in the same order.
Explanation:
(1+*) # Add one to the interest rate
*** # Raise to the power of the year
* # And multiply by
(*Z*1,29,493).sum # The number of Knuts in the input
+|0 # And floor it
( ).polymod(29,17) # Get the modulos after divmoding by 29 and 17
$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,493]
÷ȷ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$
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 |
$begingroup$
Batch, 171 bytes
@set i=%4
@set/af=0,i=8*%i:.=,f=%,f*=8
@set/ai+=%f:~,1%,k=%1*493+%2*29+%3
@for /l %%y in (1,1,%5)do @set/ak+=k*i/800
@set/ag=k/493,s=k/29%%17,k%%=29
@echo %g% %s% %k%
Takes input as command-line arguments in the order Galleons, Sickles, Knuts, interest, years. Interest is a percentage but expressed without the % sign. Truncates after every year. Output is in the order Galleons, Sickles, Knuts. Supports at least 5000 Galleons. Explanation:
@set i=%4
@set/af=0,i=8*%i:.=,f=%,f*=8
Batch only has integer arithmetic. Fortunately, the interest rate is always a multiple of 0.125
. We start by splitting on the decimal point, so that i
becomes the integer part of the interest rate and f
the decimal fraction. These are then multiplied by 8. The first digit of f
is now the number of eighths in the percentage interest rate.
@set/ai+=%f:~,1%,k=%1*493+%2*29+%3
This is then extracted using string slicing and added on to give an interest rate in 1/800ths. The number of Knuts is also calculated.
@for /l %%y in (1,1,%5)do @set/ak+=k*i/800
Calculate and add on each year's interest.
@set/ag=k/493,s=k/29%%17,k%%=29
@echo %g% %s% %k%
Convert back to Galleons and Sickles.
$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
9 Answers
9
active
oldest
votes
9 Answers
9
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
yesterday
$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
yesterday
$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
yesterday
$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
yesterday
$begingroup$
FYI, a useful trick to make anonymous functions testable on TIO is to putI=
in the header like this. Also, it looks likek//29//17
can bek//493
.
$endgroup$
– xnor
yesterday
|
show 1 more comment
$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
yesterday
$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
yesterday
$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
yesterday
$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
yesterday
$begingroup$
FYI, a useful trick to make anonymous functions testable on TIO is to putI=
in the header like this. Also, it looks likek//29//17
can bek//493
.
$endgroup$
– xnor
yesterday
|
show 1 more comment
$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 yesterday
answered yesterday
senox13senox13
915
915
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
yesterday
$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
yesterday
$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
yesterday
$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
yesterday
$begingroup$
FYI, a useful trick to make anonymous functions testable on TIO is to putI=
in the header like this. Also, it looks likek//29//17
can bek//493
.
$endgroup$
– xnor
yesterday
|
show 1 more comment
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
yesterday
$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
yesterday
$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
yesterday
$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
yesterday
$begingroup$
FYI, a useful trick to make anonymous functions testable on TIO is to putI=
in the header like this. Also, it looks likek//29//17
can bek//493
.
$endgroup$
– xnor
yesterday
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
yesterday
$begingroup$
Good catch. Updating answer
$endgroup$
– senox13
yesterday
$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
yesterday
$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
yesterday
$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
yesterday
$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
yesterday
$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
yesterday
$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
yesterday
$begingroup$
FYI, a useful trick to make anonymous functions testable on TIO is to put
I=
in the header like this. Also, it looks like k//29//17
can be k//493
.$endgroup$
– xnor
yesterday
$begingroup$
FYI, a useful trick to make anonymous functions testable on TIO is to put
I=
in the header like this. Also, it looks like k//29//17
can be k//493
.$endgroup$
– xnor
yesterday
|
show 1 more comment
$begingroup$
APL+WIN, 37 28 26 bytes
⌊a⊤((a←0 17 29)⊥⎕)×(1+⎕)*⎕
2 bytes saved thanks to lirtosiast
Try it online! Courtesy of Dyalog Classic
Explanation:
(1+⎕)*⎕ prompts for years followed by decimal interest rate and calculates
compounding multiplier
((a←0 17 29)⊥⎕) prompts for Galleons, Sickles and Knuts and converts to Knuts
⌊a⊤ converts back to Galleons, Sickles and Knuts and floor
after applying compound interest.
$endgroup$
$begingroup$
⌊a⊤(⎕⊥⍨a←0 17 29)×⎕*⍨1+⎕
for 24?
$endgroup$
– lirtosiast
19 hours ago
$begingroup$
@lirtosiast Thanks but I am afraid my ancient APL+WIN interpreter does not have the ⍨ function. By all means submit this as your own APL solution.
$endgroup$
– Graham
19 hours ago
$begingroup$
@lirtosiast Thanks again I have taken the 2 bytes resulting from the assignment to a.
$endgroup$
– Graham
18 hours ago
add a comment |
$begingroup$
APL+WIN, 37 28 26 bytes
⌊a⊤((a←0 17 29)⊥⎕)×(1+⎕)*⎕
2 bytes saved thanks to lirtosiast
Try it online! Courtesy of Dyalog Classic
Explanation:
(1+⎕)*⎕ prompts for years followed by decimal interest rate and calculates
compounding multiplier
((a←0 17 29)⊥⎕) prompts for Galleons, Sickles and Knuts and converts to Knuts
⌊a⊤ converts back to Galleons, Sickles and Knuts and floor
after applying compound interest.
$endgroup$
$begingroup$
⌊a⊤(⎕⊥⍨a←0 17 29)×⎕*⍨1+⎕
for 24?
$endgroup$
– lirtosiast
19 hours ago
$begingroup$
@lirtosiast Thanks but I am afraid my ancient APL+WIN interpreter does not have the ⍨ function. By all means submit this as your own APL solution.
$endgroup$
– Graham
19 hours ago
$begingroup$
@lirtosiast Thanks again I have taken the 2 bytes resulting from the assignment to a.
$endgroup$
– Graham
18 hours ago
add a comment |
$begingroup$
APL+WIN, 37 28 26 bytes
⌊a⊤((a←0 17 29)⊥⎕)×(1+⎕)*⎕
2 bytes saved thanks to lirtosiast
Try it online! Courtesy of Dyalog Classic
Explanation:
(1+⎕)*⎕ prompts for years followed by decimal interest rate and calculates
compounding multiplier
((a←0 17 29)⊥⎕) prompts for Galleons, Sickles and Knuts and converts to Knuts
⌊a⊤ converts back to Galleons, Sickles and Knuts and floor
after applying compound interest.
$endgroup$
APL+WIN, 37 28 26 bytes
⌊a⊤((a←0 17 29)⊥⎕)×(1+⎕)*⎕
2 bytes saved thanks to lirtosiast
Try it online! Courtesy of Dyalog Classic
Explanation:
(1+⎕)*⎕ prompts for years followed by decimal interest rate and calculates
compounding multiplier
((a←0 17 29)⊥⎕) prompts for Galleons, Sickles and Knuts and converts to Knuts
⌊a⊤ converts back to Galleons, Sickles and Knuts and floor
after applying compound interest.
edited 19 hours ago
answered yesterday
GrahamGraham
2,46678
2,46678
$begingroup$
⌊a⊤(⎕⊥⍨a←0 17 29)×⎕*⍨1+⎕
for 24?
$endgroup$
– lirtosiast
19 hours ago
$begingroup$
@lirtosiast Thanks but I am afraid my ancient APL+WIN interpreter does not have the ⍨ function. By all means submit this as your own APL solution.
$endgroup$
– Graham
19 hours ago
$begingroup$
@lirtosiast Thanks again I have taken the 2 bytes resulting from the assignment to a.
$endgroup$
– Graham
18 hours ago
add a comment |
$begingroup$
⌊a⊤(⎕⊥⍨a←0 17 29)×⎕*⍨1+⎕
for 24?
$endgroup$
– lirtosiast
19 hours ago
$begingroup$
@lirtosiast Thanks but I am afraid my ancient APL+WIN interpreter does not have the ⍨ function. By all means submit this as your own APL solution.
$endgroup$
– Graham
19 hours ago
$begingroup$
@lirtosiast Thanks again I have taken the 2 bytes resulting from the assignment to a.
$endgroup$
– Graham
18 hours ago
$begingroup$
⌊a⊤(⎕⊥⍨a←0 17 29)×⎕*⍨1+⎕
for 24?$endgroup$
– lirtosiast
19 hours ago
$begingroup$
⌊a⊤(⎕⊥⍨a←0 17 29)×⎕*⍨1+⎕
for 24?$endgroup$
– lirtosiast
19 hours ago
$begingroup$
@lirtosiast Thanks but I am afraid my ancient APL+WIN interpreter does not have the ⍨ function. By all means submit this as your own APL solution.
$endgroup$
– Graham
19 hours ago
$begingroup$
@lirtosiast Thanks but I am afraid my ancient APL+WIN interpreter does not have the ⍨ function. By all means submit this as your own APL solution.
$endgroup$
– Graham
19 hours ago
$begingroup$
@lirtosiast Thanks again I have taken the 2 bytes resulting from the assignment to a.
$endgroup$
– Graham
18 hours ago
$begingroup$
@lirtosiast Thanks again I have taken the 2 bytes resulting from the assignment to a.
$endgroup$
– Graham
18 hours ago
add a comment |
$begingroup$
R, 70 bytes
function(d,i,y,m=sum(d*(a=c(1,29,493))))(m*(1+i)^y)%/%a%%c(29,17,1e99)
Try it online!
Takes input as d: deposit in knuts, sickles, galleons; i: interest rate as decimal; y: years. Outputs final deposit in knuts, sickles, galleons. Galleons would wrap round at 1e99 which I hope is acceptable.
$endgroup$
add a comment |
$begingroup$
R, 70 bytes
function(d,i,y,m=sum(d*(a=c(1,29,493))))(m*(1+i)^y)%/%a%%c(29,17,1e99)
Try it online!
Takes input as d: deposit in knuts, sickles, galleons; i: interest rate as decimal; y: years. Outputs final deposit in knuts, sickles, galleons. Galleons would wrap round at 1e99 which I hope is acceptable.
$endgroup$
add a comment |
$begingroup$
R, 70 bytes
function(d,i,y,m=sum(d*(a=c(1,29,493))))(m*(1+i)^y)%/%a%%c(29,17,1e99)
Try it online!
Takes input as d: deposit in knuts, sickles, galleons; i: interest rate as decimal; y: years. Outputs final deposit in knuts, sickles, galleons. Galleons would wrap round at 1e99 which I hope is acceptable.
$endgroup$
R, 70 bytes
function(d,i,y,m=sum(d*(a=c(1,29,493))))(m*(1+i)^y)%/%a%%c(29,17,1e99)
Try it online!
Takes input as d: deposit in knuts, sickles, galleons; i: interest rate as decimal; y: years. Outputs final deposit in knuts, sickles, galleons. Galleons would wrap round at 1e99 which I hope is acceptable.
answered 15 hours ago
Nick KennedyNick Kennedy
29115
29115
add a comment |
add a comment |
$begingroup$
Perl 6, 47 bytes
((1+*)*** *(*Z*1,29,493).sum+|0).polymod(29,17)
Try it online!
I'm surprised I managed to get this into an anonymous Whatever lambda! Especially the part where it's more *
s than anything else. Takes input as interest rate (e.g. 0.0725), years, [Knuts, Sickles, Galleons]
and returns a list of currencies in the same order.
Explanation:
(1+*) # Add one to the interest rate
*** # Raise to the power of the year
* # And multiply by
(*Z*1,29,493).sum # The number of Knuts in the input
+|0 # And floor it
( ).polymod(29,17) # Get the modulos after divmoding by 29 and 17
$endgroup$
add a comment |
$begingroup$
Perl 6, 47 bytes
((1+*)*** *(*Z*1,29,493).sum+|0).polymod(29,17)
Try it online!
I'm surprised I managed to get this into an anonymous Whatever lambda! Especially the part where it's more *
s than anything else. Takes input as interest rate (e.g. 0.0725), years, [Knuts, Sickles, Galleons]
and returns a list of currencies in the same order.
Explanation:
(1+*) # Add one to the interest rate
*** # Raise to the power of the year
* # And multiply by
(*Z*1,29,493).sum # The number of Knuts in the input
+|0 # And floor it
( ).polymod(29,17) # Get the modulos after divmoding by 29 and 17
$endgroup$
add a comment |
$begingroup$
Perl 6, 47 bytes
((1+*)*** *(*Z*1,29,493).sum+|0).polymod(29,17)
Try it online!
I'm surprised I managed to get this into an anonymous Whatever lambda! Especially the part where it's more *
s than anything else. Takes input as interest rate (e.g. 0.0725), years, [Knuts, Sickles, Galleons]
and returns a list of currencies in the same order.
Explanation:
(1+*) # Add one to the interest rate
*** # Raise to the power of the year
* # And multiply by
(*Z*1,29,493).sum # The number of Knuts in the input
+|0 # And floor it
( ).polymod(29,17) # Get the modulos after divmoding by 29 and 17
$endgroup$
Perl 6, 47 bytes
((1+*)*** *(*Z*1,29,493).sum+|0).polymod(29,17)
Try it online!
I'm surprised I managed to get this into an anonymous Whatever lambda! Especially the part where it's more *
s than anything else. Takes input as interest rate (e.g. 0.0725), years, [Knuts, Sickles, Galleons]
and returns a list of currencies in the same order.
Explanation:
(1+*) # Add one to the interest rate
*** # Raise to the power of the year
* # And multiply by
(*Z*1,29,493).sum # The number of Knuts in the input
+|0 # And floor it
( ).polymod(29,17) # Get the modulos after divmoding by 29 and 17
answered 14 hours ago
Jo KingJo King
24.1k357124
24.1k357124
add a comment |
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,493]
÷ȷ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,493]
÷ȷ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,493]
÷ȷ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,493]
÷ȷ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 7 hours ago
answered yesterday
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 yesterday
J. SendraJ. Sendra
37625
37625
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 23 hours ago
answered yesterday
Embodiment of IgnoranceEmbodiment of Ignorance
1,388122
1,388122
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 23 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
1,388122
1,388122
add a comment |
add a comment |
$begingroup$
Batch, 171 bytes
@set i=%4
@set/af=0,i=8*%i:.=,f=%,f*=8
@set/ai+=%f:~,1%,k=%1*493+%2*29+%3
@for /l %%y in (1,1,%5)do @set/ak+=k*i/800
@set/ag=k/493,s=k/29%%17,k%%=29
@echo %g% %s% %k%
Takes input as command-line arguments in the order Galleons, Sickles, Knuts, interest, years. Interest is a percentage but expressed without the % sign. Truncates after every year. Output is in the order Galleons, Sickles, Knuts. Supports at least 5000 Galleons. Explanation:
@set i=%4
@set/af=0,i=8*%i:.=,f=%,f*=8
Batch only has integer arithmetic. Fortunately, the interest rate is always a multiple of 0.125
. We start by splitting on the decimal point, so that i
becomes the integer part of the interest rate and f
the decimal fraction. These are then multiplied by 8. The first digit of f
is now the number of eighths in the percentage interest rate.
@set/ai+=%f:~,1%,k=%1*493+%2*29+%3
This is then extracted using string slicing and added on to give an interest rate in 1/800ths. The number of Knuts is also calculated.
@for /l %%y in (1,1,%5)do @set/ak+=k*i/800
Calculate and add on each year's interest.
@set/ag=k/493,s=k/29%%17,k%%=29
@echo %g% %s% %k%
Convert back to Galleons and Sickles.
$endgroup$
add a comment |
$begingroup$
Batch, 171 bytes
@set i=%4
@set/af=0,i=8*%i:.=,f=%,f*=8
@set/ai+=%f:~,1%,k=%1*493+%2*29+%3
@for /l %%y in (1,1,%5)do @set/ak+=k*i/800
@set/ag=k/493,s=k/29%%17,k%%=29
@echo %g% %s% %k%
Takes input as command-line arguments in the order Galleons, Sickles, Knuts, interest, years. Interest is a percentage but expressed without the % sign. Truncates after every year. Output is in the order Galleons, Sickles, Knuts. Supports at least 5000 Galleons. Explanation:
@set i=%4
@set/af=0,i=8*%i:.=,f=%,f*=8
Batch only has integer arithmetic. Fortunately, the interest rate is always a multiple of 0.125
. We start by splitting on the decimal point, so that i
becomes the integer part of the interest rate and f
the decimal fraction. These are then multiplied by 8. The first digit of f
is now the number of eighths in the percentage interest rate.
@set/ai+=%f:~,1%,k=%1*493+%2*29+%3
This is then extracted using string slicing and added on to give an interest rate in 1/800ths. The number of Knuts is also calculated.
@for /l %%y in (1,1,%5)do @set/ak+=k*i/800
Calculate and add on each year's interest.
@set/ag=k/493,s=k/29%%17,k%%=29
@echo %g% %s% %k%
Convert back to Galleons and Sickles.
$endgroup$
add a comment |
$begingroup$
Batch, 171 bytes
@set i=%4
@set/af=0,i=8*%i:.=,f=%,f*=8
@set/ai+=%f:~,1%,k=%1*493+%2*29+%3
@for /l %%y in (1,1,%5)do @set/ak+=k*i/800
@set/ag=k/493,s=k/29%%17,k%%=29
@echo %g% %s% %k%
Takes input as command-line arguments in the order Galleons, Sickles, Knuts, interest, years. Interest is a percentage but expressed without the % sign. Truncates after every year. Output is in the order Galleons, Sickles, Knuts. Supports at least 5000 Galleons. Explanation:
@set i=%4
@set/af=0,i=8*%i:.=,f=%,f*=8
Batch only has integer arithmetic. Fortunately, the interest rate is always a multiple of 0.125
. We start by splitting on the decimal point, so that i
becomes the integer part of the interest rate and f
the decimal fraction. These are then multiplied by 8. The first digit of f
is now the number of eighths in the percentage interest rate.
@set/ai+=%f:~,1%,k=%1*493+%2*29+%3
This is then extracted using string slicing and added on to give an interest rate in 1/800ths. The number of Knuts is also calculated.
@for /l %%y in (1,1,%5)do @set/ak+=k*i/800
Calculate and add on each year's interest.
@set/ag=k/493,s=k/29%%17,k%%=29
@echo %g% %s% %k%
Convert back to Galleons and Sickles.
$endgroup$
Batch, 171 bytes
@set i=%4
@set/af=0,i=8*%i:.=,f=%,f*=8
@set/ai+=%f:~,1%,k=%1*493+%2*29+%3
@for /l %%y in (1,1,%5)do @set/ak+=k*i/800
@set/ag=k/493,s=k/29%%17,k%%=29
@echo %g% %s% %k%
Takes input as command-line arguments in the order Galleons, Sickles, Knuts, interest, years. Interest is a percentage but expressed without the % sign. Truncates after every year. Output is in the order Galleons, Sickles, Knuts. Supports at least 5000 Galleons. Explanation:
@set i=%4
@set/af=0,i=8*%i:.=,f=%,f*=8
Batch only has integer arithmetic. Fortunately, the interest rate is always a multiple of 0.125
. We start by splitting on the decimal point, so that i
becomes the integer part of the interest rate and f
the decimal fraction. These are then multiplied by 8. The first digit of f
is now the number of eighths in the percentage interest rate.
@set/ai+=%f:~,1%,k=%1*493+%2*29+%3
This is then extracted using string slicing and added on to give an interest rate in 1/800ths. The number of Knuts is also calculated.
@for /l %%y in (1,1,%5)do @set/ak+=k*i/800
Calculate and add on each year's interest.
@set/ag=k/493,s=k/29%%17,k%%=29
@echo %g% %s% %k%
Convert back to Galleons and Sickles.
answered 15 hours ago
NeilNeil
81.3k745178
81.3k745178
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
yesterday
$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
yesterday
$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
yesterday
$begingroup$
In other words, please clarify the mathematical meaning of the phrase
rounding down
$endgroup$
– senox13
yesterday
1
$begingroup$
@ChasBrown: 1 Knut. Truncate/floor function to the nearest whole Knut.
$endgroup$
– Beefster
21 hours ago