Thanks to FryAmTheEggman for the idea for this second version.
Version 1 here.
Not-so-simple challenge: given a number of cards, build the biggest house of cards you can with that number of cards, according to the following building order:
/\ /\ /\ /\/\
-- -- -- ---- ----
/\ → /\/\ → /\/\ → /\/\ → /\/\/\ → /\/\/\ → /\/\/\ →
/\ /\
-- -- --
/\/\ /\/\ /\/\
---- ---- ----
→ /\/\/\ → /\/\/\ → /\/\/\/\ → ...
So you start with a single-storey house, then build the adjacent group, then put the bridge card, then build the group in the second floor, then start building groups and bridges from the first floor diagonally to reach the third floor, and so on.
A single card will be represented with a /
, a \
or a --
. If after using as many cards as possible you have one card left, just output what you have accomplished so far (see example for 3 cards, the result is the same as for 2 cards). The only exception is the case of 1 card, that must output a flat card.
Examples:
Input: 1
Output:
-- <a card lying on the floor>
Input: 2
Output:
/\
Input: 3
Output:
/\
Input: 5
Output:
--
/\/\
Input: 10
Output:
/\
----
/\/\/\
Input: 20
Output:
/\
--
/\/\/\
------
/\/\/\/\
Input: 39
Output:
--
/\/\
----
/\/\/\
------
/\/\/\/\
--------
/\/\/\/\/\
Input: 40
Output:
/\
--
/\/\
----
/\/\/\
------
/\/\/\/\
--------
/\/\/\/\/\
Input can be numeric or a string, and will always be a positive integer. Output must be exactly as shown, with leading and trailing spaces and newlines allowed.
This is code-golf, so may the shortest program/function for each language win!