Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 36 lines (29 sloc) 0.477 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
package main

import (
"log"
"container/ring"
)


func main() {
log.SetFlags(0) // quieter logging

size := 41
advance := 3

r := ring.New(size)
for j := 0; j< size; j++ {
r.Value = j
r = r.Next()
}

log.Print("initial len:", r.Len())
for r.Len()>1 {
r = r.Move(advance-1)
deleted := r.Unlink(1)
log.Print("del: ", val(deleted))
}
log.Print("survivor:", val(r))
}

func val(r *ring.Ring) int{
a, ok := r.Value.(int)
if ok {
return a
}
return -1
}
Something went wrong with that request. Please try again.