Skip to content

Commit

Permalink
Merge pull request #1 from taniaReyesM/taniaReyesM-patch-1
Browse files Browse the repository at this point in the history
3 problems solved from the code week number 35
  • Loading branch information
taniaReyesM authored Oct 21, 2018
2 parents a35d943 + e6f3165 commit 9034fa4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
30 changes: 30 additions & 0 deletions warmup/3d_surface_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'''
hacker rank
https://www.hackerrank.com/contests/w35/challenges/3d-surface-area/problem
'''

#!/bin/python

def surfaceArea(A):
cubes = 0
hidden = 0
for i in xrange(len(A)):
for j in xrange(len(A[0])):
num = A[i][j]
cubes += num
hidden += num - 1
if j > 0:
hidden += min(num, A[i][j-1])
if i > 0:
hidden += min(num, A[i-1][j])
return cubes * 6 - hidden * 2

if __name__ == "__main__":
H, W = raw_input().strip().split(' ')
H, W = [int(H), int(W)]
A = []
for A_i in xrange(H):
A_temp = map(int,raw_input().strip().split(' '))
A.append(A_temp)
result = surfaceArea(A)
print result
28 changes: 28 additions & 0 deletions warmup/lucky_purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'''
hacker rank
https://www.hackerrank.com/contests/w35/challenges/lucky-purchase/problem
'''

#!/bin/python

import sys

if __name__ == "__main__":
n = int(raw_input().strip())
price = 1000000000
name = ""
for a0 in xrange(n):
name, value = raw_input().strip().split(' ')
name, value = [str(name), int(value)]
counts = dict()
for i in str(value):
counts[i] = counts.get(i, 0) + 1

if len(counts) == 2 and counts.get("7", 0) == counts.get("4", 0) and counts.get("4", 0) > 0:
if int(value) < price:
name = name
price = value
if name == "":
print(-1)
else:
print(name)
29 changes: 29 additions & 0 deletions warmup/triple_recursion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'''
hacker rank
https://www.hackerrank.com/contests/w35/challenges/triple-recursion/problem
'''

#!/bin/python

def tripleRecursion(n, m, k):
matrix = [[0 for _ in range(n)] for _ in range(n)]

for i in xrange(n):
for j in xrange(n):
if i == j:
if i == 0:
matrix[0][0] = m
else:
matrix[i][j] = matrix[i - 1][j - 1] + k
elif i > j:
matrix[i][j] = matrix[i - 1][j] - 1
else:
matrix[i][j] = matrix[i][j - 1] - 1
for i in xrange(n):
print(' '.join(str(x) for x in matrix[i]))


if __name__ == "__main__":
n, m, k = raw_input().strip().split(' ')
n, m, k = [int(n), int(m), int(k)]
tripleRecursion(n, m, k)

0 comments on commit 9034fa4

Please sign in to comment.