summaryrefslogtreecommitdiff
path: root/problems/1-1/main.go
blob: e867d1622e91b9db2178e15e52fe0fd312881ff8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
	"fmt"
	"math"
)

func main() {
	// 1 second = 1,000,000 microseconds
	// 1 minute = 60 seconds = 60,000,000 microseconds
	// 1 hour = 60 minutes = 3600 seconds = 3,600,000,000 microseconds
	// 1 day = 24 hours = 1440 mins = 86400 seconds =  86,400,000,000 microseconds

	// lg(n)
	results := [4]float64{0, 0, 0, 0}
	i := 0
	for n := 1.0; ; n++ {
		x := math.Log2(n)

		if i == 0 && x > 1_000_000 {
			results[i] = x
			i++
		}
		if i == 1 && x > 60_000_000 {
			results[i] = x
			i++
		}
		if i == 2 && x > 3_600_000_000 {
			results[i] = x
			i++
		}
		if i == 3 && x > 86_400_000_000 {
			results[i] = x
			break
		}
	}

	fmt.Printf("lg(n)|%v|%v|%v|%v|\n", results[0], results[1], results[2], results[3])
}