6 kyu

House of cards

345 of 1,041Tuhaj

Description:

You want to build a standard house of cards, but you don't know how many cards you will need. Write a program which will count the minimal number of cards according to the number of floors you want to have. For example, if you want a one floor house, you will need 7 of them (two pairs of two cards on the base floor, one horizontal card and one pair to get the first floor). Here you can see which kind of house of cards I mean:

One floor:

 /\
 —
/\/\

Four floors:

    /\
    —
   /\/\
   — —
  /\/\/\
  — — —
 /\/\/\/\
 — — — —
/\/\/\/\/\

(See also http://www.wikihow.com/Build-a-Tower-of-Cards to see what it looks like in real life).

Note about floors:

This kata uses the British numbering system for building floors. If you want your house of cards to have a first floor, it needs a ground floor and then a first floor above that.

Details (Ruby & JavaScript & Python & R)

The input must be an integer greater than 0, for other input raise an error.

Details (Haskell)

The input must be an integer greater than 0, for other input return Nothing.

Details (COBOL)

The input will be an integer. If it is inferior or equal to 0, return -1.

Mathematics

Stats:

CreatedOct 12, 2014
PublishedOct 12, 2014
Warriors Trained1834
Total Skips128
Total Code Submissions8376
Total Times Completed1041
Ruby Completions183
JavaScript Completions417
Haskell Completions109
Python Completions345
R Completions38
COBOL Completions8
Total Stars26
% of votes with a positive feedback rating86% of 167
Total "Very Satisfied" Votes128
Total "Somewhat Satisfied" Votes31
Total "Not Satisfied" Votes8
Ad
Contributors
  • Tuhaj Avatar
  • jhoffner Avatar
  • ZozoFouchtra Avatar
  • user578387 Avatar
  • bkaes Avatar
  • filipkonieczny Avatar
  • Voile Avatar
  • rowcased Avatar
  • mentalplex Avatar
  • FArekkusu Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • dfhwze Avatar
  • saudiGuy Avatar
Ad