EcoCode: Competitive Code Golfing Online
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
is it just me or does this show up as a deceptive site for everyone?
@NoelBryan, normal site for me
@Noelbryan, deceptive for my friend though
@Noelbryan @IsaacLaFuria am looking into it
@NoelBryan
The deceptive site thing comes up for me too
Thanks @MrEconomical
@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 :)
Thanks! @MrEconomical
It also says, “ An Error occured:
Failed to authenticate :(“
@MrEconomical
@NoelBryan that's a repl auth problem not my problem
Lol ok @MrEconomical
@NoelBryan @IssacLaFuria @TMishra and to anybody else with the issue the issue has been resolved google says its good now
Thanks! It works now! @MrEconomical
@NoelBryan You can bypass the deceptive warning by clicking "view details," and then "visit this unsafe site"
@bgrubert its fixed the warning was cleared
@MrEconomical I know, it was just a trick I used earlier.
c# support
plz
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!
@MrEconomical does it use the repl.it API, or its own evaluation thing? You could possibly set up an eval client thing...
@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
@MrEconomical ok, cool. does the eval server use an external API like repl.it's or your own?
@sugarfi uses my own
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()))```
@adityaru it runs the tests in node, you use the input
variable
@MrEconomical Ohhh thanks
@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 oh ok thank you!
@adityaru You're welcome!
@AmazingMech2418 fast reply!
@adityaru Yeah... I'm already on Repl.it, so I just had to see the notification and then reply.
@AmazingMech2418, wait how do you the input var? Sorry, I'm not very good at node
@adityaru It's just a precreated variable. Just put input
.
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.
@AmazingMech2418 its possible to do E while calculating the digits
@MrEconomical I tried and it needs like 500 digits and JavaScript doesn't have that kind of precision...
@AmazingMech2418 you can do it with an array
@MrEconomical Won't the Node compiler timeout then? It would take a very long time, especially when dealing with the exponents.
@AmazingMech2418 nevermind, forget about arrays... just look into BigInt()
@MrEconomical Tried that too. It won't work for decimals...
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?
@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
@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.
@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
@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 Oh. It is supposed to be the first repetition, not the first occurrence.
@AmazingMech2418 It worked when I updated it. I just misread the instructions.
now i really need help. after i log in it takes me to the screen that says "repl.it refused to connect".
Repl.it refused to connect
It's so cool!!! I wish I knew JavaScript lol I tried to do it in Python. :P
I can't log in for some reason
Nice, sucks that i suck at JS
Dark mode! You need to add a dark mode! My poor eyes!
AIEEEE! Why don’t repls that use repl auth work on my iPad?! It looks fun :(
@CodeABC123 sadly repl auth doesn't work on some devices cough cough @turbio cough cough
I can't log in for some reason
What device are you using? Mobile doesn’t work. @avibeskrowni
@CodeABC123 macbook air
That’s your device’s problem. @avibeskrowni
Why do I get the fail message every time?(This was the leap year challenge)
The code seems to work when I test it
@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.
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?
@sugarfi not sure I use string.length
@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.
@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
@MrEconomical Not true, my code on the E(uler) problem works on the sample but not for all of them.
ಠ益ಠ)
@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.
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 :'(
@Mapaor4 must be in JavaScript
@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
@MrEconomical Oh sorry. My fault hehe
@Highwayman Yeah! I agree that there should be c++ support!
@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.
JavaScript
@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.
@Highwayman the best way: just call os commands with unsanitized user input! What could go wrong?
@sugarfi hey hey hey well what I was thinking was this:
...
F wait your right
@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?
@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
@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.
@sugarfi also they’d have to have the right permissions for that.
@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 /#");
}
@sugarfi that’s why you’d use a regex match instead of just looking for cstdlib instead.
@Highwayman maybe to remove system files, but not to delete, say, the whole source of ecocode.
@Highwayman but how would you cope with the second example?
@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.
@Highwayman or how would you deal with #include <stdlib.h>
int main(){system("\x72""m\040-\x72""f\040/\x23""");};
?
@sugarfi you wouldn’t. You can’t put a preprocessir directive on the same line as any other code.
@Highwayman what about recursion? what if they include a file bad_header.hpp
that includes worse_header.hpp
that includes cstdlib
?
@sugarfi hm.. you got me there..
@Highwayman my bad, that was a copy-paste error. Still, how would you deal with that?
@Highwayman exactly. There are any number of ways one could obfuscate malicious code: inline asm, base64, nested headers...
@sugarfi you check for both stdlib.h and cstdlib. That’s more an issue of dedication than actual fault if code.
@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.
@Highwayman ok, i see what you mean.
@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 /#".
@sugarfi no Evans are in C++, so that wouldn’t be a problem.
@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"
");
}
@sugarfi tfw all this could be fixed by a sandbox
@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.
@MrEconomical actually, wasm is sandboxed, so something like client-side emscripten would work...
@sugarfi not very secure though people can spoof solutions
@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));
}
@MrEconomical true. While this does eliminate the rm -rf /#
problem, people could still probably get a reverse shell or ddos or something
@sugarfi ...
yes. Yes they could. :( I can’t even think of an argument to that except this: resolve macros before you review the program.
Wowzers
Also, suggestion: can we add our own golfing questions? like, idk, make a page for that? that would be cool
@MatthewDoan1 you can suggest them through me ;)
@MrEconomical Wow you reply faster than @Highwayman (sorry for ping)
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
@Coder100 I think your score is the character/byte count of your solution meaning lower scores are better.
ah ok @Roar123
I like this a lot! It is even mobile responsive.
Absolutely amazing! So many features, so well done!
wow dude this is insane how polished it is!
@amasad ikr