Einzelnen Beitrag anzeigen
Alt 06.04.09, 20:14   #13 (permalink)
Ook!
 
Registriert seit: 21.04.08
Ook! Leistung: Facit NTK
Likes: 0
Standard

eine nette Python Lösung

Code:
from itertools import takewhile

def row(c, limit):
  rowSpace = (alph.find(limit) - alph.find(c) - 1) * " "
  row = "".join(takewhile(lambda x: x != c, alph))
  return rowSpace + row + row[::-1][1:] + "\n"

def pyra(limit):
  limit = chr(ord(limit)+2)
  return "".join(map(lambda c: row(c, limit), takewhile(lambda x: x != limit, alph)))[:-1]

alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
print pyra('F')
... und eine Haskell Lösung

Code:
import Data.Char
import Data.List

doIt :: Char -> [String]
doIt limit = map row $ takeWhile (/= limit) $ alph
  where
    alph = ['A'..'Z']
    row c = (rowSpace c 0) ++ (rowAlph c) ++ (drop 1 $ reverse $ rowAlph c)
    rowAlph c = takeWhile (/= c) $ alph
    rowSpace c i = if i == rowSpaceCnt c then "" else ' ' : rowSpace c (i+1)
    rowSpaceCnt c = ((index (limit, 0)) - (index (c, 0)) - 1)
    index (c, i) = if i > 25 then 1 else if alph !! i == c then i else index (c, i+1)

pyra :: Char -> String
pyra limit = concat . intersperse "\n" $ doIt (chr $ ord limit + 2)

main :: IO()
main = putStrLn $ pyra 'F'
Gruß
Felix
Ook! ist offline   Mit Zitat antworten
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61