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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"github.copilot.enable": {
"*": false
},
"prettier.enable": false,
"prettier.requireConfig": true
}
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Instructions for my repo

Install Node/NPM
`npm start`

# What is Code Golf?

> 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)
Expand All @@ -9,7 +14,6 @@
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
Expand Down Expand Up @@ -81,4 +85,3 @@ if __name__ == "__main__":
```

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

1 change: 1 addition & 0 deletions main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import * as fs from "fs";let p=[[1000,"M"],[900,'CM'],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"]],v,o,x,r,l='';for (l of fs.readFileSync(process.argv[2],'utf-8').split("\n")){v="I".repeat(0+l);o="";for([x,r]of p)while(v[x-1]){o+=r;v=v.slice(x)}console.log(o+v)}
49 changes: 49 additions & 0 deletions main.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {expect} from "vitest"
import {it, mock, vi, beforeEach} from "vitest"
import * as fs from "fs/promises"

vi.mock("fs", () => ({
readFileSync: () => `43
104
243
401
3277
90
449
1199
905
`
}))

const outputs = [
'XLIII',
'CIV',
'CCXLIII',
'CDI',
'MMMCCLXXVII',
'XC',
'CDXLIX',
'MCXCIX',
'CMV'
]

let log = vi.spyOn(console, "log")

it("produces the right output", async () => {
await import("./src.mjs")
for (let i = 0; i < outputs.length; i++) {
expect(log).toHaveBeenNthCalledWith(i + 1, outputs[i]);
}
})

it("produces the right output minified", async () => {
await import("./main.mjs")
for (let i = 0; i < outputs.length; i++) {
expect(log).toHaveBeenNthCalledWith(i + 1, outputs[i]);
}
})

it("golfs", async () => {
const content = await fs.readFile("./main.mjs", "utf-8")
expect(content.length).toMatchInlineSnapshot(`313`)
})
7 changes: 7 additions & 0 deletions min.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as fs from 'fs';


fs.watchFile('./src.mjs', { }, (cur) => {
const content = fs.readFileSync('./src.mjs', 'utf-8');
fs.writeFileSync('./main.mjs', content.replace(/\/\/.*$/gm,'').replace(/\n+/g, '').replace(/\t+/g,''));
})
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "code_golf",
"dependencies": {
"@types/node": "24.2.1"
},
"engines": {
"node": "24.5.0"
},
"volta": {
"node": "24.5.0"
},
"scripts": {
"test": "vitest",
"dev": "pnpm min && node ./main.mjs ./input.txt",
"start": "node ./main.mjs",
"min": "node ./min.mjs"
},
"devDependencies": {
"vitest": "^3.2.4"
}
}
Loading