Skip to content

Instantly share code, notes, and snippets.

View rainiera's full-sized avatar

Rainier Ababao rainiera

View GitHub Profile
@rainiera
rainiera / factorial.c
Created September 3, 2015 03:15
Rad factorial algorithm
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int factorial(int n) {
int ans[200]; // answer can have a max of 200 digits.
int temp, // <- carry
m, // <- ones place of the prod, to put in the array
prod, // product of the current digit
@rainiera
rainiera / gist:0a67c7aaad4c1c19445b
Created April 30, 2015 01:24
HPriorityQueue.java
public class HPriorityQueue<E extends Comparable<E>> {
private PQNode<E> first;
private PQNode<E> last;
private int size;
public HPriorityQueue() {
first = null;
last = null;
size = 0;
@rainiera
rainiera / gist:bfa75fc406c50920d24c
Last active August 29, 2015 14:18
Set implementation comparison
* (time in seconds)
*
* Title kb Total Distinct
*
* The Cat In The Hat 7 504 1622
* SortedSet time: 0.0343
* UnsortedSet time: 0.0169
* Java HashSet time: 0.0128
* Java TreeSet time: 0.0141
*
import java.util.HashSet;
import java.util.Random;
/*
* Given a string, write a function that returns the string, unaltered.
*/
public class StringString {
@rainiera
rainiera / TripleDuplicates.java
Created February 20, 2015 17:57
A method that returns an ArrayList of Strings that contain more than three of the same letter (case-insensitive), for the Names class of the NameSurfer project.
/**
* Returns an ArrayList of Strings of names that contain three or more
* of the same letter.
* @return A list of the names that contain three or more of the same letter.
*/
public ArrayList<String> tripleDuplicates() {
ArrayList<String> tripleDuplicates = new ArrayList<String>();
for (NameRecord name : this.names) {
HashMap<Character, Integer> map = new HashMap<Character, Integer>();
// I don't want case-sensitive letter frequencies
@rainiera
rainiera / PointDistance.java
Created February 19, 2015 22:22
example of PointDistance class for "KClosestPoints" problem
class PointDistance implements Comparable<PointDistance> {
Point p;
double dist;
public PointDistance(Point p, double dist) {
this.p = p;
this.dist = dist;
}
public int compareTo(PointDistance other) {

Keybase proof

I hereby claim:

  • I am rainiera on github.
  • I am rainiera (https://keybase.io/rainiera) on keybase.
  • I have a public key whose fingerprint is DC11 1E9D 7F57 B3F9 6340 8914 C246 9D53 5B5A 8553

To claim this, I am signing this object: