Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

pascals-triangle

Code-golf: generate pascal’s triangle

August 28, 2023 by Tarik

K (Wikipedia), 15 characters: p:{x{+’:x,0}\1} Example output: p 10 (1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 … Read more

Categories algorithm Tags algorithm, code-golf, combinatorics, discrete-mathematics, pascals-triangle Leave a comment

How to efficiently calculate a row in pascal’s triangle?

May 14, 2023 by Tarik

>>> def pascal(n): … line = [1] … for k in range(n): … line.append(line[k] * (n-k) / (k+1)) … return line … >>> pascal(9) [1, 9, 36, 84, 126, 126, 84, 36, 9, 1] This uses the following identity: C(n,k+1) = C(n,k) * (n-k) / (k+1) So you can start with C(n,0) = 1 and … Read more

Categories algorithm Tags algorithm, binomial-coefficients, combinations, pascals-triangle Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa