home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / spezial / 01 / pattern / bp4.pro < prev    next >
Encoding:
Text File  |  1987-06-05  |  2.7 KB  |  104 lines

  1. /***********************************************
  2.          Programm BP4: int_roman 
  3. ************************************************/
  4.  
  5. include "MATCH.1" 
  6. include "MATCH.2" 
  7.  
  8. predicates
  9.   literal(symbol, stringlist) 
  10.   int_roman(string, string)
  11.   replace(string, string)
  12.   equiv(string, string)
  13.   ten(string, string)    
  14.   konvert(char,string)
  15.   main
  16.   repeat
  17.  
  18. goal
  19.   main.
  20. include "MATCH.3"
  21.  
  22. clauses
  23.   literal(romans, ["IV", "IX", "XL", "XC", "CD", "CM", 
  24.                    "M", "D", "C", "L", "X", "V", "I" ] ).
  25.   
  26.   equiv("0","").      equiv("1","I").   equiv("2","II").
  27.   equiv("3","III").   equiv("4","IV").  equiv("5","V").
  28.   equiv("6","VI").    equiv("7","VII"). equiv("8","VIII").
  29.   equiv("9","IX").    equiv("10","X").
  30.   equiv("40","XL").   equiv("50","L"). 
  31.   equiv("90","XC").   equiv("100","C").  
  32.   equiv("400","CD").  equiv("500","D").  
  33.   equiv("900","CM").  equiv("1000","M").
  34.   
  35.   ten("I","X").  ten("V","L").  ten("X","C").
  36.   ten("L","D").  ten("C","M").  ten("D","*").
  37.   ten("M","*").  ten("*","*").
  38.  
  39.   replace("0",""):-!.
  40.   replace("",""):- !.
  41.   replace(A, B) :-
  42.     frontstr(1, A, X, Rest),
  43.     ten(X, X1),
  44.     replace(Rest, Rest1),
  45.     concat(X1, Rest1, B).
  46.  
  47.   int_roman("0",""):- !.
  48.   int_roman("","0"):- !.
  49.   int_roman(N, Roman) :-
  50.     bound(N), !,
  51.     match(N, [rtab(1), len(1)], [Rest, T]),
  52.     equiv(T, RX),
  53.     int_roman(Rest, RomRest),
  54.     replace(RomRest, Rom1),
  55.     concat(Rom1, RX, Roman).
  56.   int_roman(N, R) :-
  57.     bound(R), 
  58.     literal(romans, Rom),
  59.     match(R, [any(Rom), rtab(0)], [A, Rest]),
  60.     equiv(N1, A),
  61.     int_roman(N2, Rest),
  62.     str_int(N2, N2N),
  63.     str_int(N1, N1N),
  64.     NN = N1N + N2N,
  65.     str_int(N, NN).
  66.  
  67.   main :-
  68.     makewindow(1,7,7,"DEZIMAL - ROEMISCH",0,0,25,80),     
  69.     repeat,
  70.     clearwindow,
  71.     write("## Wahl der Konvertierungsrichtung ##"), 
  72.     nl, nl,
  73.     write("  A   Dezimal  --> Roemisch"), nl,
  74.     write("  B   Roemisch --> Dezimal"), nl, nl,
  75.     write("(Ende mit <Ctrl-Break>)"),
  76.     readchar(Inp),
  77.     nl, nl,
  78.     write("  Zu transformierende Zahl: "),
  79.     readln(Param),
  80.     konvert(Inp,Param),
  81.     fail.
  82.  
  83.   konvert('a',Param) :-
  84.     int_roman(Param,Res), !,
  85.     nl, nl,
  86.     write("Roemisches Aequivalent von ",
  87.           Param," ist ",Res             ),
  88.     readchar(_).
  89.   konvert('A',Param) :-
  90.     konvert('a',Param), !.
  91.   konvert('b',Param) :-
  92.     int_roman(Res,Param), !,
  93.     nl, nl,
  94.     write("Dezimales Aequivalent von ",
  95.           Param," ist ",Res             ),
  96.     readchar(_).
  97.   konvert('B',Param) :-
  98.     konvert('b',Param), !.
  99.   
  100.             
  101.   repeat.
  102.   repeat:- repeat.    
  103. /************** Ende BP4 **********************/
  104.