Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
67 chars. solution in Creative category for Univocalic davasaan by Ylliw
davasaan=d=lambda n:[+n>9,(p:=n>>4)and d(n-(p<<3)-(p<<1))+(p)][p>0]
# recursively with the greatest power of n (let's call it a) so that 10*a is less than n
# a=n>>4 = n//16 is that greatest power, so we know that 10a is less than n
# Therefore new_n=n-10a is less than n and if we know that davasaan(n)=a+davassan(new_n)
#
# It's now time to make this work, so let's define d=davassan (less char usage in recursion)
# new_n=n-10a=n-8a-2a=n-(a<<3)-(a<<1)
# and a is n>>4 (n//16)
# so main recursion element is d(n-(n>>4<<3)-(n>>4<<1))
# Let's now add the corner cases:
# We can do the recursion only if n>=16, so n>>4 and ensure n>=16 only as and does not evaluate 2nd element if 1st is False
# Finally is n is less than 16, so 15 or less, we need to return 1 if n>=10 and 0 if n<10
# n>9 is the shortest condition and +(n>9) ensure it's considered as int and not boolean
# I finally used a two element list (n<=16, n>15) with a condition (n>15) to choose as 'or' is not acceptable.
# this assertion should be stripped after self-testing.
# Last trick added (Python 3.8.1): assign n>>4 to p (p:n>>4) to reduce number of chars as it's used 4 times.
# Brackets around p:=n>>4 is mandatory as otherwise it's evaluating the 'and' part before assignment.
Jan. 21, 2020
Comments: