Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Roman-numerals-Encode/Jq/roman-numerals-encode-1.jq
Normal file
32
Task/Roman-numerals-Encode/Jq/roman-numerals-encode-1.jq
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
def to_roman_numeral:
|
||||
def romans:
|
||||
[100000, "\u2188"],
|
||||
[90000, "ↂ\u2188"],
|
||||
[50000, "\u2187"],
|
||||
[40000, "ↂ\u2187"],
|
||||
[10000, "ↂ"],
|
||||
[9000, "Mↂ"],
|
||||
[5000, "ↁ"],
|
||||
[4000, "Mↁ"],
|
||||
[1000, "M"],
|
||||
[900, "CM"],
|
||||
[500, "D"],
|
||||
[400, "CD"],
|
||||
[100, "C"],
|
||||
[90, "XC"],
|
||||
[50, "L"],
|
||||
[40, "XL"],
|
||||
[10, "X"],
|
||||
[9, "IX"],
|
||||
[5, "V"],
|
||||
[4, "IV"],
|
||||
[1, "I"] ;
|
||||
|
||||
if . < 1 or . > 399999
|
||||
then "to_roman_numeral: \(.) is out of range" | error
|
||||
else reduce romans as [$i, $r] ({n: .};
|
||||
until (.n < $i;
|
||||
.res += $r
|
||||
| .n = .n - $i ) )
|
||||
| .res
|
||||
end ;
|
||||
5
Task/Roman-numerals-Encode/Jq/roman-numerals-encode-2.jq
Normal file
5
Task/Roman-numerals-Encode/Jq/roman-numerals-encode-2.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def testcases: [1668, 1990, 2008, 2020, 4444, 5000, 8999, 39999, 89999, 399999];
|
||||
|
||||
"Decimal => Roman:",
|
||||
(testcases[]
|
||||
| " \(.) => \(to_roman_numeral)" )
|
||||
19
Task/Roman-numerals-Encode/Jq/roman-numerals-encode-3.jq
Normal file
19
Task/Roman-numerals-Encode/Jq/roman-numerals-encode-3.jq
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
def digits: tostring | explode | map( [.]|implode|tonumber);
|
||||
# Non-negative integer to Roman numeral up to 399,999
|
||||
def to_roman_numeral:
|
||||
if . < 1 or . > 399999
|
||||
then "to_roman_numeral: \(.) is out of range" | error
|
||||
else [["I", "X", "C", "M", "ↂ", "\u2188"], ["V", "L", "D", "ↁ", "\u2187"]] as $DR
|
||||
| (digits|reverse) as $digits
|
||||
| reduce range(0;$digits|length) as $omag ({rnum: ""};
|
||||
$digits[$omag] as $d
|
||||
| if $d == 0 then .omr = ""
|
||||
elif $d < 4 then .omr = $DR[0][$omag] * $d
|
||||
elif $d == 4 then .omr = $DR[0][$omag] + $DR[1][$omag]
|
||||
elif $d == 5 then .omr = $DR[1][$omag]
|
||||
elif $d < 9 then .omr = $DR[1][$omag] + ($DR[0][$omag] * ($d - 5))
|
||||
else .omr = $DR[0][$omag] + $DR[0][$omag+1]
|
||||
end
|
||||
| .rnum = .omr + .rnum )
|
||||
| .rnum
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue