Skip to content

Instantly share code, notes, and snippets.

def pig(word):
lower_word = original_word.lower()
    if lower_word[1] == "a" or lower_word[1] == "e" or lower_word[1] == "i" or lower_word[1] == "o" or lower_word[1] == "u":
        stem = lower_word[1:]
        first = lower_word[0]
        new_word = (stem + first+ "ay")
    else:
        stem2 = lower_word[2:]
        first2 = lower_word[0] + lower_word[1]
        new_word = (stem2 + first2 + "ay")
def pyg_sentence(sentence):
new_sentence = ""
for word in sentence:
new_sentence += pyg(word)
return new_sentence
def pyg(x):
if x[0] == 'a' or x[0] == 'e' or x[0] == 'i' or x[0] == 'o' or x[0] == 'u':
new_word = ' ' + x + "ay"
import time
grid = (
(8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8),
(49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0),
(81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65),
(52, 70, 95, 23, 4, 60, 11, 42, 69, 24, 68, 56, 1, 32, 56, 71, 37, 2, 36, 91),
(22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80),
(24, 47, 32, 60, 99, 3, 45, 2, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50),
(32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70),
import time
def ben_primes(limit, with_nones=False, bools=False):
"""
Find prime numbers from 2 to the specified limit, return a list.
Keyword arguments:
with_nones -- if True, will return a list like [2, 3, None, 5, None, 7, None, None, None, 11]; Nones are otherwise omitted
bools -- if True, ignores with_nones and returns a list like [True, True, False, True, False, True] where a number n's prime status can be found at list[n+2]
import time
class Cell:
def __init__(self):
self.left = None
self.right = None
self.value = 0
def increment(self):
def main():
print("I'm gonna generate a brainfuck program to print your text. It will be horribly inefficient, but it's faster",
"than writing it yourself…")
my_string = input('Enter the output string: ')
print(encode_string_to_brainfuck(my_string))
def encode_string_to_brainfuck(my_string):
@jarhill0
jarhill0 / Euler014.java
Created August 31, 2017 05:14
not working (too slow!!)
import java.util.HashMap;
public class Euler014 {
private HashMap<Integer, Integer> solvedCollatz = new HashMap<>();
private Integer collatzLength(Integer start) {
Integer len = 1;
Integer num = start;
while (num != 1) {
@jarhill0
jarhill0 / z_table.py
Last active September 1, 2017 03:50
For use as a z-score table
from math import sqrt, erf, erfc
from scipy.special import erfinv, erfcinv
class Table:
def __init__(self, precision=4):
self.precision = precision
def below(self, z_score):
@jarhill0
jarhill0 / bubblesort.py
Created November 5, 2017 04:36
Solving the complexity of bubblesort
class BubbleSort:
def __init__(self, items):
self.items = items
self.operations = 0
def sort(self):
while not self.sorted():
for i in range(1, len(self.items)):
self.operations += 1
a, b = self.items[i - 1:i + 1]
@jarhill0
jarhill0 / bf.py
Created November 6, 2017 06:31
asyncio! agh!
import asyncio
import time
class Cell:
def __init__(self):
self.left = None
self.right = None
self.value = 0