fork download
  1. :- initialization(main).
  2. main :-
  3. halt.% Fruits Identification System
  4.  
  5. % Facts: Fruit data
  6. fruit(apple, red, small, round).
  7. fruit(orange, orange, small, round).
  8. fruit(banana, yellow, medium, elongated).
  9. % Add more fruit facts here
  10.  
  11. % Rules: Fruit identification based on color, size, and shape
  12. identify_fruit(Color, Size, Shape, Fruit) :-
  13. fruit(Fruit, Color, Size, Shape).
  14.  
  15. % Sample queries
  16. % Uncomment and modify these queries to test the identification system
  17. % identify_fruit(red, small, round, X).
  18. % identify_fruit(orange, small, round, X).
  19. % identify_fruit(yellow, medium, elongated, X).
  20. % Add more sample queries here
Success #stdin #stdout 0.01s 5300KB
stdin
% Search Tree

% Tree representation: tree(Value, Left, Right)
% A tree has a value and two branches: left and right

% Base case: an empty tree
tree(empty, nil, nil).

% Recursive case: a non-empty tree with a value and two branches
tree(Value, Left, Right) :-
    tree(LeftValue, LeftLeft, LeftRight),
    tree(RightValue, RightLeft, RightRight),
    Value = [LeftValue, RightValue],
    Left = tree(LeftValue, LeftLeft, LeftRight),
    Right = tree(RightValue, RightLeft, RightRight).

% Example search tree
example_tree(T) :-
    T = tree(1,
        tree(2,
            tree(4,
                tree(8, empty, empty),
                tree(9, empty, empty)
            ),
            tree(5, empty, empty)
        ),
        tree(3,
            tree(6, empty, empty),
            tree(7, empty, empty)
        )
    ).

% Query example
% To query the example_tree for the value at a specific node, use the tree/3 predicate.
% For example, to find the value at the left branch of the root node in the example_tree:
% tree(Value, Left, _) = example_tree(T),
% write(Left).
stdout
Standard output is empty