In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive!
Hello! My name is Thomas and I'm a nerd. I like tech and gadgets and speculative fiction, and playing around with programming. It's not my day job, but I'm working on making it a side gig :)
There are filter and keepIf functions defined in the sequtils standard library but that feels like cheating :P
$ is Nim's stringify operator, and the find procedure returns -1 if it doesn't find the substring :)
importstrutils# for the 'find' procedureproc my_filter(start,stop:int):seq[int]=foriinstart..stop:iffind($i,"5")==-1:result.add(i)echomy_filter(1,9).lenechomy_filter(4,17).len
I love education and technology! If you ever want help with anything, please message me here on Dev, on Twitter (@PullJosh), or by email (hello@joshuapullen.com)
Tuesday - Don't give me five! (7 KYU)
In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive!
codewars.com/kata/dont-give-me-five
Haskell
Another Haskell solution:
Or a little bit shorter in the same language:
Ruby
Rust Solution:
Quick JS solution
This removes more than 5s
True, just realized 😂
Changing the conditional expression should fix that
Clojure
Common Lisp
Another JS solution:
Perl solution, test included:
Here's my Nim solution :)
There are
filter
andkeepIf
functions defined in thesequtils
standard library but that feels like cheating :P$ is Nim's stringify operator, and the find procedure returns -1 if it doesn't find the substring :)
Any application that can be written in JavaScript, will eventually be written in JavaScript:
Elixir:
And surprise! I wrote an F# solution in a similar fashion:
Cool solution! But this will timeout with large numbers!