Skip to content

Instantly share code, notes, and snippets.

@killerswan
Created April 27, 2011 07:53
Show Gist options
  • Save killerswan/943878 to your computer and use it in GitHub Desktop.
Save killerswan/943878 to your computer and use it in GitHub Desktop.
display palindromes, F#
let subs (s:string) =
let lim = s.Length - 1
[ for ii in [0..lim] do
for jj in [0..lim] do // can these two be combined?
if ii < jj then
yield s.[ii..jj] ]
let isPalindrome s =
let s' = Array.ofSeq s
(s' = Array.rev s')
let palindromes s =
printf "Palindromes within \"%s\": \t" s
s |> subs |> List.filter isPalindrome |> List.map (printf "%s ") |> ignore
printf "\n"
palindromes "abcbcbx"
palindromes "abcba"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment