Created
May 20, 2019 13:49
-
-
Save YuukiToriyama/bae30a18c976ba4069ccf5278c45caba to your computer and use it in GitHub Desktop.
二項係数を計算するawkだけのゴリ押しワンライナー
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/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 |
こっちのほうがエレガント?eval使うのは反則?
eval echo "1" "| awk '{print \$0}END{printf \"1 \"; for (i=1; i<NF; i++) {printf \"%s \", \$i+\$(i+1)} print \"1\"}'"{,,,,,,,,,}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
計算結果