refactor: challenge files and explanations
This commit is contained in:
123
15-arrays-project-clock/02-printing-the-clock/main.go
Normal file
123
15-arrays-project-clock/02-printing-the-clock/main.go
Normal file
@@ -0,0 +1,123 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
||||
// ★ GOAL 2 : Printing the Clock
|
||||
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
||||
//
|
||||
// 1. Get the current time
|
||||
//
|
||||
// 2. Get the current hour, minute and second from the current time
|
||||
//
|
||||
// 3. Create the clock array by getting the digits from the digits array
|
||||
//
|
||||
// 4. Print the clock by using the clock array
|
||||
//
|
||||
// 5. Create a separator array (it's also a placeholder type)
|
||||
//
|
||||
// 6. Add the separators into the correct positions of the clock array
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
type placeholder [5]string
|
||||
|
||||
zero := placeholder{
|
||||
"███",
|
||||
"█ █",
|
||||
"█ █",
|
||||
"█ █",
|
||||
"███",
|
||||
}
|
||||
|
||||
one := placeholder{
|
||||
"██ ",
|
||||
" █ ",
|
||||
" █ ",
|
||||
" █ ",
|
||||
"███",
|
||||
}
|
||||
|
||||
two := placeholder{
|
||||
"███",
|
||||
" █",
|
||||
"███",
|
||||
"█ ",
|
||||
"███",
|
||||
}
|
||||
|
||||
three := placeholder{
|
||||
"███",
|
||||
" █",
|
||||
"███",
|
||||
" █",
|
||||
"███",
|
||||
}
|
||||
|
||||
four := placeholder{
|
||||
"█ █",
|
||||
"█ █",
|
||||
"███",
|
||||
" █",
|
||||
" █",
|
||||
}
|
||||
|
||||
five := placeholder{
|
||||
"███",
|
||||
"█ ",
|
||||
"███",
|
||||
" █",
|
||||
"███",
|
||||
}
|
||||
|
||||
six := placeholder{
|
||||
"███",
|
||||
"█ ",
|
||||
"███",
|
||||
"█ █",
|
||||
"███",
|
||||
}
|
||||
|
||||
seven := placeholder{
|
||||
"███",
|
||||
" █",
|
||||
" █",
|
||||
" █",
|
||||
" █",
|
||||
}
|
||||
|
||||
eight := placeholder{
|
||||
"███",
|
||||
"█ █",
|
||||
"███",
|
||||
"█ █",
|
||||
"███",
|
||||
}
|
||||
|
||||
nine := placeholder{
|
||||
"███",
|
||||
"█ █",
|
||||
"███",
|
||||
" █",
|
||||
"███",
|
||||
}
|
||||
|
||||
digits := [...]placeholder{
|
||||
zero, one, two, three, four, five, six, seven, eight, nine,
|
||||
}
|
||||
|
||||
for line := range digits[0] {
|
||||
for digit := range digits {
|
||||
fmt.Print(digits[digit][line], " ")
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user