home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / symmetric < prev    next >
Text File  |  2020-01-01  |  2KB  |  84 lines

  1. # From: "Dat Nguyen" <thucdat@hotmail.com>
  2. # Subject: Logic Programming in C-Kermit
  3. # Date: Sat, 08 May 2004 15:36:29 -0400
  4. #
  5. # Patterns and Inference Engines.
  6. #
  7. define symmetric {
  8.     if > \find({\%2},\m(\%1.contain)) 0 {
  9.         echo Relation \%1 \%2 already defined
  10.         return 1
  11.     }
  12.     local \&z[]
  13.     void \fsplit(\%2,&z,{,})
  14.     if > \farraylook(who,&z) -1 {
  15.         echo Cannot relate with who
  16.         return 0
  17.     }
  18.     _define \%1 1
  19.     _asg \%1.contain \m(\%1.contain)|\%2|
  20.     return 1
  21. }
  22.  
  23. define prove {
  24.     if not define \m(\%1) {
  25.         echo Relation \%1 does not exist
  26.         return 0
  27.     }
  28.     local \%n \&w[] \&z[]
  29.     asg \%n \fsplit(\m(\%1.contain),&w,|)
  30.     void \fsplit(\%2,&z,{,})
  31.     if > \farraylook(\%2,&w) -1 {
  32.         echo Yes
  33.         return 1
  34.     } else if > \farraylook({\&z[2],\&z[1]},&w) -1 {
  35.         echo Yes
  36.         return 1
  37.     } else if > \find(\&z[2],who) 0 {
  38.         local \%f \%i
  39.         asg \%f 0
  40.         for \%i 1 \%n 1 {
  41.             if > \find(\&z[1],\&w[\%i]) 0 {
  42.                 echo Who = \freplace(\freplace(\&w[\%i],\&z[1]),{,})
  43.                 asg \%f 1
  44.             }
  45.         }
  46.         return \%f
  47.     } else {
  48.         echo No
  49.         return 0
  50.     }
  51. }
  52.  
  53. ###############################################################################
  54.  
  55. # In a typical soccer tournament, the following matches are usual:
  56. symmetric playsoccer Brazil,Italy
  57. symmetric playsoccer Germany,Italy
  58. symmetric playsoccer England,Brazil
  59. symmetric playsoccer England,Germany
  60. symmetric playsoccer Italy,Germany
  61. symmetric playsoccer Holland,Germany
  62. symmetric playsoccer France,Italy
  63. symmetric playsoccer England,France
  64.  
  65. # In a chess tournament, the following encounters are possible:
  66. symmetric playchess Karpov,Kasparov
  67. symmetric playchess Leko,Kasparov
  68. symmetric playchess Leko,Kramnik
  69. symmetric playchess Karpov,Kramnik
  70. symmetric playchess Annand,Kramnik
  71. symmetric playchess Leko,Karpov
  72. symmetric playchess Ponomariov,Karpov
  73. symmetric playchess Polga,Karpov
  74. symmetric playchess Leko,Polga
  75.  
  76. # In a party, the following pairs would happen:
  77. symmetric danceWith Jane,Robert
  78. symmetric danceWith Jennifer,Mark
  79. symmetric danceWith Mary,John
  80. symmetric danceWith Mary,Robert
  81. symmetric danceWith Suzie,George
  82. symmetric danceWith Kevin,Carol
  83. symmetric danceWith Mark,Carol
  84.