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
#!/bin/bash | |
Fail() | |
{ | |
echo "FATAL($0): $1" | |
exit 1 | |
} | |
# Compile the source code for mandelzoom. Optimize for speed. | |
echo "Building C++ code..." | |
g++ -Wall -Werror -Ofast -o mandelzoom mandelzoom.cpp lodepng.cpp || Fail "Error building C++ code." |
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/env python3 | |
import sys | |
import os | |
import re | |
import requests | |
import math | |
from scipy import stats | |
import datetime | |
DataUrl = 'https://raw.githubusercontent.com/datasets/covid-19/master/data/key-countries-pivoted.csv' |
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 Tally(text): | |
count = {} | |
for c in text: | |
count[c] = 1 + count.get(c, 0) | |
return count | |
print(Tally('aaabbaccaaa')) # prints {'b': 2, 'c': 2, 'a': 7} |
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 Tally(text, count): | |
for c in text: | |
count[c] = 1 + count.get(c, 0) | |
return count | |
c = {} | |
Tally('aaabbaccaaa', c) | |
Tally('xyzaa', c) | |
Tally('qrs', c) | |
print(c) |
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
print(Tally('abc', {})) # {'a': 1, 'c': 1, 'b': 1} | |
print(Tally('def', {})) # {'e': 1, 'd': 1, 'f': 1} | |
print(Tally('xyz', {})) # {'x': 1, 'y': 1, 'z': 1} |
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
# WARNING: This code contains a subtle bug! | |
def Tally(text, count = {}): | |
for c in text: | |
count[c] = 1 + count.get(c, 0) | |
return count |
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
print(Tally('abc')) | |
# {'c': 1, 'b': 1, 'a': 1} | |
print(Tally('def')) | |
# {'c': 1, 'f': 1, 'b': 1, 'd': 1, 'a': 1, 'e': 1} | |
print(Tally('xyz')) | |
# {'c': 1, 'f': 1, 'x': 1, 'b': 1, 'd': 1, 'z': 1, 'a': 1, 'e': 1, 'y': 1} |
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
GlobalCount = {} | |
def Tally(text, count = GlobalCount): | |
for c in text: | |
count[c] = 1 + count.get(c, 0) | |
return count |
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 Tally(text, count = None): | |
if count is None: | |
# Create a brand new, empty dictionary! | |
count = {} | |
for c in text: | |
count[c] = 1 + count.get(c, 0) | |
return count | |
print(Tally('abc')) | |
# {'a': 1, 'c': 1, 'b': 1} |
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
bestSize = None | |
bestSourceCode = None | |
for algorithm in AlgorithmList: | |
compressedDataCode = algorithm.Compress(words) | |
stubFileName = os.path.join(StubDirName, algorithm.Name() + '.py') | |
with open(stubFileName, 'rt') as infile: | |
stubCode = infile.read() | |
targetFileName = os.path.join(OutputDirName, algorithm.Name() + '.py') | |
code = CommonHeadCode + compressedDataCode + stubCode + CommonTailCode | |
with open(targetFileName, 'wt') as outfile: |