From 35b162fc9dfed97c0709d85589243670566d4ab7 Mon Sep 17 00:00:00 2001 From: TheLie0 Date: Sun, 19 Mar 2017 14:12:48 +0100 Subject: [PATCH] Add files via upload now it's here --- builtin_filters.py | 85 ++++++++++++++++++++++++++++++++++++++++++++ builtin_filters.pyc | Bin 0 -> 2552 bytes custom_filters.py | 4 +++ custom_filters.pyc | Bin 0 -> 203 bytes main.py | 32 +++++++++++++++++ triangle.py | 64 +++++++++++++++++++++++++++++++++ triangle.pyc | Bin 0 -> 2154 bytes 7 files changed, 185 insertions(+) create mode 100644 builtin_filters.py create mode 100644 builtin_filters.pyc create mode 100644 custom_filters.py create mode 100644 custom_filters.pyc create mode 100644 main.py create mode 100644 triangle.py create mode 100644 triangle.pyc diff --git a/builtin_filters.py b/builtin_filters.py new file mode 100644 index 0000000..75f4ca4 --- /dev/null +++ b/builtin_filters.py @@ -0,0 +1,85 @@ +import math + +def Modulo2(num): + return num % 2 + +def Modulo3(num): + return num % 3 + +def Digits(num): + return int(math.log10(num)) + 1 + +def IsPrime(num): + if num == 1: + return 0 + elif num == 2: + return 1 + primeVar = 1 + digits = int(math.log10(num)) + 1 + if digits > 12: + for divider in range(2, int(num/10000000000)): + if num % divider == 0: + primeVar = 0 + for i in range(2,10000000001): + for divider in range(int((i-1)*num/10000000000), int(i*num/10000000000)): + if num % divider == 0: + primeVar = 0 + return primeVar + + elif digits > 9: + for divider in range(2, int(num/10000000)): + if num % divider == 0: + primeVar = 0 + for i in range(2,10000001): + for divider in range(int((i-1)*num/10000000), int(i*num/10000000)): + if num % divider == 0: + primeVar = 0 + return primeVar + + elif digits > 6: + for divider in range(2, int(num/10000)): + if num % divider == 0: + primeVar = 0 + for i in range(2,10001): + for divider in range(int((i-1)*num/10000), int(i*num/10000)): + if num % divider == 0: + primeVar = 0 + return primeVar + + elif digits > 3: + for divider in range(2, int(num/10)): + if num % divider == 0: + primeVar = 0 + for i in range(2,11): + for divider in range(int((i-1)*num/10), int(i*num/10)): + if num % divider == 0: + primeVar = 0 + return primeVar + + else: + for divider in range(2,num): + if num % divider == 0: + primeVar = 0 + return primeVar + +def Mod2Vis(num): + if Modulo2(num) == 0: + return " " + else: + return "X" + +def Mod3Vis(num): + if Modulo3(num) == 0: + return " " + elif Modulo3(num) == 1: + return "X" + else: + return "O" + +def PrimeVis(num): + if IsPrime(num) == 0: + return "_" + else: + return "X" + + diff --git a/builtin_filters.pyc b/builtin_filters.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cfa2c4276e3727105f38b2783645c5e96c70d832 GIT binary patch literal 2552 zcmb_eTTc^F5T3JJdVvDPOVJn08~b1gf=WV+Q6Mos2xOa3G&Q7jD;(&B?JlMyH1YPp zJBi_c_#b@ao!{Y;35m`(+rp+uQEabP@$i;d zID9B76TM-@pf9W_a!gSSaw4LbaXD7`ExinCiV);bd;TSVnMul z*hg9Td??y7P@~TZ2Um2oT`APZ!t+ujUG@D4UsMYIrr*a(xwi3OQi|9E)PTC6H?;3z zIm4h43U>wcI>QOpbK9VL3jLGCwMn=hlZN0Fn(C6&nw+Zi*mi{KKdCW`+;}z@0&e=~ zHp*bo!rKfrP1yELN^=yrFCiSec1t*Njjh&XZcv%>nwk-6EW-+a+_{SGu!~zQzkxAi zxGd0dJJ2z?$CPuAD7Vj@4&*Tc@^7jWdAuv~jA|jzC^w@*$P-r~5B!FZcMo*X4s@X0 z1C?`ab%wlOkXMXO_$C zoydo}B0p?9JT%-xBUJO@tB?nNL&&=aI&B9!HQZB1{yjk6m~6EtH{4~7He@(x*uYI zg#{9^VY5ZU{uVx|7pfa23zxztew?+Px~`N~3UwbY9pMKdTSvdwPN~l1#a{oPFJF4g z2!ss1JPT4u6_F8DclkV~Qfg48)nh)7sEBbbiUZs`QyX1aHV35c!-^%1gem_= IiD)AJ8_9&k=l}o! literal 0 HcmV?d00001 diff --git a/custom_filters.py b/custom_filters.py new file mode 100644 index 0000000..28e6041 --- /dev/null +++ b/custom_filters.py @@ -0,0 +1,4 @@ +#put your own filters right here... +"""Example filter: +def AddOne(num): + return num + 1""" \ No newline at end of file diff --git a/custom_filters.pyc b/custom_filters.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3b3c2298ca7885c81c15296410bea10b2aa79942 GIT binary patch literal 203 zcmZSn%*$ogcrGHD0SXv_v;z8hNF;npRw#MX4pFMR^K9o`SZ5p`QlG$P#uS5g(tDpBx{r0c0{D zh+b>KI3^&mI5{yVCb_h@BtJJEVqvjfL1hUCP=`%! QeoARhsvQfET@1tw0Ekd9X#fBK literal 0 HcmV?d00001 diff --git a/main.py b/main.py new file mode 100644 index 0000000..44faddc --- /dev/null +++ b/main.py @@ -0,0 +1,32 @@ +from triangle import Triangle, BeautifyTri, FilterTri + +print """Hi! I'm glad You chose me as your go to Pascal's Triangle software! You are currently running my main.py, +so I assume You're interested in using my friendly I/O access. Feel free to also implement my functions +in any of your own code. For now, I will just ask you for the numbers of lines you want and which filter +to apply. A filter usually applies some function to each number in the triangle. You can create your own +filters in custom_filters.py. If you don't know what to do use the filter "help" ;). Have Fun!""" + +while True: + error = False + try: + size = int(raw_input("Number of rows: ")) + except ValueError: + print "Damn, I couldn't get that number. Please only use numerical characters here..." + error = True + if not error: + filter = raw_input("Filter: ") + if filter == "none": + print BeautifyTri(Triangle(size)) + elif filter == "help" or filter == "Help" or filter == "HELP": + print """Here are all the builtin filters, try them out as you like: +- Modulo2 +- Modulo3 +- Digits +- IsPrime +- Mod2Vis +- Mod3Vis +- PrimeVis + +!The Prime family of filters might take a while for triangles over 20 rows!""" + else: + print BeautifyTri(FilterTri(Triangle(size), filter)) \ No newline at end of file diff --git a/triangle.py b/triangle.py new file mode 100644 index 0000000..e59a42f --- /dev/null +++ b/triangle.py @@ -0,0 +1,64 @@ +from builtin_filters import * +from custom_filters import * + +def Triangle(size): + """takes int size. Generates a pascals triangle with that number of rows.""" + if size == 1: + return [[1]] + else: + rows = Triangle(size-1) + newRow = [1] + for index in range(len(rows[-1])-1): + newRow.append(rows[-1][index] + rows[-1][index+1]) + newRow.append(1) + rows.append(newRow) + return rows + +def BeautifyTri(triangle = Triangle(10)): + """takes triangle (default is normal Tri with length 10), returns middle-aligned tri.""" + rowStrList = [] + outStr = "" + for row in triangle: + rowStr = "" + for num in row: + rowStr += str(num) + " " + rowStrList.append(rowStr[:len(rowStr)]) + for rowStr in rowStrList: + while len(rowStr) < len(rowStrList[-1]): + rowStr = " " + rowStr + if len(rowStr) < len(rowStrList[-1]): + rowStr += " " + rowStr += "\n" + outStr += rowStr + return outStr + +def FilterTri(inTri = Triangle(10), filterFunc = Modulo2): + """takes triangle inTri and/or function filterFunc (defaults are Triangle(10) and Modulo2). + Returns filtered Triangle.""" + failed = False + if type(filterFunc) == str: + try: + filterFunc = eval(filterFunc) + except NameError: + failed = True + if failed: + print """This filter doesn't seem to exist :/ I imagine it would be really +cool if it did... Maybe create it? ^^ But since it would be really +boring if nothing happened, have a normal pascal's triangle.""" + return Triangle(10) + outTri = [] + for row in inTri: + outRow = [] + for num in row: + try: + outNum = filterFunc(num) + outRow.append(outNum) + except NameError: + failed = True + outTri.append(outRow) + if failed: + print """This filter doesn't seem to exist :/ I imagine it would be really +cool if it did... Maybe create it? ^^ But since it would be really +boring if nothing happened, have a normal pascal's triangle.""" + return Triangle(10) + return outTri \ No newline at end of file diff --git a/triangle.pyc b/triangle.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3192c0859e13a7f44bb021bde52911f6e05c626a GIT binary patch literal 2154 zcmbVN+ioL85Un0xLd<4Kf8RNGq<3a{;kYWJgLAC5t9AZM&24j6L16 zu_OBdk-y+Sc;6r36Oee|3-|yy)#F(sv@fjVu5?#bcXih}RWALtRQv3w-;M*CeM@nOKSj8Vn-7Q_4kF>xU;JxX8W*j@K++rn@M@umpr)KiZ}yL_7UXac22>wFzS z?A1K`h^8f)cys}oTPG!2pHJbqw!Q{eG5ns6a!2S`0Vm$&6^k}r+OG3u%?^b1FO`ux zw$kWp)sVX?R;h2H^X0%dfgc%ZQ|-syNXaX0d(!rNE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