Skip to content

Instantly share code, notes, and snippets.

View Raynes's full-sized avatar

Anthony Grimes Raynes

View GitHub Profile
module Main where
import Control.Monad
import Data.List
import Data.Char
import System.IO
import Text.Regex.Posix
import Text.Regex
getSecondWord :: String -> String
middleList xs =
let n = length xs
fnum = 2*((n `div` 2) `div` 2)
in take (if odd n then 1 else 2) $ drop fnum xs
middleList xs =
let n = length xs
fnum = 2*(n `div` 4)
in take (if odd n then 1 else 2) $ drop fnum xs
module Main where
import Control.Monad
import Data.List
import Data.Char
import System.IO
import Text.Regex.Posix
import Text.Regex
getSecondWord :: String -> String
middleList xs@(_:_:_:_) =
let n = length xs
en = if n < 5 then 1 else 2 * (n `div` 4)
in take (if odd n then 1 else 2) $ drop en xs
middleList xs = xs
middleList xs@(_:_:_:_) = take (if odd n then 1 else 2) $ drop en xs
where n = length xs
en = if n < 5 then 1 else 2 * (n `div` 4)
middleList xs = xs
middleList xs@(_:_:_:_) =
let n = length xs
en = if n < 5 then 1 else 2 * (n `div` 4)
in take (if odd n then 1 else 2) $ drop en xs
middleList _ = error "List is too short."
middleList xs@[x] = xs
middleList xs@[x,y] = xs
middleList xs =
let n = length xs
en = if n < 5 then 1 else 2 * (n `div` 4)
in take (if odd n then 1 else 2) $ drop en xs
middleList xs@[x] = xs
middleList xs@[x,y] = xs
middleList xs =
let n = length xs
en = if n < 5 then 1 else 2 * (n `div` 4)
in take (if odd n then 1 else 2) $ drop en xs
GHCi, version 6.10.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> :load "/home/rayne/hsprojs/learn/Test.hs"
[1 of 1] Compiling Main ( /home/rayne/hsprojs/learn/Test.hs, interpreted )
Ok, modules loaded: Main.
*Main> :load "/home/rayne/hsprojs/learn/Test.hs"
[1 of 1] Compiling Main ( /home/rayne/hsprojs/learn/Test.hs, interpreted )