I feel that I am not capable of programing buttsorts. Should I quit programming now or just try a lot harder?
Name:
Anonymous2009-09-03 20:06
>>123
Dont feel too bad about it. Buttsorts requires advanced knowledge of parsing and string manipulation. They are a good exercise for an expert programmer, but for a beginner like yourself you shouldn't try and tackle them until you've learned enough about the aforementioned subjects.
>>124-chan here. Disregard that, I suck cocks! Buttsorting might be advanced material for Prague, but in the grand Scheme of things it's a fairly elementary exercise for anyone with a few weeks of experience. Also, ignore my next post, since I'll just be trolling you with it anyway. Have a nice anus !!
>>125
A Fibonacci Buttsort is an operation that can be performed on a string which outputs the string with alternating underline and overline tags. THISISAFIBONACCIBUTTSORT
-- buttsort.hs - an implementation of the Fibonacci Buttsort
import Data.Char (isSpace)
import Control.Monad.State
data Tag = Tag String
deriving (Show, Eq)
class Text a where
value :: a -> String
instance Text Char where
value = (:[])
instance (Text a) => Text [a] where
value = concatMap value
(<<) :: (Text a) => Tag -> a -> String
infixr <<
(Tag t) << x = "[" ++ t ++ "]" ++ value x ++ "[/" ++ t ++ "]"
[b, i, o, u, m] = map Tag ["b", "i", "o", "u", "m"]
buttsortW, buttsortC :: String -> String
buttsortW = (b <<) . (i <<) . unwords . zipWith (<<) (cycle [u, o]) . words
buttsortC = (b <<) . (i <<) . concat . flip evalState (cycle [u, o]) . mapM f
where f c = if isSpace c then return [c]
else do t <- get
modify tail
return $ head t << c
EXPERTHASKELLPROGRAMMING
Name:
Anonymous2009-09-07 17:24
>>139
That looks remarkably like the one I posted in the other thread — whereëver it went — in the control flow and use of cycle, anyway.
________ tag t str = "[" ++ t ++ "]" ++ str ++ "[/" ++ t ++ "]"
[b,i,o,u] = tag `map` words "b i o u"
dabs = b . i . unwords . zipWith id (cycle [o,u]) . words
fbs = b . i . concat . flip evalState (cycle [o,u]) . mapM f where
f ' ' = return " "
f c = (liftM . concatMap) ($ [c]) (State $ splitAt 1)