Skip to content

Instantly share code, notes, and snippets.

@jonelf
Last active August 29, 2015 14:10
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 jonelf/9d67da670ddba9639a8a to your computer and use it in GitHub Desktop.
Save jonelf/9d67da670ddba9639a8a to your computer and use it in GitHub Desktop.
Diamond
first, last = "A".ord, "D".ord;
rows = (first...last).to_a + last.downto(first).to_a
cols = last.downto(first).to_a + (first + 1..last).to_a
rows.each do |row|
line = cols.map do |col|
col == row ? col.chr : "-"
end
puts line.join
end
@jonelf
Copy link
Author

jonelf commented Dec 4, 2014

A,Z=65,90;((A...Z).to_a+Z.downto(A).to_a).map{|r|puts (Z.downto(A).to_a+(A+1..Z).to_a).map{|c|c==r ?c.chr: " "}*""}

@davidallsopp
Copy link

let c=['A'..'C'];d=reverse c in mapM_ putStrLn$chunksOf 5$(\x y->if(x==y)then x else '-')<$>c++tail d<*>d++tail c

(Although it requires a few imports, so is perhaps cheating ;-) But pretty much everything in Haskell needs a few imports...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment