Last active
August 29, 2015 14:05
-
-
Save chris-martin/bc208ea3340e2fd6532d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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