2015-07-27
- Hannah Lorrimore, Cardiff University
- James Campbell, Cardiff University
- Tobenna P. Igwe, University of Liverpool, (Google Summer of Code)
- Vincent Knight, Cardiff University
phrases = ['Cats are nice', 'Dogs are awesome', 'Python is the best', 'I like doughnuts'] | |
words_to_check = ['are', 'awesome', 'brilliant', 'cake'] | |
# This might be your question | |
print 50 * "=" | |
print 'Checking pairwise' | |
print 50 * '-' | |
for pair in zip(phrases, words_to_check): # You don't know the zip command yet I think but look it up and this could easily be done using other tools (iterating over things) | |
if pair[1] in pair[0]: |
import difflib | |
usr_input = 'Vodca' | |
drinks = ['Jargerbomb', 'Vodka', 'Rum and Coke'] | |
best_match = max(drinks, key=lambda x: difflib.SequenceMatcher(None, usr_input, x).ratio()) | |
print best_match |
import difflib | |
usr_input = 'Rum and Juice' | |
drinks = ['Jargerbomb', 'Vodka', 'Rum and Coke'] | |
def match_ratio(string): | |
return difflib.SequenceMatcher(None, usr_input, string).ratio() | |
best_match = max(drinks, key=match_ratio) | |
print best_match |
""" | |
A quick ceaser cipher; used to decrypt a message from a mysterious twitter account: https://twitter.com/cryptogram_app | |
""" | |
import string | |
alphabet = string.ascii_lowercase | |
def decrypt(encryption, key): | |
""" | |
Decrypt a ceaser cypher encrypted message |
\begin{tikzpicture} | |
\tikzstyle{state}=[minimum width=2cm, font=\boldmath]; | |
% First row | |
\node (00) at (0,0) [state] {$(0,0)$}; | |
\node (01) at ($(00)+(3,0)$) [state] {$(0,1)$}; | |
\node (02) at ($(01)+(3,0)$) [state] {$(0,2)$}; | |
\node (03) at ($(02)+(3,0)$) [state] {$(0,3)$}; | |
\node (04) at ($(03)+(3,0)$) [state] {$(0,4)$}; | |
% Second row |
\documentclass{article} | |
\usepackage{tikz} | |
\usetikzlibrary{calc} | |
\begin{document} | |
\begin{tikzpicture} | |
\draw (0,0) -- (2,2); | |
\node (first_node) at (2,1) [draw, fill=red!20] {\(x^2\)}; |
import axelrod | |
strategies = axelrod.basic_strategies | |
strategies += axelrod.ordinary_strategies | |
strategies += axelrod.cheating_strategies | |
count = 0 | |
for s in strategies: | |
s = s() | |
if None in s.behaviour.values(): |
sed -i "" s/behaviour/classifier/g *py |
count = 0 # Initialising a variable to count numbers divisible by 11 | |
s = 0 # Initialising a variable to add all numbers divisible by 11 | |
powers = 1 # Multiple 2 together as many times as we have numbers divisible by 11 | |
for i in range(101): # Loop over numbers we want | |
if i % 11 == 0: # Identify numbers that are divisible by 11 | |
count += + 1 # Add 1 | |
s += i # Add the number itself | |
powers = powers * 2 # Multiple by 2 |