Skip to main content

Hackerrank > Ruby > Tutorial

                                  Tutorial

01-Hello World!

Let's get started with Ruby!
Go ahead and type the following code in the code-editor:
print "Hello HackerRank!!"
Solution
print "Hello HackerRank!!"

02-Everything is an Object

Everything is an object in Ruby. For instance, if you type
print self
in the code-editor, Ruby treats self as the object in which it is currently referred to.
Solution
print self

03-Object Methods

Each object in Ruby may have methods associated with it. To demonstrate this, we want you to print whether a number is even or odd. A number has aneven? method associated with it, which returns true or false based on the parity of the number.
Assuming a variable number is already defined, check whether a given numberis even or not.
Hint
Type in the code-editor
return number.even?
or
number.even?
Solution
number.even?

04-Object Method Parameters

A method may take zero or more parameters as input. To demonstrate this, we look at the asserts we use on HackerRank. Sometimes, we have to check whether a given number a is within the range b and c (where b  c, and both inclusive ).
Three variables ab, and c are already defined. Your task is to write code that checks whether a is within the range of b and c by calling the methodrange? (which we have defined for you as a method for this example) on aand passing b and c as arguments.
Hint
a.range?(b, c)
or
return a.range?(b, c)
or
a.range? b, c
or
return a.range? b, c
Solution
a.range? b, c

Comments

Popular posts from this blog

C Questions

C Questions
C Questions

Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:

void main()
{
int const * p=5; printf("%d",++(*p));
}
Answer:
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
main()
{
char s[ ]="man"; int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Answer: mmmm
aaaa nnnn
Explanation

Zoho Interview | Set 1 (Advanced Programming Round)

Third Round: (Advanced Programming Round) Here they asked us to create a “Railway reservation system” and gave us 4 modules. The modules were:
    1. Booking
    2. Availability checking
    3. Cancellation
    4. Prepare chart
We were asked to create the modules for representing each data first and to continue with the implementation phase.

 My Solution :

#include<stdio.h>#include<conio.h>#include<stdlib.h>#include<string.h>#include<iostream.h>#include<time.h>#include<iomanip.h>#include<fstream.h>char f[10]="f";char s[10]="s";int addr,ad,flag,f1,d,m,i,amt;float tamt; class login {public:char id[100];char pass[100];char*password;void getid(){ cout<<"Enter your id:";gets(id); password=getpass("Enter the password:");strcpy(pass,password);}void displayid(){ cout<<"Id:";puts(id); cout<<"Password:";puts(pass);}}; class detail {public:in…

Hackerrank > SQL > Basic Select

Select
01-Select All
Given a City table, whose fields are described as +-------------+----------+ | Field       | Type     | +-------------+----------+ | ID          | int(11)  | | Name        | char(35) | | CountryCode | char(3)  | | District    | char(20) | | Population  | int(11)  | +-------------+----------+
write a query that will fetch all columns for every row in the table.

My Solution
SELECT*FROM city;
---------------------------------------------------------------------------------
02-Select by ID
Given a City table, whose fields are described as