Skip to content

Instantly share code, notes, and snippets.

package shuffle
// Shuffle implements the Fischer-Yates shuffle
// algorith for generic slice types.
import (
math/rand
time
)
@valtyriel
valtyriel / main.go
Last active January 12, 2019 23:48
package main
import "fmt"
// Q1. Write a function that takes in a number and
// returns the next number that is divisible by 7.
func next7(n int) int {
n++
if n%7 == 0 {
return n
@valtyriel
valtyriel / tonerow
Last active April 7, 2017 16:32
Generates a tone row in 12-tone equal temperament.
This file has been truncated, but you can view the full file.
@valtyriel
valtyriel / deque.go
Created July 25, 2012 16:15
Implementation of a deque: A doubly-linked list where items can be added or removed from either end of the list.
package deque
// A single element of the deque.
// The leftmost element has left = nil,
// and the rightmost element has right = nil.
type element struct{
// The elements to the left and right of this one.
left, right *element
// The deque to which this element belongs.
@valtyriel
valtyriel / stack.go
Created July 24, 2012 19:13
Implementation of a stack: a singly-linked list where items are added and removed from the same end, in first-in, last-out order.
package stack
type element struct {
// Pointer to the next element in the list.
// The last element has next = nil.
next *Element
// The stack to which this element belongs.
stack *Stack
// The contents of this stack element.
@valtyriel
valtyriel / roll.go
Created June 25, 2012 22:09
roll -- a simple dice-rolling program
package main
import (
"flag"
"fmt"
"math/rand"
"os"
"time"
)