GithubHelp home page GithubHelp logo

code-golf / code-golf Goto Github PK

View Code? Open in Web Editor NEW
1.1K 1.1K 102.0 14.52 MB

A game designed to let you show off your code-fu by solving problems in the least number of characters.

Home Page: https://code.golf

License: MIT License

Go 41.20% Shell 0.91% CSS 7.09% Dockerfile 11.01% C 4.42% HTML 9.58% Makefile 0.43% Raku 9.78% C# 1.37% F# 0.28% Nim 0.06% PLpgSQL 2.11% C++ 0.02% TypeScript 11.43% Perl 0.09% JavaScript 0.22%
hacktoberfest

code-golf's Introduction

Code Golf

This is the repository behind the website and community https://code.golf

Quickstart

Alternatively, see the Vagrant section below to create a virtual machine with everything pre-installed.

  1. Install dependencies:
  1. Install the local CA:
$ make cert
Using the local CA at "~/.local/share/mkcert" ✨
The local CA is now installed in the system trust store! ⚡️
The local CA is now installed in the Firefox and/or Chrome/Chromium trust store (requires browser restart)! 🦊


Created a new certificate valid for the following names 📜
 - "localhost"

The certificate is at "./localhost.pem" and the key at "./localhost-key.pem" ✅
  1. Install the NPM packages:

NOTE: if your host OS is not the same architecture / executable format as your Docker environment, this can result in incorrect format binaries installed into node_modules, so you may want to skip this step.

$ npm install
  1. Bring up the website:
$ make dev
  1. Optionally, load information from the code.golf database.
$ go run utils/update_sql_from_api.go
  1. Navigate to https://localhost

Hacking

Some of ancillary scripts are written in Raku, to run these ensure you have a recent install of Raku installed and use Zef to install the dependencies:

$ zef install --deps-only .

TypeScript

The js/ directory contains the TypeScript files which will be transpiled by esbuild into JavaScript files for serving. .tsx files can additionally make use of JSX.

Linting

Run make lint to lint the code before a pull request. This lints the TypeScript code, then the Go code.

In Visual Studio Code, the following settings are helpful for editor support for ESLint:

"eslint.validate": ["typescript", "typescriptreact"],
"eslint.format.enable": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint"

Testing

  1. Run the unit tests:
$ make test
  1. Run the e2e tests:
$ make e2e

Vagrant

Using Vagrant and VirtualBox, with one command you can create a virtual machine, install all of the other dependencies onto it (Docker, Docker Compose, Go, Raku + zef dependencies, npm, etc.), and forward port 443 (https) to it.

  1. Install the dependencies:

If you have homebrew, you can install with:

$ brew install vagrant virtualbox
  1. Create the virtual machine:
$ git config core.autocrlf false && git checkout utils/vagrant-bootstrap && vagrant up
  1. Install certificates. Ideally, you should run the following command outside of the virtual machine, the same as in the quickstart, because it will install the certificate in your browser. Alternatively, you can run the command in a virtual machine shell and then install the certificates manually.
$ make cert

or

$ vagrant ssh --command 'cd /vagrant/ && make cert'
  1. Bring up the website:
$ vagrant ssh --command 'cd /vagrant/ && make dev'
  1. Optionally, load information from the code.golf database.
$ vagrant ssh --command 'cd /vagrant/ && go run utils/update_sql_from_api.go'
  1. Navigate to https://localhost

Database Access

If you have PostgreSQL installed You can access the SQL database directly with the following command. If you are using Vagrant, PostgreSQL is pre-installed.

$ make db-dev

API

Validate API definition with vacuum.

Style

URL slugs are consistently abbreviated (e.g. cheevos, langs, stats) but page titles aren't (e.g. Achievements, Languages, Statistics).

Paginated URLs use a trailing number but only on pages after the first (e.g. /rankings/medals/all, /rankings/medals/all/2, etc.).

arm64/aarch64 Architecture (Ex: Apple Silicon)

If your machine has arm64 architecture, then there are a few options for running a local instance of the site. You can attempt to use QEMU emulation which is supported by Docker Desktop, but may be slower. The default when you make dev is that the docker images will be built with arm64 architecture.

You may be able to use some languages without building them locally. Here is a list of some of the languages that are able to run the sample code, without rebuilding individual docker containers: AWK Bash Berry Lua Perl PHP Python Raku Ruby sed SQL Wren

For other languages, you will need to build them locally. For example:

$ ./build-langs --no-push C

Otherwise, you may see the following error:

assertion failed [!result.is_error]: Unable to open /proc/sys/vm/mmap_min_addr
(VMAllocationTracker.cpp:281 init)
 signal: trace/breakpoint trap

code-golf's People

Contributors

akshatj27 avatar alemelis avatar andre-lameirinhas avatar andriamanitra avatar btnlq avatar commandblockguy avatar defterade avatar dependabot[bot] avatar edre avatar grayjoking avatar ian-h-chamberlain avatar irratix avatar jared-hughes avatar jayxon avatar jraspass avatar kg583 avatar lydxn avatar lynn avatar mewheni avatar michalmarsalek avatar mousetail avatar newdefectus avatar primo-ppcg avatar prplz avatar sirbogman avatar sisyphus-ppcg avatar stefangimmillaro avatar steffan153 avatar tfeld00 avatar yewzir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

code-golf's Issues

Create a local dev environment

  • Create a docker-compose.yml file, app & db
  • Have the db.sql be applied to the db container
  • Hack up TLS to work, probably needs a fake root cert being committed to the repo and added to browser
  • Add a README.md on how to run locally
  • App container will probably need to be privileged since it spawns its own containers

If this all works it'll be good enough, long term it would be nice to be able to update assets without having to rebuild the binary on dev, or at least detect the change and automatically rebuild.

Suggestion: Move code output to below editor

Right now, the STDERR and STDOUT appear above the explanation after pressing Run. This is usually fine, but on long questions like the morse encoder/decoder you have to scroll a fair way to check it. Also, on some browsers like Chrome, the page will jump around as new elements appear and disappear, which is a bit distracting. This can be solved by placing the console output at the bottom of the page, below the code editor itself.

Incorrect placement on leaderboard

My current Perl 6 solution for the emirps hole (49 bytes) shows as tied with a 50 byte solution at 13th place. When filtering by only Perl 6 solutions, it displays correctly.

I've also noticed xsot's 57 byte Ruby solution is also misplaced at 17th. Also solutions at 95th,125th, 128th, and 136th (last but not least)

Redesign the "hole" page

Redesign the "hole" page to be both lighter and fix some long standing issues.

Available to try on live by prefixing a hole with "ng/", e.g. https://code-golf.io/ng/divisors

I'll update master with force commits for the time being, this redesign might take awhile, don't expect "ng/" to always work.

TODO

  • Add a diff output view of STDOUT (#11)
  • Add Perl 6 syntax highlighting
  • Add prev/next/random hole button to the top right (#29)
  • Collapse unselected tabs down to just the logo to save space, expand on hover/selection.
  • Allow the hole description to be collapsed

DONE

  • Replace CodeMirror with CodeFlask
  • Move status below the code
  • Clearly show the different ARGV (#31)

stderr does not count?

It seems that the solution is correct even if there are some warnings in stderr. Is it supposed to be like this?

python quine not accepted

The quine r='r=%r;print(r%%r)';print(r%r) succesfully prints exactly itself to standard output, but is not accepted as a correct answer.

Broken Leaderboard

The Leaderboard is no long shown correctly when "All Holes" is selected

Brainfuck problem needs more detail

When trying the BF problem, my attempted solutions print only 1 line and nothing else. Trying the sample input in online BF interpreters also have similar issue - they print 1 line and the rest is garbled. Seems to me BF here makes some undocumented implications, like that memory cells are certain size (0-255 unsigned octets?! or what) or that the memory tape is invinite in right direction but stops at 0 on the left. Whatever the assumptions - that should be pointed out since not part of the BF "spec" (there is no ISO standard :) )

Stats page looks terrible in Firefox

Seriously, you can't even read anything. I've played around with the CSS a little bit, but I can't see an easy fix. Possibly an upstream issue in FF or Chart.js?

Add more entropy to brainfuck answers

My brainfuck solution that just encodes the answers in a lookup table is shorter than all the other entries. I suggest adding a test case that generates a long and difficult to generate blob of text.

Here is one example
Input: "+++++[>+++++[>++>++>+++>+++>++++>++++<<<<<<-]<-]+++++[>>[>]<[+.<<]>[++.>>>]<[+.<]>[-.>>]<[-.<<<]>[.>]<[+.<]<-]"
Output: "eL34NfeOL454KdeJ44JOdefePK55gQ67ShfTL787KegJ77JTeghfUK88iV9:XjgYL:;:KfiJ::JYfijgZK;;k[<=]lh^L=>=KgkJ==J^gklh_K>>m`?@bnicL@A@KhmJ@@JchmnidKAA"

It would also be nice to extend this hole to implement all of brainfuck and accept input. Either alternate code arguments with input arguments, or put code and input separated with a "!" for each argument, as I've seen some other sites do.

JS error when typing PHP tags

There is a JS error when I type the following PHP code:

?><?

The same error occurs if there is text between the tags:

?>foo bar<?

Screenshot:
js-error

Stack trace:

Uncaught TypeError: r.indent is not a function
    at Object.token (aVYNTJK5PuEMBYVX5U9kdw:429)
    at Ld (aVYNTJK5PuEMBYVX5U9kdw:43)
    at ze (aVYNTJK5PuEMBYVX5U9kdw:45)
    at ye (aVYNTJK5PuEMBYVX5U9kdw:41)
    at Ae (aVYNTJK5PuEMBYVX5U9kdw:42)
    at Fe (aVYNTJK5PuEMBYVX5U9kdw:48)
    at Ke (aVYNTJK5PuEMBYVX5U9kdw:60)
    at Vg (aVYNTJK5PuEMBYVX5U9kdw:60)
    at Ie (aVYNTJK5PuEMBYVX5U9kdw:58)
    at xh (aVYNTJK5PuEMBYVX5U9kdw:126)

Python Quine not validated correctly

I have tested a solution which should work and it says the solution is wrong, giving the expected output and standard output. I have copied and pasted them independently on a text compare application and they are both identical.

How can i see my own solution?!

Just played a hole, saw my rating, tried going back to the editor to improve and... my code is nowhere to be found. I may be missing something, in which case should better document how to access own submittals - but if they are not available, they should be - for example when clicking on the board that shows i have already played a problem/lang combo - re-direct me to my best solution (or history of my attempts)?

Julia Language

Add Jullia programming language. It has many things for code golfing

The website is not usable with µBlock (RU_AdList)

Static filter /^https?:\/\/[^/]+\/[a-z0-9]{15,}(\?hope=.*)?$/$script,domain=~coco.fr|~sap.com|~stumbleupon.com|~tv.yandex.by|~tv.yandex.kz|~tv.yandex.ru|~tv.yandex.ua

found in:

    RUS: RU AdList

I guess the filter is too aggressive, but why do you have to use links like https://code-golf.io/6OQ9d0QseMIhQb08mXrD8Q?

Morse encoder and decoder

Those holes both say that:

The space between words is seven units

However, it seems like the space between words is actually ten units.

π and 𝑒 tasks are bound by performance

It is easy to generate 1000 characters of π and 𝑒 in under 10 seconds (on a relatively old hardware), but because the limit is 2 seconds, these solutions are not accepted at all.

Moreover, these solutions are definitely shorter than the currently winning hacks, so it seems unfair that “proper” solutions are not accepted.

I don't know, maybe performance should be taken into account. But if I can generate 1000 digits of π in 9 seconds on my old laptop, why can't we accept it? It's not like I'm asking for 10 hours :)

Looking at Other Solutions

IMO not being able to look at other solutions is better (actually, I'm no longer sure), so I don't think there's a need to any dramatic changes. However, I still want to show off some of the perl 6 tricks, so maybe some solutions should become public under certain conditions?

For example, if some solution was 1st for 1 year, let's make it public? Maybe this way others will have a chance to beat it.

See also: https://irclog.perlgeek.de/perl6/2017-09-19#i_15187089

Add a LICENSE file

The website claims this is open source, but this repo needs a particular license.

Command-line arguments (ARGV) not properly separated

For example, it took me a while to realize that the sentences given as arguments in the Pangram Grep hole are not one and the same argument, and I thought I had to recognize punctuation too. I'd say that a new textbox should be made for each argument or something.

Please add some kind of auto-save feature!

I was working on a hole for a while and the page crashed after being stuck in an infinite loop while running, causing me to lose all of my work. It just defaulted back to an earlier, much worse solution.

Null byte causes successful test to fail

And hangs during the JS JSON encoding time.

I had this for Evil Numbers. If I take out any character in the string, it correctly says my results are wrong. If I take the initial null byte out of the string, and throw 0, in front, it works (but one more character! 😖).

say for unpack"U*",'����	
���������!"$\'(+-.0'

Haskell quine invalid?

In my Haskell quine, I use putStr, which should print without a newline. However, I still have to add a newline at the end of the source to make it valid

Wrong links in the user page

Some links are wrong in the user page. See example below:
codegolf

Here the list of the wrong links:

  • 12 Days of Christmas
  • 99 Bottles of Beers
  • Arabic to Roman
  • Brainfuck
  • Christmas Trees
  • Morse Decoder
  • Morse Encoder
  • Roman to Arabic
  • Sierpiński Triangle
  • Spelling Numbers

Time Out Message

It would be nice if there was a time out message for when your code goes over the 5 second limit. I spent way too long 'debugging' before I realised my code worked perfectly fine locally. (On a side note, my Perl 6 BF solution finishes in less than 3 seconds locally, but times out here :( )

Emirp expects palindromic primes

Not sure if it's intentional, but reading 'a prime number that results in a different prime' in the description led me to believe that it might not be!

Language request: J

I would like to see J added to the site.

For reference, here is the source with build instructions to obtain the executable jconsole. And to run it, you have to do jconsole [code_file] [args] < [input_file]

More holes needed

This was mentioned in #2.

Maybe this ticket can be the place where we can discuss ideas for new holes.

Add language filter on the homepage.

Some languages are more apt for golfing than others and dominate the Top 5 . It would be nice to have a language filter to see the Top 5 for all holes per language.

perl \r sequence

I noticed that \r sequence is not available. there is a particular reason?
It is useful to clear the output and it's used in golf

$|++;for(1..$ARGV[0]){print qq(\r$_);sleep 1;}

See a Diff for Failing Solutions

In “Spelling Numbers” the program is given 35 numbers but if there's something wrong it's really hard to see what exactly. A diff can help.

Test set for Pangram Grep is flawed

Sorry don't have time to investigate now, but I think that there are only a few letters that you have to check in order to get the right output. Feel free to disqualify my 29 character submission (and replace it with 30 character one).

Color coding

I see that a task can either be green, yellow, or red. However, I'm failing to see any logic for the current color coding.

I'm proposing to change the colors like this:

Task Color New color ≈length of minimal solution
99 Bottles of Beer GREEN YELLOW 206
Fibonacci GREEN GREEN 18
Fizz Buzz GREEN GREEN 39
Prime Numbers GREEN GREEN 24
Arabic to Roman YELLOW RED 112
Pascal's Triangle YELLOW GREEN 31
Seven Segment YELLOW YELLOW 112
Spelling Numbers YELLOW RED 362
𝑒 RED YELLOW 105
π RED YELLOW 192

PHP Errors sent to STDOUT

According the the About page:

"Only STDOUT is checked against the solution, STDERR is however shown back to you to ease debugging."

This is however not true for PHP. Errors and even Warnings are sent to STDOUT. This can be changed in the .ini with display_errors = stderr.

For example, the following issues a Warning to STDERR, while outputting INF:

ini_set('display_errors', 'stderr');
echo 1/0

Time limit (perl 6/rakudo)

I'm hitting Killed for exceeding 750ms timeout. error when doing 99 Bottles of Beer task. On my old laptop it runs in 550ms, where half of that is rakudo startup. Somehow it feels like this limit was not intended to be so low.

Explain Rule 110 more

Rule 110 doesn't really explain how you're meant to solve it, this would be a simple Hacktoberfest issue, you only need to edit holes.toml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.