Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaska1706 committed Dec 5, 2024
1 parent c6e1540 commit 5e44d3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Coding Challenges
This repository is a collection of different solutions to coding challenges and problems, written in Golang

aluta continua
## Source of Challenges
- [Cyber Dojo](https://cyber-dojo.org/creator/choose_problem)

Expand Down
25 changes: 13 additions & 12 deletions WonderlandNumber/wonderlandnumber.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,32 @@ func generateWonderlandNumber(size int) int {
return 0
}
for i := MIN_SIZE_NUMBER; i <= size; i++ {
check := wonderlandNumber(i)
if check {
if wonderlandNumber(i) {
result = i
}
}
return result
}

func wonderlandNumber(number int) bool {
var b bool
var results int
var storeresults []int
var (
b bool
results int
storeresults []int
)

store := storePresentDigits(number)
for i := 1; i <= 6; i++ {
results = number * i
check := checkNumbersExist(results, store)
if check {
if checkNumbersExist(results, store) {
storeresults = append(storeresults, results)
}
}

if len(storeresults) == len(store) {
b = true
return true
} else if len(storeresults) < len(store) {
b = false
return false
}

return b
Expand All @@ -51,7 +52,7 @@ func countDigits(number int) int {

func storePresentDigits(number int) []int {
n := countDigits(number)
if n < 6 || n > 6 {
if n != 6 {
return []int{}
}
store := make([]int, 6)
Expand All @@ -75,9 +76,9 @@ func checkNumbersExist(number int, store []int) bool {
}
}
if len(results) == len(store) {
b = true
return true
} else if results == nil {
b = false
return false
}

return b
Expand Down

0 comments on commit 5e44d3c

Please sign in to comment.