Skip to content

Instantly share code, notes, and snippets.

Jon Bodner jonbodner

Block or report user

Report or block jonbodner

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jonbodner
jonbodner / firstNonRepeat.go
Created Jul 1, 2014
First non-repeated character in a string in Go
View firstNonRepeat.go
package main
import "fmt"
func firstNonRepeatChar(s string) rune {
useMap := make(map[rune]bool)
for _, v := range s {
_, ok := useMap[v]
useMap[v] = ok
}
@jonbodner
jonbodner / fizzbuzz.go
Created Jul 1, 2014
Very silly FizzBuzz in Go
View fizzbuzz.go
package main
import "fmt"
type data struct {
i int
s string
}
func (d data) String() string {
@jonbodner
jonbodner / monty_hall.go
Created Jul 5, 2014
Simple implementation to demonstrate the Monty Hall Problem (http://en.wikipedia.org/wiki/Monty_Hall_problem)
View monty_hall.go
package main
import (
"fmt"
"math/rand"
"os"
"strconv"
"time"
)
@jonbodner
jonbodner / star_solve.go
Created Jul 14, 2014
Solver for the 6-point Magic Star Problem
View star_solve.go
package main
import (
"fmt"
)
type ValSet struct {
one, two, three, four *int
}
@jonbodner
jonbodner / fizzbuzz_no_cond.go
Last active Aug 29, 2015
FizzBuzz for Go with no conditionals.
View fizzbuzz_no_cond.go
package main
import "fmt"
type fber func(int)string
func fizzer(i int) string {
return "fizz"
}
@jonbodner
jonbodner / YFact.java
Created May 1, 2012
Generic Y Combinator in Java
View YFact.java
//based on code from http://www.arcfn.com/2009/03/y-combinator-in-arc-and-java.html
class YFact {
// T function returning a T
// T -> T
public static interface Func<T> {
T apply(T n);
}
// Higher-order function returning a T function
@jonbodner
jonbodner / YFact.go
Created May 3, 2012
Y Combinator in Go
View YFact.go
package main
import "fmt"
//based on code from http://www.arcfn.com/2009/03/y-combinator-in-arc-and-java.html
type Func func (interface{}) interface{}
type FuncToFunc func (Func) Func
@jonbodner
jonbodner / even_first.go
Created May 7, 2012
Even-Odd Partition in Go
View even_first.go
package main
import "fmt"
import "math/rand"
import "time"
func main() {
rand.Seed(time.Now().UnixNano())
vals := rand.Perm(10)
fmt.Println(vals)
@jonbodner
jonbodner / partition.go
Created May 13, 2012
Calculate Partition in Go
View partition.go
package main
import "fmt"
import "sort"
type EMPTY struct {}
var PRESENT EMPTY = EMPTY{}
func partition(val int) []string {
View Streaming_Knapsack.go
package main
import (
"fmt"
"math/rand"
)
/*
A famous problem of computer science is the knapsack problem, in which you are to find a combination of items from a population that sums to a given target,
often with some kind of constraint such as maximizing the value of the items. In today’s problem we want to find the first possible combination
You can’t perform that action at this time.