Compound Interest… with Wizard Money












4












$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!










share|improve this question









$endgroup$








  • 3




    $begingroup$
    Can we take the interest rate as a decimal instead of a percentage? (e.g., 0.0725 instead of 7.25)
    $endgroup$
    – Shaggy
    5 hours ago










  • $begingroup$
    @Shaggy I would also like to know this
    $endgroup$
    – senox13
    3 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
    1 hour ago










  • $begingroup$
    In other words, please clarify the mathematical meaning of the phrase rounding down
    $endgroup$
    – senox13
    1 hour ago
















4












$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!










share|improve this question









$endgroup$








  • 3




    $begingroup$
    Can we take the interest rate as a decimal instead of a percentage? (e.g., 0.0725 instead of 7.25)
    $endgroup$
    – Shaggy
    5 hours ago










  • $begingroup$
    @Shaggy I would also like to know this
    $endgroup$
    – senox13
    3 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
    1 hour ago










  • $begingroup$
    In other words, please clarify the mathematical meaning of the phrase rounding down
    $endgroup$
    – senox13
    1 hour ago














4












4








4





$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!










share|improve this question









$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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 5 hours ago









BeefsterBeefster

1,896833




1,896833








  • 3




    $begingroup$
    Can we take the interest rate as a decimal instead of a percentage? (e.g., 0.0725 instead of 7.25)
    $endgroup$
    – Shaggy
    5 hours ago










  • $begingroup$
    @Shaggy I would also like to know this
    $endgroup$
    – senox13
    3 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
    1 hour ago










  • $begingroup$
    In other words, please clarify the mathematical meaning of the phrase rounding down
    $endgroup$
    – senox13
    1 hour ago














  • 3




    $begingroup$
    Can we take the interest rate as a decimal instead of a percentage? (e.g., 0.0725 instead of 7.25)
    $endgroup$
    – Shaggy
    5 hours ago










  • $begingroup$
    @Shaggy I would also like to know this
    $endgroup$
    – senox13
    3 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
    1 hour ago










  • $begingroup$
    In other words, please clarify the mathematical meaning of the phrase rounding down
    $endgroup$
    – senox13
    1 hour ago








3




3




$begingroup$
Can we take the interest rate as a decimal instead of a percentage? (e.g., 0.0725 instead of 7.25)
$endgroup$
– Shaggy
5 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
5 hours ago












$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
3 hours ago




$begingroup$
@Shaggy I would also like to know this
$endgroup$
– senox13
3 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
1 hour 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
1 hour ago












$begingroup$
In other words, please clarify the mathematical meaning of the phrase rounding down
$endgroup$
– senox13
1 hour ago




$begingroup$
In other words, please clarify the mathematical meaning of the phrase rounding down
$endgroup$
– senox13
1 hour ago










5 Answers
5






active

oldest

votes


















1












$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!






share|improve this answer











$endgroup$













  • $begingroup$
    Good catch. Updating answer
    $endgroup$
    – senox13
    2 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
    2 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
    2 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
    1 hour 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
    1 hour ago



















0












$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)





share|improve this answer











$endgroup$





















    0












    $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 kuts


    • 1+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






    share|improve this answer









    $endgroup$





















      0












      $begingroup$


      C# (Visual C# Interactive Compiler), 85 bytes





      (a,b,c)=>((k=(int)((a.a*17+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!






      share|improve this answer











      $endgroup$





















        0












        $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





        share|improve this answer











        $endgroup$













          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
          });


          }
          });














          draft saved

          draft discarded


















          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

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1












          $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!






          share|improve this answer











          $endgroup$













          • $begingroup$
            Good catch. Updating answer
            $endgroup$
            – senox13
            2 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
            2 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
            2 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
            1 hour 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
            1 hour ago
















          1












          $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!






          share|improve this answer











          $endgroup$













          • $begingroup$
            Good catch. Updating answer
            $endgroup$
            – senox13
            2 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
            2 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
            2 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
            1 hour 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
            1 hour ago














          1












          1








          1





          $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!






          share|improve this answer











          $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!







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 23 mins ago

























          answered 3 hours ago









          senox13senox13

          714




          714












          • $begingroup$
            Good catch. Updating answer
            $endgroup$
            – senox13
            2 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
            2 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
            2 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
            1 hour 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
            1 hour ago


















          • $begingroup$
            Good catch. Updating answer
            $endgroup$
            – senox13
            2 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
            2 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
            2 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
            1 hour 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
            1 hour ago
















          $begingroup$
          Good catch. Updating answer
          $endgroup$
          – senox13
          2 hours ago




          $begingroup$
          Good catch. Updating answer
          $endgroup$
          – senox13
          2 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
          2 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
          2 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
          2 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
          2 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
          1 hour 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
          1 hour 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
          1 hour 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
          1 hour ago











          0












          $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)





          share|improve this answer











          $endgroup$


















            0












            $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)





            share|improve this answer











            $endgroup$
















              0












              0








              0





              $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)





              share|improve this answer











              $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)






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 4 hours ago

























              answered 4 hours ago









              Jonathan AllanJonathan Allan

              52.4k535170




              52.4k535170























                  0












                  $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 kuts


                  • 1+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






                  share|improve this answer









                  $endgroup$


















                    0












                    $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 kuts


                    • 1+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






                    share|improve this answer









                    $endgroup$
















                      0












                      0








                      0





                      $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 kuts


                      • 1+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






                      share|improve this answer









                      $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 kuts


                      • 1+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







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 2 hours ago









                      J. SendraJ. Sendra

                      37625




                      37625























                          0












                          $begingroup$


                          C# (Visual C# Interactive Compiler), 85 bytes





                          (a,b,c)=>((k=(int)((a.a*17+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!






                          share|improve this answer











                          $endgroup$


















                            0












                            $begingroup$


                            C# (Visual C# Interactive Compiler), 85 bytes





                            (a,b,c)=>((k=(int)((a.a*17+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!






                            share|improve this answer











                            $endgroup$
















                              0












                              0








                              0





                              $begingroup$


                              C# (Visual C# Interactive Compiler), 85 bytes





                              (a,b,c)=>((k=(int)((a.a*17+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!






                              share|improve this answer











                              $endgroup$




                              C# (Visual C# Interactive Compiler), 85 bytes





                              (a,b,c)=>((k=(int)((a.a*17+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!







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 2 hours ago

























                              answered 3 hours ago









                              Embodiment of IgnoranceEmbodiment of Ignorance

                              1,368122




                              1,368122























                                  0












                                  $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





                                  share|improve this answer











                                  $endgroup$


















                                    0












                                    $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





                                    share|improve this answer











                                    $endgroup$
















                                      0












                                      0








                                      0





                                      $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





                                      share|improve this answer











                                      $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






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited 1 hour ago

























                                      answered 3 hours ago









                                      GrahamGraham

                                      2,45678




                                      2,45678






























                                          draft saved

                                          draft discarded




















































                                          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).





                                          draft saved


                                          draft discarded














                                          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





















































                                          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







                                          Popular posts from this blog

                                          Statuo de Libereco

                                          Tanganjiko

                                          Liste der Baudenkmäler in Enneberg