Created
April 27, 2011 07:53
-
-
Save killerswan/943878 to your computer and use it in GitHub Desktop.
display palindromes, F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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