6
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ずんだのハロウィン問題 awkワンライナー編

Last updated at Posted at 2018-10-31

ずんだのハロウィン問題 Ruby編
ずんだのハロウィン問題 Go編

ルール

  • 入力として "trick", "treat", "sushi", "poyayou", "tamakatsu" がランダムに与えられる
  • 入力をそのまま標準出力する
  • 入力が "trick" または "treat" だったら "happy halloween" と標準出力する
  • 入力が "trick" または "treat" ではなかったら "sleepy" と標準出力する

プログラム

  • sort -Rが使える環境
echo -e "trick\ntreat\nsushi\npoyayou\ntamakatsu\n" | sort -R | awk '{printf "%s\n", match($0, /trick|treat/) ? "happy halloween" : "sleepy"}'
  • sort -Rが使えない環境(bash)
echo -e "trick\ntreat\nsushi\npoyayou\ntamakatsu\n" | while read x; do echo -e "$RANDOM\t$x"; done | sort -k1,1n | cut -f 2- | awk '{printf "%s\n", match($0, /trick|treat/) ? "happy halloween" : "sleepy"}'

#出力例

sleepy
sleepy
sleepy
happy halloween
happy halloween
sleepy

ずんだ問題まとめ - Qiita

6
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?