Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java Homework

Name: Anonymous 2007-04-09 13:17 ID:HpLdMw06

Ok /prog/, this is very simple.

You're going to do my programming homework. Because want you to.

This is very simple... Work + No Spare Time = No Homework Done

So here's the deal: I supply to you my Java Homeworks and you'll do it.
If you're unable to do it, feel free to post whatever you like.
If you're a fucking coding god, you will post your ultimate solution, and face the criticism from other coding gods, including moot.

Cruel Leonidas demanded that you stand. I require only that you kneel.

Name: Anonymous 2007-04-10 3:44 ID:bQtu3QZF

As promised, here's your homework:

module Main where

import Char (digitToInt)
import Data.List (intersperse, transpose)
import System.IO

import Prelude hiding (Left, Right)

data Position = Left | Right | Both
data Digit = Digit Bool Position Bool Position Bool

digit :: Int -> Digit
digit 0 = Digit True  Both  False Both  True
digit 1 = Digit False Right False Right False
digit 2 = Digit True  Right True  Left  True
digit 3 = Digit True  Right True  Right True
digit 4 = Digit False Both  True  Right False
digit 5 = Digit True  Left  True  Right True
digit 6 = Digit True  Left  True  Both  True
digit 7 = Digit True  Right False Right False
digit 8 = Digit True  Both  True  Both  True
digit 9 = Digit True  Both  True  Right True

horiz :: Int -> Bool -> [String]
horiz n False = [replicate n ' ']
horiz n True  = [replicate n '-']

vert :: Int -> Position -> [String]
vert n pos = replicate n $ vert' n pos

vert' n Left  = "|" ++ replicate (n-1) ' '
vert' n Right =        replicate (n-1) ' ' ++ "|"
vert' n Both  = "|" ++ replicate (n-2) ' ' ++ "|"

showDigit :: Int -> Digit -> [String]
showDigit n (Digit t u m l b) =
    hor t ++ ver u ++ hor m ++ ver l ++ hor b
    where hor = horiz n
          ver = vert n

showDigits :: Int -> [Int] -> String
showDigits n = concat .
               map ((++ "\n") . concat . intersperse " ") .
               transpose . map (showDigit n . digit)

mongleLine :: String -> String
mongleLine (n:' ':digits) = showDigits
                            (digitToInt n)
                            (map digitToInt digits)
mongleLine x = ""

main :: IO ()
main = getContents >>= mapM_ (putStr . mongleLine) . lines


>>16
What does this have to do with the topic? Or is this just your way to say "I've read SICP"?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List