[ create a new paste ] login | about

Link: http://codepad.org/0J61y6m6    [ raw code | output | fork ]

Haskell, pasted on Mar 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import Data.List (sort)

isAnagram :: String -> String -> Bool
isAnagram s1 s2 = sort s1 == sort s2

isAnagramWithin :: String -> String -> Bool
isAnagramWithin shortStr = isAnagramWithin'
  where shortLen = length shortStr
        isAnagramWithin' [] = False
        isAnagramWithin' longStr'@(_:ls) = let longLen' = length longStr'
                                           in longLen' >= shortLen &&
                                              (isAnagram shortStr (take shortLen longStr') || isAnagramWithin' ls)

main :: IO ()
main = do
  s1 <- getLine
  s2 <- getLine
  print $ isAnagramWithin s1 s2


Output:
1
2

Program error: <stdin>: IO.hGetChar: end of file (end of file)


Create a new paste based on this one


Comments: