Don't give me five!

JavaScript (ES6), 36 33 bytes

Takes input with currying syntax (a)(b).

a=>F=b=>b<a?0:!/5/.test(b)+F(b-1)

Formatted and commented

a =>                 // outer function: takes 'a' as argument, returns F
  F = b =>           // inner function F: takes 'b' as argument, returns the final result
    b < a ?          // if b is less than a
      0              //   return 0
    :                // else
      !/5/.test(b) + //   add 1 if the decimal representation of b does not contain any '5'
      F(b - 1)       //   and do a recursive call to F with b - 1

Test cases

let f =

a=>F=b=>b<a?0:!/5/.test(b)+F(b-1)

console.log(f(1)(9))
console.log(f(4)(17))
console.log(f(50)(60))
console.log(f(-50)(-59))


Jelly, 8 7 bytes

-1 byte thanks to Dennis (use fact that indexing into a number treats that number as a decimal list)

rAw€5¬S

TryItOnline!

How?

rAw€5¬S - Main link: from, to    e.g. -51, -44
r       - range(from, to)        e.g. [-51,-50,-49,-48,-47,-46,-45,-44]
 A      - absolute value         e.g. [51,50,49,48,47,46,45,44]
  w€    - first index of... for €ach (0 if not present)
    5   - five                   e.g. [1,1,0,0,0,0,2,0]
     ¬  - logical not            e.g. [0,0,1,1,1,1,0,1]
      S - sum                    e.g. 5

* The absolute value atom, A is necessary since a negative number cast to a decimal list has negative entries, none of which would ever be a 5 (the given example would count all eight rather than two).


Bash + grep, 17 bytes

seq $@|grep -cv 5

Try it online!

Tags:

Math

Code Golf