HASKELL

Help Plz String -> [String]

Page 1 of 1

2 Replies - 967 Views - Last Post: 30 May 2009 - 05:38 AM

#1 jewel123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-March 09

HASKELL

Post icon  Posted 15 March 2009 - 06:29 PM

Hello everyone,
I've created runs function that should take a string such as "bbbbbbsssddd", and then it should give as an output ["bbb","bbb","sss","ddd"]..I was able to do ["bbbbbb","sss","ddd"], But what I couldn't is that I should allow maximum 3 characters in each..can someone provide me with a help plz?

runs :: String -> [String]
runs [] = []
runs (x:xs)= (x:ys) : runs(zs)
where (ys,zs) = span ((==) x) xs

Thanks,

Is This A Good Question/Topic? 0
  • +

Replies To: HASKELL

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,520
  • Joined: 23-August 08

Re: HASKELL

Posted 15 March 2009 - 06:52 PM

Moving to Functional Programming.
Was This Post Helpful? 0
  • +
  • -

#3 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 611
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: HASKELL

Posted 30 May 2009 - 05:38 AM

runs :: String -> [String]
runs [] = []
runs xs = ys : runs ds
where (ys,ds) = splitAt 3 xs

Using splitAt gives you the ability to pinpoint the precise index location in list.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1