Cody

Problem 1771. Polygonal numbers

Created by Jan Orwat in Community

The task of Problem 5 is to calculate triangular numbers. By playing with dots we can produce also square numbers like:

                                 * * * *
                     * * *       * * * *
           * *       * * *       * * * *
1: *    4: * *    9: * * *   16: * * * *

or hexagonal numbers:

                                          * * * *
                                         *       *
                         * * *          * * * *   *
                        *     *        * *     *   *
            * *        * * *   *        * * *   * * 
           *   *        *   * *          *   * * *
1: *    6:  * *    15:   * * *       28:  * * * *

 

According to those rules we can create polygonal numbers for all regular polygons.

 

Your task: given S and N calculate N-th S-gonal numbers P(S,N)

 

Examples:

  1. P(4, 3) returns [9] because 3-rd square number is 9,
  2. P(3, 1:5) returns [1, 3, 6, 10, 15] first 5 triangular numbers,
  3. P(3:6, 4) returns [10, 16, 22, 28] 4-th triangular, square, pentagonal and hexagonal numbers,
  4. P([3, 4], [1; 2]) returns [1, 1; 3, 4].

see the test suite for more hints

Solution Stats

46.01% Correct | 53.99% Incorrect
Last solution submitted on Jun 07, 2019

Problem Comments