mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
1.5 KiB
101 lines
1.5 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
5 years ago
|
"fmt"
|
||
5 years ago
|
"unicode"
|
||
5 years ago
|
|
||
5 years ago
|
student "student"
|
||
|
|
||
4 years ago
|
"github.com/01-edu/public/go/tests/lib"
|
||
5 years ago
|
)
|
||
|
|
||
|
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-- {
|
||
5 years ago
|
fmt.Printf("%c", result[j])
|
||
5 years ago
|
a++
|
||
|
}
|
||
|
return a
|
||
|
}
|
||
|
|
||
5 years ago
|
func printLine(elems [10]int, start int) {
|
||
|
size := len(elems)
|
||
5 years ago
|
a := start
|
||
|
var aux, b int
|
||
5 years ago
|
|
||
5 years ago
|
for a < start+16 && a < size {
|
||
5 years ago
|
if a%4 == 0 && a != 0 {
|
||
5 years ago
|
fmt.Println()
|
||
5 years ago
|
}
|
||
5 years ago
|
b = 8 - printBase(elems[a])
|
||
5 years ago
|
for aux != b {
|
||
|
if b == 6 {
|
||
5 years ago
|
fmt.Print("0")
|
||
5 years ago
|
}
|
||
|
if aux == 1 {
|
||
5 years ago
|
fmt.Print(" ")
|
||
5 years ago
|
}
|
||
|
if b < 6 {
|
||
5 years ago
|
fmt.Print("0")
|
||
5 years ago
|
}
|
||
|
aux++
|
||
|
}
|
||
5 years ago
|
fmt.Print(" ")
|
||
5 years ago
|
aux = 0
|
||
|
a++
|
||
|
}
|
||
5 years ago
|
fmt.Println()
|
||
5 years ago
|
c := start
|
||
5 years ago
|
for c < start+16 && c < size {
|
||
4 years ago
|
if unicode.IsGraphic(rune(elems[c])) {
|
||
5 years ago
|
fmt.Printf("%c", rune(elems[c]))
|
||
5 years ago
|
} else {
|
||
5 years ago
|
fmt.Print(".")
|
||
5 years ago
|
}
|
||
5 years ago
|
c++
|
||
|
}
|
||
5 years ago
|
fmt.Println()
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
func printMemory(a [10]int) {
|
||
5 years ago
|
i := 0
|
||
5 years ago
|
for i < len(a) {
|
||
|
printLine(a, i)
|
||
5 years ago
|
i += 16
|
||
|
}
|
||
|
}
|
||
5 years ago
|
|
||
|
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}
|
||
5 years ago
|
lib.Challenge("PrintMemory", student.PrintMemory, printMemory, table2)
|
||
5 years ago
|
}
|
||
|
|
||
|
// TODO: this can be simplified a lot
|