Naismith's rule

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
13
down vote

favorite












Naismith's rule helps to work out the length of time needed for a walk or hike, given the distance and ascent.



Given a non-empty list of the altitude at points evenly spaced along a path and the total distance of that path in metres, you should calculate the time needed according to Naismith's rule.



Naismith's rule is that you should allow one hour for every five kilometres, plus an additional hour for every 600 metres of ascent.



Input must be taken in metres, which is guaranteed to consist of non-negative integers, and output should consistently be either hours or minutes (but not both), and must be able to give decimal numbers where applicable (floating point inaccuracies are OK).



For example, given:



[100, 200, 400, 200, 700, 400], 5000


For the first two elements [100, 200] you have 100 metres of ascent which is 10 minutes. With [200, 400] you have 200 metres of ascent which is 20 minutes, [400, 200] is not ascending so no time is added for that. [200, 700] is 500 metres of ascent which is 50 minutes, and finally [700, 400] is not ascending. One extra hour is added for the distance of five kilometres. This totals to 140 minutes or 2.333... hours.



Test Cases



[0, 600] 2500 -> 1.5 OR 90
[100, 200, 300, 0, 100, 200, 300] 10000 -> 2.8333... OR 170
[40, 5, 35] 1000 -> 0.25 OR 15
[604] 5000 -> 1 OR 60
[10, 10, 10] 2000 -> 0.4 OR 24






share|improve this question





















  • The test cases outputs all have whole-minute results, is that intentional? Are inputs like [10], 5125 or [10, 25, 55], 1000 valid and required to be handled?
    – sundar
    20 hours ago










  • @sundar Yes, they should.
    – Okx
    14 hours ago














up vote
13
down vote

favorite












Naismith's rule helps to work out the length of time needed for a walk or hike, given the distance and ascent.



Given a non-empty list of the altitude at points evenly spaced along a path and the total distance of that path in metres, you should calculate the time needed according to Naismith's rule.



Naismith's rule is that you should allow one hour for every five kilometres, plus an additional hour for every 600 metres of ascent.



Input must be taken in metres, which is guaranteed to consist of non-negative integers, and output should consistently be either hours or minutes (but not both), and must be able to give decimal numbers where applicable (floating point inaccuracies are OK).



For example, given:



[100, 200, 400, 200, 700, 400], 5000


For the first two elements [100, 200] you have 100 metres of ascent which is 10 minutes. With [200, 400] you have 200 metres of ascent which is 20 minutes, [400, 200] is not ascending so no time is added for that. [200, 700] is 500 metres of ascent which is 50 minutes, and finally [700, 400] is not ascending. One extra hour is added for the distance of five kilometres. This totals to 140 minutes or 2.333... hours.



Test Cases



[0, 600] 2500 -> 1.5 OR 90
[100, 200, 300, 0, 100, 200, 300] 10000 -> 2.8333... OR 170
[40, 5, 35] 1000 -> 0.25 OR 15
[604] 5000 -> 1 OR 60
[10, 10, 10] 2000 -> 0.4 OR 24






share|improve this question





















  • The test cases outputs all have whole-minute results, is that intentional? Are inputs like [10], 5125 or [10, 25, 55], 1000 valid and required to be handled?
    – sundar
    20 hours ago










  • @sundar Yes, they should.
    – Okx
    14 hours ago












up vote
13
down vote

favorite









up vote
13
down vote

favorite











Naismith's rule helps to work out the length of time needed for a walk or hike, given the distance and ascent.



Given a non-empty list of the altitude at points evenly spaced along a path and the total distance of that path in metres, you should calculate the time needed according to Naismith's rule.



Naismith's rule is that you should allow one hour for every five kilometres, plus an additional hour for every 600 metres of ascent.



Input must be taken in metres, which is guaranteed to consist of non-negative integers, and output should consistently be either hours or minutes (but not both), and must be able to give decimal numbers where applicable (floating point inaccuracies are OK).



For example, given:



[100, 200, 400, 200, 700, 400], 5000


For the first two elements [100, 200] you have 100 metres of ascent which is 10 minutes. With [200, 400] you have 200 metres of ascent which is 20 minutes, [400, 200] is not ascending so no time is added for that. [200, 700] is 500 metres of ascent which is 50 minutes, and finally [700, 400] is not ascending. One extra hour is added for the distance of five kilometres. This totals to 140 minutes or 2.333... hours.



Test Cases



[0, 600] 2500 -> 1.5 OR 90
[100, 200, 300, 0, 100, 200, 300] 10000 -> 2.8333... OR 170
[40, 5, 35] 1000 -> 0.25 OR 15
[604] 5000 -> 1 OR 60
[10, 10, 10] 2000 -> 0.4 OR 24






share|improve this question













Naismith's rule helps to work out the length of time needed for a walk or hike, given the distance and ascent.



Given a non-empty list of the altitude at points evenly spaced along a path and the total distance of that path in metres, you should calculate the time needed according to Naismith's rule.



Naismith's rule is that you should allow one hour for every five kilometres, plus an additional hour for every 600 metres of ascent.



Input must be taken in metres, which is guaranteed to consist of non-negative integers, and output should consistently be either hours or minutes (but not both), and must be able to give decimal numbers where applicable (floating point inaccuracies are OK).



For example, given:



[100, 200, 400, 200, 700, 400], 5000


For the first two elements [100, 200] you have 100 metres of ascent which is 10 minutes. With [200, 400] you have 200 metres of ascent which is 20 minutes, [400, 200] is not ascending so no time is added for that. [200, 700] is 500 metres of ascent which is 50 minutes, and finally [700, 400] is not ascending. One extra hour is added for the distance of five kilometres. This totals to 140 minutes or 2.333... hours.



Test Cases



[0, 600] 2500 -> 1.5 OR 90
[100, 200, 300, 0, 100, 200, 300] 10000 -> 2.8333... OR 170
[40, 5, 35] 1000 -> 0.25 OR 15
[604] 5000 -> 1 OR 60
[10, 10, 10] 2000 -> 0.4 OR 24








share|improve this question












share|improve this question




share|improve this question








edited yesterday
























asked yesterday









Okx

11.9k27100




11.9k27100











  • The test cases outputs all have whole-minute results, is that intentional? Are inputs like [10], 5125 or [10, 25, 55], 1000 valid and required to be handled?
    – sundar
    20 hours ago










  • @sundar Yes, they should.
    – Okx
    14 hours ago
















  • The test cases outputs all have whole-minute results, is that intentional? Are inputs like [10], 5125 or [10, 25, 55], 1000 valid and required to be handled?
    – sundar
    20 hours ago










  • @sundar Yes, they should.
    – Okx
    14 hours ago















The test cases outputs all have whole-minute results, is that intentional? Are inputs like [10], 5125 or [10, 25, 55], 1000 valid and required to be handled?
– sundar
20 hours ago




The test cases outputs all have whole-minute results, is that intentional? Are inputs like [10], 5125 or [10, 25, 55], 1000 valid and required to be handled?
– sundar
20 hours ago












@sundar Yes, they should.
– Okx
14 hours ago




@sundar Yes, they should.
– Okx
14 hours ago










13 Answers
13






active

oldest

votes

















up vote
6
down vote














R,  44  43 42 bytes





function(A,D)sum(pmax(0,diff(A)),D*.12)/10


Try it online!



-1 byte by using pmax as multiple other answers do



Takes inputs as Ascent and Distance, and returns the time in minutes.



function(A,D) # take Ascent and Distance
diff(A) # take successive differences of ascents
pmax(0, ) # get the positive elements of those
D*.12 # multiply distance by 0.12
sum( , ) # take the sum of all elements
/10 # and divide by 10, returning the result






share|improve this answer























  • You can get 4 more bytes using pryr::f(sum(pmax(0,diff(A)),D*.12)/10) instead of using function
    – Shayne03
    11 hours ago










  • @Shayne03 that would technically change this answer to "R + pryr" which on the rules of the site counts as a different language than base R, so I'll keep this as it is. Thanks for the suggestion, though!
    – Giuseppe
    10 hours ago










  • Thanks, I was unaware.
    – Shayne03
    10 hours ago










  • The explanation is shaped like a hill
    – John Doe
    6 hours ago

















up vote
3
down vote













JavaScript (ES6), 50 bytes



Saved 1 byte thanks to Giuseppe's answer (dividing by 10 at the end of the process)



Takes input as ([altitudes])(distance). Returns the time in minutes.





a=>d=>a.map(p=n=>d-=(x=p-(p=n))<0&&x,d*=.12)&&d/10


Try it online!






share|improve this answer






























    up vote
    2
    down vote














    05AB1E, 15 bytes



    ¥ʒ0›}OT÷s₄;6//+


    Try it online!



    Returns time in minutes.



    Explanation



     + # sum of ...
    ¥ʒ0›}OT÷ # the sum of positive deltas of the altitude divided by 10
    s₄;6// # the distance divided by 83.33333333 (500/6, or the amount of meters per minute)





    share|improve this answer





















    • Almost exactly what I had in mind. Only difference I had was ₄12// instead of ₄;6//. So obvious +1 from me.
      – Kevin Cruijssen
      21 hours ago

















    up vote
    2
    down vote













    Haskell, 47 46 bytes



    d#l@(_:t)=d/5e3+sum(max 0<$>zipWith(-)t l)/600


    Returns the time in hours.



    Try it online!






    share|improve this answer






























      up vote
      2
      down vote













      Python 2, 62 60 bytes



      Saved 2 bytes thanks to ovs.



      lambda e,d:sum((a-b)*(a>b)for a,b in zip(e[1:],e))*.1+d*.012


      Try it online!



      Returns time in minutes.



      # add all increasing slope differences together
      sum(
      # multiply the difference by 0 if a<b, else by 1
      (a-b)*(a>b)
      # create a list of pairs by index, like [(1,0), (2,1) ...(n, n-1)]
      # then interate thru the pairs where a is the higher indexed item and b is the lower indexed item
      for a,b in zip(e[1:],e)
      )
      # * 60 minutes / 600 meters == .1 min/m
      *.1
      # 60 minutes / 5000 meters = .012 min/m
      +d*.012





      share|improve this answer























      • 60 bytes
        – ovs
        yesterday

















      up vote
      2
      down vote














      Perl 6, 45 39 bytes



      6 bytes saved thanks to Jo King.





      $^l*.012+.1*sum (@^a[1..*]Z-@a)Xmax 0


      Try it online!



      The first argument is the list with elevations, the second argument is the length of the trek.



      Let's start from the middle: @^a[1..*]Z-@a takes the first argument (saying @^a, we essentially mean: This is the first argument, and I will be referring to it with @a from now on. (All the variables with ^ correspond to the arguments in the alphabetical order.)), removes the first element and subtracts the same unmodified list element-by-element from it (stopping when the shorter list runs out). That forms a list of differences. Then we do a "cross product" with a zero using the operator max, which returns the list of results of the operator max used on all possible pairs of one element from the list on the left and one on the right. But, since there is only one element on the right, it just acts as a shorthand for using * max 0 on each element of the list. We then sum the results, divide by 10 and add the length $^l$ multiplied by .012, which gives the result in minutes.






      share|improve this answer



















      • 1




        42 bytes using X
        – Jo King
        yesterday










      • @JoKing, that's a nice use of X, thanks!
        – Ramillies
        yesterday






      • 1




        Actually, we can avoid the last X/ by just dividing the sum by 10. 39 bytes
        – Jo King
        yesterday










      • 37 bytes using WhateverCode and .& (returns hours).
        – nwellnhof
        7 hours ago


















      up vote
      1
      down vote














      Jelly, 12 bytes



      ×.12;I}»0÷⁵S


      Try it online!



      -1 thanks to Mr. Xcoder.






      share|improve this answer



















      • 1




        Doesn't ×.12 work?
        – Mr. Xcoder
        yesterday










      • @Mr.Xcoder It does, I was in a hurry.
        – Erik the Outgolfer
        yesterday

















      up vote
      1
      down vote














      oK, 22 bytes



      1_-':x..1.012*


      Try it online! Abusing a parsing bug where .1.012 is the same as .1 .012.



       .1.012* /a = [0.1 * input[0], 0.012 * input[1]]
      . /function(x=a[0], y=a[1])
      1_-':x / a = subtract pairs of elements from x
      0| / a = max(a, 0) w/ implicit map
      y++/ / y + sum(a)



      k, 23 bytes



      .1*(.12*y)++/0


      Try it online!






      share|improve this answer





















      • 1_-':x..1.012* for 21 bytes? start accumulator with y.
        – streetster
        15 hours ago

















      up vote
      1
      down vote














      Pyth, 15 bytes



      c+*E.12s>#0.+QT


      Full program, expects the set of heights as the first argument, distance as the second. Returns the time in minutes.



      Try it online here, or verify all test cases at once here.



      c+*E.12s>#0.+QT Implicit: Q=input 1, E=input 2
      .+Q Take the differences between each height point
      >#0 Filter to remove negative values
      s Take the sum
      *E.12 Multiply the distance by 0.12
      + Add the two previous results
      c T Divide the above by 10, implicit print





      share|improve this answer




























        up vote
        1
        down vote














        APL (Dyalog Unicode), 21 20 18 bytes





        .1×.12⊥⎕,-+/0⌊2-/⎕


        Try it online!



        Traditional function taking input (from right to left) as 1st ⎕=Heights/Depths, 2nd ⎕=Distance.



        Thanks to @ngn for being a wizard one three bytes.



        How it works:



        .1×.12⊥⎕,-+/0⌊2-/⎕ ⍝ Function;
        ⎕ ⍝ Append 0 to the heights vector;
        2-/ ⍝ Pairwise (2) differences (-/);
        0⌊ ⍝ Minimum between 0 and the vector's elements;
        +/ ⍝ Sum (yields the negated total height);
        - ⍝ Subtract from;
        .12⊥⎕, ⍝ Distance × 0.12;
        .1× ⍝ And divide by 10;





        share|improve this answer























        • thanks for "wizard" :) you don't have to copy the expression multiple times in order to test it, put it in a tradfn instead; ,0 is unnecessary, the ⍵ for the problematic test should be ,604, not 604
          – ngn
          20 hours ago










        • See, that's why you're a wizard. The copying the expression multiple times part is totally my fault, I just replaced the ⍺ and ⍵ in the old code with ⎕ and was too lazy to put the tradfn header/footer. The ,0 bit though? Gold.
          – J. Sallé
          15 hours ago

















        up vote
        0
        down vote














        Python 2, 59 bytes





        lambda a,d:d/5e3+sum(max(0,y-x)/6e2for x,y in zip(a,a[1:]))


        Try it online!



        returns hours as a decimal.






        share|improve this answer




























          up vote
          0
          down vote













          Java 8, 89 bytes





          a->n->int s=0,p=0,i=a.length;for(;i-->0;p=a[i])s+=(p=p-a[i])>0?p:0;return s/10+n/500*6;


          Try it online.



          Explanation:



          a->n-> // Method with integer-array and integer parameter and integer return-type
          int s=0, // Sum-integers, starting at 0
          p=0, // Previous integer, starting at 0
          i=a.length;for(;i-->0; // Loop `i` backwards over the array
          ; // After every iteration:
          p=a[i]) // Set `p` to the current value for the next iteration
          s+=(p=p-a[i])>0? // If the previous minus current item is larger than 0:
          p // Add that difference to the sum `s`
          : // Else:
          0; // Leave the sum the same
          return s/10 // Return the sum integer-divided by 10
          +n/500*6; // Plus the second input divided by 500 and then multiplied by 6





          share|improve this answer




























            up vote
            0
            down vote














            Japt, 39 bytes



            0oUl)x@W=UgXÄ -UgX)g ¥É?0:W/#ɘ} +V/(#Ǵ0


            Try it online!



            Likely can be golfed quite a bit more.






            share|improve this answer























              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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              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%2f170075%2fnaismiths-rule%23new-answer', 'question_page');

              );

              Post as a guest






























              13 Answers
              13






              active

              oldest

              votes








              13 Answers
              13






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              6
              down vote














              R,  44  43 42 bytes





              function(A,D)sum(pmax(0,diff(A)),D*.12)/10


              Try it online!



              -1 byte by using pmax as multiple other answers do



              Takes inputs as Ascent and Distance, and returns the time in minutes.



              function(A,D) # take Ascent and Distance
              diff(A) # take successive differences of ascents
              pmax(0, ) # get the positive elements of those
              D*.12 # multiply distance by 0.12
              sum( , ) # take the sum of all elements
              /10 # and divide by 10, returning the result






              share|improve this answer























              • You can get 4 more bytes using pryr::f(sum(pmax(0,diff(A)),D*.12)/10) instead of using function
                – Shayne03
                11 hours ago










              • @Shayne03 that would technically change this answer to "R + pryr" which on the rules of the site counts as a different language than base R, so I'll keep this as it is. Thanks for the suggestion, though!
                – Giuseppe
                10 hours ago










              • Thanks, I was unaware.
                – Shayne03
                10 hours ago










              • The explanation is shaped like a hill
                – John Doe
                6 hours ago














              up vote
              6
              down vote














              R,  44  43 42 bytes





              function(A,D)sum(pmax(0,diff(A)),D*.12)/10


              Try it online!



              -1 byte by using pmax as multiple other answers do



              Takes inputs as Ascent and Distance, and returns the time in minutes.



              function(A,D) # take Ascent and Distance
              diff(A) # take successive differences of ascents
              pmax(0, ) # get the positive elements of those
              D*.12 # multiply distance by 0.12
              sum( , ) # take the sum of all elements
              /10 # and divide by 10, returning the result






              share|improve this answer























              • You can get 4 more bytes using pryr::f(sum(pmax(0,diff(A)),D*.12)/10) instead of using function
                – Shayne03
                11 hours ago










              • @Shayne03 that would technically change this answer to "R + pryr" which on the rules of the site counts as a different language than base R, so I'll keep this as it is. Thanks for the suggestion, though!
                – Giuseppe
                10 hours ago










              • Thanks, I was unaware.
                – Shayne03
                10 hours ago










              • The explanation is shaped like a hill
                – John Doe
                6 hours ago












              up vote
              6
              down vote










              up vote
              6
              down vote










              R,  44  43 42 bytes





              function(A,D)sum(pmax(0,diff(A)),D*.12)/10


              Try it online!



              -1 byte by using pmax as multiple other answers do



              Takes inputs as Ascent and Distance, and returns the time in minutes.



              function(A,D) # take Ascent and Distance
              diff(A) # take successive differences of ascents
              pmax(0, ) # get the positive elements of those
              D*.12 # multiply distance by 0.12
              sum( , ) # take the sum of all elements
              /10 # and divide by 10, returning the result






              share|improve this answer
















              R,  44  43 42 bytes





              function(A,D)sum(pmax(0,diff(A)),D*.12)/10


              Try it online!



              -1 byte by using pmax as multiple other answers do



              Takes inputs as Ascent and Distance, and returns the time in minutes.



              function(A,D) # take Ascent and Distance
              diff(A) # take successive differences of ascents
              pmax(0, ) # get the positive elements of those
              D*.12 # multiply distance by 0.12
              sum( , ) # take the sum of all elements
              /10 # and divide by 10, returning the result







              share|improve this answer















              share|improve this answer



              share|improve this answer








              edited yesterday


























              answered yesterday









              Giuseppe

              13.8k3946




              13.8k3946











              • You can get 4 more bytes using pryr::f(sum(pmax(0,diff(A)),D*.12)/10) instead of using function
                – Shayne03
                11 hours ago










              • @Shayne03 that would technically change this answer to "R + pryr" which on the rules of the site counts as a different language than base R, so I'll keep this as it is. Thanks for the suggestion, though!
                – Giuseppe
                10 hours ago










              • Thanks, I was unaware.
                – Shayne03
                10 hours ago










              • The explanation is shaped like a hill
                – John Doe
                6 hours ago
















              • You can get 4 more bytes using pryr::f(sum(pmax(0,diff(A)),D*.12)/10) instead of using function
                – Shayne03
                11 hours ago










              • @Shayne03 that would technically change this answer to "R + pryr" which on the rules of the site counts as a different language than base R, so I'll keep this as it is. Thanks for the suggestion, though!
                – Giuseppe
                10 hours ago










              • Thanks, I was unaware.
                – Shayne03
                10 hours ago










              • The explanation is shaped like a hill
                – John Doe
                6 hours ago















              You can get 4 more bytes using pryr::f(sum(pmax(0,diff(A)),D*.12)/10) instead of using function
              – Shayne03
              11 hours ago




              You can get 4 more bytes using pryr::f(sum(pmax(0,diff(A)),D*.12)/10) instead of using function
              – Shayne03
              11 hours ago












              @Shayne03 that would technically change this answer to "R + pryr" which on the rules of the site counts as a different language than base R, so I'll keep this as it is. Thanks for the suggestion, though!
              – Giuseppe
              10 hours ago




              @Shayne03 that would technically change this answer to "R + pryr" which on the rules of the site counts as a different language than base R, so I'll keep this as it is. Thanks for the suggestion, though!
              – Giuseppe
              10 hours ago












              Thanks, I was unaware.
              – Shayne03
              10 hours ago




              Thanks, I was unaware.
              – Shayne03
              10 hours ago












              The explanation is shaped like a hill
              – John Doe
              6 hours ago




              The explanation is shaped like a hill
              – John Doe
              6 hours ago










              up vote
              3
              down vote













              JavaScript (ES6), 50 bytes



              Saved 1 byte thanks to Giuseppe's answer (dividing by 10 at the end of the process)



              Takes input as ([altitudes])(distance). Returns the time in minutes.





              a=>d=>a.map(p=n=>d-=(x=p-(p=n))<0&&x,d*=.12)&&d/10


              Try it online!






              share|improve this answer



























                up vote
                3
                down vote













                JavaScript (ES6), 50 bytes



                Saved 1 byte thanks to Giuseppe's answer (dividing by 10 at the end of the process)



                Takes input as ([altitudes])(distance). Returns the time in minutes.





                a=>d=>a.map(p=n=>d-=(x=p-(p=n))<0&&x,d*=.12)&&d/10


                Try it online!






                share|improve this answer

























                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  JavaScript (ES6), 50 bytes



                  Saved 1 byte thanks to Giuseppe's answer (dividing by 10 at the end of the process)



                  Takes input as ([altitudes])(distance). Returns the time in minutes.





                  a=>d=>a.map(p=n=>d-=(x=p-(p=n))<0&&x,d*=.12)&&d/10


                  Try it online!






                  share|improve this answer















                  JavaScript (ES6), 50 bytes



                  Saved 1 byte thanks to Giuseppe's answer (dividing by 10 at the end of the process)



                  Takes input as ([altitudes])(distance). Returns the time in minutes.





                  a=>d=>a.map(p=n=>d-=(x=p-(p=n))<0&&x,d*=.12)&&d/10


                  Try it online!







                  share|improve this answer















                  share|improve this answer



                  share|improve this answer








                  edited yesterday


























                  answered yesterday









                  Arnauld

                  60.4k472253




                  60.4k472253




















                      up vote
                      2
                      down vote














                      05AB1E, 15 bytes



                      ¥ʒ0›}OT÷s₄;6//+


                      Try it online!



                      Returns time in minutes.



                      Explanation



                       + # sum of ...
                      ¥ʒ0›}OT÷ # the sum of positive deltas of the altitude divided by 10
                      s₄;6// # the distance divided by 83.33333333 (500/6, or the amount of meters per minute)





                      share|improve this answer





















                      • Almost exactly what I had in mind. Only difference I had was ₄12// instead of ₄;6//. So obvious +1 from me.
                        – Kevin Cruijssen
                        21 hours ago














                      up vote
                      2
                      down vote














                      05AB1E, 15 bytes



                      ¥ʒ0›}OT÷s₄;6//+


                      Try it online!



                      Returns time in minutes.



                      Explanation



                       + # sum of ...
                      ¥ʒ0›}OT÷ # the sum of positive deltas of the altitude divided by 10
                      s₄;6// # the distance divided by 83.33333333 (500/6, or the amount of meters per minute)





                      share|improve this answer





















                      • Almost exactly what I had in mind. Only difference I had was ₄12// instead of ₄;6//. So obvious +1 from me.
                        – Kevin Cruijssen
                        21 hours ago












                      up vote
                      2
                      down vote










                      up vote
                      2
                      down vote










                      05AB1E, 15 bytes



                      ¥ʒ0›}OT÷s₄;6//+


                      Try it online!



                      Returns time in minutes.



                      Explanation



                       + # sum of ...
                      ¥ʒ0›}OT÷ # the sum of positive deltas of the altitude divided by 10
                      s₄;6// # the distance divided by 83.33333333 (500/6, or the amount of meters per minute)





                      share|improve this answer














                      05AB1E, 15 bytes



                      ¥ʒ0›}OT÷s₄;6//+


                      Try it online!



                      Returns time in minutes.



                      Explanation



                       + # sum of ...
                      ¥ʒ0›}OT÷ # the sum of positive deltas of the altitude divided by 10
                      s₄;6// # the distance divided by 83.33333333 (500/6, or the amount of meters per minute)






                      share|improve this answer













                      share|improve this answer



                      share|improve this answer











                      answered yesterday









                      Kaldo

                      9149




                      9149











                      • Almost exactly what I had in mind. Only difference I had was ₄12// instead of ₄;6//. So obvious +1 from me.
                        – Kevin Cruijssen
                        21 hours ago
















                      • Almost exactly what I had in mind. Only difference I had was ₄12// instead of ₄;6//. So obvious +1 from me.
                        – Kevin Cruijssen
                        21 hours ago















                      Almost exactly what I had in mind. Only difference I had was ₄12// instead of ₄;6//. So obvious +1 from me.
                      – Kevin Cruijssen
                      21 hours ago




                      Almost exactly what I had in mind. Only difference I had was ₄12// instead of ₄;6//. So obvious +1 from me.
                      – Kevin Cruijssen
                      21 hours ago










                      up vote
                      2
                      down vote













                      Haskell, 47 46 bytes



                      d#l@(_:t)=d/5e3+sum(max 0<$>zipWith(-)t l)/600


                      Returns the time in hours.



                      Try it online!






                      share|improve this answer



























                        up vote
                        2
                        down vote













                        Haskell, 47 46 bytes



                        d#l@(_:t)=d/5e3+sum(max 0<$>zipWith(-)t l)/600


                        Returns the time in hours.



                        Try it online!






                        share|improve this answer

























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          Haskell, 47 46 bytes



                          d#l@(_:t)=d/5e3+sum(max 0<$>zipWith(-)t l)/600


                          Returns the time in hours.



                          Try it online!






                          share|improve this answer















                          Haskell, 47 46 bytes



                          d#l@(_:t)=d/5e3+sum(max 0<$>zipWith(-)t l)/600


                          Returns the time in hours.



                          Try it online!







                          share|improve this answer















                          share|improve this answer



                          share|improve this answer








                          edited yesterday


























                          answered yesterday









                          nimi

                          29.6k31880




                          29.6k31880




















                              up vote
                              2
                              down vote













                              Python 2, 62 60 bytes



                              Saved 2 bytes thanks to ovs.



                              lambda e,d:sum((a-b)*(a>b)for a,b in zip(e[1:],e))*.1+d*.012


                              Try it online!



                              Returns time in minutes.



                              # add all increasing slope differences together
                              sum(
                              # multiply the difference by 0 if a<b, else by 1
                              (a-b)*(a>b)
                              # create a list of pairs by index, like [(1,0), (2,1) ...(n, n-1)]
                              # then interate thru the pairs where a is the higher indexed item and b is the lower indexed item
                              for a,b in zip(e[1:],e)
                              )
                              # * 60 minutes / 600 meters == .1 min/m
                              *.1
                              # 60 minutes / 5000 meters = .012 min/m
                              +d*.012





                              share|improve this answer























                              • 60 bytes
                                – ovs
                                yesterday














                              up vote
                              2
                              down vote













                              Python 2, 62 60 bytes



                              Saved 2 bytes thanks to ovs.



                              lambda e,d:sum((a-b)*(a>b)for a,b in zip(e[1:],e))*.1+d*.012


                              Try it online!



                              Returns time in minutes.



                              # add all increasing slope differences together
                              sum(
                              # multiply the difference by 0 if a<b, else by 1
                              (a-b)*(a>b)
                              # create a list of pairs by index, like [(1,0), (2,1) ...(n, n-1)]
                              # then interate thru the pairs where a is the higher indexed item and b is the lower indexed item
                              for a,b in zip(e[1:],e)
                              )
                              # * 60 minutes / 600 meters == .1 min/m
                              *.1
                              # 60 minutes / 5000 meters = .012 min/m
                              +d*.012





                              share|improve this answer























                              • 60 bytes
                                – ovs
                                yesterday












                              up vote
                              2
                              down vote










                              up vote
                              2
                              down vote









                              Python 2, 62 60 bytes



                              Saved 2 bytes thanks to ovs.



                              lambda e,d:sum((a-b)*(a>b)for a,b in zip(e[1:],e))*.1+d*.012


                              Try it online!



                              Returns time in minutes.



                              # add all increasing slope differences together
                              sum(
                              # multiply the difference by 0 if a<b, else by 1
                              (a-b)*(a>b)
                              # create a list of pairs by index, like [(1,0), (2,1) ...(n, n-1)]
                              # then interate thru the pairs where a is the higher indexed item and b is the lower indexed item
                              for a,b in zip(e[1:],e)
                              )
                              # * 60 minutes / 600 meters == .1 min/m
                              *.1
                              # 60 minutes / 5000 meters = .012 min/m
                              +d*.012





                              share|improve this answer















                              Python 2, 62 60 bytes



                              Saved 2 bytes thanks to ovs.



                              lambda e,d:sum((a-b)*(a>b)for a,b in zip(e[1:],e))*.1+d*.012


                              Try it online!



                              Returns time in minutes.



                              # add all increasing slope differences together
                              sum(
                              # multiply the difference by 0 if a<b, else by 1
                              (a-b)*(a>b)
                              # create a list of pairs by index, like [(1,0), (2,1) ...(n, n-1)]
                              # then interate thru the pairs where a is the higher indexed item and b is the lower indexed item
                              for a,b in zip(e[1:],e)
                              )
                              # * 60 minutes / 600 meters == .1 min/m
                              *.1
                              # 60 minutes / 5000 meters = .012 min/m
                              +d*.012






                              share|improve this answer















                              share|improve this answer



                              share|improve this answer








                              edited yesterday


























                              answered yesterday









                              Triggernometry

                              934




                              934











                              • 60 bytes
                                – ovs
                                yesterday
















                              • 60 bytes
                                – ovs
                                yesterday















                              60 bytes
                              – ovs
                              yesterday




                              60 bytes
                              – ovs
                              yesterday










                              up vote
                              2
                              down vote














                              Perl 6, 45 39 bytes



                              6 bytes saved thanks to Jo King.





                              $^l*.012+.1*sum (@^a[1..*]Z-@a)Xmax 0


                              Try it online!



                              The first argument is the list with elevations, the second argument is the length of the trek.



                              Let's start from the middle: @^a[1..*]Z-@a takes the first argument (saying @^a, we essentially mean: This is the first argument, and I will be referring to it with @a from now on. (All the variables with ^ correspond to the arguments in the alphabetical order.)), removes the first element and subtracts the same unmodified list element-by-element from it (stopping when the shorter list runs out). That forms a list of differences. Then we do a "cross product" with a zero using the operator max, which returns the list of results of the operator max used on all possible pairs of one element from the list on the left and one on the right. But, since there is only one element on the right, it just acts as a shorthand for using * max 0 on each element of the list. We then sum the results, divide by 10 and add the length $^l$ multiplied by .012, which gives the result in minutes.






                              share|improve this answer



















                              • 1




                                42 bytes using X
                                – Jo King
                                yesterday










                              • @JoKing, that's a nice use of X, thanks!
                                – Ramillies
                                yesterday






                              • 1




                                Actually, we can avoid the last X/ by just dividing the sum by 10. 39 bytes
                                – Jo King
                                yesterday










                              • 37 bytes using WhateverCode and .& (returns hours).
                                – nwellnhof
                                7 hours ago















                              up vote
                              2
                              down vote














                              Perl 6, 45 39 bytes



                              6 bytes saved thanks to Jo King.





                              $^l*.012+.1*sum (@^a[1..*]Z-@a)Xmax 0


                              Try it online!



                              The first argument is the list with elevations, the second argument is the length of the trek.



                              Let's start from the middle: @^a[1..*]Z-@a takes the first argument (saying @^a, we essentially mean: This is the first argument, and I will be referring to it with @a from now on. (All the variables with ^ correspond to the arguments in the alphabetical order.)), removes the first element and subtracts the same unmodified list element-by-element from it (stopping when the shorter list runs out). That forms a list of differences. Then we do a "cross product" with a zero using the operator max, which returns the list of results of the operator max used on all possible pairs of one element from the list on the left and one on the right. But, since there is only one element on the right, it just acts as a shorthand for using * max 0 on each element of the list. We then sum the results, divide by 10 and add the length $^l$ multiplied by .012, which gives the result in minutes.






                              share|improve this answer



















                              • 1




                                42 bytes using X
                                – Jo King
                                yesterday










                              • @JoKing, that's a nice use of X, thanks!
                                – Ramillies
                                yesterday






                              • 1




                                Actually, we can avoid the last X/ by just dividing the sum by 10. 39 bytes
                                – Jo King
                                yesterday










                              • 37 bytes using WhateverCode and .& (returns hours).
                                – nwellnhof
                                7 hours ago













                              up vote
                              2
                              down vote










                              up vote
                              2
                              down vote










                              Perl 6, 45 39 bytes



                              6 bytes saved thanks to Jo King.





                              $^l*.012+.1*sum (@^a[1..*]Z-@a)Xmax 0


                              Try it online!



                              The first argument is the list with elevations, the second argument is the length of the trek.



                              Let's start from the middle: @^a[1..*]Z-@a takes the first argument (saying @^a, we essentially mean: This is the first argument, and I will be referring to it with @a from now on. (All the variables with ^ correspond to the arguments in the alphabetical order.)), removes the first element and subtracts the same unmodified list element-by-element from it (stopping when the shorter list runs out). That forms a list of differences. Then we do a "cross product" with a zero using the operator max, which returns the list of results of the operator max used on all possible pairs of one element from the list on the left and one on the right. But, since there is only one element on the right, it just acts as a shorthand for using * max 0 on each element of the list. We then sum the results, divide by 10 and add the length $^l$ multiplied by .012, which gives the result in minutes.






                              share|improve this answer
















                              Perl 6, 45 39 bytes



                              6 bytes saved thanks to Jo King.





                              $^l*.012+.1*sum (@^a[1..*]Z-@a)Xmax 0


                              Try it online!



                              The first argument is the list with elevations, the second argument is the length of the trek.



                              Let's start from the middle: @^a[1..*]Z-@a takes the first argument (saying @^a, we essentially mean: This is the first argument, and I will be referring to it with @a from now on. (All the variables with ^ correspond to the arguments in the alphabetical order.)), removes the first element and subtracts the same unmodified list element-by-element from it (stopping when the shorter list runs out). That forms a list of differences. Then we do a "cross product" with a zero using the operator max, which returns the list of results of the operator max used on all possible pairs of one element from the list on the left and one on the right. But, since there is only one element on the right, it just acts as a shorthand for using * max 0 on each element of the list. We then sum the results, divide by 10 and add the length $^l$ multiplied by .012, which gives the result in minutes.







                              share|improve this answer















                              share|improve this answer



                              share|improve this answer








                              edited 21 hours ago


























                              answered yesterday









                              Ramillies

                              1,321411




                              1,321411







                              • 1




                                42 bytes using X
                                – Jo King
                                yesterday










                              • @JoKing, that's a nice use of X, thanks!
                                – Ramillies
                                yesterday






                              • 1




                                Actually, we can avoid the last X/ by just dividing the sum by 10. 39 bytes
                                – Jo King
                                yesterday










                              • 37 bytes using WhateverCode and .& (returns hours).
                                – nwellnhof
                                7 hours ago













                              • 1




                                42 bytes using X
                                – Jo King
                                yesterday










                              • @JoKing, that's a nice use of X, thanks!
                                – Ramillies
                                yesterday






                              • 1




                                Actually, we can avoid the last X/ by just dividing the sum by 10. 39 bytes
                                – Jo King
                                yesterday










                              • 37 bytes using WhateverCode and .& (returns hours).
                                – nwellnhof
                                7 hours ago








                              1




                              1




                              42 bytes using X
                              – Jo King
                              yesterday




                              42 bytes using X
                              – Jo King
                              yesterday












                              @JoKing, that's a nice use of X, thanks!
                              – Ramillies
                              yesterday




                              @JoKing, that's a nice use of X, thanks!
                              – Ramillies
                              yesterday




                              1




                              1




                              Actually, we can avoid the last X/ by just dividing the sum by 10. 39 bytes
                              – Jo King
                              yesterday




                              Actually, we can avoid the last X/ by just dividing the sum by 10. 39 bytes
                              – Jo King
                              yesterday












                              37 bytes using WhateverCode and .& (returns hours).
                              – nwellnhof
                              7 hours ago





                              37 bytes using WhateverCode and .& (returns hours).
                              – nwellnhof
                              7 hours ago











                              up vote
                              1
                              down vote














                              Jelly, 12 bytes



                              ×.12;I}»0÷⁵S


                              Try it online!



                              -1 thanks to Mr. Xcoder.






                              share|improve this answer



















                              • 1




                                Doesn't ×.12 work?
                                – Mr. Xcoder
                                yesterday










                              • @Mr.Xcoder It does, I was in a hurry.
                                – Erik the Outgolfer
                                yesterday














                              up vote
                              1
                              down vote














                              Jelly, 12 bytes



                              ×.12;I}»0÷⁵S


                              Try it online!



                              -1 thanks to Mr. Xcoder.






                              share|improve this answer



















                              • 1




                                Doesn't ×.12 work?
                                – Mr. Xcoder
                                yesterday










                              • @Mr.Xcoder It does, I was in a hurry.
                                – Erik the Outgolfer
                                yesterday












                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote










                              Jelly, 12 bytes



                              ×.12;I}»0÷⁵S


                              Try it online!



                              -1 thanks to Mr. Xcoder.






                              share|improve this answer
















                              Jelly, 12 bytes



                              ×.12;I}»0÷⁵S


                              Try it online!



                              -1 thanks to Mr. Xcoder.







                              share|improve this answer















                              share|improve this answer



                              share|improve this answer








                              edited yesterday


























                              answered yesterday









                              Erik the Outgolfer

                              29.1k42697




                              29.1k42697







                              • 1




                                Doesn't ×.12 work?
                                – Mr. Xcoder
                                yesterday










                              • @Mr.Xcoder It does, I was in a hurry.
                                – Erik the Outgolfer
                                yesterday












                              • 1




                                Doesn't ×.12 work?
                                – Mr. Xcoder
                                yesterday










                              • @Mr.Xcoder It does, I was in a hurry.
                                – Erik the Outgolfer
                                yesterday







                              1




                              1




                              Doesn't ×.12 work?
                              – Mr. Xcoder
                              yesterday




                              Doesn't ×.12 work?
                              – Mr. Xcoder
                              yesterday












                              @Mr.Xcoder It does, I was in a hurry.
                              – Erik the Outgolfer
                              yesterday




                              @Mr.Xcoder It does, I was in a hurry.
                              – Erik the Outgolfer
                              yesterday










                              up vote
                              1
                              down vote














                              oK, 22 bytes



                              1_-':x..1.012*


                              Try it online! Abusing a parsing bug where .1.012 is the same as .1 .012.



                               .1.012* /a = [0.1 * input[0], 0.012 * input[1]]
                              . /function(x=a[0], y=a[1])
                              1_-':x / a = subtract pairs of elements from x
                              0| / a = max(a, 0) w/ implicit map
                              y++/ / y + sum(a)



                              k, 23 bytes



                              .1*(.12*y)++/0


                              Try it online!






                              share|improve this answer





















                              • 1_-':x..1.012* for 21 bytes? start accumulator with y.
                                – streetster
                                15 hours ago














                              up vote
                              1
                              down vote














                              oK, 22 bytes



                              1_-':x..1.012*


                              Try it online! Abusing a parsing bug where .1.012 is the same as .1 .012.



                               .1.012* /a = [0.1 * input[0], 0.012 * input[1]]
                              . /function(x=a[0], y=a[1])
                              1_-':x / a = subtract pairs of elements from x
                              0| / a = max(a, 0) w/ implicit map
                              y++/ / y + sum(a)



                              k, 23 bytes



                              .1*(.12*y)++/0


                              Try it online!






                              share|improve this answer





















                              • 1_-':x..1.012* for 21 bytes? start accumulator with y.
                                – streetster
                                15 hours ago












                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote










                              oK, 22 bytes



                              1_-':x..1.012*


                              Try it online! Abusing a parsing bug where .1.012 is the same as .1 .012.



                               .1.012* /a = [0.1 * input[0], 0.012 * input[1]]
                              . /function(x=a[0], y=a[1])
                              1_-':x / a = subtract pairs of elements from x
                              0| / a = max(a, 0) w/ implicit map
                              y++/ / y + sum(a)



                              k, 23 bytes



                              .1*(.12*y)++/0


                              Try it online!






                              share|improve this answer














                              oK, 22 bytes



                              1_-':x..1.012*


                              Try it online! Abusing a parsing bug where .1.012 is the same as .1 .012.



                               .1.012* /a = [0.1 * input[0], 0.012 * input[1]]
                              . /function(x=a[0], y=a[1])
                              1_-':x / a = subtract pairs of elements from x
                              0| / a = max(a, 0) w/ implicit map
                              y++/ / y + sum(a)



                              k, 23 bytes



                              .1*(.12*y)++/0


                              Try it online!







                              share|improve this answer













                              share|improve this answer



                              share|improve this answer











                              answered yesterday









                              zgrep

                              1,12138




                              1,12138











                              • 1_-':x..1.012* for 21 bytes? start accumulator with y.
                                – streetster
                                15 hours ago
















                              • 1_-':x..1.012* for 21 bytes? start accumulator with y.
                                – streetster
                                15 hours ago















                              1_-':x..1.012* for 21 bytes? start accumulator with y.
                              – streetster
                              15 hours ago




                              1_-':x..1.012* for 21 bytes? start accumulator with y.
                              – streetster
                              15 hours ago










                              up vote
                              1
                              down vote














                              Pyth, 15 bytes



                              c+*E.12s>#0.+QT


                              Full program, expects the set of heights as the first argument, distance as the second. Returns the time in minutes.



                              Try it online here, or verify all test cases at once here.



                              c+*E.12s>#0.+QT Implicit: Q=input 1, E=input 2
                              .+Q Take the differences between each height point
                              >#0 Filter to remove negative values
                              s Take the sum
                              *E.12 Multiply the distance by 0.12
                              + Add the two previous results
                              c T Divide the above by 10, implicit print





                              share|improve this answer

























                                up vote
                                1
                                down vote














                                Pyth, 15 bytes



                                c+*E.12s>#0.+QT


                                Full program, expects the set of heights as the first argument, distance as the second. Returns the time in minutes.



                                Try it online here, or verify all test cases at once here.



                                c+*E.12s>#0.+QT Implicit: Q=input 1, E=input 2
                                .+Q Take the differences between each height point
                                >#0 Filter to remove negative values
                                s Take the sum
                                *E.12 Multiply the distance by 0.12
                                + Add the two previous results
                                c T Divide the above by 10, implicit print





                                share|improve this answer























                                  up vote
                                  1
                                  down vote










                                  up vote
                                  1
                                  down vote










                                  Pyth, 15 bytes



                                  c+*E.12s>#0.+QT


                                  Full program, expects the set of heights as the first argument, distance as the second. Returns the time in minutes.



                                  Try it online here, or verify all test cases at once here.



                                  c+*E.12s>#0.+QT Implicit: Q=input 1, E=input 2
                                  .+Q Take the differences between each height point
                                  >#0 Filter to remove negative values
                                  s Take the sum
                                  *E.12 Multiply the distance by 0.12
                                  + Add the two previous results
                                  c T Divide the above by 10, implicit print





                                  share|improve this answer














                                  Pyth, 15 bytes



                                  c+*E.12s>#0.+QT


                                  Full program, expects the set of heights as the first argument, distance as the second. Returns the time in minutes.



                                  Try it online here, or verify all test cases at once here.



                                  c+*E.12s>#0.+QT Implicit: Q=input 1, E=input 2
                                  .+Q Take the differences between each height point
                                  >#0 Filter to remove negative values
                                  s Take the sum
                                  *E.12 Multiply the distance by 0.12
                                  + Add the two previous results
                                  c T Divide the above by 10, implicit print






                                  share|improve this answer













                                  share|improve this answer



                                  share|improve this answer











                                  answered 19 hours ago









                                  Sok

                                  2,821622




                                  2,821622




















                                      up vote
                                      1
                                      down vote














                                      APL (Dyalog Unicode), 21 20 18 bytes





                                      .1×.12⊥⎕,-+/0⌊2-/⎕


                                      Try it online!



                                      Traditional function taking input (from right to left) as 1st ⎕=Heights/Depths, 2nd ⎕=Distance.



                                      Thanks to @ngn for being a wizard one three bytes.



                                      How it works:



                                      .1×.12⊥⎕,-+/0⌊2-/⎕ ⍝ Function;
                                      ⎕ ⍝ Append 0 to the heights vector;
                                      2-/ ⍝ Pairwise (2) differences (-/);
                                      0⌊ ⍝ Minimum between 0 and the vector's elements;
                                      +/ ⍝ Sum (yields the negated total height);
                                      - ⍝ Subtract from;
                                      .12⊥⎕, ⍝ Distance × 0.12;
                                      .1× ⍝ And divide by 10;





                                      share|improve this answer























                                      • thanks for "wizard" :) you don't have to copy the expression multiple times in order to test it, put it in a tradfn instead; ,0 is unnecessary, the ⍵ for the problematic test should be ,604, not 604
                                        – ngn
                                        20 hours ago










                                      • See, that's why you're a wizard. The copying the expression multiple times part is totally my fault, I just replaced the ⍺ and ⍵ in the old code with ⎕ and was too lazy to put the tradfn header/footer. The ,0 bit though? Gold.
                                        – J. Sallé
                                        15 hours ago














                                      up vote
                                      1
                                      down vote














                                      APL (Dyalog Unicode), 21 20 18 bytes





                                      .1×.12⊥⎕,-+/0⌊2-/⎕


                                      Try it online!



                                      Traditional function taking input (from right to left) as 1st ⎕=Heights/Depths, 2nd ⎕=Distance.



                                      Thanks to @ngn for being a wizard one three bytes.



                                      How it works:



                                      .1×.12⊥⎕,-+/0⌊2-/⎕ ⍝ Function;
                                      ⎕ ⍝ Append 0 to the heights vector;
                                      2-/ ⍝ Pairwise (2) differences (-/);
                                      0⌊ ⍝ Minimum between 0 and the vector's elements;
                                      +/ ⍝ Sum (yields the negated total height);
                                      - ⍝ Subtract from;
                                      .12⊥⎕, ⍝ Distance × 0.12;
                                      .1× ⍝ And divide by 10;





                                      share|improve this answer























                                      • thanks for "wizard" :) you don't have to copy the expression multiple times in order to test it, put it in a tradfn instead; ,0 is unnecessary, the ⍵ for the problematic test should be ,604, not 604
                                        – ngn
                                        20 hours ago










                                      • See, that's why you're a wizard. The copying the expression multiple times part is totally my fault, I just replaced the ⍺ and ⍵ in the old code with ⎕ and was too lazy to put the tradfn header/footer. The ,0 bit though? Gold.
                                        – J. Sallé
                                        15 hours ago












                                      up vote
                                      1
                                      down vote










                                      up vote
                                      1
                                      down vote










                                      APL (Dyalog Unicode), 21 20 18 bytes





                                      .1×.12⊥⎕,-+/0⌊2-/⎕


                                      Try it online!



                                      Traditional function taking input (from right to left) as 1st ⎕=Heights/Depths, 2nd ⎕=Distance.



                                      Thanks to @ngn for being a wizard one three bytes.



                                      How it works:



                                      .1×.12⊥⎕,-+/0⌊2-/⎕ ⍝ Function;
                                      ⎕ ⍝ Append 0 to the heights vector;
                                      2-/ ⍝ Pairwise (2) differences (-/);
                                      0⌊ ⍝ Minimum between 0 and the vector's elements;
                                      +/ ⍝ Sum (yields the negated total height);
                                      - ⍝ Subtract from;
                                      .12⊥⎕, ⍝ Distance × 0.12;
                                      .1× ⍝ And divide by 10;





                                      share|improve this answer
















                                      APL (Dyalog Unicode), 21 20 18 bytes





                                      .1×.12⊥⎕,-+/0⌊2-/⎕


                                      Try it online!



                                      Traditional function taking input (from right to left) as 1st ⎕=Heights/Depths, 2nd ⎕=Distance.



                                      Thanks to @ngn for being a wizard one three bytes.



                                      How it works:



                                      .1×.12⊥⎕,-+/0⌊2-/⎕ ⍝ Function;
                                      ⎕ ⍝ Append 0 to the heights vector;
                                      2-/ ⍝ Pairwise (2) differences (-/);
                                      0⌊ ⍝ Minimum between 0 and the vector's elements;
                                      +/ ⍝ Sum (yields the negated total height);
                                      - ⍝ Subtract from;
                                      .12⊥⎕, ⍝ Distance × 0.12;
                                      .1× ⍝ And divide by 10;






                                      share|improve this answer















                                      share|improve this answer



                                      share|improve this answer








                                      edited 15 hours ago


























                                      answered yesterday









                                      J. Sallé

                                      1,288218




                                      1,288218











                                      • thanks for "wizard" :) you don't have to copy the expression multiple times in order to test it, put it in a tradfn instead; ,0 is unnecessary, the ⍵ for the problematic test should be ,604, not 604
                                        – ngn
                                        20 hours ago










                                      • See, that's why you're a wizard. The copying the expression multiple times part is totally my fault, I just replaced the ⍺ and ⍵ in the old code with ⎕ and was too lazy to put the tradfn header/footer. The ,0 bit though? Gold.
                                        – J. Sallé
                                        15 hours ago
















                                      • thanks for "wizard" :) you don't have to copy the expression multiple times in order to test it, put it in a tradfn instead; ,0 is unnecessary, the ⍵ for the problematic test should be ,604, not 604
                                        – ngn
                                        20 hours ago










                                      • See, that's why you're a wizard. The copying the expression multiple times part is totally my fault, I just replaced the ⍺ and ⍵ in the old code with ⎕ and was too lazy to put the tradfn header/footer. The ,0 bit though? Gold.
                                        – J. Sallé
                                        15 hours ago















                                      thanks for "wizard" :) you don't have to copy the expression multiple times in order to test it, put it in a tradfn instead; ,0 is unnecessary, the ⍵ for the problematic test should be ,604, not 604
                                      – ngn
                                      20 hours ago




                                      thanks for "wizard" :) you don't have to copy the expression multiple times in order to test it, put it in a tradfn instead; ,0 is unnecessary, the ⍵ for the problematic test should be ,604, not 604
                                      – ngn
                                      20 hours ago












                                      See, that's why you're a wizard. The copying the expression multiple times part is totally my fault, I just replaced the ⍺ and ⍵ in the old code with ⎕ and was too lazy to put the tradfn header/footer. The ,0 bit though? Gold.
                                      – J. Sallé
                                      15 hours ago




                                      See, that's why you're a wizard. The copying the expression multiple times part is totally my fault, I just replaced the ⍺ and ⍵ in the old code with ⎕ and was too lazy to put the tradfn header/footer. The ,0 bit though? Gold.
                                      – J. Sallé
                                      15 hours ago










                                      up vote
                                      0
                                      down vote














                                      Python 2, 59 bytes





                                      lambda a,d:d/5e3+sum(max(0,y-x)/6e2for x,y in zip(a,a[1:]))


                                      Try it online!



                                      returns hours as a decimal.






                                      share|improve this answer

























                                        up vote
                                        0
                                        down vote














                                        Python 2, 59 bytes





                                        lambda a,d:d/5e3+sum(max(0,y-x)/6e2for x,y in zip(a,a[1:]))


                                        Try it online!



                                        returns hours as a decimal.






                                        share|improve this answer























                                          up vote
                                          0
                                          down vote










                                          up vote
                                          0
                                          down vote










                                          Python 2, 59 bytes





                                          lambda a,d:d/5e3+sum(max(0,y-x)/6e2for x,y in zip(a,a[1:]))


                                          Try it online!



                                          returns hours as a decimal.






                                          share|improve this answer














                                          Python 2, 59 bytes





                                          lambda a,d:d/5e3+sum(max(0,y-x)/6e2for x,y in zip(a,a[1:]))


                                          Try it online!



                                          returns hours as a decimal.







                                          share|improve this answer













                                          share|improve this answer



                                          share|improve this answer











                                          answered yesterday









                                          Chas Brown

                                          3,570216




                                          3,570216




















                                              up vote
                                              0
                                              down vote













                                              Java 8, 89 bytes





                                              a->n->int s=0,p=0,i=a.length;for(;i-->0;p=a[i])s+=(p=p-a[i])>0?p:0;return s/10+n/500*6;


                                              Try it online.



                                              Explanation:



                                              a->n-> // Method with integer-array and integer parameter and integer return-type
                                              int s=0, // Sum-integers, starting at 0
                                              p=0, // Previous integer, starting at 0
                                              i=a.length;for(;i-->0; // Loop `i` backwards over the array
                                              ; // After every iteration:
                                              p=a[i]) // Set `p` to the current value for the next iteration
                                              s+=(p=p-a[i])>0? // If the previous minus current item is larger than 0:
                                              p // Add that difference to the sum `s`
                                              : // Else:
                                              0; // Leave the sum the same
                                              return s/10 // Return the sum integer-divided by 10
                                              +n/500*6; // Plus the second input divided by 500 and then multiplied by 6





                                              share|improve this answer

























                                                up vote
                                                0
                                                down vote













                                                Java 8, 89 bytes





                                                a->n->int s=0,p=0,i=a.length;for(;i-->0;p=a[i])s+=(p=p-a[i])>0?p:0;return s/10+n/500*6;


                                                Try it online.



                                                Explanation:



                                                a->n-> // Method with integer-array and integer parameter and integer return-type
                                                int s=0, // Sum-integers, starting at 0
                                                p=0, // Previous integer, starting at 0
                                                i=a.length;for(;i-->0; // Loop `i` backwards over the array
                                                ; // After every iteration:
                                                p=a[i]) // Set `p` to the current value for the next iteration
                                                s+=(p=p-a[i])>0? // If the previous minus current item is larger than 0:
                                                p // Add that difference to the sum `s`
                                                : // Else:
                                                0; // Leave the sum the same
                                                return s/10 // Return the sum integer-divided by 10
                                                +n/500*6; // Plus the second input divided by 500 and then multiplied by 6





                                                share|improve this answer























                                                  up vote
                                                  0
                                                  down vote










                                                  up vote
                                                  0
                                                  down vote









                                                  Java 8, 89 bytes





                                                  a->n->int s=0,p=0,i=a.length;for(;i-->0;p=a[i])s+=(p=p-a[i])>0?p:0;return s/10+n/500*6;


                                                  Try it online.



                                                  Explanation:



                                                  a->n-> // Method with integer-array and integer parameter and integer return-type
                                                  int s=0, // Sum-integers, starting at 0
                                                  p=0, // Previous integer, starting at 0
                                                  i=a.length;for(;i-->0; // Loop `i` backwards over the array
                                                  ; // After every iteration:
                                                  p=a[i]) // Set `p` to the current value for the next iteration
                                                  s+=(p=p-a[i])>0? // If the previous minus current item is larger than 0:
                                                  p // Add that difference to the sum `s`
                                                  : // Else:
                                                  0; // Leave the sum the same
                                                  return s/10 // Return the sum integer-divided by 10
                                                  +n/500*6; // Plus the second input divided by 500 and then multiplied by 6





                                                  share|improve this answer













                                                  Java 8, 89 bytes





                                                  a->n->int s=0,p=0,i=a.length;for(;i-->0;p=a[i])s+=(p=p-a[i])>0?p:0;return s/10+n/500*6;


                                                  Try it online.



                                                  Explanation:



                                                  a->n-> // Method with integer-array and integer parameter and integer return-type
                                                  int s=0, // Sum-integers, starting at 0
                                                  p=0, // Previous integer, starting at 0
                                                  i=a.length;for(;i-->0; // Loop `i` backwards over the array
                                                  ; // After every iteration:
                                                  p=a[i]) // Set `p` to the current value for the next iteration
                                                  s+=(p=p-a[i])>0? // If the previous minus current item is larger than 0:
                                                  p // Add that difference to the sum `s`
                                                  : // Else:
                                                  0; // Leave the sum the same
                                                  return s/10 // Return the sum integer-divided by 10
                                                  +n/500*6; // Plus the second input divided by 500 and then multiplied by 6






                                                  share|improve this answer













                                                  share|improve this answer



                                                  share|improve this answer











                                                  answered 21 hours ago









                                                  Kevin Cruijssen

                                                  27.4k545151




                                                  27.4k545151




















                                                      up vote
                                                      0
                                                      down vote














                                                      Japt, 39 bytes



                                                      0oUl)x@W=UgXÄ -UgX)g ¥É?0:W/#ɘ} +V/(#Ǵ0


                                                      Try it online!



                                                      Likely can be golfed quite a bit more.






                                                      share|improve this answer



























                                                        up vote
                                                        0
                                                        down vote














                                                        Japt, 39 bytes



                                                        0oUl)x@W=UgXÄ -UgX)g ¥É?0:W/#ɘ} +V/(#Ǵ0


                                                        Try it online!



                                                        Likely can be golfed quite a bit more.






                                                        share|improve this answer

























                                                          up vote
                                                          0
                                                          down vote










                                                          up vote
                                                          0
                                                          down vote










                                                          Japt, 39 bytes



                                                          0oUl)x@W=UgXÄ -UgX)g ¥É?0:W/#ɘ} +V/(#Ǵ0


                                                          Try it online!



                                                          Likely can be golfed quite a bit more.






                                                          share|improve this answer
















                                                          Japt, 39 bytes



                                                          0oUl)x@W=UgXÄ -UgX)g ¥É?0:W/#ɘ} +V/(#Ǵ0


                                                          Try it online!



                                                          Likely can be golfed quite a bit more.







                                                          share|improve this answer















                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited 14 hours ago


























                                                          answered 14 hours ago









                                                          Bejofo

                                                          212




                                                          212






















                                                               

                                                              draft saved


                                                              draft discarded


























                                                               


                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function ()
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f170075%2fnaismiths-rule%23new-answer', 'question_page');

                                                              );

                                                              Post as a guest













































































                                                              Popular posts from this blog

                                                              How to check contact read email or not when send email to Individual?

                                                              Bahrain

                                                              Postfix configuration issue with fips on centos 7; mailgun relay