Skip to content

Instantly share code, notes, and snippets.

@wray
Created January 28, 2018 21:02
Show Gist options
  • Save wray/572481263ee8c97fb97127e4b98fa6b8 to your computer and use it in GitHub Desktop.
Save wray/572481263ee8c97fb97127e4b98fa6b8 to your computer and use it in GitHub Desktop.
Break up the problem space for parallel submission to lambda
import pywren
import time
import itertools
def brute_force_digits(pin):
""" Uses itertools to create a cartesian product of the possible pins """
for guess in list(itertools.product(list(range(10)),repeat=len(str(pin)))):
if pin == int(len(str(pin))*'%d' % (guess)):
return guess
def brute_force_split(pin,n):
""" Breaking up the problem space to minimize memory for brute_force_digits """
split = len(pin)//n
l = [ int(pin[i*n:(i+1)*n]) for i in range(split) ]
pwex = pywren.default_executor()
# Executing on lambda in parallel
futures = pwex.map(brute_force_digits,l)
return pywren.get_all_results(futures)
if __name__ == '__main__':
""" PyWren/lambda beats local when dividing sol'n space by 6 for a pin sized 360 """
print('Provide a digit-only pin whose length is divisible by 6 to be brute-forced guessed')
pin = input()
t1 = time.time()
guess = brute_force_split(pin,6)
print('Found: ' + str(guess))
t2 = time.time()
print('Elapsed time was ' + str(t2-t1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment