#!/usr/bin/pike void main(int argc, array(string) argv) { if(argc < 2) { write("usage: foodfind food_or_color\n"); } string given = argv[1]; mapping color = ([ "Apple":"red", "Banana":"yellow", "Lemon":"yellow", "Carrot":"orange" ]); if(color[given]) write("%s is a food with color %s\n", given, color[given]); string food = search(color, given); if(food) write("%s is a food with color %s\n", food, given); // search will only find one value, // but it can be given a place where it should start searching array foods = ({ search(color, given) }); food = 0; while(food = search(color, given, foods[-1])) { foods += ({ food }); } write("%{%s %}were %s foods.\n", foods, given); }