Skip to content

Add Prime Number in Elvish#4297

Merged
rzuckerm merged 4 commits into
TheRenegadeCoder:mainfrom
Kaamkiya:elvish-prime
Jan 17, 2025
Merged

Add Prime Number in Elvish#4297
rzuckerm merged 4 commits into
TheRenegadeCoder:mainfrom
Kaamkiya:elvish-prime

Conversation

@Kaamkiya
Copy link
Copy Markdown
Member

I Am Adding a New Code Snippet in an Existing Language

Copy link
Copy Markdown
Collaborator

@rzuckerm rzuckerm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When checking if a number is prime, you only have to check up to and including the square root of n. Also, this should error out for a negative value

@rzuckerm
Copy link
Copy Markdown
Collaborator

Looks like you need to cast the square root operation to an integer. I think exact-num will do that

@rzuckerm
Copy link
Copy Markdown
Collaborator

Also, it looks like range works the same as in python where the end value needs to be one more than what you actually want. For example:

~> range 2 3
▶ (num 2)
~> range 2 4
▶ (num 2)
▶ (num 3)

@Kaamkiya Kaamkiya marked this pull request as draft January 17, 2025 15:24
@Kaamkiya
Copy link
Copy Markdown
Member Author

exact-num seems to return a fraction. I may need to do exact-num (math:ceil (math:sqrt $n))...

@Kaamkiya Kaamkiya marked this pull request as ready for review January 17, 2025 15:34
@Kaamkiya
Copy link
Copy Markdown
Member Author

Seems to be fixed now.

Copy link
Copy Markdown
Collaborator

@rzuckerm rzuckerm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, @Kaamkiya . Thanks, for your contribution!

@rzuckerm rzuckerm merged commit 7551f15 into TheRenegadeCoder:main Jan 17, 2025
@Kaamkiya Kaamkiya deleted the elvish-prime branch January 19, 2025 03:14
@rzuckerm rzuckerm added enhancement Any code that improves the repo prime number See: https://sampleprograms.io/projects/prime-number/ labels Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Any code that improves the repo prime number See: https://sampleprograms.io/projects/prime-number/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Prime Number in Elvish

2 participants