-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from taniaReyesM/taniaReyesM-patch-1
3 problems solved from the code week number 35
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |