Last active
November 30, 2020 14:07
-
-
Save rw-r-r-0644/024a4823adba2169a8ffc0d60cadb4b7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/python3 | |
# manhattan.py | |
# Solves "paths of Manhattan (2d)" problem | |
# | |
# Copyright(C) 2020 rw-r-r-0644 | |
# This file is under GNU GPLv2 | |
import math, sys | |
def tartaglia(n, k): | |
return math.factorial(n) // (math.factorial(k) * math.factorial(n - k)) | |
def manhattan(i, j): | |
return tartaglia(i + j, min(i, j)) | |
i = int(sys.argv[1]) | |
j = int(sys.argv[2]) | |
print(manhattan(i, j)) |
This file contains hidden or 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
; manhattan.rkt | |
; Solves "paths of Manhattan (2d)" problem | |
; | |
; Copyright(C) 2020 rw-r-r-0644 | |
; This file is under GNU GPLv2 | |
(define factorial | |
(lambda (n) | |
(if (= n 0) 1 | |
(* n (factorial (- n 1)))) | |
)) | |
(define tartaglia | |
(lambda (n k) | |
(quotient (factorial n) (* (factorial k) (factorial (- n k)))) | |
)) | |
(define manhattan-2d | |
(lambda (i j) | |
(tartaglia (+ i j) (min i j)) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment