From babde01d169bf66582124808b65051cd6cb43c92 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:45:00 +0000 Subject: [PATCH] [Sync Iteration] go/collatz-conjecture/1 --- .../1/collatz_conjecture.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 solutions/go/collatz-conjecture/1/collatz_conjecture.go diff --git a/solutions/go/collatz-conjecture/1/collatz_conjecture.go b/solutions/go/collatz-conjecture/1/collatz_conjecture.go new file mode 100644 index 0000000..b3a1486 --- /dev/null +++ b/solutions/go/collatz-conjecture/1/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 % 2 == 0{ + num = num / 2 + }else{ + num = (3 * num)+1 + } + i++ + } + count = i + } + return count,nil +}