Skip to main content
4 of 6
byte improvement: updated code & TIO link
Matsyir
  • 101
  • 3

JavaScript (V8), 142 132 bytes

-10 bytes: applied -9 to ranges and input after division rather than only dividing by 10 (inspired by other answers, understood why it was worth it after observing my range/10 numbers)

d=>(d=d/10-9,r=[11,17,9,14.5,8,12,7,11,6,9.5,5,8,4,7,3,6,2,5,0.5,4,-1,2.5,-3,0],r.map((e,i)=>t+=i%2==1?0:d>=e&&d<=r[i+1]?1:0,t=0),t)

Try it online!

Pretty naive solution but I wasn't comfortable attempting more complex methods used in other answers (not to mention I'm not sure if they're even possible/worth golfing with in JS!). I'll happily take advice/improvements, though.

Slightly unminified & explained:

f = (distance) => {
    // divide input by 10 and subtract 9 since the hardcoded ranges are shorter when those operations are done.
    distance = distance / 10 - 9

    // hardcoded ranges divided by 10 then subtracted 9 to save bytes (probably can be done better).
    // Will be used in pairs, only processing even indexes and using i & i+1
    //ranges = [20,26,18,23.5,17,21,16,20,15,18.5,14,17,13,16,12,15,11,14,9.5,13,8,11.5,6,9] // /10
    //ranges = [14,20,12,17.5,11,15,10,14,9,12.5,8,11,7,10,6,9,5,8,3.5,7,2,5.5,0,3] // /10 -6
    ranges = [11,17,9,14.5,8,12,7,11,6,9.5,5,8,4,7,3,6,2,5,0.5,4,-1,2.5,-3,0] // /10 -9 (winner! inspired by other answers)

    // .map used as .reduce
    ranges.map((e, i)=> { // e: current element, i: current index
        totalValidClubs += ( // increment total 'valid' counter if within range
            i%2 == 1 ? 0 : // skip odd indexes, will use i & i+1 on even indexes only
            distance>=e && distance<=ranges[i+1] ? 1 : 0) // if even index and distance is between ranges[i] & [i+1] (inclusive), increment by 1.
    }, totalValidClubs=0); // initialize valid club counter as 0
    return totalValidClubs;
}
Matsyir
  • 101
  • 3