From: Luke Kenneth Casson Leighton Date: Wed, 15 Nov 2023 14:17:09 +0000 (+0000) Subject: python conversion of maxloc.c X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d7241876642935d3b2d9de2f61b968eb140dc035;p=openpower-isa.git python conversion of maxloc.c --- diff --git a/maxloc/maxloc.py b/maxloc/maxloc.py new file mode 100644 index 00000000..bb260d25 --- /dev/null +++ b/maxloc/maxloc.py @@ -0,0 +1,25 @@ +def m2(a): + m = 0; + nm = -1; + i = 0; + n = len(a) + + while (i m) : + print("%d idx %d > m %d" % (i, a[i], m)) + m = a[i] + nm = i + i += 1 + return nm; + +# /*Testbench*/ + +if __name__ == '__main__': + arr = [5,2,8,1,3,7,9,4] + print("search list", arr) + result = m2(arr) + + print("Index of the maximum value in an array is: %d" % result)