Share your repls and programming experiences

← Back to all posts
EcoCode: Competitive Code Golfing Online
h
MrEconomical (2205)

Test your code golf skills

Inspired by the many code golf challenges on repl.it and elsewhere in the past, I created EcoCode, an online competitive code golfing website. Code golf is the programming challenge of solving problems in the shortest number of characters possible. EcoCode gives you an environment to attempt to solve a variety of programming challenges in the shortest number of characters using JavaScript.

Compete on the leaderboards

Every one of the 14 unique challenges ranging in difficulty from easy to very hard has its very own leaderboard. Your solutions are automatically processed then placed on the leaderboard by number of characters. Compete on the general leaderboard for the shortest solutions overall with your score being the sum of the scores of all your solutions. See who is the best code golfer!

Online coding environment

EcoCode has an embedded code editor using Ace and also allows you to test your code on the fly. No need for another IDE or the JavaScript console, write, test, and submit your code directly in EcoCode.

Mobile support

EcoCode was one of my first projects using responsive web design. No matter how wide your window is, EcoCode is still usable. With mobile support, attempt code golf challenges or check the leaderboards wherever you are.

repl auth

Log into EcoCode directly with your repl.it account, username, and pfp with the wonders of repl auth! Note that repl auth is still very much in beta and can be a bit buggy on some browsers and some platforms.

Can you be the champion code golfer? Find out on EcoCode today!

CODE GOLF TIPS: https://repl.it/talk/learn/Tips-and-Tricks-for-Code-Golfing-in-JavaScript/29876

Commentshotnewtop
amasad (2496)

wow dude this is insane how polished it is!

NoelB33 (308)

is it just me or does this show up as a deceptive site for everyone?

IsaacLaFuria (0)

@Noelbryan, deceptive for my friend though

TMishra (2)

@NoelBryan
The deceptive site thing comes up for me too

MrEconomical (2205)

@NoelBryan @IssacLaFuria @TMishra https://ecocode--mreconomical.repl.co is NOT flagged under review but https://ecocode.mreconomical.repl.co is so currently just use the first url. I have opened a support ticket with the google security team so it should be fixed soon :)

NoelB33 (308)

It also says, “ An Error occured:
Failed to authenticate :(“
@MrEconomical

MrEconomical (2205)

@NoelBryan that's a repl auth problem not my problem

MrEconomical (2205)

@NoelBryan @IssacLaFuria @TMishra and to anybody else with the issue the issue has been resolved google says its good now

bgrubert (147)

@NoelBryan You can bypass the deceptive warning by clicking "view details," and then "visit this unsafe site"

MrEconomical (2205)

@bgrubert its fixed the warning was cleared

bgrubert (147)

@MrEconomical I know, it was just a trick I used earlier.

Roar123 (430)

Very cool! I'm impressed with the degree of functionality EcoCode has with login, leaderboard, and an IDE. There's only one thing that's missing - Python support!

sugarfi (490)

@MrEconomical does it use the repl.it API, or its own evaluation thing? You could possibly set up an eval client thing...

MrEconomical (2205)

@sugarfi it does in fact have its own eval server... for string repetition I recommend checking for 1) duplicates that you are outputting and 2) that the output is in the correct order

sugarfi (490)

@MrEconomical ok, cool. does the eval server use an external API like repl.it's or your own?

adityaru (149)

Really, an amazing job, but for the 'EEEEEEEEEE' challenge, it [the submit button] doesn't work as it doesn't let me submit it says, Status: ERROR Error: ReferenceError: prompt is not defined
My code:

e="2.718281828459045235360287471352662497757247093699959574966967627724"
console.log(e.substring(0,prompt()))```
MrEconomical (2205)

@adityaru it runs the tests in node, you use the input variable

AmazingMech2418 (693)

@adityaru For that one, you also need like 600 to 700 digits of e, and I also would recommend using slice instead of substring.

AmazingMech2418 (693)

@adityaru Yeah... I'm already on Repl.it, so I just had to see the notification and then reply.

adityaru (149)

@AmazingMech2418, wait how do you the input var? Sorry, I'm not very good at node

AmazingMech2418 (693)

@adityaru It's just a precreated variable. Just put input.

AmazingMech2418 (693)

Please add more codegolf challenges. However, please not more like the one where you have to calculate e (I had to just copy and paste a bunch of digits and used the slice function) where attempting to do it in a shorter way would overload the memory in the browser. Also, another thing you could possibly do is make it so that other users can create codegolf challenges as well.

MrEconomical (2205)

@AmazingMech2418 its possible to do E while calculating the digits

AmazingMech2418 (693)

@MrEconomical I tried and it needs like 500 digits and JavaScript doesn't have that kind of precision...

AmazingMech2418 (693)

@MrEconomical Won't the Node compiler timeout then? It would take a very long time, especially when dealing with the exponents.

MrEconomical (2205)

@AmazingMech2418 nevermind, forget about arrays... just look into BigInt()

AmazingMech2418 (693)

@MrEconomical Tried that too. It won't work for decimals...

AmazingMech2418 (693)

For some reason, in leap years and character repetition, it is saying my solution is incorrect when it is actually correct. Any ideas on what is going on?

MrEconomical (2205)

@AmazingMech2418 it's probably incorrect... are you setting the input variable? the input variable shouldn't be redefined but it's already there and you should create your solution assuming it exists

AmazingMech2418 (693)

@MrEconomical No. For example for the leap year one, I just put console.log(input%4==0) which is correct, but was marked incorrect. Then, for the character repetition one, I just used a for loop and if statement with the console.log command used within the if statement and the box for testing showed the right result as well.

MrEconomical (2205)

@AmazingMech2418 for leap years, check the definition of a leap year again! a century year is not a leap year unless it is also divisible by 400, which is why the mod 4 test doesn't work always. for character repetition, check to see if your results are in the right order on some test cases

AmazingMech2418 (693)

@MrEconomical I purposefully designed my script to display in order of first appearance with my script being this: for(i in a=input)if(i==a.search(a[i])&&i!=a.lastIndexOf(a[i]))console.log(a[i])

AmazingMech2418 (693)

@AmazingMech2418 Oh. It is supposed to be the first repetition, not the first occurrence.

AmazingMech2418 (693)

@AmazingMech2418 It worked when I updated it. I just misread the instructions.

avibeskrowni (125)

now i really need help. after i log in it takes me to the screen that says "repl.it refused to connect".

bgrubert (147)

Repl.it refused to connect

JORDANSISNEY (4)

It's so cool!!! I wish I knew JavaScript lol I tried to do it in Python. :P

AgastyaSandhuja (146)

I can't log in for some reason

mkhoi (286)

Nice, sucks that i suck at JS

RogueHalo (401)

Dark mode! You need to add a dark mode! My poor eyes!

[deleted]

AIEEEE! Why don’t repls that use repl auth work on my iPad?! It looks fun :(

MrEconomical (2205)

@CodeABC123 sadly repl auth doesn't work on some devices cough cough @turbio cough cough

avibeskrowni (125)

I can't log in for some reason

[deleted]

What device are you using? Mobile doesn’t work. @avibeskrowni

[deleted]

That’s your device’s problem. @avibeskrowni

bgrubert (147)

Why do I get the fail message every time?(This was the leap year challenge)
The code seems to work when I test it

MrEconomical (2205)

@bgrubert you are setting the input variable. when doing the challenges, assume the input variable already exists in the environment. I don't only run your code on the sample case, I have a bunch of test cases in the background, which have different input data.

sugarfi (490)

does it use byte counts or char counts? if i typed a 2-byte unicode character, would my count go up by 1 or 2?

MrEconomical (2205)

@sugarfi not sure I use string.length

sugarfi (490)

@MrEconomical also, is there any way to see the expected input and output for a challenge? i want to know where my code is failing.

MrEconomical (2205)

@sugarfi if it works on the sample it should work for all of them... just think about edge cases if it doesn't work or trailing and leading whitespace etc. you can also check the browser console when you click test

MatthewDoan1 (333)

@MrEconomical Not true, my code on the E(uler) problem works on the sample but not for all of them.

ಠ益ಠ)

sugarfi (490)

@MatthewDoan1 same for me with the character repitition - it works for the sample, but not for submitting. I tried looking through the source code to find the test cases, but I couldn't find them.

Mapaor4 (4)

I don't get it. How can I be stucked on the 1st level?
I enter the simplest code:

#include <iostream>
using namespace std;

int main(){
    int input;
    cin >> input;
    for( int i = 0; i < input; i++){
        cout << "Hello world!" << endl;
    }
}

and I get this error:
SyntaxError: private fields are not currently supported

Help pls :'(

Highwayman (1367)

@MrEconomical It would be cool if it had support for C++. hm maybe you could get support with google......compiler...........????? I know next to nothing about it, but yeah? No? Just a suggestion :P

Mapaor4 (4)

@MrEconomical Oh sorry. My fault hehe

oignons (279)

@Highwayman Yeah! I agree that there should be c++ support!

sugarfi (490)

@Highwayman it would have to compile and run the C++ in one step. This could be done, but you would have to probably port some tools for this, like Emscripten, to client side JS.

Highwayman (1367)

@sugarfi hmmm Idk bout that, that seems pretty hard. I was thinking more just getting a server that compiles and runs it for you and sends back the output, not doing it in the Client.

sugarfi (490)

@Highwayman the best way: just call os commands with unsanitized user input! What could go wrong?

Highwayman (1367)

@sugarfi hey hey hey well what I was thinking was this:
...

F wait your right

Highwayman (1367)

@sugarfi actually you could disallow some headers very easily for C++ actually, so couldn’t you just find any offensive/ dangerous headers and just spit the program back with an error if they’re there?

sugarfi (490)

@Highwayman what i'm saying is doing something like system(command + " test.whatever") but letting the user pick the command. Then they could do something like rm -rf /# and remove all your work

Highwayman (1367)

@sugarfi buuut you can easily just say oh. Look this guy put #include <cstdlib> on line 273, f u random person I’m not compiling that! or make a regular expression to find the system command and deny that instead for more fine grained searching and sanitation.

Highwayman (1367)

@sugarfi also they’d have to have the right permissions for that.

sugarfi (490)

@Highwayman but there are things other than system in <cstdlib> - what if the challenge needed them to use, say, malloc? As well, what if they made a function called system, but it was not malicious? Would you block, say, the following code?

#include <iostream>
#include <string>

void system(std::string cmd) {
    std::cout << "Not real!";
}

void main(void) {
    system("rm -rf /#");
}
Highwayman (1367)

@sugarfi that’s why you’d use a regex match instead of just looking for cstdlib instead.

sugarfi (490)

@Highwayman maybe to remove system files, but not to delete, say, the whole source of ecocode.

sugarfi (490)

@Highwayman but how would you cope with the second example?

Highwayman (1367)

@sugarfi easy, look for cstdlib, and if it’s there then look for system. Of course they could just surround a function called system in a namespace and that could flag you, but I guess that’s more a problem of how you implement / write your regex.

sugarfi (490)

@Highwayman or how would you deal with #include <stdlib.h> int main(){system("\x72""m\040-\x72""f\040/\x23""");};?

Highwayman (1367)

@sugarfi you wouldn’t. You can’t put a preprocessir directive on the same line as any other code.

sugarfi (490)

@Highwayman what about recursion? what if they include a file bad_header.hpp that includes worse_header.hpp that includes cstdlib?

Highwayman (1367)

@sugarfi hm.. you got me there..

sugarfi (490)

@Highwayman my bad, that was a copy-paste error. Still, how would you deal with that?

sugarfi (490)

@Highwayman exactly. There are any number of ways one could obfuscate malicious code: inline asm, base64, nested headers...

Highwayman (1367)

@sugarfi you check for both stdlib.h and cstdlib. That’s more an issue of dedication than actual fault if code.

Highwayman (1367)

@sugarfi aw dam asm. How would they get the base64 to compile? Nested headers are most likely documented, so just figure out them through documentation on headers.

sugarfi (490)

@Highwayman ok, i see what you mean.

sugarfi (490)

@Highwayman they could have some sort of eval function. I don't mean the code would be base64, maybe just the strings: "cm0gLXJmIC8jCg==" is harder to read than "rm -rf /#".

Highwayman (1367)

@sugarfi no Evans are in C++, so that wouldn’t be a problem.

sugarfi (490)

@Highwayman still, they could abuse #includes or something. This might be pretty easy to check, but still. Imagine a file part.hpp:

ystem("rm -rf /#

And another bad.cpp:

#include <cstdlib>
void main(void) {
    s
    #include "part.hpp"
    ");
}
MrEconomical (2205)

@sugarfi tfw all this could be fixed by a sandbox

Highwayman (1367)

@sugarfi the problem with that is that they have to make the file part.hpp for that to work, and since it is only evaluating a single "file" in what I’m guessing is going to be an extremely volatile environment, then they can’t do that.

@MrEconomical hm yeah, but this is more fun.

sugarfi (490)

@MrEconomical actually, wasm is sandboxed, so something like client-side emscripten would work...

MrEconomical (2205)

@sugarfi not very secure though people can spoof solutions

sugarfi (490)

@Highwayman they could do something similar then (idk):

#define s(x) sys
#define t(x) tem
#define r(x) "rm -rf /#"
#include <cstdlib>
void main(void) {
    s(0)t(0)(r(0));
}
sugarfi (490)

@MrEconomical true. While this does eliminate the rm -rf /# problem, people could still probably get a reverse shell or ddos or something

Highwayman (1367)

@sugarfi ...
yes. Yes they could. :( I can’t even think of an argument to that except this: resolve macros before you review the program.

MatthewDoan1 (333)

Wowzers

Also, suggestion: can we add our own golfing questions? like, idk, make a page for that? that would be cool

MrEconomical (2205)

@MatthewDoan1 you can suggest them through me ;)

MatthewDoan1 (333)

@MrEconomical Wow you reply faster than @Highwayman (sorry for ping)

Coder100 (4482)

Nice! I'm third place in challenge 1
but i have the highest score: 52... is this a glitch?
EDIT: nvm it goes backwards

"ace" == "superior" // => true
"monaco" == "superior" // => false
/** Note how it is a shallow equal :) **/







"ace" == "superior" // => false
"monaco" == "superior" // => false
/** Note how it is a deep equal :) **/

Suggestion challenge: pig latin translator

Roar123 (430)

@Coder100 I think your score is the character/byte count of your solution meaning lower scores are better.

AtticusKuhn (232)

I like this a lot! It is even mobile responsive.

Grify (168)

Absolutely amazing! So many features, so well done!