Skip to main content
17/25

Generate a Number Pyramid with Row Sums

Easy
Problem
Given an integer n, generate a number pyramid where:
  • Row i contains numbers from 1 through i.
  • Each row should also display the sum of the numbers in that row.
  • Return the result as a list of strings.
  • Do not use reverse(), reduce(), or a!flatten()

ri! Rule Inputs

ri!nNumber (Integer)
5

Example 1: Case 1

Input: ri!n
5
Output:
{
  "1 | Sum: 1",
  "1 2 | Sum: 3",
  "1 2 3 | Sum: 6",
  "1 2 3 4 | Sum: 10",
  "1 2 3 4 5 | Sum: 15"
}

Example 2: Case 2

Input: ri!n
8
Output:
{
  "1 | Sum: 1",
  "1 2 | Sum: 3",
  "1 2 3 | Sum: 6",
  "1 2 3 4 | Sum: 10",
  "1 2 3 4 5 | Sum: 15",
  "1 2 3 4 5 6 | Sum: 21",
  "1 2 3 4 5 6 7 | Sum: 28",
  "1 2 3 4 5 6 7 8 | Sum: 36"
}

Example 3: Case 3

Input: ri!n
2
Output:
{
  "1 | Sum: 1",
  "1 2 | Sum: 3"
}

Appian Expression Tips

  • • Use ri!variableName for rule inputs
  • • Use a!localVariables(local!x: …, body) for locals
  • • Use a!forEach(items: …, expression: fv!item) to iterate
  • • Use where() / reject(fn!isnull, list) to filter