Skip to content

Commit f6d87e1

Browse files
Luke Skrzypek - Submission #2
Switched to Python (included previous Javascript and C# attempts for posterity)
1 parent 5a2d2e1 commit f6d87e1

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import sys
2+
def F(n,c):
3+
return((((c[::2],c[1]+c[0]*(n-5))[n<9]),c[:2])[n==4],c[0]*n)[n<4]
4+
for s in open(sys.argv[1]):
5+
n=int(s)
6+
print(n//1000*'M'+F(n//100%10,'CDM')+F(n//10%10,'XLC')+F(n%10,'IVX'))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
o=require('fs')
22
F=(n,f,i,d)=>n<4?f.repeat(n):n==4?f+i:n<9?i+f.repeat(n-5):f+d
3-
o.readFileSync(process.argv[2],'utf8').split('\n').forEach(x=>{n=-(-x)
4-
console.log('M'.repeat(n/1e3|0)+F(n/100%10|0,'C','D','M')+F(n/10%10|0,'X','L','C')+F(n%10|0,'I','V','X'))})
3+
o.readFileSync(process.argv[2],'utf8').split('\n').forEach(x=>n=-(-x)
4+
console.log('M'.repeat(n/1e3|0)+F(n/100%10|0,'C','D','M')+F(n/10%10|0,'X','L','C')+F(n%10|0,'I','V','X')))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
using S=string;var F=(int n,char f,char i,S d)=>n<4?new S(f,n):n==4?$"{f}{i}":n<9?i+new S(f,n-5):d;File.ReadAllText(args[0]).Split('\n').ToList().ForEach(l=>{var n=int.Parse(l);Console.WriteLine($"{new S('M',n/1000)}{F(n/100%10,'C','D',"CM")}{F(n/10%10,'X','L',"XC")}{F(n%10,'I','V',"IX")}");});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

Luke Skrzypek Submission/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
Requires node to be installed.
1+
This includes all three of my attempts with the main one (shortest) being the one in `1- Python`.
2+
The others have been included for posterity :)
23

3-
4-
Usage:
5-
`node RomanNumerals.js <FullInputFilePath>`
4+
1) Python: `python RomanNumeralsPython.py <file>` - 185 chars without spaces
5+
2) Javascript: `node RomanNumerals.js <file>` - 251 chars without spaces
6+
3) C#: `dotnet build RomanNumerals.csproj` - 288 chars without spaces

0 commit comments

Comments
 (0)