Skip to content

Instantly share code, notes, and snippets.

@ad2476
ad2476 / largestprimefactor.java
Last active August 29, 2015 14:00
Largest prime factor
// Largest prime factor of number
public long primeFactor(long number) {
long largestFactor=0;
for (long n=2; n<=(int)Math.sqrt(number); n++) {
// n is a factor of number
if(number%n == 0) {
// Is n prime?
boolean isPrime=true;
for (long i=2; i<=(int)Math.sqrt(n); i++) {
if(n%i == 0) { // i is a factor of n
/* Returns the nth prime number - uses the Sieve of Eratosthenes */
public int calculatePrime(int limit, int n) {
List<Integer> working_set = new ArrayList<Integer>();
int p=2;
// Fill our working set with consecutive integers (longs) from 2 through n
System.out.println("Populating working set...");
for(int i=2; i<=limit; i++)
working_set.add(i);
@ad2476
ad2476 / APCompSci.java
Last active August 29, 2015 14:01
Sorting/Searching practice
abstract class Structure {
public final int ASCENDING=1;
public final int DESCENDING=-1;
public final int NONE=0;
protected int[] storage;
protected boolean sorted;
protected int order;
/* Determine the ordering state of storage */
@ad2476
ad2476 / redistribute.py
Created February 24, 2016 01:10
Redistribution of winnings
# Redistribute the PolyHack winnings:
# Returns list of all the people who need money, and all who have too much
# in the form of (receivers, givers)
def findCreditorsDebtors(allocs, desiredAllocs):
receivers, givers = [], []
for person,amt in allocs.iteritems():
desired = desiredAllocs[person]
if amt < desired:
{
"Working Directory" : "HOME_CHANGE_THIS",
"Prompt Before Closing 2" : 0,
"Selected Text Color" : {
"Green Component" : 0.5648583769798279,
"Red Component" : 0.5059919357299805,
"Blue Component" : 0.5636365413665771
},
"Rows" : 37,
"Ansi 11 Color" : {
@ad2476
ad2476 / tf.py
Created October 3, 2016 17:55
cs295k hw3 conv net for mnist
import tensorflow as tf
import sys
from tensorflow.examples.tutorials.mnist import input_data
# Initialize weights with a small amount of noise for symmetry breaking, and to prevent 0 gradients.
# For ReLU neurons, good practice to initialize with a slightly positive initial bias to avoid "dead neurons"
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
@ad2476
ad2476 / hw4.py
Created October 13, 2016 00:25
cs295k hw4
import tensorflow as tf
import sys
import argparse
import pickle
batch_size = 20
embed_size = 30
hidden_size = 100
# text is a list of sentences
@ad2476
ad2476 / Makefile
Created February 22, 2017 20:51
Automate compiling cs142 writeup and sending it to CIT printers
.PHONY: all clean print friend
HW = $(shell basename $(CURDIR))
PRINTER = c4
USER = username
FRIEND = yourfriend
DEPS = cover.pdf writeup.pdf hw2.pdf
TARGET = $(HW).pdf

Keybase proof

I hereby claim:

  • I am ad2476 on github.
  • I am quallius (https://keybase.io/quallius) on keybase.
  • I have a public key ASALc0tSwiZvPMQaUVraNHXvIhwVXxgkzA9SXserJ_AFjgo

To claim this, I am signing this object: