Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Approved some time ago
Approved
Approved
The point of this kata is not to write a function
boolean isDiv5(String s)
, but to create a regular expression that will match all strings that represent in binary a number divisible by five and only these strings.For example, this regular expression should match
"101"
,"0"
and"1111"
because they represent5
,0
and15
.But it should not match
"111"
,"10000"
nor"1"
as they represent7
,16
and1
.You mad genius
This comment is hidden because it contains spoiler information about the solution
Approved
Approved
You are doing WAY too much work generating all the permutations. Let's take the example in the description :
The whole list of permutations of "abc" is
["abc", "acb", "bac", "bca", "cab", "cba"]
, and the answer is"bac"
.Do you really need to know that
"abc"
comes before"acb"
to determine the middle permutation ? No you don't.Do you even need to generate them ? Once again, no you don't. After all,
'a'
is the very first letter in order, so there's not much chance for it to be the middle permutation's first letter.It's really quite simple, actually : look at the fork.
Edit : similar solution (except that I used 128 instead of 1000)
there are empty matrices (
[]
) in the random tests. I personally think it's a valid edge case, but it's not aligned with the other languages which never generate themI like your fork good fellow Glinator :)
what the heck
Approved
You are correct, thank you, - I completely forgot about those. Alas, I don't get to code in OCaml as much as I'd like - I might actually attempt to translate some of my favorite katas into OCaml. :)
Loading more items...