fork download
  1. % 商品データ: product(商品名, 価格, 評価, レビュー数)
  2. product(item1, 3000, 4.8, 20).
  3. product(item2, 1800, 4.2, 200).
  4. product(item3, 5000, 4.9, 5).
  5. product(item4, 2500, 4.5, 80).
  6.  
  7. % --- おすすめ判定のルール ---
  8.  
  9. % 「評価が4.5以上」かつ「レビュー数が50件以上」の商品を「おすすめ」とする
  10. recommended(Item) :-
  11. product(Item, _, Rating, Reviews),
  12. Rating >= 4.5,
  13. Reviews >= 50.
  14.  
  15. % 「評価が4.8以上」という「超高評価」な商品もおすすめとする
  16. recommended(Item) :-
  17. product(Item, _, Rating, _),
  18. Rating >= 4.8.:- set_prolog_flag(verbose,silent).
  19. :- prompt(_, '').
  20. :- use_module(library(readutil)).
  21.  
  22. main:-
  23. process,
  24.  
  25. process:-
  26. /* your code goes here */
  27. true.% 商品データ: product(商品名, 価格, 評価, レビュー数)
  28. product(item1, 3000, 4.8, 20).
  29. product(item2, 1800, 4.2, 200).
  30. product(item3, 5000, 4.9, 5).
  31. product(item4, 2500, 4.5, 80).
  32.  
  33. % --- おすすめ判定のルール ---
  34.  
  35. % 「評価が4.5以上」かつ「レビュー数が50件以上」の商品を「おすすめ」とする
  36. recommended(Item) :-
  37. product(Item, _, Rating, Reviews),
  38. Rating >= 4.5,
  39. Reviews >= 50.
  40.  
  41. % 「評価が4.8以上」という「超高評価」な商品もおすすめとする
  42. recommended(Item) :-
  43. product(Item, _, Rating, _),
  44. Rating >= 4.8.
  45.  
  46. :- main.
Success #stdin #stdout #stderr 0.03s 6392KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/YW9AVR/prog:18:16: Syntax error: Operator expected
Warning: /home/YW9AVR/prog:29:
	Clauses of product/4 are not together in the source-file
	  Earlier definition at /home/YW9AVR/prog:2
	  Current predicate: process/0
	  Use :- discontiguous product/4. to suppress this message
Warning: /home/YW9AVR/prog:37:
	Clauses of recommended/1 are not together in the source-file
	  Earlier definition at /home/YW9AVR/prog:10
	  Current predicate: product/4
	  Use :- discontiguous recommended/1. to suppress this message