all_rooms = ['Library' 'Kitchen'] all_suspects = ['White' 'Green'] all_weapons = ['Rope' 'Lead_Pipe'] is_ready_to_solve = |state| => { ((length state:suspects) == 1) && ((length state:rooms) == 1) && ((length state:weapons) == 1) } take_turn = |opponent_card state| => { state = (remove_card state opponent_card) (make_guess state) state } remove_card = |state opponent_card| => { rooms = filter card in state:rooms { card != opponent_card } suspects = filter card in state:suspects { card != opponent_card } weapons = filter card in state:weapons { card != opponent_card } { current_room = state:current_room rooms = rooms suspects = suspects weapons = weapons } } make_guess = |state| => { if (is_ready_to_solve state) { (output 'It was ' + state:suspects:0 + ' in the ' + state:rooms:0 + ' with the ' + state:weapons:0 + '!') } else { (output 'I accuse ' + (random state:suspects) + ' in the ' # + state:current_room + ' with the ' + (random state:weapons) + '!') } } init_state = { current_room = 'Library' rooms = all_rooms suspects = all_suspects weapons = all_weapons } (take_turn 'Green' (take_turn 'Kitchen' (take_turn 'Rope' init_state)))