From 431f6b3267d83f16055848c2d45cbddb3509bfd3 Mon Sep 17 00:00:00 2001 From: Stephen Lynn Date: Mon, 26 Feb 2024 07:25:11 +0800 Subject: ch-1 only no blog --- challenge-257/steve-g-lynn/python/ch-1.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-257/steve-g-lynn/python/ch-1.py (limited to 'challenge-257/steve-g-lynn/python') diff --git a/challenge-257/steve-g-lynn/python/ch-1.py b/challenge-257/steve-g-lynn/python/ch-1.py new file mode 100644 index 0000000000..49d2196a1f --- /dev/null +++ b/challenge-257/steve-g-lynn/python/ch-1.py @@ -0,0 +1,22 @@ +# Python 1.4 beta on DOSBOX + +def smaller_than_current( intuple ): + ranks=[] + for i in range(len(intuple)): + ranks.append((intuple[i],i)) + ranks.sort() + ranks=map(lambda x:x[1], ranks) + retval=[None]*len(intuple) + retval[ranks[0]]=0 + for i in range(1,len(ranks)): + if intuple[ranks[i]]==intuple[ranks[i-1]]: + retval[ranks[i]]=retval[ranks[i-1]] + else: + retval[ranks[i]]=i + return retval + + +print smaller_than_current( (5,2,1,6) ) # (2,1,0,3) +print smaller_than_current( (1,2,0,3) ) # (1,2,0,3) +print smaller_than_current( (0,1) ) # (0,1) +print smaller_than_current( (9,4,9,2) ) # (2,1,2,0) -- cgit