Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions 149.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sys
for x in open(sys.argv[1]):
o=''
for s,m,l,n in zip('IXCM','VLD.','XCM.',x[:-1][::-1]):
n=int(n)+1
f=n%5-1
if n>9:
m=l
o+=s*f+m*(n>4)+s*(-f)
print(o[::-1])
10 changes: 10 additions & 0 deletions 152.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sys
for x in open(sys.argv[1]):
o=''
for s,m,l,n in zip('IXCM','VLD.','XCM.',x.strip()[::-1]):
n=int(n)+1
f=n%5-1
if n>9:
m=l
o+=s*f+m*(n>4)+s*(-f)
print(o[::-1])
101 changes: 20 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,23 @@
# What is Code Golf?
# How to kill a joke
### ...or Jason really is the smarter one here

> Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that solves a certain problem. Code golf challenges and tournaments may also be named with the programming language used. --- [Wikipedia](https://en.wikipedia.org/wiki/Code_golf)
Contains three submissions. Please grade according to your understanding of the rules.

# Rules

1. Submit code you wrote. Don't reuse someone else's code.
2. **NO AI**
3. Don't Google/Bing/DDG/Kagi for answers.
4. All pull requests must be opened before Aug 14 2025 11:30 AM EDT.


The shortest _correct_ program wins. In the event no submissions fully pass the test suite winners will be selected by number of passing test cases and code brevity.

## Supported Languages

* C#
* Python
* Go
* Typescript/Javascript

# The Problem

Convert numbers written with Arabic numerals into Roman numerals.

| Arabic | Roman |
| -----: | ----: |
| 1 | I |
| 2 | II |
| 3 | III |
| 4 | IV |
| 5 | V |
| 10 | X |
| 20 | XX |
| 25 | XXV |
| 30 | XXX |
| 40 | XL |
| 50 | L |
| 100 | C |
| 200 | CC |
| 400 | CD |
| 500 | D |
| 1000 | M |

## Example Conversions

`27` → `XXVII`

`238` → `CCXXXVIII`

`2019` → `MMXIX`

# Submission Requirements

All submissions should expect to be invoked from the command line with a single argument, the path to a text file. This file will contain 5 numbers written using Arabic numerals. Numbers are separated by a newline (`\n`). Submissions are expected to iterate over the numbers printing the Roman numeral translation for each to the console/stdout.

## Example

```python
import sys


def main():
# Exit with error status if no filename provided
if len(sys.argv) < 1:
print("Filename missing!")
sys.exit(1)

print(f"Input file: {sys.argv[0]}")
# Open the file for reading
with open(sys.argv[1], "r") as fd:
line = fd.readline().strip()
while line != "":
# Convert line to Roman numeral
print(line)
line = fd.readline().strip()


if __name__ == "__main__":
main()
If input files **never** contain trailing spaces, only digits separated by newlines:
```sh
$ python3 149.py <<filename>>
```

This repo contains a [sample file](https://github.com/kevsmith/code_golf/blob/main/input.txt) you can use for development.

If input files **can** contain trailing spaces, and lines need to be stripped before parsing:
```sh
$ python3 152.py <<filename>>
```
If whitespace truly doesn't count, no matter what:
```sh
$ python3 cheating.py <<filename>>
```
If you don't want to run an `exec` blob for fear of having a rootkit installed, and would instead like to compile your own whitespace bomb:
```sh
$ python3 how_to_cheat.py 152.py > runme.py
$ python3 runme.py <<filename>>
```
You can also swap the `exec` for `print` to see what you'll be running before you run it.
1 change: 1 addition & 0 deletions cheating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec(int( ' '.translate({32:48,9:49}),2).to_bytes(length=223).decode())
5 changes: 5 additions & 0 deletions how_to_cheat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys
with open(sys.argv[1]) as f:
filebytes = f.read().encode()
fileint = int.from_bytes(filebytes, 'big')
print(f"exec(int( '{str(bin(fileint))[2:].replace('0', ' ').replace('1', '\t')}'.translate({{32:48,9:49}}),2).to_bytes(length={len(filebytes)}).decode())", end='')