<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> import scipy . spatial . distance as sd <EOL> def conway ( population , generations = <NUM_LIT:100> ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( generations ) : <EOL> population = evolve ( population ) <EOL> return population <EOL> def evolve ( population ) : <EOL> """<STR_LIT>""" <EOL> cbdist = sd . cdist ( population , population , metric = '<STR_LIT>' ) <EOL> print ( cbdist == <NUM_LIT:1> ) . sum ( axis = <NUM_LIT:0> ) <EOL> exit ( ) <EOL> active_cells = population [ : ] <EOL> for cell in population : <EOL> for neighbor in neighbors ( cell ) : <EOL> if neighbor not in active_cells : <EOL> active_cells . append ( neighbor ) <EOL> new_population = [ ] <EOL> for cell in active_cells : <EOL> count = sum ( neighbor in population for neighbor in neighbors ( cell ) ) <EOL> if count == <NUM_LIT:3> or ( count == <NUM_LIT:2> and cell in population ) : <EOL> if cell not in new_population : <EOL> new_population . append ( cell ) <EOL> return new_population <EOL> def neighbors ( popultion ) : <EOL> """<STR_LIT>""" <EOL> shift = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ - <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , - <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , - <NUM_LIT:1> ] , [ - <NUM_LIT:1> , <NUM_LIT:1> ] , [ - <NUM_LIT:1> , - <NUM_LIT:1> ] ] ) <EOL> return np . array ( cell ) + shift <EOL> blinker = np . array ( [ ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( - <NUM_LIT:1> , <NUM_LIT:0> ) ] ) <EOL> end = conway ( blinker ) <EOL> print '<STR_LIT>' , blinker <EOL> print '<STR_LIT>' , end </s>
