Skip to main content
fix name typo
Source Link
Matsyir
  • 101
  • 3

-15 bytes thanks to Arnold'sArnauld's improvements

Slightly unminifiedUnminified & explained (slightly outdated but still explains the overall process):

-15 bytes thanks to Arnold's improvements

Slightly unminified & explained:

-15 bytes thanks to Arnauld's improvements

Unminified & explained (slightly outdated but still explains the overall process):

Update with improvements from comments
Source Link
Matsyir
  • 101
  • 3

JavaScript (V8), 142 132142 132 117 113 bytes

-15 bytes thanks to Arnold's improvements

-5 bytes thanks to Shaggy's further improvements

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

Try it online!Try it online!

JavaScript (V8), 142 132 bytes

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!

JavaScript (V8), 142 132 117 113 bytes

-15 bytes thanks to Arnold's improvements

-5 bytes thanks to Shaggy's further improvements

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

Try it online!

byte improvement: updated code & TIO link
Source Link
Matsyir
  • 101
  • 3

JavaScript (V8), 142142 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=>(dd=d/=1010-9,r=[20r=[11,2617,189,2314.5,178,2112,167,2011,156,189.5,145,178,134,167,123,156,112,145,90.5,134,8-1,112.5,6-3,9]0],r.map((e,i)=>t+=i%2==1?0:d>=e&&d<=r[i+1]?1:0,t=0),t)

Try it online!Try it online!

f = (distance) => {
    distance /= 10 // divide input by 10 and subtract 9 since the hardcoded ranges take lessare charsshorter when dividedthose byoperations 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;
}

JavaScript (V8), 142 bytes

d=>(d/=10,r=[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],r.map((e,i)=>t+=i%2==1?0:d>=e&&d<=r[i+1]?1:0,t=0),t)

Try it online!

f = (distance) => {
    distance /= 10 // divide input by 10 since the hardcoded ranges take less chars when divided by 10

    // hardcoded ranges divided by 10 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]

    // .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;
}

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!

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;
}
Added unminified version w/ explanation/comments, minor clarifications
Source Link
Matsyir
  • 101
  • 3
Loading
Added unminified version w/ explanation/comments
Source Link
Matsyir
  • 101
  • 3
Loading
Source Link
Matsyir
  • 101
  • 3
Loading