Skip to content

Commit

Permalink
Merge pull request swapnanildutta#119 from sunny52525/30-days-of-code…
Browse files Browse the repository at this point in the history
…-kotlin

added kotlin
  • Loading branch information
swapnanildutta committed Oct 6, 2020
2 parents 69c235b + 4f728d7 commit a8ffa2a
Show file tree
Hide file tree
Showing 15 changed files with 1,124 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 30 Days of Code (Kotlin)/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
![GitHub contributors](https://img.shields.io/github/contributors/swapnanildutta/Hackerrank-Codes?style=plastic)
# 30 Days of Code in Kotlin.
> [Questions](https://www.hackerrank.com/domains/tutorials/30-days-of-code)
### Test Kotlin codes [here](https://play.kotlinlang.org/).
45 changes: 45 additions & 0 deletions 30 Days of Code (Kotlin)/day0-HelloWorld.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Question
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
Welcome to 30 Days of Code!
Sample Output
Hello, World.
Welcome to 30 Days of Code!
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.
*/

fun main() {
val inputString=readLine()!!;
println("Hello, World.");
println(inputString);
}
63 changes: 63 additions & 0 deletions 30 Days of Code (Kotlin)/day10-binaryNumbers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Question
Today, we're working with binary numbers. Check out the Tutorial tab for learning materials and an instructional video!
Task
Given a base-
integer, , convert it to binary (base-). Then find and print the base- integer denoting the maximum number of consecutive 's in
's binary representation.
Input Format
A single integer,
.
Constraints
Output Format
Print a single base-
integer denoting the maximum number of consecutive 's in the binary representation of
.
Sample Input 1
5
Sample Output 1
1
Sample Input 2
13
Sample Output 2
2
Explanation
Sample Case 1:
The binary representation of
is , so the maximum number of consecutive 's is
.
Sample Case 2:
The binary representation of
is , so the maximum number of consecutive 's is .
*/

fun main(args: Array<String>) {
var n:Int=readLine()!!.toInt();
var ans=0;
while(n!=0){
n=(n and (n shl 1));
ans++;
}
print(ans);
}
118 changes: 118 additions & 0 deletions 30 Days of Code (Kotlin)/day11-2dArrays.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
Question
Today, we're building on our knowledge of Arrays by adding another dimension. Check out the Tutorial tab for learning materials and an instructional video!
Context
Given a
2D Array,
:
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
We define an hourglass in
to be a subset of values with indices falling in this pattern in
's graphical representation:
a b c
d
e f g
There are
hourglasses in
, and an hourglass sum is the sum of an hourglass' values.
Task
Calculate the hourglass sum for every hourglass in
, then print the maximum hourglass sum.
Input Format
There are
lines of input, where each line contains space-separated integers describing 2D Array ; every value in will be in the inclusive range of to
.
Constraints
Output Format
Print the largest (maximum) hourglass sum found in
.
Sample Input
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 2 4 4 0
0 0 0 2 0 0
0 0 1 2 4 0
Sample Output
19
Explanation
contains the following hourglasses:
1 1 1 1 1 0 1 0 0 0 0 0
1 0 0 0
1 1 1 1 1 0 1 0 0 0 0 0
0 1 0 1 0 0 0 0 0 0 0 0
1 1 0 0
0 0 2 0 2 4 2 4 4 4 4 0
1 1 1 1 1 0 1 0 0 0 0 0
0 2 4 4
0 0 0 0 0 2 0 2 0 2 0 0
0 0 2 0 2 4 2 4 4 4 4 0
0 0 2 0
0 0 1 0 1 2 1 2 4 2 4 0
The hourglass with the maximum sum (
) is:
2 4 4
2
1 2 4
*/

import java.util.Scanner
fun main(args: Array<String>) {
var matrix=Array(6){IntArray(6)}

val input = Scanner(System.`in`);

for(i in 0..5){
for(j in 0..5){
matrix[i][j]=input.nextInt();
}
}

var sum=Int.MIN_VALUE;

for(i in 0..3){
for(j in 0..3){
val curSum=matrix[i][j] + matrix[i][j+1] + matrix[i][j+2]+ matrix[i+1][j+1]+ matrix[i+2][j] + matrix[i+2][j+1] + matrix[i+2][j+2];
if(curSum>sum){
sum=curSum;
}
}
}

print(sum);
}
85 changes: 85 additions & 0 deletions 30 Days of Code (Kotlin)/day2-Operators.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Question
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
lines of numeric input:
The first line has a double, (the cost of the meal before tax and tip).
The second line has an integer, (the percentage of being added as tip).
The third line has an integer, (the percentage of
being added as tax).
Output Format
Print the total meal cost, where
is the rounded integer result of the entire bill (
with added tax and tip).
Sample Input
12.00
20
8
Sample Output
15
Explanation
Given:
, , Calculations:
We round to the nearest dollar (integer) and then print our result, .
*/
import java.io.*
import java.math.*
import java.security.*
import java.text.*
import java.util.*
import java.util.concurrent.*
import java.util.function.*
import java.util.regex.*
import java.util.stream.*
import kotlin.collections.*
import kotlin.comparisons.*
import kotlin.io.*
import kotlin.jvm.*
import kotlin.jvm.functions.*
import kotlin.jvm.internal.*
import kotlin.ranges.*
import kotlin.sequences.*
import kotlin.text.*

// Complete the solve function below.
fun solve(meal_cost: Double, tip_percent: Int, tax_percent: Int): Unit {

val tip:Double = meal_cost*(tip_percent.toDouble()/100);
val tax:Double = meal_cost*(tax_percent.toDouble()/100);
val totalCost:Double = meal_cost + tip + tax;

print(Math.round(totalCost));
}

fun main() {
val scan = Scanner(System.`in`)

val meal_cost = scan.nextLine().trim().toDouble()

val tip_percent = scan.nextLine().trim().toInt()

val tax_percent = scan.nextLine().trim().toInt()

solve(meal_cost, tip_percent, tax_percent)
}
Loading

0 comments on commit a8ffa2a

Please sign in to comment.