Skip to content

Instantly share code, notes, and snippets.

@vnprc
vnprc / DigitCount.java
Last active August 29, 2015 14:13
Generate a list of random doubles. For each double, take the first digit after the decimal and count how many times that digit appears in the double. Sum the counts and print the results.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeSet;
/**
* This is a programming exercise to generate a series of random doubles between
* 0.0 and 1.0 and return an ordered list of the count of the first digit after
@vnprc
vnprc / calculate_change.py
Created December 29, 2014 04:52
Given a list of change denominations and a target amount of money, calculate the number of ways to make that amount of change.
"""
Given a list of change denominations and a target amount of money,
calculate the number of ways to make that amount of change.
"""
def calculate_variations(total, denomination):
"""
return all possible sequences of denomination whose sum is <= desired_sum
"""
list = []
@vnprc
vnprc / permutations.py
Created December 28, 2014 00:44
Programming exercise to print all permutations of an input strings. Contains two implementations, one with duplicates (in the case of repeated characters), and one without.
"""
Programming exercise to print all the permutations of an input string.
"""
import sys
def get_permutations(string):
permutations = []
if len(string) == 1:
@vnprc
vnprc / hanoi.py
Created December 28, 2014 00:34
This is a programming exercise to solve the towers of hanoi puzzle. The physical puzzle has three pegs in a row. On the first peg is a stack of disks of descending diameter. You are only allowed to put a smaller disk on top of a larger disk, never the reverse. The task is to move the entire pile from the far left peg, to the far right peg. This …
"""
This is a programming exercise to solve the towers of hanoi puzzle.
The physical puzzle has three pegs in a row. On the first peg is a
stack of disks of descending diameter. You are only allowed to put
a smaller disk on top of a larger disk, never the reverse. The task
is to move the entire pile from the far left peg, to the far right
peg.
This script accepts one input argument, n, for the number of disks.
"""
@vnprc
vnprc / spiral.py
Created December 28, 2014 00:24
This is a programming exercise to print a spiral array of numbers to the screen. The spiral starts with 0 in the middle (or upper left of the middle square) and iterates in concentric square spiral pattern in a clockwise direction.
"""
This is a programming exercise to print a spiral array of numbers to
the screen. The spiral starts with 0 in the middle (or upper left of
the middle square) and iterates in concentric square spiral pattern in
a clockwise direction.
"""
import sys
import math