From 0b9501345b0685d31b355f2e85d3121f398b28c8 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 13 Oct 2015 13:39:50 +0200 Subject: Cleanup --- ops.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ops.go') diff --git a/ops.go b/ops.go index 73a2d38..bca0acd 100644 --- a/ops.go +++ b/ops.go @@ -2,6 +2,7 @@ package main import ( "container/list" + "fmt" "log" ) @@ -81,3 +82,26 @@ func (m Element) sub(n Element) Element { } return m.sub(n.prev()).prev() } + +// Equals compares two elements +func (m Element) Equals(n Element) bool { + return m.Value == n.Value +} + +// String pretty-prints value +func (m Element) String() string { + return fmt.Sprint(m.Value) +} + +// Scan returns n-th Element +func Scan(n int) Element { + if n > alphabet.Len() { + log.Fatal("out of range ", n) + return Element{} + } + e := alphabet.Front() + for i := 0; i < n; i++ { + e = e.Next() + } + return Element{e} +} -- cgit v1.2.3