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.
It seems this kata actually requires finding those prime factors which is a (very) hard problem in general. I'm not sure whether non-sophisticated approaches will work here (that depends on the size of the input numbers), so I will skip this kata for now.
Great stuff, love it! Contains some nice hidden details such as using
operator<
onstd::pair<>
, C++14 lambda captures with initializer, etc. that make the solution very dense.Greatest drawback, in my opinion, is that it doesn't work for empty lists of intervals where it does invoke UB (because of
intervals[0]
). I fixed that in a fork, and additionally improved readability a bit more by using some other modern C++ features.This kata has been much more fun than I initially thought it would!
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Dope!
This comment is hidden because it contains spoiler information about the solution
Lol
I wouldn't want the (unnecessary) memory consumption of the intermediate
ranges
vector in this solution. Imagine millions of ranges the size of 1 or 2...When the integer list
args
is empty on input, wouldn't you then get an emptyresult
string, callpop_back()
on an empty string thereby triggering Undefined Behaviour?This comment is hidden because it contains spoiler information about the solution
Slow but nice and simple.
And after that, try to do it with only one single pass over the input! That is, look at each character only once. ;-)
enumerate() returns a special generator from an iterable. In itself, it has O(1) runtime and does not split anything. If anything it is the iterator of
str
that is "splitting" (or better: iterating) the string into individual characters if you mean that. enumerate() just adds indices on top of that.Loading more items...