Documentation
¶
Overview ¶
Package cc provides functionalities related to coding challenges, where problems are read from a text file and solutions are written back in an other file.
The package name "cc" stands for "Coding Challenge"
See sources at http://github.com/xeonx/cc
For example to create a program testing whether the input is odd or even:
package main
import(
"github.com/xeonx/cc"
)
func main() {
cc.Run(func() cc.Problem{
return &problem{}
})
}
type problem struct {
a int
}
func (pb *problem) Init(lines []cc.String) int
pb.a = lines[0].Int()
return 1
}
func (pb *problem) Solve() interface{}
if a%2 == 0 {
return "ODD"
}
return "EVEN"
}
Index ¶
- Variables
- func Run(factory ProblemFactory)
- func RunFrom(r io.Reader, w io.Writer, factory ProblemFactory)
- type Problem
- type ProblemFactory
- type String
- func (s String) Int() int
- func (s String) Int2() (int, int)
- func (s String) Int3() (int, int, int)
- func (s String) Int64() int64
- func (s String) Int64Array() []int64
- func (s String) Int642() (int64, int64)
- func (s String) Int643() (int64, int64, int64)
- func (s String) IntArray() []int
- func (s String) SingleDigitIntArray() []int
- func (s String) Split() []String
- func (s String) String() string
Constants ¶
This section is empty.
Variables ¶
View Source
var ( //DefaultInput is the default name for input files DefaultInput = "sample.in" //PrintFormat is the format for writing the result in the output file PrintFormat = "Case #%d: %v\n" )
Functions ¶
func Run ¶
func Run(factory ProblemFactory)
Run reads from file, solves and writes problem results in files.
Types ¶
type ProblemFactory ¶
type ProblemFactory func() Problem
A ProblemFactory is a factory for creating Problems
type String ¶
type String string
String provides helper function when reading problem data from string.
func (String) Int64Array ¶
Int64Array convert the value into an array of int64
func (String) SingleDigitIntArray ¶
SingleDigitIntArray convert the value into an array of ints. Each characters is converted individually.
Directories
¶
| Path | Synopsis |
|---|---|
|
cc_template generates a new go package usable as a base for coding challenges.
|
cc_template generates a new go package usable as a base for coding challenges. |
Click to show internal directories.
Click to hide internal directories.