From 83946615a8fa953fa63e3852ed5f53135eba3d65 Mon Sep 17 00:00:00 2001 From: oabrivard Date: Fri, 20 Oct 2023 12:01:07 +0200 Subject: [PATCH] Cleaned code of Number Spiral exercise --- introductory.go | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/introductory.go b/introductory.go index 0627646..18eb7cf 100644 --- a/introductory.go +++ b/introductory.go @@ -120,37 +120,19 @@ func NumberSpiral(row, col int) int64 { } switch { - case row == col: - return result case col > row: if col%2 == 1 { - return result + int64(size-row) + result = result + int64(size-row) } else { - return result + int64(row-size) + result = result + int64(row-size) } case col < row: if row%2 == 1 { - return result + int64(col-size) + result = result + int64(col-size) } else { - return result + int64(size-col) + result = result + int64(size-col) } } - return 0 - - /* - maxLoops := size * size - i := int32(1) - j := int32(1) - - for n := int64(1); n <= maxLoops; n++ { - if i == y && j == x { - return n - } - - - } - - return 0 - */ + return result }