Skip to content

Instantly share code, notes, and snippets.

View Koitaro's full-sized avatar

Yasusi Koibuti Koitaro

View GitHub Profile
@Koitaro
Koitaro / Slots.pm
Last active August 29, 2015 14:04
Slots - Perl module / Class builder
package Slots;
sub import {
shift;
my $pkg = caller;
my $index = -1;
eval join "\n",
"package $pkg;",
"\@${pkg}::ISA = 'Slots';",
map { $index++; "sub $_ { \$_[0][$index] }" } @_;
class MinHeap
def initialize (arr = [])
@arr = arr.dup.sort!
end
def push(v)
i = @arr.size
@arr.push(v)
upheap(i)
end
@Koitaro
Koitaro / primes.rb
Last active December 29, 2015 17:59
class Primes < Array
def initialize(n)
@max = n
super n+1, false
self[2] = true
i = 3
while i <= n
self[i] = true
i += 2
end
@Koitaro
Koitaro / example.go
Last active December 29, 2015 02:39
Stack package for Go language.
package main
import (
"fmt"
"stack"
)
func main() {
s := stack.New()
for i := 1; i <= 5; i++ {
@Koitaro
Koitaro / problem42.go
Created January 14, 2013 17:47
Go/goroutine: Project Euler 40-49
package main
import (
"fmt"
"io/ioutil"
"runtime"
"strings"
"time"
)
@Koitaro
Koitaro / problem30.go
Last active December 10, 2015 04:38
Go/goroutine: Project Euler 30-39
package main
import (
"fmt"
"math"
"runtime"
"sort"
"time"
)
@Koitaro
Koitaro / problem26.go
Last active October 13, 2015 23:08
Go/goroutine: Project Euler 20-29
package main
import (
"fmt"
"runtime"
"time"
)
func init() {
runtime.GOMAXPROCS(8)
@Koitaro
Koitaro / problem12.go
Last active October 13, 2015 18:27
Go/goroutine: Project Euler 10-19
package main
import (
"fmt"
"time"
)
type primeFactors map[int]int
func newPrimeFactors(n int) (answer primeFactors) {
@Koitaro
Koitaro / problem1.go
Last active October 13, 2015 09:57
Go/goroutine: Project Euler 1-9
package main
import (
"fmt"
"time"
)
func sum(n int) (out chan int) {
out = make(chan int)
go func() {
@Koitaro
Koitaro / graph.go
Created August 28, 2012 12:13
Go: package Graph
package graph
type Graph map[string]*vertex
func New() Graph {
return make(Graph)
}
func (g Graph) Vertices() (answer []string) {
for v := range g {