Skip to content

Instantly share code, notes, and snippets.

@KorigamiK
Last active December 30, 2021 21:13
Show Gist options
  • Save KorigamiK/6e4bffac30f8d84e80a9c1a155991d79 to your computer and use it in GitHub Desktop.
Save KorigamiK/6e4bffac30f8d84e80a9c1a155991d79 to your computer and use it in GitHub Desktop.
a super hideous problem on hackerrank
import math
def nCr(n, r):
if r == 0:
return 1
return math.factorial(n)/(math.factorial(r)*math.factorial(n-r))
def pascal(N):
print(1)
for n in range(2, N+1):
for r in range(n+1):
print(int(nCr(n, r)), end=' ')
print()
def given(N):
it = list(range(0, 2 + (N-1)*2, 2))
# This is the fucking ultimate hack
empty_string = dir(list)[0].removesuffix(dir(list)[0])
def get_next(i, line_range):
return lambda j: print(
j if j < i else 2*i - j,
end=empty_string
if j != line_range - 1
else None
)
for i in range(1, N+1):
line_range = it[i-1] + 2
get_next_element = get_next(i, line_range)
[*map(get_next_element, range(1, line_range))]
N = int(input())
given(N)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment