<p align="center">
<picture>
<source media="(prefers-color-scheme: light)" srcset="assets/logo_light.svg">
<img alt="openleetcode" src="https://raw.githubusercontent.com/therepanic/openleetcode/HEAD/assets/logo_dark.svg" width="760">
</picture>
<br>
<em>"마법의 기계나 마법의 연산자는 없습니다." - DHH</em>
<br>
<br>
<a href="https://www.haskell.org/"><img alt="Made in Haskell" src="https://img.shields.io/badge/made%20in-Haskell-5e5086?style=flat"></a>
<a href="https://www.haskell.org/cabal/"><img alt="Build with Cabal" src="https://img.shields.io/badge/build-Cabal-1f6feb?style=flat"></a>
<a href="tests"><img alt="Supported problems" src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/therepanic/openleetcode/main/.badges/problems.json"></a>
<a href="https://github.com/therepanic/openleetcode/actions/workflows/ci.yml"><img alt="ci" src="https://img.shields.io/github/actions/workflow/status/therepanic/openleetcode/ci.yml?branch=main&label=ci&style=flat&logo=github&logoColor=white"></a>
<a href="https://unlicense.org"><img alt="License Unlicense" src="https://img.shields.io/badge/license-Unlicense-lightgrey?style=flat"></a>
</p>
openleetcode는 오픈 테스트 스위트(open test suites)를 기반으로 만들어진 로컬 LeetCode 러너이며, Haskell로 제작되었습니다.
일반적인 솔루션 파일(solution file)을 받아, 일치하는 문제 매니페스트(problem manifest)를 찾고, 작고 언어별 특화된 하네스(harness)를 구축하며, 이를 플러그인 가능한 실행 백엔드(pluggable execution backend)로 전송하여 로컬에서 결과를 판정합니다. 테스트는 레포지토리에 존재합니다. 런타임 템플릿 역시 레포지토리에 있습니다. CLI는 단순히 접착제 역할을 합니다.
$ openleetcode submit ./solution.py --id 1
$ openleetcode submit ./solution.rs --title two-sum
데모 (Demo)
<p align="center">
<img src="https://raw.githubusercontent.com/therepanic/openleetcode/HEAD/assets/demo.gif" alt="openleetcode demo" width="860">
</p>
설치 (Install)
실행 백엔드(execution backend)를 위해 Docker가 필요합니다. Linux 및 macOS에서는 설치 프로그램이 Docker Compose를 통해 기본 Piston 백엔드를 자동으로 시작하려고 시도할 것입니다. Windows의 경우, 설치 프로그램은 CLI만 설치합니다. 사용자가 직접 Docker를 가져와서 백엔드를 수동으로 시작해야 합니다.
Linux 및 macOS:
curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/install.sh | sh
Windows PowerShell:
irm https://raw.githubusercontent.com/therepanic/openleetcode/main/install.ps1 | iex
Docker:
curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/openleetcode.yml -o openleetcode.yml
curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/backends/piston/docker-compose.yml -o piston.yml
docker compose -f piston.yml up -d
...
백엔드는 첫 시작 시 런타임(runtimes)을 설치하는 데 시간이 걸릴 수 있습니다.
백엔드 (Backend)
openleetcode는 현재 실행 백엔드로 Piston을 사용합니다. 기본 설정은 다음을 가리킵니다:
체크아웃 후, 번들된 백엔드를 다음 명령으로 시작합니다:
docker compose -f backends/piston/docker-compose.yml up -d
그런 다음 CLI 설정을 확인합니다:
$ openleetcode config list
$ openleetcode config set backend.url http://localhost:2000
사용법 (Usage)
최신 공개 데이터 자산(public data assets)을 다운로드합니다:
$ openleetcode download all
문제 ID로 솔루션을 실행합니다:
$ openleetcode submit ./two_sum.py --id 1
제목으로 솔루션을 실행합니다:
$ openleetcode submit ./solution.cpp --title "two-sum"
파일 확장자가 모호할 때 언어 감지(language detection)를 재정의합니다:
$ openleetcode submit ./main.abc --id 1 --lang python3
openleetcode 업데이트:
언어 (Languages)
러너는 다음 언어에 대한 템플릿을 가지고 있습니다:
cpp, rust, python3, python2, ruby, java, csharp, kotlin, go, dart, swift, typescript
각 런타임은 LeetCode 문제가 필요로 하는 작은 호환성 계층(compatibility layer)을 제공합니다: JSON 출력, 배열(arrays), 행렬(matrices), 연결 리스트(linked lists), 이진 트리(binary trees) 등이 있습니다. 가져오기 및 공통 라이브러리는 공식 LeetCode 환경과 가깝게 유지되므로, 솔루션은 사용자 지정 openleetcode 프로그램이 아니라 일반적인 LeetCode 제출물처럼 보여야 합니다.
기여 (Contributing)
코드 변경을 위해서는 Cabal이 포함된 Haskell 툴체인(toolchain)이 필요합니다.
CLI 빌드:
$ cabal build exe:openleetcode
테스트 스위트 실행:
$ cabal test core-tests
$ cabal test cli-tests
빌드된 실행 파일 직접 실행:
코드 없이 기여하기 (Contributing Without Code)
[TEST_FORMAT.md]부터 시작하세요. 진심으로요. 이것은 YAML, 런타임 템플릿(runtime templates), 그리고 채점기(judge) 사이의 계약입니다.
모든 문제는 manifest.yaml을 가진 디렉토리로 구성됩니다:
tests/1-500/1. two-sum/manifest.yaml
tests/1-500/1. two-sum/sol.py
tests/1-500/1. two-sum/sol.cpp
또한 헬퍼 스크립트도 있습니다. 왜냐하면 우리 모두는 인간이고, 39번째 엣지 케이스(edge case)를 손으로 작성하는 것은 사람들이 스프레드시트를 가지고 흥정하기 시작하는 방식이기 때문입니다.
$ python generate_prompt.py two-sum
$ python spartan.py --skip 0 --limit 10 --no-generate --concurrency 5
$ python molotov.py --skip 0 --limit 10 --concurrency 5
generate_prompt.py는 문제 설명(statement), 코드 스니펫, 그리고 참고 Python 솔루션을 기반으로 하나의 LeetCode 문제에 대한 프롬프트를 생성합니다. spartan.py는 이를 배치(batches)로 처리하며, OPENROUTER_API_KEY가 설정되어 있으면 OpenRouter를 통해 manifests를 generated_problems/ 디렉토리에 초안 작성할 수 있습니다. molotov.py는 생성된 폴더에서 prompt.txt와 sol.py를 재사용하여 sol.{lang} 파일을 채웁니다. 이 출력을 무한한 인내심을 가진 주니어 기여자처럼 취급하세요: 유용하고, 빠르지만, 여전히 검토가 매우 필요한 상태입니다.
현황 (Status)
openleetcode는 아직 초기 단계이며, 일부 매니페스트(manifest)들은 다른 것들보다 더 좋을 수 있습니다. 이는 괜찮습니다. 중요한 점은 채점기(judge)와 테스트가 어딘가에 봉인되어 있지 않다는 것입니다.