|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
student "student"
|
|
|
|
|
|
|
|
"base"
|
|
|
|
"lib"
|
|
|
|
)
|
|
|
|
|
|
|
|
func convertNbrBase(n int, base string) string {
|
|
|
|
var result string
|
|
|
|
length := len(base)
|
|
|
|
|
|
|
|
for n >= length {
|
|
|
|
result = string(base[(n%length)]) + result
|
|
|
|
n = n / length
|
|
|
|
}
|
|
|
|
result = string(base[n]) + result
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertBase(nbr, baseFrom, baseTo string) string {
|
|
|
|
resultIntermediary := base.Atoi(nbr, baseFrom)
|
|
|
|
|
|
|
|
resultFinal := convertNbrBase(resultIntermediary, baseTo)
|
|
|
|
|
|
|
|
return resultFinal
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
type node struct {
|
|
|
|
nbr string
|
|
|
|
baseFrom string
|
|
|
|
baseTo string
|
|
|
|
}
|
|
|
|
table := []node{}
|
|
|
|
|
|
|
|
for i := 0; i < 30; i++ {
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
validBaseToInput1 := base.Valid()
|
|
|
|
validBaseToInput2 := base.Valid()
|
|
|
|
str := base.ConvertNbr(lib.RandIntBetween(0, 1000000), validBaseToInput1)
|
|
|
|
val := node{
|
|
|
|
nbr: str,
|
|
|
|
baseFrom: validBaseToInput1,
|
|
|
|
baseTo: validBaseToInput2,
|
|
|
|
}
|
|
|
|
table = append(table, val)
|
|
|
|
}
|
|
|
|
|
|
|
|
table = append(table, node{
|
|
|
|
nbr: "101011",
|
|
|
|
baseFrom: "01",
|
|
|
|
baseTo: "0123456789"},
|
|
|
|
)
|
|
|
|
|
|
|
|
for _, arg := range table {
|
|
|
|
lib.Challenge("ConvertBase", student.ConvertBase, convertBase, arg.nbr, arg.baseFrom, arg.baseTo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: fix base exercises
|