Skip to content

Added 30 Days Code Hackerrank #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 30DaysCode/day10_Binary_Numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
count_dict, count, Last_item = {}, 0, None
binario = str(bin(int(input())))

binary_list = [n for n in binario]
for item in binary_list:
if Last_item != item:
Last_item = item
count = 1
else:
count += 1

if count > count_dict.get(item, 0):
count_dict[item] = count

print(count_dict.get('1'))
16 changes: 16 additions & 0 deletions 30DaysCode/day11_2d_arrays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def definition(args):
list_patterns, list_range = [], range(4)
for i in list_range:
for j in list_range:
list_patterns.append([args[i][j], args[i][j+1], args[i][j+2],
args[i+1][j+1], args[i+2][j], args[i+2][j+1], args[i+2][j+2]])
return list_patterns


if __name__ == '__main__':
arr = []
for _ in range(6):
arr.append(list(map(int, input().rstrip().split())))

result = max([sum(list_patt) for list_patt in definition(arr)])
print(result)
15 changes: 15 additions & 0 deletions 30DaysCode/day1_data_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
i = 4
d = 4.0
s = 'HackerRank '

'''Declare second integer, double, and String variables.
Read and save an integer, double, and String to your variables.'''

ii, dd, ss = int(input()), float(input()), input()

'''Print the sum of both integer variables on a new line.
Print the sum of the double variables on a new line.
Concatenate and print the String variables on a new line
The 's' variable above should be printed first.'''

print('{}\n{:.1f}\n{}'.format(i+ii, d+dd, s+ss))
20 changes: 20 additions & 0 deletions 30DaysCode/day2_operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the solve function below.
def solve(meal_cost, tip_percent, tax_percent):
return print(round(meal_cost*(1+tip_percent*0.01 +tax_percent*0.01)))

if __name__ == '__main__':
meal_cost = float(input())

tip_percent = int(input())

tax_percent = int(input())

solve(meal_cost, tip_percent, tax_percent)
21 changes: 21 additions & 0 deletions 30DaysCode/day3_Intro_Cond_Statments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/python3

import math
import os
import random
import re
import sys

if __name__ == '__main__':
N = int(input())
if N % 2 != 0:
print('Weird')
elif 2 <= N <= 5:
print('Not Weird')
elif 6 <= N <= 20:
print('Weird')
elif N > 20:
print('Not Weird')



28 changes: 28 additions & 0 deletions 30DaysCode/day4_class_vs_instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Person:
def __init__(self,initialAge):
if(initialAge > 0):
self.initialAge=initialAge
else:
print("Age is not valid, setting age to 0.")
self.initialAge=0

def amIOld(self):
if(self.initialAge < 13):
print("You are young.")
elif 13 <= self.initialAge < 18:
print("You are a teenager.")
else:
print("You are old.")

def yearPasses(self):
self.initialAge += 1

t = int(input())
for i in range(0, t):
age = int(input())
p = Person(age)
p.amIOld()
for j in range(0, 3):
p.yearPasses()
p.amIOld()
print("")
16 changes: 16 additions & 0 deletions 30DaysCode/day5_loops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
n = int(input())
if 2<=n<=20:
#Print ten lines where 1<=i<=10, result = n*i
for i in range(1,11):
print('{} x {} = {}'.format(str(n),str(i),str(n*i)))
17 changes: 17 additions & 0 deletions 30DaysCode/day6_lets_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def lets_review(t):
#Constraints t and s
if 1 <= t <= 10:
s = input()
if 2 <= len(s) <= 10000:
even_s, odd_s = '', ''
for j, letter in enumerate(s):
if j % 2 == 0:
even_s += letter
else:
odd_s += letter
return print('{} {}'.format(even_s, odd_s)), lets_review(t-1)


if __name__ == '__main__':
t = int(input())
lets_review(t)
6 changes: 6 additions & 0 deletions 30DaysCode/day7_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/python3

if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().rstrip().split()))
print(' '.join(list(map(str,arr[::-1]))))
16 changes: 16 additions & 0 deletions 30DaysCode/day8_dictionaries_and_maps.py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
n = int(input())
data = []
while 1 <= n <= 1e5:
data.append(input().split(' '))
n -= 1
phonebook = dict(data)

while True:
try:
query = input()
if phonebook.get(query):
print('{}={}'.format(query, phonebook[query]))
else:
print('Not found')
except:
break
24 changes: 24 additions & 0 deletions 30DaysCode/day8_dictionaries_maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def phonebook(n):
data = []
while 1 <= n <= 1e5:
data.append(input().split(' '))
n -= 1
return data


def queries(n):
phone = dict(phonebook(n))
while True:
try:
query = input()
if phone.get(query):
print('{}={}'.format(query, phone[query]))
else:
print('Not found')
except:
break


if __name__ == "__main__":
n = int(input())
queries(n)
16 changes: 16 additions & 0 deletions 30DaysCode/day9_recursion3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/python3
import os

def factorial(n):
if 0 <= n <= 1:
return 1
elif 2 <= n <= 12:
return n*factorial(n-1)


if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
result = factorial(n)
fptr.write(str(result) + '\n')
fptr.close()