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.
How curious that all these people put that redundant code at the end...
Confused as to why this solution is considered best practice and clever. It's a fairly simple solution that is at least O(n^2) for a problem that can be solved in O(n). The (!!) operator is also fairly inefficient.
Duplicate?
https://www.codewars.com/kata/5728a1bc0838ffea270018b2
At year 1: f0=10000
At year 2: f1=10000-10000=0
Therefore at the end of year 2 John still has a non-negative amount on money.
This would occur if n is a single digit number, because the product of all the digis in a single digit number is that number.
Instead of this:
perhaps use this:
This is a 6 kyu? You are basically given the program in the description.
check_prime
function could be improved vastly, check out Blind4Basics solution for inspiration.I would not consider this the best solution since this problem can be solved in
O(1)
.I agree,
field.index(subfield)
adds an extra loop that is not necessarily needed.Counter(arr).items()
returns a list of[(key1, value1), (key2, value2), ...]
where the keys are the distinct numbers inarr
and the values are the occurrences of that key inarr
. You can pass this into themax
function with a customkey
to retrieve the max value. The key takes in a(key, value)
instance and compares it against other elements by first comparingx[1]
thenx[0]
wherex[1]
is the occurrence of that number andx[0]
is the number as stated before. You need to apply[0]
to the outputted(key,value)
of the max function to obtain the distinct number.This comment is hidden because it contains spoiler information about the solution
Better safe than sorry I guess. In this kata it is not needed however.
Nice but you are counting every digit regardless if it is in digits_list. Not too important but would speed up your solution for large integers_list and small digits_list.
This didn't age well.
Loading more items...