This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import string | |
import random | |
LETTERS = string.ascii_letters + ' ' + '!' + '?' | |
class GeneticHelloWorld(object): | |
def __init__(self, | |
target = "Hello Python World!", # Target string we're going for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run(self): | |
# Create a random sample of chromos | |
sample = self.generate_random_chromosomes() | |
# Main loop: each generation select a subset of the sample and breed from | |
# them. | |
generation = -1 | |
while self.fitness(sample[0]) != 0: | |
generation += 1 | |
# Generate the selected group from sample- take the top 1% of samples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn generate-selected | |
"The selected group is generated by taking the best 10 chromos (elitism), | |
then repeated calling tourny-select on the sample to generate 90 more." | |
[sample] | |
(concat | |
(take 10 sample) | |
(take 90 (repeatedly #(tourny-select-chromo sample))))) | |
(defn generate-solution | |
"Generates the solution set by repeatedly selecting two chromos (at random) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compare -subimage-search floor-11.png crystal.png result-11-%d.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat result-11-1.txt | grep white | awk -F"[,| |:]" '{print "["$1 " " $2 "]"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used to determine if we are running a new install or an upgrade by checking | |
// for the AppID in the registry. | |
function IsNewInstall(): Boolean; | |
var | |
AppID: String; | |
UninstallPath: String; | |
begin | |
AppID := '{enter-AppID-here}' | |
UninstallPath := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\' + AppID + '_is1'; | |
Result := not (RegKeyExists(HKEY_CURRENT_USER, UninstallPath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
768,419: (133,133,133) #858585 rgb(133,133,133) | |
769,419: (131,131,131) #838383 rgb(131,131,131) | |
770,419: (129,129,129) #818181 rgb(129,129,129) | |
771,419: (129,129,129) #818181 rgb(129,129,129) | |
772,419: (127,127,127) #7F7F7F rgb(127,127,127) | |
773,419: (126,126,126) #7E7E7E rgb(126,126,126) | |
774,419: (126,126,126) #7E7E7E rgb(126,126,126) | |
775,419: (137,137,137) #898989 rgb(137,137,137) | |
776,419: (255,255,255) #FFFFFF white |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[776 419] | |
[714 421] | |
[645 422] | |
[643 474] | |
[777 477] | |
[640 540] | |
[778 540] | |
[707 543] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn find-prime [bit-length] | |
(. BigInteger (probablePrime bit-length (new java.util.Random)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@staticmethod | |
def _hash_function(string): | |
# Covert each char of string to an ordinal number and sum them. Mod this | |
# by the number of buckets. | |
return sum(map(ord, string)) % num_buckets |
OlderNewer