source: applications/trunk/UGPSummerSchool2008/src/Alien.rf @ 3836

Last change on this file since 3836 was 3836, checked in by yura, 12 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 937 bytes
Line 
1$module Alien;
2
3$use StdIO Access Arithm Dos;
4
5$func ToInt (e.system) (e.number) = s.int;
6$func FromInt e.system s.int = e.number;
7
8ToInt (e.system) (e.number) =
9        <Length e.system> :: s.base,
10        0 e.number $iter {
11                e.number : s.d e.number2 = e.system : e.head s.d e.tail,
12                        <Add <Mult s.int s.base> <Length e.head>> e.number2;           
13        } :: s.int e.number, e.number :, s.int;
14
15FromInt e.system s.int =
16        <Length e.system> :: s.base,
17        <DivRem s.int s.base> :: s.quo s.rem,
18        { s.quo : 0 = ; <FromInt e.system s.quo>;} :: ex,
19        ex <L s.rem e.system >;
20
21$func Main = e;
22
23Main = <Channel> :: s.in, <Channel> :: s.out,
24        <OpenFile s.in <Arg 1> "R">,
25        <OpenFile s.out <Arg 2> "W">,
26        <ReadLineCh s.in> : e,
27        1 $iter {
28                <ReadLineCh s.in> : ex, <WriteLn ex>, ex: e.n ' ' e.inf ' ' e.outf,
29                        <PrintLnCh s.out 'Case #'s.i': '<FromInt e.outf <ToInt (e.inf) (e.n)>>>,
30                        <Add s.i 1>;
31                <CloseChannel s.in> <CloseChannel s.out><Exit 0>, -1;
32        } :: s.i, $fail;
Note: See TracBrowser for help on using the repository browser.