Recently I appeared for the Cisco programming test.

There were 4 question that need to be completed in 1.5 hrs.

Platform: Hacker-Earth

The nth term of the sequence of triangle numbers is given by tn = n(n+1)/2. So the first 10 triangle numbers are:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55 ...

Eg: the word value for SKY is 19 + 11 + 25 = 55 = t(10)

If the word value is a triangle number then we call the word a triangle word. Print true if the word is a triangle word.

If the numbers 1 to 5 are written out in words - one, two, three, four, five then there are 3+3+5+4+4 = 19 letters used in total.

For a number x such that 1 < x < 1000, print the total number of letters used for writing all numbers from 1 to x (inclusive) in words.

Note: Do not count spaces

342 is worded as three hundred and fourty two

The base 10 number 585 expressed in binary is 1001001001. The number is a palindrome in both the bases

For input x such that 1 < x < 10000. print true if its a palindrome in both base 10 and 2 otherwise false

A niven number is a number that is divisible by the sum of its digits.

Eg: 201 is a niven number because its divisible by 3 (sum of 2 + 0 + 1)

Truncating right digit of 201 gives 20 which is again a Niven number

Truncating again gives a niven number

Let's call a niven number while recursively truncating the last digit also results in a niven number, a Right Truncatable Niven Number

Also, the starting number 201 which when divided by sum of its digits yields a prime number (201/3 = 67). Lets call such a number a Strong Niven Number

Now take the number 2011 which is a prime number, Truncating the right digit, we get 201 which is a strong niven number which is also a Right Truncatable Niven number

Lets call number like 2011 Strong Right Truncatable Niven Prime

For a number x such that 10 < x < 100000, print true if x is a Strong Right truncatable Niven prime else false.

There were 4 question that need to be completed in 1.5 hrs.

Platform: Hacker-Earth

**Q1 Triangle Words**The nth term of the sequence of triangle numbers is given by tn = n(n+1)/2. So the first 10 triangle numbers are:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55 ...

**By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value.**

Eg: the word value for SKY is 19 + 11 + 25 = 55 = t(10)

If the word value is a triangle number then we call the word a triangle word. Print true if the word is a triangle word.

**Q2 Number Letter Counts**If the numbers 1 to 5 are written out in words - one, two, three, four, five then there are 3+3+5+4+4 = 19 letters used in total.

For a number x such that 1 < x < 1000, print the total number of letters used for writing all numbers from 1 to x (inclusive) in words.

Note: Do not count spaces

342 is worded as three hundred and fourty two

**Q3 Double-base Palindrome**The base 10 number 585 expressed in binary is 1001001001. The number is a palindrome in both the bases

For input x such that 1 < x < 10000. print true if its a palindrome in both base 10 and 2 otherwise false

**Q4 Niven Numbers**A niven number is a number that is divisible by the sum of its digits.

Eg: 201 is a niven number because its divisible by 3 (sum of 2 + 0 + 1)

Truncating right digit of 201 gives 20 which is again a Niven number

Truncating again gives a niven number

Let's call a niven number while recursively truncating the last digit also results in a niven number, a Right Truncatable Niven Number

Also, the starting number 201 which when divided by sum of its digits yields a prime number (201/3 = 67). Lets call such a number a Strong Niven Number

Now take the number 2011 which is a prime number, Truncating the right digit, we get 201 which is a strong niven number which is also a Right Truncatable Niven number

Lets call number like 2011 Strong Right Truncatable Niven Prime

For a number x such that 10 < x < 100000, print true if x is a Strong Right truncatable Niven prime else false.

## No comments :

## Post a Comment