HackerRank – 30 Days of Code – Day 3: Intro to Conditional Statements – Ruby Program

Objective

In this challenge, we’re getting started with conditional statements. Check out the Tutorial tab for learning materials and an instructional video!

Task

Given an integer, n, perform the following conditional actions:

If n is odd, print Weird
If n is even and in the inclusive range of 2 to 5, print Not Weird
If n is even and in the inclusive range of 6 to 20, print Weird
If n is even and greater than 20, print Not Weird
Complete the stub code provided in your editor to print whether or not n is weird.

Input Format

A single line containing a positive integer, n.

Constraints 1 < = n <= 100

Output Format

Print Weird if the number is weird; otherwise, print Not Weird.

Explanation

Sample Case 0: n=3
n is odd and odd numbers are weird, so we print Weird.

Sample Case 1: n=24
n>20 and n is even, so it isn’t weird. Thus, we print Not Weird.

Ruby Program


Sourcehttps://www.hackerrank.com/challenges/30-conditional-statements

HackerRank – 30 Days of Code – Day 2: Operators – Ruby Program

Objective

In this challenge, you’ll work with arithmetic operators. Check out the Tutorial tab for learning materials and an instructional video!

Task

Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal’s total cost.

Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result!

Input Format

There are 3 lines of numeric input:
The first line has a double, mealCost (the cost of the meal before tax and tip).
The second line has an integer, tipPercent (the percentage of mealCost being added as tip).
The third line has an integer, taxPercent (the percentage of mealCost being added as tax).

Output Format

Print The total meal cost is totalCost dollars., where totalCost is the rounded integer result of the entire bill ( mealCost with added tax and tip).

Sample Input

Sample Output

Explanation

Given:
1. mealCost

2. tipPercent

3. taxPercent

Calculations:

tip = 12 x 20/100 = 2.4

tax = 12 X 8/100  = 0.96

totalCost = mealCost + tip + tax = 12 + 2.4 + 0.96  = 15.36

We round totalCost to the nearest dollar (integer) and then print our result:

The total meal cost is 15 dollars.

Ruby Implementation


Sourcehttps://www.hackerrank.com/challenges/30-operators

HackerRank – 30 Days of Code – Day 1: Data Types – Ruby Program

Objective

Today, we’re discussing data types. Check out the Tutorial tab for learning materials and an instructional video!

Task

Complete the code in the editor below. The variables i, d,s  and are already declared and initialized for you. You must:

  1. Declare 3 variables: one of type int, one of type double, and one of type String.
  2. Read 3 lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your 3 variables.
  3. Use the + operator to perform the following operations:
  • Print the sum of i plus your int variable on a new line.
  • Print the sum of d plus your double variable to a scale of one decimal place on a new line.
  • Concatenate with the string s you read as input and print the result on a new line.

Note: If you are using a language that doesn’t support using + for string concatenation (e.g.: C), you can just print one variable immediately following the other on the same line. The string provided in your editor must be printed first, immediately followed by the string you read as input.

Input Format

The first line contains an integer that you must sum with i.
The second line contains a double that you must sum with d.
The third line contains a string that you must concatenate with s.

Output Format

Print the sum of both integers on the first line, the sum of both doubles (scaled to 1 decimal place) on the second line, and then the two concatenated strings on the third line.

Sample Input

Sample Output

Explanation

When we sum the integers 4 and 12, we get the integer 16.
When we sum the floating-point numbers 4.0 and 4.0, we get 8.0.
When we concatenate HackerRank with is the best place to learn and practice coding!, we get HackerRank is the best place to learn and practice coding!.

Ruby Program

Source: https://www.hackerrank.com/challenges/30-data-types

HackerRank – 30 Days of Code – Day 0: Hello, World. – Ruby Program

Objective

In this challenge, we review some basic concepts that will get you started with this series. You will need to use the same (or similar) syntax to read input and write output in challenges throughout HackerRank. Check out the Tutorial tab for learning materials and an instructional video!

Task

To complete this challenge, you must save a line of input from stdin to a variable, print Hello, World. on a single line, and finally print the value of your variable on a second line.

You’ve got this!

Note: The instructions are Java-based, but we support submissions in many popular languages. You can switch languages using the drop-down menu above your editor, and the variable may be written differently depending on the best-practice conventions of your submission language.

Input Format

A single line of text denoting (the variable whose contents must be printed).

Output Format

Print Hello, World. on the first line, and the contents of on the second line.

Sample Input

 

Sample Output

 

Explanation

On the first line, we print the string literal Hello, World.. On the second line, we print the contents of the variable which, for this sample case, happens to be Welcome to 30 Days of Code!. If you do not print the variable’s contents to stdout, you will not pass the hidden test case.

Ruby Program

Source: https://www.hackerrank.com/challenges/30-hello-world

How to test CCAvenue Payment Gateway in localhost? (Avoid Error Code: 10002 Merchant Authentication failed)

In this tutorial, I am going to discuss how to test a CCAvenue payment gateway on your local system.

Why this tutorial?

  1. To test CCAvenue in localhost.
  2. To avoid issues on the Live website.

CCAvenue is one of the leading payment gateway providers in India, though their documentation is not up to the industry standard. It is hard to understand. While googling I found many peoples are getting 1002 Authentication Failed.

Reason for CCAvenue 10002 Authentication Failure

  • Wrong/invalid merchant ID
  • Wrong/invalid Working Key
  • Wrong/invalid access Key
  • URL of the registered website

aravin.net_10002_error_code_this_happen_to_best_of_us

But, that CCAvenue error message 10002 does not provide much information on which part it is failing because of security reason. However, many of them think that they are using wrong merchant id or access key or working key. But actual reason for this issue is URL of the account.

Example

If you are registered for www.aravin.net, your payment gateway will work only on www.aravin.net, you cannot use it for any other website.

Also, you cannot use this API keys for your localhost such as http://localhost/ or http://127.0.0.1

So, How to test CCAvenue in localhost or Testing Environment?

  1. Adding your localhost URL to CCAvenue Account
  2. Getting API Keys (Merchant ID, Access Code, Working key)
  3. Start Testing in localhost

1. Adding your localhost URL to CCAvenue Account

In order to add your localhost URL to CCAvenue account, you have to write an email to service@ccavenue.com from your registered email with required localhost URL.

Sample Localhost URL

2. Getting API Keys (Merchant ID, Access Code, Working key)

Once, your localhost or local IP address is added to your account, you can find the valid API keys in the following path

CCAvenue website -> Settings -> API Keys

Sample API Keys for localhostCCAvenue Account

3. Start Testing in localhost

Now, you can download your preferred programming language integration from the CCAvenue website & use the test API Keys.

That’s all 🙂


Quick Links

  1. CCAvenue Best Practice: http://aravin.net/best-practices-ensure-transaction-integrity-ccavenue-payment-gateway/
  2. How to integrate CCAvenue in ASP.NET website: http://aravin.net/how-to-integration-ccavenue-payment-gateway-into-your-website-using-asp-net-with-screenshot/