|
|
|
package solutions
|
|
|
|
|
|
|
|
import (
|
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"
|
|
|
|
|
|
|
|
"github.com/01-edu/z01"
|
|
|
|
)
|
|
|
|
|
|
|
|
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-- {
|
|
|
|
z01.PrintRune(result[j])
|
|
|
|
a++
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func printLine(arr [10]int, start int) {
|
|
|
|
size := len(arr)
|
|
|
|
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 {
|
|
|
|
z01.PrintRune('\n')
|
|
|
|
}
|
|
|
|
b = 8 - printBase(arr[a])
|
|
|
|
for aux != b {
|
|
|
|
if b == 6 {
|
|
|
|
z01.PrintRune('0')
|
|
|
|
}
|
|
|
|
if aux == 1 {
|
|
|
|
z01.PrintRune(' ')
|
|
|
|
}
|
|
|
|
if b < 6 {
|
|
|
|
z01.PrintRune('0')
|
|
|
|
}
|
|
|
|
aux++
|
|
|
|
}
|
|
|
|
z01.PrintRune(' ')
|
|
|
|
aux = 0
|
|
|
|
a++
|
|
|
|
}
|
|
|
|
z01.PrintRune('\n')
|
|
|
|
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.IsPrint() {
|
|
|
|
z01.PrintRune(rune(arr[c]))
|
|
|
|
} else {
|
|
|
|
z01.PrintRune('.')
|
|
|
|
}
|
|
|
|
c++
|
|
|
|
}
|
|
|
|
z01.PrintRune('\n')
|
|
|
|
}
|
|
|
|
|
|
|
|
func PrintMemory(arr [10]int) {
|
|
|
|
i := 0
|
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 i < len(arr) {
|
|
|
|
printLine(arr, i)
|
|
|
|
i += 16
|
|
|
|
}
|
|
|
|
}
|