Skip to content

Commit d645af1

Browse files
committed
Added Golang Solutions
1 parent 34579d9 commit d645af1

File tree

15 files changed

+1059
-215
lines changed

15 files changed

+1059
-215
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/watcherTasks.xml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 164 additions & 204 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Find all the possible solutions of the N queens problem by using just 3 binary representations
2+
3+
The ChessBoard will be 8x* but the solution should be applicable for larger board sizes as well
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package main
2+
3+
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package main
22

3-
import "fmt"
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"strconv"
8+
)
49

510
func main() {
6-
i, j := 42, 2701
7-
8-
p := &i
9-
fmt.Println(*p)
10-
*p = 21
11-
fmt.Println(i)
12-
13-
p = &j
14-
*p = *p / 37
15-
fmt.Println(j)
11+
reader := bufio.NewReader(os.Stdin)
12+
text, _ := reader.ReadString('\n')
13+
text = text[:len(text) -1]
14+
number, _ := strconv.Atoi(text)
15+
if(number % 2 == 0) {
16+
fmt.Println("YES")
17+
} else {fmt.Println("NO")}
18+
}

go_study/test_here.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"sync"
6+
"sync/atomic"
7+
"time"
8+
)
9+
10+
func fibonacci(a ,b , level uint64) uint64 {
11+
fmt.Println(a)
12+
if level == 0 {
13+
return b
14+
}
15+
return fibonacci(b, a+b , level-1 )
16+
}
17+
18+
func createFibonacci(reqlevel uint64) uint64 {
19+
return fibonacci(0,1 , reqlevel - 2)
20+
}
21+
22+
func main() {
23+
mainQ()
24+
}
25+
26+
27+
func f(from string , timeOut time.Duration) {
28+
for i := 0; i < 3; i++ {
29+
fmt.Println(from, ":", i)
30+
time.Sleep(timeOut)
31+
}
32+
}
33+
34+
func mainT() {
35+
36+
f("direct" , 0)
37+
38+
go f("goroutine 1",time.Second)
39+
go f("goroutine 2",time.Millisecond * 10)
40+
41+
go func(msg string) {
42+
fmt.Println(msg)
43+
}("going")
44+
45+
time.Sleep(time.Second * 5)
46+
fmt.Println("done")
47+
}
48+
49+
50+
func mainW() {
51+
52+
messages := make(chan string, 2)
53+
54+
go func() { messages <- "ping" ; time.Sleep(time.Second * 2) ; messages <- "After Timeout" }()
55+
56+
msg := <-messages
57+
fmt.Println(msg)
58+
msg1 := <-messages
59+
fmt.Println(msg1)
60+
}
61+
62+
63+
64+
func mainQ() {
65+
66+
var ops,_ops uint64
67+
68+
var wg sync.WaitGroup
69+
70+
for i := 0; i < 50; i++ {
71+
wg.Add(1)
72+
73+
go func() {
74+
for c := 0; c < 1000; c++ {
75+
_ops++;
76+
atomic.AddUint64(&ops, 1)
77+
}
78+
wg.Done()
79+
}()
80+
}
81+
82+
wg.Wait()
83+
84+
fmt.Println("ops:", ops)
85+
fmt.Println("_ops:", _ops)
86+
87+
}

0 commit comments

Comments
 (0)