Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
18
Task/Roman-numerals-Decode/ECL/roman-numerals-decode-1.ecl
Normal file
18
Task/Roman-numerals-Decode/ECL/roman-numerals-decode-1.ecl
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
MapChar(STRING1 c) := CASE(c,'M'=>1000,'D'=>500,'C'=>100,'L'=>50,'X'=>10,'V'=>5,'I'=>1,0);
|
||||
|
||||
RomanDecode(STRING s) := FUNCTION
|
||||
dsS := DATASET([{s}],{STRING Inp});
|
||||
R := { INTEGER2 i; };
|
||||
|
||||
R Trans1(dsS le,INTEGER pos) := TRANSFORM
|
||||
SELF.i := MapChar(le.Inp[pos]) * IF ( MapChar(le.Inp[pos]) < MapChar(le.Inp[pos+1]), -1, 1 );
|
||||
END;
|
||||
|
||||
RETURN SUM(NORMALIZE(dsS,LENGTH(TRIM(s)),Trans1(LEFT,COUNTER)),i);
|
||||
END;
|
||||
|
||||
RomanDecode('MCMLIV'); //1954
|
||||
RomanDecode('MCMXC'); //1990
|
||||
RomanDecode('MMVIII'); //2008
|
||||
RomanDecode('MDCLXVI'); //1666
|
||||
RomanDecode('MDLXVI'); //1566
|
||||
41
Task/Roman-numerals-Decode/ECL/roman-numerals-decode-2.ecl
Normal file
41
Task/Roman-numerals-Decode/ECL/roman-numerals-decode-2.ecl
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
IMPORT STD;
|
||||
RomanDecode(STRING s) := FUNCTION
|
||||
SetWeights := [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
|
||||
SetSymbols := ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
|
||||
ProcessRec := RECORD
|
||||
UNSIGNED val;
|
||||
STRING Roman;
|
||||
END;
|
||||
dsSymbols := DATASET(13,TRANSFORM(ProcessRec,SELF.Roman := s, SELF := []));
|
||||
|
||||
RECORDOF(dsSymbols) XF(dsSymbols L, dsSymbols R, INTEGER C) := TRANSFORM
|
||||
ThisRoman := IF(C=1,R.Roman,L.Roman);
|
||||
IsDone := ThisRoman = '';
|
||||
Repeatable := C IN [1,5,9,13];
|
||||
SymSize := IF(C % 2 = 0, 2, 1);
|
||||
IsNext := STD.Str.StartsWith(ThisRoman,SetSymbols[C]);
|
||||
SymLen := IF(IsNext,
|
||||
IF(NOT Repeatable,
|
||||
SymSize,
|
||||
MAP(NOT IsDone AND ThisRoman[1] = ThisRoman[2] AND ThisRoman[1] = ThisRoman[3] => 3,
|
||||
NOT IsDone AND ThisRoman[1] = ThisRoman[2] => 2,
|
||||
NOT IsDone => 1,
|
||||
0)),
|
||||
0);
|
||||
|
||||
SymbolWeight(STRING s) := IF(NOT Repeatable,
|
||||
SetWeights[C],
|
||||
CHOOSE(LENGTH(s),SetWeights[C],SetWeights[C]*2,SetWeights[C]*3,0));
|
||||
|
||||
SELF.Roman := IF(IsDone,ThisRoman,ThisRoman[SymLen+1..]);
|
||||
SELF.val := IF(IsDone,L.val,L.Val + IF(IsNext,SymbolWeight(ThisRoman[1..SymLen]),0));
|
||||
END;
|
||||
i := ITERATE(dsSymbols,XF(LEFT,RIGHT,COUNTER));
|
||||
RETURN i[13].val;
|
||||
END;
|
||||
|
||||
RomanDecode('MCMLIV'); //1954
|
||||
RomanDecode('MCMXC'); //1990
|
||||
RomanDecode('MMVIII'); //2008
|
||||
RomanDecode('MDCLXVI'); //1666
|
||||
RomanDecode('MDLXVI'); //1566
|
||||
Loading…
Add table
Add a link
Reference in a new issue