Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import random
- def circular_difference(a, b, modulus=256):
- diff = (b - a) % modulus
- if diff > modulus // 2:
- diff -= modulus
- return diff
- def errorsingle (acc,end):
- return abs(circular_difference(acc,end))
- def iDEADS (acc):
- return (acc+1)%256
- def iDEAD (acc):
- return list(map(iDEADS,acc))
- def dDEADS (acc):
- return (acc-1)%256
- def dDEAD (acc):
- return list(map(dDEADS,acc))
- def sDEADS (acc):
- return (acc*acc)%256
- def sDEAD (acc):
- return list(map(sDEADS,acc))
- def error (acc,ends):
- err = list(map(errorsingle,acc,ends))
- return sum(err)
- def advancedError1 (accc,ends):
- # First layer of "Inteligence"
- return min(error(iDEAD(accc),ends),error(dDEAD(accc),ends),error(sDEAD(accc),ends),error(accc,ends)*2)
- def advancedError2 (accc,ends):
- # Second layer of "Inteligence" that somehow is worse
- return min(advancedError1(iDEAD(accc),ends),advancedError1(dDEAD(accc),ends),advancedError1(sDEAD(accc),ends),advancedError1(accc,ends))
- def FindCommands(starts,ends,epochs):
- acc=starts
- program=""
- currEpoch=0
- while currEpoch<epochs:
- currEpoch=currEpoch+1
- bestName="i"
- errforI=advancedError1(iDEAD(acc),ends)
- bestError=errforI
- errforD=advancedError1(dDEAD(acc),ends)
- if errforD<bestError:
- bestName="d"
- bestError=errforD
- errforS=advancedError1(sDEAD(acc),ends)
- if errforS<bestError:
- bestName="s"
- print("Lowest error:"+bestName)
- program=program+bestName
- if bestName == "i":
- acc = iDEAD(acc)
- if bestName == "d":
- acc = dDEAD(acc)
- if bestName == "s":
- acc = sDEAD(acc)
- print("Program:"+program)
- if (ends == acc):
- return program
- if (bestName == "d" and program[ len(program)-2]=="i"):
- print("Trying another solution...")
- if random.randint(0.0,1.0)>0.65:
- print("Trying decrementing...")
- acc = dDEAD(acc)
- program=program+"d"
- else:
- print("Trying squaring...")
- acc = sDEAD(acc)
- program=program+"s"
- time.sleep(0.1)
- return "Solution not found"
- def compress (program):
- layer=0
- compressed=program
- while layer<5:
- layer=layer+1
- compressed=compressed.replace("di","")
- compressed=compressed.replace("id","")
- compressed=compressed.replace("ssssss","sssss")
- return compressed
- solutionfound=FindCommands([0,1,2],[1,0,1],100)
- print("Solution found:"+compress(solutionfound))
Advertisement
Add Comment
Please, Sign In to add comment