commit
8e2ad7fa2a
5 changed files with 248 additions and 0 deletions
-
96.gitignore
-
86brute.py
-
6clipboard.py
-
39funcs.py
-
21uniPerm.py
@ -0,0 +1,96 @@ |
|||||
|
# ---> Python |
||||
|
# Byte-compiled / optimized / DLL files |
||||
|
__pycache__/ |
||||
|
*.py[cod] |
||||
|
*$py.class |
||||
|
|
||||
|
# C extensions |
||||
|
*.so |
||||
|
|
||||
|
# Distribution / packaging |
||||
|
.Python |
||||
|
env/ |
||||
|
build/ |
||||
|
develop-eggs/ |
||||
|
dist/ |
||||
|
downloads/ |
||||
|
eggs/ |
||||
|
.eggs/ |
||||
|
lib/ |
||||
|
lib64/ |
||||
|
parts/ |
||||
|
sdist/ |
||||
|
var/ |
||||
|
wheels/ |
||||
|
*.egg-info/ |
||||
|
.installed.cfg |
||||
|
*.egg |
||||
|
|
||||
|
# PyInstaller |
||||
|
# Usually these files are written by a python script from a template |
||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it. |
||||
|
*.manifest |
||||
|
*.spec |
||||
|
|
||||
|
# Installer logs |
||||
|
pip-log.txt |
||||
|
pip-delete-this-directory.txt |
||||
|
|
||||
|
# Unit test / coverage reports |
||||
|
htmlcov/ |
||||
|
.tox/ |
||||
|
.coverage |
||||
|
.coverage.* |
||||
|
.cache |
||||
|
nosetests.xml |
||||
|
coverage.xml |
||||
|
*,cover |
||||
|
.hypothesis/ |
||||
|
|
||||
|
# Translations |
||||
|
*.mo |
||||
|
*.pot |
||||
|
|
||||
|
# Django stuff: |
||||
|
*.log |
||||
|
local_settings.py |
||||
|
|
||||
|
# Flask stuff: |
||||
|
instance/ |
||||
|
.webassets-cache |
||||
|
|
||||
|
# Scrapy stuff: |
||||
|
.scrapy |
||||
|
|
||||
|
# Sphinx documentation |
||||
|
docs/_build/ |
||||
|
|
||||
|
# PyBuilder |
||||
|
target/ |
||||
|
|
||||
|
# Jupyter Notebook |
||||
|
.ipynb_checkpoints |
||||
|
|
||||
|
# pyenv |
||||
|
.python-version |
||||
|
|
||||
|
# celery beat schedule file |
||||
|
celerybeat-schedule |
||||
|
|
||||
|
# SageMath parsed files |
||||
|
*.sage.py |
||||
|
|
||||
|
# dotenv |
||||
|
.env |
||||
|
|
||||
|
# virtualenv |
||||
|
.venv |
||||
|
venv/ |
||||
|
ENV/ |
||||
|
|
||||
|
# Spyder project settings |
||||
|
.spyderproject |
||||
|
|
||||
|
# Rope project settings |
||||
|
.ropeproject |
||||
|
|
||||
@ -0,0 +1,86 @@ |
|||||
|
from funcs import * |
||||
|
from termcolor import colored |
||||
|
ops = ( |
||||
|
'+', |
||||
|
'-', |
||||
|
'*', |
||||
|
'/', |
||||
|
) |
||||
|
|
||||
|
par = ( |
||||
|
'{n[0]}{o[0]}{n[1]}{o[1]}{n[2]}{o[2]}{n[3]}', |
||||
|
'({n[0]}{o[0]}{n[1]}){o[1]}({n[2]}{o[2]}{n[3]})', |
||||
|
'({n[0]}{o[0]}{n[1]}{o[1]}{n[2]}){o[2]}{n[3]}', |
||||
|
'({n[0]}{o[0]}{n[1]}){o[1]}{n[2]}{o[2]}{n[3]}', |
||||
|
) |
||||
|
colors = [ |
||||
|
'red', |
||||
|
'green', |
||||
|
'yellow', |
||||
|
'blue', |
||||
|
'magenta', |
||||
|
'cyan' |
||||
|
] |
||||
|
var = ('a','b','c','d') |
||||
|
ps = perms(4) |
||||
|
|
||||
|
def find(numbs,fast = False): |
||||
|
|
||||
|
answers = [[],[]] |
||||
|
|
||||
|
t = True |
||||
|
|
||||
|
for perm in ps: |
||||
|
perm = list( |
||||
|
map( |
||||
|
lambda x:x-1,perm |
||||
|
) |
||||
|
) |
||||
|
org = perm |
||||
|
perm = choose(numbs,perm) |
||||
|
|
||||
|
for o in range(4**3): |
||||
|
o = zp(con_base(o,4),3) |
||||
|
o = choose(ops,o) |
||||
|
|
||||
|
for p in par: |
||||
|
g = p.format(**{'n':perm,'o':o}) |
||||
|
|
||||
|
try: |
||||
|
if round(eval(g),2) == 10: |
||||
|
if fast: |
||||
|
return [g] |
||||
|
else: |
||||
|
var_subbed = choose(var,org) |
||||
|
org = p.format(**{ |
||||
|
'n':var_subbed, |
||||
|
'o':o |
||||
|
}) |
||||
|
|
||||
|
d = simplify(org) |
||||
|
if not (d in answers[0]): |
||||
|
answers[0].append(d) |
||||
|
answers[1].append(g) |
||||
|
except: |
||||
|
pass |
||||
|
return tuple(set(answers[1])) |
||||
|
|
||||
|
Strng0 = 'Fancy colors? (y or n):' |
||||
|
Strng1 = 'One or all solutions (one or all):' |
||||
|
|
||||
|
fancy_colors = input(Strng0) == 'y' |
||||
|
fast = input(Strng1) == 'all' |
||||
|
print( |
||||
|
find( |
||||
|
list(range(1,5)),False |
||||
|
) |
||||
|
) |
||||
|
while True: |
||||
|
if fancy_colors: |
||||
|
random.shuffle(colors) |
||||
|
for col in colors: |
||||
|
for ans in find(getInput(input('Numbers:')),fast): |
||||
|
print(colored(ans,col)) |
||||
|
else: |
||||
|
for ans in find(getInput(input('Numbers:')),fast): |
||||
|
print(ans) |
||||
@ -0,0 +1,6 @@ |
|||||
|
import sl4a |
||||
|
def copy(st): |
||||
|
sl4a.Android().setClipboard(st) |
||||
|
return |
||||
|
def paste(): |
||||
|
return sl4a.Android().getClipboard().result |
||||
@ -0,0 +1,39 @@ |
|||||
|
from uniPerm import perms |
||||
|
from math import log |
||||
|
import random |
||||
|
from sympy.core.sympify import sympify |
||||
|
from sympy.simplify.simplify import simplify |
||||
|
def con_base(n,b): |
||||
|
out = [] |
||||
|
if n == 0: |
||||
|
return [0] |
||||
|
for p in range(int(log(n,b)),-1,-1): |
||||
|
out.append(n//(b**p)) |
||||
|
n %= b**p |
||||
|
return out |
||||
|
def zp(lst,n): |
||||
|
l = [] |
||||
|
for i in range(n-len(lst)): |
||||
|
l.append(0) |
||||
|
return l + lst |
||||
|
|
||||
|
def getInput(blah): |
||||
|
sanitized = list( |
||||
|
filter( |
||||
|
lambda x: x,blah.split(' ') |
||||
|
) |
||||
|
) |
||||
|
return list( |
||||
|
map( |
||||
|
lambda x: int(x),sanitized |
||||
|
) |
||||
|
) |
||||
|
|
||||
|
def choose(lst,select): |
||||
|
return list(map(lambda x: lst[x],select)) |
||||
|
|
||||
|
def rand_4(): |
||||
|
l = [] |
||||
|
for i in range(4): |
||||
|
l.append(random.randint(0,20)) |
||||
|
return l |
||||
@ -0,0 +1,21 @@ |
|||||
|
def circle(l, n = 1): |
||||
|
return l[n:] + l[:n] |
||||
|
|
||||
|
def perms(n): |
||||
|
d = 3 |
||||
|
l = 2 |
||||
|
combs = [[1,2],[2,1]] |
||||
|
if n == 2: |
||||
|
return combs |
||||
|
else: |
||||
|
for d in range(3,n+1): |
||||
|
for i in range(l): |
||||
|
combs[i].append(d) |
||||
|
for i in range(l*(d-1)): |
||||
|
combs.append(circle(combs[i])) |
||||
|
l *= d |
||||
|
return combs |
||||
|
#import time |
||||
|
#for i in perms(3): |
||||
|
# time.sleep(1) |
||||
|
# print(i) |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue