Monkey man algorithm
Monkey man algorithm, who jumps and slip on wall

A monkey man caught inside a jail. He can jumps across the wall. He can jump 'X' meters, but due to slippery walls he falls 'Y' meters after each jump. To escape from jail, he has to cross 'N' number of walls, where height of each wall is given in an array.

Write a program to find total number of jumps, he has to make, to escape

Input Format

Your function will take three arguments, where:

Argument 1: An integer depicting X, which he can jump

Argument 2: An integer depicting Y, which he falls

Argument 3: An array of N integers having the height of each wall.

Constraints

1<=X<=109

1<=Y<=105

Output Format

Your program should return total number of jumps required to escape.


Sample Test Case

Test case 1

Sample Input 10 1 1 10

Sample Output 1

Explanation

Here monkey man can jump 10 meters high, but slides down by 1 meter. He has 1 wall to jump and the height of the wall is 10 meters. Since he jumps 10 meters in the first attempt he cross the wall easily in the first attempt only.

Test case 2

Sample Input 5 1 2 9 10

Sample Output 5

Explanation

Here, the monkey man can jump 5 meters high, but slides down by 1 meters. He has 2 walls to jump and the walls are 9 and 10 meters hight respectively.

While crossing the first wall, he takes 2 attempts, because during the first attempt he jumps 5 meters but slides down by 1 meters since he didn't cross the wall. In the next attempt he jumps 5 more meters from that position and this time he doesn't slide because he crossed the wall in this attempt because 4+5=9 and 9 meters is the actual height of the wall.

Similarly, while crossing the second wall, he takes 3 attempts because during his second attempt on this wall, he silides down by 1 meters since 4+5=9 and the height of the wall is 10 meters. During his third attempt, he was able to escape.

Tidy number
Tidy Numbers - Display all positive integers in ascending order

Ananya likes to keep things tidy. Her toys are sorted from smallest to largest and pencils are sorted from shortest to longest. One day, when practicing her counting skills, she noticed that some integers, have their digits sorted in non-decreasing order. She calls 8, 123, 555, and 224488 as numbers tidy. Numbers that do not have this property, like 20, 321, 495 and 999990, are not tidy.

She just finished counting all positive integers in ascending order from 1 to N. What was the last tidy number she counted?

Input

The first line of the input gives the number of test cases, T. T lines follow. Each line describes a test case with a single integer N, the last number counted by Ananya.

Output

For each test case, output is the last tidy number counted by Ananya.

1 ≤ T ≤ 100.

Sample Input:

5
132
1000
7
621
489

Sample Output:

129
999
7
599
489

sum maximum value in triangle
Find sum of maximum values in each row of a triangle

Input string: "5#9#6#4#6#8#0#7#1#5"

Triangle will be created as

5

9 6

4 6 8

0 7 1 5

 

Sum of highest in each row

5+9+8+7=29

algrorithm super reduced string
Solution for super reduced string algorithm in php
User has n string in english lowercase. In one operation, he can delete any pair of adjacent letters with same value. User wants to reduce string as much as possible. To do this, he will repeat the above operation as many times as it can be performed. Help user to find and print most reducible form of string. If the final string is empty, print Empty String.
algorithm individual divisible digit
Solution for individual divisible digit algorithm in php

Given an integer, NN, traverse its digits (dd1,dd2,...,ddn) and determine how many digits evenly divide NN (i.e.: count the number of times NN divided by each digit ddi has a remainder of 00). Print the number of evenly divisible digits.

 

 

Note: Each digit is considered to be unique, so each occurrence of the same evenly divisible digit should be counted (i.e.: for N=111N=111, the answer is 33).

Right side triangle
Draw right side elevated triangle in php, problem 3

You need to draw a right side staircase structure i.e. right side triangle structue . It seems to stand as right angle triangle from right side.

 

Input

Input is given integer N,consider it the height of staircase


Output

Print right side staircase with symbol '*' and spaces.

Inverted left triangle structure
Draw inverted staricase structure (Left side inverted triangle) problem-2

You need to draw a inverted staircase structure i.e. triangle structue which is inverted to left side. It seems to be stand as inverted right angle triangle.

 

Input

Input is given integer N,consider it the height of staircase


Output

Print inverted staircase with symbol '*' and spaces.

Triangle elevated left
Draw staircase structure (Left side elevated triangle) problem-1

You need to draw a staircase structure i.e. triangle structue which is elevated to left side. It seems to be stand as right angle triangle.

 

Input

Input is given integer N,consider it the height of staircase


Output

Print staircase with symbol '*' and spaces.

Funding

We need your support to operate it properly. We have lots of ideas but less fund, so help us with your funding.

Thoughts for the day

If A is a success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut.

Albert Einstein
Polls
Which device you use most for facebook application?
Laptop/PC
25%

 


Android
50%

 


IOS
16%

 


Blackberry
9%

 


Tutorial On Request
Q. Ask us for any tutorial or any thing which helps to build your career better.
Email:
Query: