Skip to content

Instantly share code, notes, and snippets.

@snarkbait
snarkbait / Advent7.java
Created December 8, 2015 03:18
Advent of Code Day 7
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.IntBinaryOperator;
/**
* @author /u/Philboyd_Studge on 12/6/2015.
*/
public class Advent7 {
@snarkbait
snarkbait / FileIO.java
Created December 6, 2015 21:31
FileIO.java Simplified static file functions, made specifically for the AdventOfCode challenges.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.regex.PatternSyntaxException;
@snarkbait
snarkbait / BitStream.java
Created August 9, 2015 00:45
Huffman Tree example
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
@snarkbait
snarkbait / MergeSort.java
Last active August 29, 2015 14:23
Top-Down Merge Sort
/*
* Generic Top-Down Merge Sort
* Based on this
* https://en.wikipedia.org/wiki/Merge_sort#Top-down_implementation_using_lists
*
* for http://www.reddit.com/r/javaexamples
* by user /u/Philboyd_Studge
*
* PUBLIC LICENSE - This software is released with an unlimited license.
* There is no specification of any kind on its usage or implementation.
@snarkbait
snarkbait / DiGraph.java
Created June 2, 2015 06:10
Generic Directed, Weighted Graph with Dijkstra's Shortest Path
/* Generic Directed Weighted Graph with Dijkstra's Shortest Path Algorithm
* by /u/Philboyd_Studge
* for /r/javaexamples
*/
import java.util.List;
import java.util.Queue;
import java.util.PriorityQueue;
import java.util.Deque;
import java.util.LinkedList;
@snarkbait
snarkbait / BinaryHeap.java
Last active December 10, 2022 22:45
Generic Min/Max Binary Heap
/* Generic Min/Max Binary Heap
* for /r/javaexamples
*
*/
import java.util.Arrays;
@SuppressWarnings("unchecked")
/**
* Creates an array-based binary heap. Defaults to 'min' (Priority Queue)
@snarkbait
snarkbait / Inventory.java
Last active March 31, 2021 17:11
InventoryGUI SQlite Example for /r/javaexamples
/* Inventory class
* for /r/javaexamples
* by /u/Philboyd_Studge
*
*/
package philboyd.studge;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Random;
@snarkbait
snarkbait / BinaryTreeKV.java
Created May 22, 2015 06:38
Generic Self-Balancing Key-Value Binary Search Tree for /r/javaexamples
/* Generic Self-Balancing Key-Value Binary Search Tree
for /r/javaexamples
by /u/Philboyd_Studge
*/
import java.util.Queue;
import java.util.LinkedList;
import java.util.List;
@SuppressWarnings("unchecked")
@snarkbait
snarkbait / Inventory.java
Last active November 9, 2016 21:29
Sorted Doiubly-Linked List example for /r/javaexamples
public class Inventory implements Comparable<Inventory>
{
private String item;
private int qty;
private float price;
public Inventory(String item, int qty, float price)
{
this.item = item;
this.qty = qty;
import java.util.Random;
public class Game21
{
private int[] heap;
private Random rand = new Random();
private boolean computerOpponent;
private boolean lastPlayWins;