From 9d2b9ff22d610907f9a645334e66055f9cd0e424 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Sun, 17 May 2026 14:47:55 +0000 Subject: [PATCH] [Sync Iteration] go/collatz-conjecture/2 --- .../2/collatz_conjecture.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 solutions/go/collatz-conjecture/2/collatz_conjecture.go diff --git a/solutions/go/collatz-conjecture/2/collatz_conjecture.go b/solutions/go/collatz-conjecture/2/collatz_conjecture.go new file mode 100644 index 0000000..dcfd3d4 --- /dev/null +++ b/solutions/go/collatz-conjecture/2/collatz_conjecture.go @@ -0,0 +1,22 @@ +package collatzconjecture +import "errors" +func CollatzConjecture(n int) (int, error) { + num := n + var count int + if n <= 0 { + return 0, errors.New("n is a negative value") + } + if num > 1{ + i:= 0 + for num != 1 { + if num & 1 == 0{ + num = num / 2 + }else{ + num = (3 * num)+1 + } + i++ + } + count = i + } + return count,nil +}