Skip to content

Add Palindromic Number in OCaml#5970

Merged
pascalecu merged 5 commits into
TheRenegadeCoder:mainfrom
alope107:ocamlPalinNum
May 17, 2026
Merged

Add Palindromic Number in OCaml#5970
pascalecu merged 5 commits into
TheRenegadeCoder:mainfrom
alope107:ocamlPalinNum

Conversation

@alope107
Copy link
Copy Markdown
Contributor

I Am Adding a New Code Snippet in an Existing Language

@github-actions github-actions Bot added enhancement Any code that improves the repo palindromic number See: https://sampleprograms.io/projects/palindromic-number/ labels May 17, 2026
@@ -0,0 +1,24 @@
let ( let* ) = Option.bind

let palindrome str =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this just String.equal str (String.rev str)?

Copy link
Copy Markdown
Contributor Author

@alope107 alope107 May 17, 2026

Choose a reason for hiding this comment

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

String.rev is part of the Jane Street Base, not Stdlib. Using only Stdlib you could convert the string into a list and reverse that, but I think you incur a O(len(string)) space penalty.

My solution should be O(1) space due to the tail call, which I've now added an attribute to confirm.

Comment thread archive/o/ocaml/palindromic-number.ml Outdated
@alope107 alope107 requested a review from pascalecu May 17, 2026 20:44
@pascalecu pascalecu merged commit 1363f14 into TheRenegadeCoder:main May 17, 2026
5 checks passed
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 palindromic number See: https://sampleprograms.io/projects/palindromic-number/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Palindromic Number in OCaml

3 participants