Skip to content

Instantly share code, notes, and snippets.

View jjfiv's full-sized avatar
🦀
RiiR

John Foley jjfiv

🦀
RiiR
View GitHub Profile
@jjfiv
jjfiv / 03_desc.md
Last active October 1, 2021 12:48
Project 3 for CS145, F2021

Q1: Draw the Chessboard

Fill in draw_chessboard() with a two-dimensional loop that calls the given draw_chessboard_cell(t, x, y) with 64 x,y pairs.

Q2: is_prime(n)

Write a function is_prime that takes an integer n and determines whether any numbers besides n and 1 evenly divide it.

  • Consider zero not prime.
  • Consider a negative number prime if it is prime when positive.
@jjfiv
jjfiv / proj2_starter.py
Last active September 23, 2021 19:08
CS145-Fall-2021 Project 2
### Q1: Making Change [4 points]
#
# US Currency:
# dollar = 100c
# quarter = 25c
# dime = 10c
# nickel = 5c
# penny = 1c
#
# We would expect the following for 99 cents:
@jjfiv
jjfiv / dtree_classes.py
Created April 29, 2021 13:28
Starter code for implementing a decision or regression tree in Python.
from dataclasses import dataclass
from typing import List
from abc import ABC, abstractmethod
class DTreeNode(ABC):
""" DTreeNode is an abstract class. All nodes in the Decision Tree can 'predict'. """
@abstractmethod
def predict(self, x: List[float]) -> float:
@jjfiv
jjfiv / step1_collection_info.sh
Created April 13, 2021 14:21
Update v2->v3 qrel/topic files for TREC News
# v3_ids.gz
# gzipped list of document ids in v3 collection
python3 wapo-print-docids.py $COLLECTION | gzip > v3_ids.gz
# data/dup-pairs.gz
cat wapo-near-duplicates | awk '{print $1, $2}' > dup-pairs
gzip dup-pairs
@jjfiv
jjfiv / extract_numbers.py
Created January 4, 2021 17:00
Roll through poetry dataset looking for numeric tokens.
import json, gzip, os
from tqdm import tqdm
import re
DIGITS = re.compile('\d+')
DATASET_PATH = os.path.join(os.environ['HOME'], 'data', 'poetry50k.dedup.jsonl.gz')
with gzip.open('windows.jsonl.gz', 'wt') as out:
with gzip.open(DATASET_PATH, 'rt') as fp:
@jjfiv
jjfiv / hmmm-automatic-numbering.py
Created November 18, 2020 16:48
Automatic Numbering for HMMM Code (Project 8, Q2):
NICER_HMMM = """
#
# Calculate N factorial.
#
# Input: N
# Output: N!
#
# Register usage:
#
# r1 N
@jjfiv
jjfiv / bubblesort.py
Created October 23, 2020 15:54
Bubble Sort (Lab 7Opt)
def swap(xs, i, j):
"""
Proj. 5:
Given the list xs, swap elements i and j.
Modify xs; don't return anything.
"""
tmp = xs[i]
xs[i] = xs[j]
xs[j] = tmp
@jjfiv
jjfiv / sorting_lab_xyz.py
Last active October 22, 2020 18:53
Lab 7: F2020; CS145; Modified from Lab W.
def swap(xs, i, j):
"""
Proj. 5:
Given the list xs, swap elements i and j.
"""
tmp = xs[i]
xs[i] = xs[j]
xs[j] = tmp
swap_ex = [1,2,3,4]
@jjfiv
jjfiv / sorting_lab.py
Created October 22, 2020 13:02
Lab 7: F2020; CS145
def swap(xs, i, j):
"""
Proj. 5:
Given the list xs, swap elements i and j.
"""
tmp = xs[i]
xs[i] = xs[j]
xs[j] = tmp
swap_ex = [1,2,3,4]
@jjfiv
jjfiv / lab6-starter.py
Created October 15, 2020 13:40
has_duplicates; filter_duplicates
def has_duplicates(xs):
# Now with dictionaries:
# create a dictionary "seen_already" that is empty.
# loop over every element of xs
# if an element is in seen_already, return True
# else; add it to seen_already
# if we haven't returned True by the end of the function, return False
return False
assert(has_duplicates([1,2]) == False)