mchirico / zDaily

Playground to hack and test ideas with Zoe
1 stars 2 forks source link

Day 13: Finish Day 12 #15

Open mchirico opened 3 years ago

mchirico commented 3 years ago

Show the work for Day 12...

tacomonkautobot[bot] commented 3 years ago

mchirico, Thanks for opening this issue!

mchirico commented 3 years ago

Take a look...

package main

import (
    "fmt"
    "sync"
    "time"
)

type MF struct {
    l int
    sync.Mutex
}

func (mf *MF) mfmt(txt string, timeSleep int) {
    mf.Mutex.Lock()
    defer mf.Mutex.Unlock()

    for i := 0; i < mf.l; i++ {
        fmt.Printf("\b") // backspace
    }

    mf.l = len(txt)
    fmt.Printf("%s", txt)
    time.Sleep(time.Duration(timeSleep) * time.Millisecond)
}

func main() {

    m := &MF{}
    for i := 0; i < 1000; i++ {
        now := time.Now()
        timeString := fmt.Sprintf("%02d:%02d:%02d     ", now.Hour(), now.Minute(), now.Second())
        m.mfmt(timeString, 100)

    }

}
ZoeChiri commented 3 years ago

func (mf *MF) mfmt(txt string, timeSleep int) { mf.Mutex.Lock() defer mf.Mutex.Unlock()

for i := 0; i < mf.l; i++ {
    fmt.Printf("\b") // backspace
}

mf.l = len(txt)
fmt.Printf("%s", txt)
time.Sleep(time.Duration(timeSleep) * time.Millisecond) **<--- clock moves per** millisecond

} func main() {

m := &MF{}
for i := 0; i < 1000; i++ {
    now := time.Now()
    timeString := fmt.Sprintf("%02d:%02d:%02d     ", now.Hour(), now.Minute(), now.Second())
    m.mfmt(timeString, 100)

}

} main function prints out the hour, minutes, and seconds

so why wont time.Sleep(time.Duration(timeSleep) * time.now.Hour()) work