Iterative fibonacci result is incorrect #20

Closed
opened 2025-08-21 21:04:08 +00:00 by ed · 1 comment
Owner

The following assertion fails:

main() {
	assert fib(10) == 55
}

fib(n int) -> int {
	b := 0
	c := 1

	loop 0..n {
		a := b
		b = c
		c = a + b
	}

	return b
}

The returned value is 1024 (2^10) instead of 55.

The following assertion fails: ``` main() { assert fib(10) == 55 } fib(n int) -> int { b := 0 c := 1 loop 0..n { a := b b = c c = a + b } return b } ``` The returned value is 1024 (2^10) instead of 55.
ed self-assigned this 2025-08-21 21:07:55 +00:00
Author
Owner

Fixed in cli/q@87aa424d77.

Fixed in https://git.urbach.dev/cli/q/commit/87aa424d77701084de50d68bc5cc85b8ba4f58ea.
ed closed this issue 2025-08-22 05:43:46 +00:00
ed added spent time 2025-08-29 07:49:02 +00:00
2 hours
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Total time spent: 2 hours
ed
2 hours
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cli/q#20
No description provided.