Home > other >  In codewars brush to a 4 kyu python functions
In codewars brush to a 4 kyu python functions

Time:05-12

Def c (n) :
"" "function to judge whether the square of n is from 1 to n - 1 a few digits in the sum of squares, 5 * * 2=3 * * 2 * 2 + 4, it returns [3, 4], otherwise it returns False, the returned sequence must conform to the ascending order, can not have repeat number, if there are multiple data meet the requirements is to maximize the list that set of data output "" "

# a=50, it returns the group that contains 49
A=5
Print (c) (a)

Main learning is limited, do not know whether the map method inline lambda, consider data execution speed, otherwise the debug data is large enough, will timeout

CodePudding user response:

 def DataSplit (N, N) : 
If resL!=[] and sum (map ((x, 2), lambda x: pow resL))==N * * 2:
Result. Append (resL. Copy ())

For I in range (n - 1, 0, 1) :
ResL. The extend ([I])
DataSplit (N, I)
ResL. Pop ()

N=20
ResL=[]
Result=[]
DataSplit (n, n)

X=[sorted (I)
For I the result if the sum in (I)==Max (map (lambda x: sum (x), the result))]
Print (x)
  • Related