Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] issorted subject #2821

Open
danielkotsi opened this issue Dec 4, 2024 · 1 comment
Open

[QUESTION] issorted subject #2821

danielkotsi opened this issue Dec 4, 2024 · 1 comment
Assignees
Labels
🙋 question Questions or other issues

Comments

@danielkotsi
Copy link

issorted

in quest 09 of the piscine i encountered this problem.

the purpose of the exercise was to spot a sorted [][]ints either descending or asceding. and print true if it indeed is sorted.
in the case in which it is not sorted, neither ascending, nor descending, the function had to print false. and after submitting my code which is this one:


package piscine

func IsSorted(f func(a, b int) int, a []int) bool {
if len(a) > 1 {
if a[0] > a[1] {
for i := 0; i < len(a)-1; i++ {
if f(a[i], a[i+1]) < 0 {
return false
}
}
} else {
for i := 0; i < len(a)-1; i++ {
if f(a[i], a[i+1]) > 0 {
return false
}
}
}
return true
}
return true
}


the feedback that i had from intra after not accepting my code was the one below:
IsSorted(main.isSortedWrong, []int{637701, -359259, -521426, 690762, -653243, 771578, 382101, 681961}) == false instead of true
exit status 1.

in which, there is indeed a [][]int which is not sorted, so based on the purpose of the exercise the function should indeed print false, as did my function.

and the only way to get through this exercise was to change my code into this:


package piscine

func IsSorted(f func(a, b int) int, a []int) bool {
ascending := true
descending := true

for i := 1; i < len(a)-1; i++ {
	if f(a[i-1], a[i]) > 0 {
		ascending = false
	}

	if f(a[i-1], a[i]) < 0 {
		descending = false
	}

	if !ascending && !descending {
		return false
	}

}

return ascending || descending

}


i thought that you would be interested to have a second look at this exercise, because one could argue that the first solution should also be accepted.

@HarryVasanth HarryVasanth changed the title issorted subject [QUESTION] issorted subject Dec 5, 2024
@HarryVasanth HarryVasanth added the 🙋 question Questions or other issues label Dec 5, 2024
@MSilva95 MSilva95 self-assigned this Dec 9, 2024
@MSilva95
Copy link
Member

hello @danielkotsi we will take a look as soon as possible! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 question Questions or other issues
Projects
None yet
Development

No branches or pull requests

3 participants