Last active
August 29, 2015 14:12
-
-
Save mikkun/065645a7fbcfee9b47f6 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
2014/12/30「年末年始シェル芸問題集」の解答例 | |
問題URL: http://blog.ueda.asia/?p=4852 | |
A1: | |
find ~/ -type f -a \( -iname '*.jpg' -o -iname '*.jpeg' \) -print0 | xargs -0 md5sum | sort -k1d | awk '{if($1==M){print M,P"\n"$1,$2}{M=$1;P=$2}}' | uniq | |
A2: | |
curl -s 'http://www.geocoding.jp/api/?q=羽田空港' | grep '^<\(lat\|lng\)_' | sed 's/<[^>]\+>//g' | awk -F',' '{print "緯度:"$1"度"$2"分"$3"秒"}' | sed '2s/^緯/経/' | |
A3(「ruby -e 'puts Math::E'」相当): | |
awk 'BEGIN{OFMT="%.16g";F=1;N=1;for(i=1;i<100;i++){F*=i;N+=1/F};print N-5/(10^16)}' | |
A3(小数点以下第1000位まで出力する別解): | |
echo 'scale=1000+5;f=1;n=1;for(i=1;i<1000;i++){f*=i;n+=(1/f)};n' | bc | tr -d '\\\n' | sed 's/.....$/\n/' | |
A4: | |
B=$(cat message2015.txt); for n in $(seq 31); do B=$(echo $B | base64 -d); done; echo $B | |
A5(「ruby -e 'puts Math::PI'」相当): | |
awk 'BEGIN{OFMT="%.16g";print atan2(1,1)*4}' | |
A5(小数点以下第1000位まで出力する別解): | |
echo 'scale=1000+5;a(1)*4' | bc -l | tr -d '\\\n' | sed 's/.....$/\n/' | |
A6: | |
echo {a,}{b,}{c,}{d,}{e,} | tr ' ' '\n' | sed 's/\(.\)/\1,/g' | sed 's/^\(.*\),$/{\1}/' | sed '$a\{}' | |
A7(13164036458569648337239753460458722910223472318386943117783728128まで対応): | |
I=8128; for N in $(seq 108); do [ $(echo "2^($N+1)-1" | bc | factor | awk 'NF==2{print 0}') ] && echo "$(echo "2^$N*(2^($N+1)-1)" | bc) は完全数です(n=$N)"; done | grep "^$I " | |
A8(ページ取得時にウェイトをかけているため出力に時間がかかります): | |
for N in $(seq 0 10 100); do w3m -dump "https://www.google.co.jp/search?q=シェル芸+site:twitter.com&start=$N"; sleep 1; done | grep 'https://twitter\.com/[0-9A-Za-z_]\+/status/[0-9]\+' | tr -d ' ' | sed 's/^.*https:/https:/g' | while read U; do w3m -dump "$U" | sed '/保留中キャンセル$/,/[0-9]件のお気に入り$/!d' | tail -n+2 | head -n-2; sleep 1; done | sed 's/^\[.*\[S:@:S\]\(.*[0-9]日\)$/================\n\1/g' | sed 's/\[S:\([#@]\):S\]/\1/g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment