You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I clone the repo, replace the GCD function with your code:
package module01
funcGCD(a, bint) int {
for {
ifb==0 {
returna
}
a, b=b, a%b
}
}
And then run go run module01/std_demo/main.go < module01/std_demo/input.txt from the root directory, I get the following output:
5
4
11
33
This suggests that something isn't wrong with your code, but something is wrong somewhere else. My best guess is that you are on a different OS or something else is causing your code to not work. On possible answer is that newlines are treated slightly different in your OS (are you on Windows?) and the following might work better:
// std_demo/main.gofuncmain() {
varnintfmt.Scanf("%d", &n)
fori:=0; i<n; i++ {
vara, bintfmt.Scanf("%d %d\n", &a, &b) // < this is the changegcd:=module01.GCD(a, b)
fmt.Println(gcd)
}
}
If that doesn't work, I still suspect the issue is related to something along these lines, as the gcd_test.go file covers plenty of cases to suggest your code is working.
I'm using go1.16.4 in windows 10.
when I try:
go run main.go < input.txt
im getting
0
5
0
4
but according to the video, it should be:
5
4
11
33
im using the following GCD function:
for {
if b == 0 {
return a
}
a, b = b, a%b
}
all the test cases passed for that GCD function,
can someone explain to me, what is going on?
thanks,
The text was updated successfully, but these errors were encountered: