Created
September 16, 2025 02:58
-
-
Save jyi2ya/71eea1fa1a3a18eed558640ea4cf8a8c 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
| #!/usr/bin/env perl | |
| use 5.020; | |
| use utf8; | |
| use warnings; | |
| use autodie; | |
| use feature qw/signatures postderef/; | |
| no warnings qw/experimental::postderef/; | |
| binmode STDOUT, ':utf8'; | |
| use List::Util qw/shuffle/; | |
| my @questions = qw/ | |
| 是否含肉 | |
| 是否辣 | |
| 是否主食 | |
| 是否汤类 | |
| /; | |
| my @data = ( | |
| [ '红烧肉', 'Y', 'N', 'N', 'N' ], | |
| [ '宫保鸡丁', 'Y', 'Y', 'N', 'N' ], | |
| [ '鱼香肉丝', 'Y', 'Y', 'N', 'N' ], | |
| [ '麻婆豆腐', 'N', 'Y', 'N', 'N' ], | |
| [ '西红柿炒鸡蛋', 'N', 'N', 'N', 'N' ], | |
| [ '青椒土豆丝', 'N', 'N', 'N', 'N' ], | |
| [ '糖醋排骨', 'Y', 'N', 'N', 'N' ], | |
| [ '水煮鱼', 'Y', 'Y', 'N', 'N' ], | |
| [ '回锅肉', 'Y', 'Y', 'N', 'N' ], | |
| [ '清炒时蔬', 'N', 'N', 'N', 'N' ], | |
| [ '酸辣土豆丝', 'N', 'Y', 'N', 'N' ], | |
| [ '蒸鸡蛋羹', 'N', 'N', 'N', 'N' ], | |
| [ '红烧茄子', 'N', 'N', 'N', 'N' ], | |
| [ '炒饭', 'N', 'N', 'Y', 'N' ], | |
| [ '牛肉面', 'Y', 'N', 'Y', 'N' ], | |
| [ '紫菜蛋花汤', 'N', 'N', 'N', 'Y' ] | |
| ); | |
| my @remains = @data; | |
| for my $quest_id (shuffle(0..$#questions)) { | |
| say "> $questions[$quest_id]? Y(es)/N(o)/A(ny)"; | |
| my $response = readline; | |
| if ($response =~ /^\s*Y/i) { | |
| @remains = grep { $_->[$quest_id + 1] eq 'Y' } @remains; | |
| } elsif ($response =~ /\s*N/i) { | |
| @remains = grep { $_->[$quest_id + 1] eq 'N' } @remains; | |
| } elsif ($response =~ /\s*A/i) { | |
| # pass | |
| } else { | |
| redo; | |
| } | |
| } | |
| if (@remains) { | |
| @remains = shuffle @remains; | |
| say "你吃:$remains[0]->[0]"; | |
| } else { | |
| say 'byd 吃个饭要求这么多'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment