Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Temporary Programming Challanges!
New Posts  All Forums:Forum Nav:

Temporary Programming Challanges! - Page 3

post #21 of 23
Here's mine. Give Haskell a try I'm quite a noob with Haskell, and I believe it's completely possibile to write a better, more elegant and possibly shorter version...

Anyway, 6 lines

Code:
aTree n c = do putStr $ unlines $ upTree
               putStr $ unlines $ tail bottomTree
  where upTree = reverse (zipWith (++) spaces (reverse tokens))
        bottomTree = zipWith (++) spaces (reverse tokens) 
spaces = take n (iterate(" "++) " ")
tokens = filter (\\x -> length x <= n) (take n (iterate((c++c)++) c))
Where n is the number of element and c is a char.
post #22 of 23
Thats awesome.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #23 of 23
Ok, then I'll stop. Promise!

5 lines version:

Code:
aTree n c = do putStr $ unlines $ reverse theTree
               putStr $ unlines $ tail theTree
  where theTree = zipWith (++) spaces (reverse tokens) 
        spaces = take n (iterate(" "++) " ")
        tokens = takeWhile (\\x -> length x <= n) (iterate((c++c)++) c)
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Temporary Programming Challanges!