Skip to content

Instantly share code, notes, and snippets.

@mebsout
mebsout / gaspal.ml
Created September 4, 2014 11:35
Gas prices palindromes finder ;)
let is_palindrome f =
let s = Format.sprintf "%.2f" f in
let pos_dot = String.index s '.' in
String.blit s (pos_dot + 1) s pos_dot 2;
let s = String.sub s 0 (String.length s - 1) in
let l, u = ref 0, ref (String.length s - 1) in
while !l < !u && s.[!l] = s.[!u] do
incr l; decr u;
done;
!l >= !u