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.
99 lines
1.5 KiB
99 lines
1.5 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
5 years ago
|
"fmt"
|
||
5 years ago
|
"unicode"
|
||
5 years ago
|
|
||
|
"./student"
|
||
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(arr [10]int, start int) {
|
||
|
size := len(arr)
|
||
|
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
|
}
|
||
|
b = 8 - printBase(arr[a])
|
||
|
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 {
|
||
5 years ago
|
if unicode.IsPrint(rune(arr[c])) {
|
||
5 years ago
|
fmt.Printf("%c", rune(arr[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}
|
||
|
lib.Challenge("PrintMemory", student.PrintMemory, correct.PrintMemory, table2)
|
||
|
}
|
||
|
|
||
|
// TODO: this can be simplified a lot
|