|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
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
|
|
|
"unicode"
|
|
|
|
|
|
|
|
student "student"
|
|
|
|
|
|
|
|
"github.com/01-edu/public/test-go/lib"
|
|
|
|
)
|
|
|
|
|
|
|
|
func printBase(nbr int) int {
|
|
|
|
var result []rune
|
|
|
|
base := "0123456789abcdef"
|
|
|
|
typeBase := []rune(base)
|
|
|
|
a := 0
|
|
|
|
pos := 0
|
|
|
|
i := 0
|
|
|
|
if nbr == 0 {
|
|
|
|
result = append(result, '0', '0')
|
|
|
|
i = 2
|
|
|
|
}
|
|
|
|
for nbr > 0 {
|
|
|
|
pos = nbr % 16
|
|
|
|
nbr = nbr / 16
|
|
|
|
result = append(result, typeBase[pos])
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
if i == 1 {
|
|
|
|
result = append(result, '0')
|
|
|
|
i = 2
|
|
|
|
}
|
|
|
|
for j := i - 1; j >= 0; j-- {
|
|
|
|
fmt.Printf("%c", result[j])
|
|
|
|
a++
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
func printLine(elems [10]int, start int) {
|
|
|
|
size := len(elems)
|
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
|
|
|
a := start
|
|
|
|
var aux, b int
|
|
|
|
|
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
|
|
|
for a < start+16 && a < size {
|
|
|
|
if a%4 == 0 && a != 0 {
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
b = 8 - printBase(elems[a])
|
|
|
|
for aux != b {
|
|
|
|
if b == 6 {
|
|
|
|
fmt.Print("0")
|
|
|
|
}
|
|
|
|
if aux == 1 {
|
|
|
|
fmt.Print(" ")
|
|
|
|
}
|
|
|
|
if b < 6 {
|
|
|
|
fmt.Print("0")
|
|
|
|
}
|
|
|
|
aux++
|
|
|
|
}
|
|
|
|
fmt.Print(" ")
|
|
|
|
aux = 0
|
|
|
|
a++
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
c := start
|
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
|
|
|
for c < start+16 && c < size {
|
|
|
|
if unicode.IsGraphic(rune(elems[c])) {
|
|
|
|
fmt.Printf("%c", rune(elems[c]))
|
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
|
|
|
} else {
|
|
|
|
fmt.Print(".")
|
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
|
|
|
}
|
|
|
|
c++
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
func printMemory(a [10]int) {
|
|
|
|
i := 0
|
|
|
|
for i < len(a) {
|
|
|
|
printLine(a, i)
|
|
|
|
i += 16
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var table [10]int
|
|
|
|
|
|
|
|
for j := 0; j < 5; j++ {
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
table[i] = lib.RandIntBetween(0, 1000)
|
|
|
|
}
|
|
|
|
lib.Challenge("PrintMemory", student.PrintMemory, printMemory, table)
|
|
|
|
}
|
|
|
|
table2 := [10]int{104, 101, 108, 108, 111, 16, 21, 42}
|
|
|
|
lib.Challenge("PrintMemory", student.PrintMemory, printMemory, table2)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this can be simplified a lot
|