Browse Source

First commit

master
Martins Eglitis 1 year ago
commit
06ef248ed1
1 changed files with 65 additions and 0 deletions
  1. +65
    -0
      main.go

+ 65
- 0
main.go View File

@@ -0,0 +1,65 @@
package main

import (
"fmt"
"strconv"
"strings"
"sync"
)

const concurrency = 8

func main() {
//file, err := os.OpenFile("trace.out", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
//if err != nil {
// log.Fatal(err)
//}
//defer file.Close()

//err := trace.Start(file)
//if err != nil {
// log.Fatal(err)
//}
//defer trace.Stop()

var numbers = make(chan uint64, 0)

var wg sync.WaitGroup
wg.Add(concurrency)

for i := 0; i < concurrency; i++ {
go func() {
for number := range numbers {
Calculate(number)
}

wg.Done()
}()
}

go func() {
for i := uint64(1_000_000_000); i < 1_000_000_000_0; i++ {
numbers <- i
}

close(numbers)
}()

wg.Wait()
}

func Calculate(num uint64) {
number := strconv.FormatUint(num, 10)
exploded := strings.Split(number, "")

for i := 0; i < 10; i++ {
digit, _ := strconv.Atoi(exploded[i])
count := strings.Count(number, strconv.Itoa(i))

if count != digit {
return
}
}

fmt.Println(number)
}

Loading…
Cancel
Save