diff --git a/149.py b/149.py new file mode 100644 index 0000000..2201ee8 --- /dev/null +++ b/149.py @@ -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]) diff --git a/152.py b/152.py new file mode 100644 index 0000000..ed72cdf --- /dev/null +++ b/152.py @@ -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]) diff --git a/README.md b/README.md index f7fdde3..fbcf23e 100644 --- a/README.md +++ b/README.md @@ -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 <> ``` - -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 <> +``` +If whitespace truly doesn't count, no matter what: +```sh +$ python3 cheating.py <> +``` +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 <> +``` +You can also swap the `exec` for `print` to see what you'll be running before you run it. diff --git a/cheating.py b/cheating.py new file mode 100644 index 0000000..2d3f221 --- /dev/null +++ b/cheating.py @@ -0,0 +1 @@ +exec(int( ' '.translate({32:48,9:49}),2).to_bytes(length=223).decode()) diff --git a/how_to_cheat.py b/how_to_cheat.py new file mode 100644 index 0000000..4cbaa4b --- /dev/null +++ b/how_to_cheat.py @@ -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='')