From 9fd2918b0fc3dda166a4de058143b081c85a73ef Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Tue, 12 Aug 2025 16:27:12 -0400 Subject: [PATCH 01/17] submission #1 --- 177.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 177.py diff --git a/177.py b/177.py new file mode 100644 index 0000000..b2eabc3 --- /dev/null +++ b/177.py @@ -0,0 +1,9 @@ +import sys +o = '' +for x in open(sys.argv[1]).read()[::-1].split('\n'): + for s, m, l, n in zip('IXCM', 'VLD.', 'XCM.', x): + n = int(n) + f = n % 5 + o += s * f * (f < 4) + (m if n < 9 else l) * (n > 3) + s * (f == 4) + o += '\n' +print(o[::-1]) From 7db81d9573a5136ba21dd3919533375cb8307202 Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Tue, 12 Aug 2025 16:46:15 -0400 Subject: [PATCH 02/17] Update and rename 177.py to 180.py --- 177.py => 180.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename 177.py => 180.py (93%) diff --git a/177.py b/180.py similarity index 93% rename from 177.py rename to 180.py index b2eabc3..0141ac3 100644 --- a/177.py +++ b/180.py @@ -6,4 +6,4 @@ f = n % 5 o += s * f * (f < 4) + (m if n < 9 else l) * (n > 3) + s * (f == 4) o += '\n' -print(o[::-1]) +print(o[-2:1:-1]) From 8dbc266f343fb61e7157275a4df2e54e83f3ceff Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 09:36:26 -0400 Subject: [PATCH 03/17] Fix bug with last character stripping --- 180.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/180.py b/180.py index 0141ac3..c215b17 100644 --- a/180.py +++ b/180.py @@ -6,4 +6,4 @@ f = n % 5 o += s * f * (f < 4) + (m if n < 9 else l) * (n > 3) + s * (f == 4) o += '\n' -print(o[-2:1:-1]) +print(o[-2:0:-1]) From 0b608ef98c1c341a9a83ef123a44f3bf0f051d70 Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 09:49:09 -0400 Subject: [PATCH 04/17] Update and rename 180.py to 156.py, fix empty file bug --- 156.py | 8 ++++++++ 180.py | 9 --------- 2 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 156.py delete mode 100644 180.py diff --git a/156.py b/156.py new file mode 100644 index 0000000..168bf7c --- /dev/null +++ b/156.py @@ -0,0 +1,8 @@ +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) + f = n % 5 + o += s * f * (f < 4) + (m if n < 9 else l) * (n > 3) + s * (f == 4) + print(o[::-1]) diff --git a/180.py b/180.py deleted file mode 100644 index c215b17..0000000 --- a/180.py +++ /dev/null @@ -1,9 +0,0 @@ -import sys -o = '' -for x in open(sys.argv[1]).read()[::-1].split('\n'): - for s, m, l, n in zip('IXCM', 'VLD.', 'XCM.', x): - n = int(n) - f = n % 5 - o += s * f * (f < 4) + (m if n < 9 else l) * (n > 3) + s * (f == 4) - o += '\n' -print(o[-2:0:-1]) From 33eef030fb75cc520c3f7163a31ce1a1edd259de Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 12:38:11 -0400 Subject: [PATCH 05/17] Update and rename 156.py to 154.py --- 154.py | 8 ++++++++ 156.py | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 154.py delete mode 100644 156.py diff --git a/154.py b/154.py new file mode 100644 index 0000000..8e5f667 --- /dev/null +++ b/154.py @@ -0,0 +1,8 @@ +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) + f=(n+1)%5-1 + o+=s*f+(m if n<9 else l)*(n>3)+s*(-f) + print(o[::-1]) diff --git a/156.py b/156.py deleted file mode 100644 index 168bf7c..0000000 --- a/156.py +++ /dev/null @@ -1,8 +0,0 @@ -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) - f = n % 5 - o += s * f * (f < 4) + (m if n < 9 else l) * (n > 3) + s * (f == 4) - print(o[::-1]) From aacddb9cbe0219722a641dc85d743beb07823433 Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 14:41:42 -0400 Subject: [PATCH 06/17] Update and rename 154.py to 153.py --- 154.py => 153.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename 154.py => 153.py (60%) diff --git a/154.py b/153.py similarity index 60% rename from 154.py rename to 153.py index 8e5f667..072c495 100644 --- a/154.py +++ b/153.py @@ -2,7 +2,7 @@ for x in open(sys.argv[1]): o='' for s,m,l,n in zip('IXCM','VLD.','XCM.',x[:-1][::-1]): - n=int(n) - f=(n+1)%5-1 - o+=s*f+(m if n<9 else l)*(n>3)+s*(-f) + n=int(n)+1 + f=n%5-1 + o+=s*f+(m if n<10 else l)*(n>4)+s*(-f) print(o[::-1]) From 15f429f8b312b7244b2cf7ba85a4a2ad660a8fd2 Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 14:45:45 -0400 Subject: [PATCH 07/17] swap to tabs --- 153.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/153.py b/153.py index 072c495..505f2df 100644 --- a/153.py +++ b/153.py @@ -1,8 +1,8 @@ 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 - o+=s*f+(m if n<10 else l)*(n>4)+s*(-f) - print(o[::-1]) + o='' + for s,m,l,n in zip('IXCM','VLD.','XCM.',x[:-1][::-1]): + n=int(n)+1 + f=n%5-1 + o+=s*f+(m if n<10 else l)*(n>4)+s*(-f) + print(o[::-1]) From f79b98fe02aca0b63afc8e6f7b1ee8946b838cc9 Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 14:55:21 -0400 Subject: [PATCH 08/17] Update and rename 153.py to 152.py --- 153.py => 152.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename 153.py => 152.py (77%) diff --git a/153.py b/152.py similarity index 77% rename from 153.py rename to 152.py index 505f2df..a7bc8b7 100644 --- a/153.py +++ b/152.py @@ -4,5 +4,5 @@ for s,m,l,n in zip('IXCM','VLD.','XCM.',x[:-1][::-1]): n=int(n)+1 f=n%5-1 - o+=s*f+(m if n<10 else l)*(n>4)+s*(-f) + o+=s*f+(l if n>9 else m)*(n>4)+s*(-f) print(o[::-1]) From a455133907f621493741eb082be3b15b37a71341 Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 20:36:10 -0400 Subject: [PATCH 09/17] Create 155.py --- 155.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 155.py diff --git a/155.py b/155.py new file mode 100644 index 0000000..5fc3c25 --- /dev/null +++ b/155.py @@ -0,0 +1,8 @@ +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 + o+=s*f+(l if n>9 else m)*(n>4)+s*(-f) + print(o[::-1]) From 61549f6218fbeb6b13b799ee7a264e812c5932cb Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 20:36:50 -0400 Subject: [PATCH 10/17] Create cheating.py --- cheating.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 cheating.py diff --git a/cheating.py b/cheating.py new file mode 100644 index 0000000..e551e05 --- /dev/null +++ b/cheating.py @@ -0,0 +1 @@ +exec(int( ' '.translate({32:48,9:49}),2).to_bytes(length=226).decode()) From 9f875f007a343efb69e1e2e68f9ab265968d78cd Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 20:38:03 -0400 Subject: [PATCH 11/17] Update cheating.py --- cheating.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheating.py b/cheating.py index e551e05..2d3f221 100644 --- a/cheating.py +++ b/cheating.py @@ -1 +1 @@ -exec(int( ' '.translate({32:48,9:49}),2).to_bytes(length=226).decode()) +exec(int( ' '.translate({32:48,9:49}),2).to_bytes(length=223).decode()) From 0f539a74e5754b8c5657faf5c4850f01b6fc3d61 Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 20:42:54 -0400 Subject: [PATCH 12/17] Create how_to_cheat.py --- how_to_cheat.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 how_to_cheat.py 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='') From c5982097348497b809fbf52066eea54837e3c981 Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 20:47:36 -0400 Subject: [PATCH 13/17] Update README.md --- README.md | 100 +++++++++++------------------------------------------- 1 file changed, 19 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index f7fdde3..7ea77e7 100644 --- a/README.md +++ b/README.md @@ -1,84 +1,22 @@ -# 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 152.py <> +``` +If input files **can** contain trailing spaces, and lines need to be stripped before parsing: +```sh +$ python3 155.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 155.py > runme.py +$ python3 runme.py <> ``` - -This repo contains a [sample file](https://github.com/kevsmith/code_golf/blob/main/input.txt) you can use for development. - From 1191f317455089465d258b2a6dc0f07b73b4347d Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Wed, 13 Aug 2025 20:48:45 -0400 Subject: [PATCH 14/17] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ea77e7..d4326d3 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,9 @@ 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: +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 155.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. From a9737b0fb4489f9694d0f6d54bd06b5e47904001 Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Thu, 14 Aug 2025 11:22:30 -0400 Subject: [PATCH 15/17] Update and rename 152.py to 149.py --- 152.py => 149.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename 152.py => 149.py (77%) diff --git a/152.py b/149.py similarity index 77% rename from 152.py rename to 149.py index a7bc8b7..2201ee8 100644 --- a/152.py +++ b/149.py @@ -4,5 +4,7 @@ for s,m,l,n in zip('IXCM','VLD.','XCM.',x[:-1][::-1]): n=int(n)+1 f=n%5-1 - o+=s*f+(l if n>9 else m)*(n>4)+s*(-f) + if n>9: + m=l + o+=s*f+m*(n>4)+s*(-f) print(o[::-1]) From 24966ed8c3577ee475880e28632c3faa5190d63f Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Thu, 14 Aug 2025 11:23:20 -0400 Subject: [PATCH 16/17] Update and rename 155.py to 152.py --- 155.py => 152.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename 155.py => 152.py (77%) diff --git a/155.py b/152.py similarity index 77% rename from 155.py rename to 152.py index 5fc3c25..ed72cdf 100644 --- a/155.py +++ b/152.py @@ -4,5 +4,7 @@ for s,m,l,n in zip('IXCM','VLD.','XCM.',x.strip()[::-1]): n=int(n)+1 f=n%5-1 - o+=s*f+(l if n>9 else m)*(n>4)+s*(-f) + if n>9: + m=l + o+=s*f+m*(n>4)+s*(-f) print(o[::-1]) From bbffaf5c99174cca9d5be81115a9b9e154eb33aa Mon Sep 17 00:00:00 2001 From: Quaker Schneider Date: Thu, 14 Aug 2025 11:23:51 -0400 Subject: [PATCH 17/17] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d4326d3..fbcf23e 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ Contains three submissions. Please grade according to your understanding of the If input files **never** contain trailing spaces, only digits separated by newlines: ```sh -$ python3 152.py <> +$ python3 149.py <> ``` If input files **can** contain trailing spaces, and lines need to be stripped before parsing: ```sh -$ python3 155.py <> +$ python3 152.py <> ``` If whitespace truly doesn't count, no matter what: ```sh @@ -17,7 +17,7 @@ $ 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 155.py > runme.py +$ 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.