Skip to content

Instantly share code, notes, and snippets.

@YuukiToriyama
Created May 20, 2019 13:49
Show Gist options
  • Save YuukiToriyama/bae30a18c976ba4069ccf5278c45caba to your computer and use it in GitHub Desktop.
Save YuukiToriyama/bae30a18c976ba4069ccf5278c45caba to your computer and use it in GitHub Desktop.
二項係数を計算するawkだけのゴリ押しワンライナー
#!/bin/bash
# Usage
# 先頭のecho ""にパスカルの三角形の何段目まで二項係数を計算したいか入力します。
# 8行目行中にある「{print $0}」の部分を削除すれば、パスカルの三角形は表示せずに求めたい段の二項係数のみが表示されるようになります。
# Copyright 2019 YUUKIToriyama All Rights Reserved
echo "10" | awk '{for (n=1; n<=$1; n++){ for (m=1; m<=n; m++){printf "$"m"+$"m+1","} printf "\n" }}' \
| awk 'BEGIN{printf "echo 1 1"}{printf " | awk \047{print $0}END{print 1," $0 "1}\047"}' \
| bash
@YuukiToriyama
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment