Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-martin/bc208ea3340e2fd6532d to your computer and use it in GitHub Desktop.
Save chris-martin/bc208ea3340e2fd6532d to your computer and use it in GitHub Desktop.
1 1
22 22
333 333
4444 4444
55555 55555
666666 666666
7777777 7777777
88888888 88888888
999999999999999999
999999999999999999
88888888 88888888
7777777 7777777
666666 666666
55555 55555
4444 4444
333 333
22 22
1 1
def bowtie(n):
return '\n'.join(map(lambda i: (' '*2*(n-i)).join([str(i)*i]*2),
range(0, n+1) + list(reversed(range(n+1)))))
bowtie :: Int -> [Char]
bowtie n = intercalate "\n" $ mirror2 quadrant
where
quadrant :: [[Char]]
quadrant = [ (digits i) ++ (spaces $ n-i) | i <- [1..n] ]
where
digits i = replicate i $ intToDigit i
spaces i = replicate i ' '
mirror2 :: [[Char]] -> [[Char]]
mirror2 = mirror . (map mirror)
where mirror xs = xs ++ (reverse xs)
def bowtie(n):
quadrant = [str(i)*i + " "*(n-i) for i in range(1, n+1)]
def mirror2(xs):
mirror = lambda xs: list(xs) + list(reversed(xs))
return mirror([''.join(mirror(x)) for x in xs])
return '\n'.join(mirror2(quadrant))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment