Lab 1: C

Please write the following two programs.

1. Vedic Square and Vedic Star

(1) Problem Description

The Vedic Square is a 9 × 9 table originating in ancient Indian mathematics. It is similar to a multiplication table for the numbers 1 through 9, except that each cell contains the digital root of the product of its row and column numbers, rather than the product itself.

To find the digital root of a non-negative integer, add its digits together. Repeat this process with the resulting sum until only one digit remains. That digit is the digital root of the original number. For example:

Note: Adding 9 to a positive integer does not change its digital root. Every positive multiple of 9 has a digital root of 9.

The following images show the Vedic Square.

Vedic Square: a 9 by 9 table of digital roots, with row and column labels from 1 to 9.
Vedic Square: console output.
The same Vedic Square, with matching digital roots shown in matching colors.
Vedic Square: color-coded view.

(2) Vedic Star

The Vedic Square contains many geometric patterns and symmetries. Replace every occurrence of a particular digit with an asterisk (*) and all other digits with spaces. You will see a symmetric pattern emerge from the square.

(3) Programming Task

Write a program that first prints the Vedic Square and then prints the Vedic Star pattern for each digit from 1 through 9. The three examples below correspond to the digits 1, 2, and 3, respectively.

Vedic Star for digit 1: asterisks mark all cells whose digital root is 1.
Vedic Star for digit 1.
Vedic Star for digit 2: asterisks mark all cells whose digital root is 2.
Vedic Star for digit 2.
Vedic Star for digit 3: asterisks mark all cells whose digital root is 3.
Vedic Star for digit 3.

2. Elevator Problem

(1) Problem Description

An elevator is instructed to visit N floors in a specified order. It takes 6 seconds to move up one floor and 4 seconds to move down one floor. At each requested floor, it stops for 5 seconds.

Given a sequence of requested floors, calculate the total time required. The elevator starts at floor 0. After completing the sequence, it remains at the last requested floor and does not need to return to floor 0.

(2) Input

The input is a sequence of N + 1 non-negative integers. The first integer, N, specifies the number of requested stops. The next N integers give the floors to visit, in order.

(3) Output

Print the total time, in seconds, required for the elevator to complete the sequence of stops.

(4) Sample Input and Output

Example 1

Input:

1 2

Output:

17

Explanation: 6 × 2 + 5 = 17 seconds.

Example 2

Input:

3 2 3 1

Output:

41

Explanation: 6 × 2 + 5 + 6 × 1 + 5 + 4 × 2 + 5 = 41 seconds.