Updates from the Repl.it team about the product

← Back to all posts
Weekly Challenge #2!
DynamicSquid (5027)

Hi!

Welcome back! Excited to be hosting it this week :)

And thanks to everyone who participated last week! Four people got full marks, wow! Here's the top five:

  1. @Nayoar
  2. @SpicedSpices
  3. @Th3Coder
  4. @xxpertHacker
  5. @MattDESTROYER

To view the full leaderboard, go here.

Anyway, let's jump right into this week's challenge!


Have you heard of code golf? So you know how in normal golf you have to try to get the ball in the hole in the least number of strokes possible? Well in code golf you have to accomplish a task in the least number of characters possible!

For example, if the task is to print "Hello World!", a bad submission would look like this:

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello World!";
}

That file is a whopping 91 characters!! Now a good submission would look like this:

#include<cstdio>
int main(){puts("Hello World!");}

That file is only 52 characters! Much better!

With that said, this weekly challenge will be code golf!

Also, for this competition, 1 newline counts as 2 characters, so try to keep as few lines as possible!

I will also be judging these based on language groups as each language has a shorter/longer syntax.

  • C, C++
  • Java, C#
  • Python, Ruby, JS
  • Crystal, Elixir
  • Esolangs

I'll probably adjust that list depending on the types of submissions we get.


So, what's the challenge? It comes in two parts, and you can only do Part 2 if you did Part 1. Think of Part 2 as an extension to Part 1 if you want to earn more points :)

Part 1

Determine the winner, if there is one, of a Connect 3 game. User input will be in the form of 9 characters (3 by 3 grid), either, R (red circle), B (blue circle), or . (empty space). Output the winner, either red or blue, or tie if there is no winner. Remember, the winner of the game is the person that connects three pieces in a horizontal, vertical, or diagonal line. The input is guaranteed to show a realistic game of Connect 3, and has exactly one winner, or a tie.

Part 2

Part 2 is similar to Part 1, except that the input is not guaranteed to be a possible real life game of Connect 3. It's your job to determine if the board can actually be played. That means the difference between red and blue pieces can not be more than one, no piece can have an empty space underneath it (laws of gravity exist), and there is only one winner. If the game is impossible, output "impossible". Otherwise output "possible", followed by who won, either red or blue, or tie if it was a tie.

And just to remind you, here's s sample of Connect 3 gameplay (the real game is Connect 4, but to make it a bit easier we're doing Connect 3)

Part #1 Example #1

Input:

. . R
. . R
B B R

Output:

red

Part #1 Example #2

Input:

B R R
R B B
B R R

Output:

tie

Part #2 Example #1

Input:

. . .
. R B
B R .

Output:

impossible

Part #2 Example #2

. . .
. R R
B R B

Output:

possible
tie

Here's some tips:

  1. Code normally, then once you're done, remove all unnecessary whitespace (spaces, tabs, newlines) from your program
  2. Keep the number of lines to a minimum, remember, each newline counts as 2 characters!
  3. You can paste your code in my little character count thingy I made to easily find out how many characters are in your code
  4. You might want to make two versions of your code. If you think you have a way to reduce the characters, make that change on the second version, so you can compare both versions to see if your change actually reduced the character count

Btw I got 537 characters in C/C++, and uh 663 in Python... weird. I'm not great with Python, so I had a bunch of indents and lines, so all the Python experts out there could probably reduce that. Also C/C++ have macros, which helped :)


Submissions will be judged on a curve by the number of characters, and creativity.

To submit your repl, publish it to Apps with the tag weekly2. If you can't publish it to Apps, comment it here. Submission deadline is next week Friday!

And once you've published your repl you can still make changes, but once I score it, and I'll score it as soon as I see it, you can't make any more changes.

Have fun :)

Comments
hotnewtop
JackFly26 (114)

For the character counter, why not just do len(file)+file.count("\n") or whatever?

DynamicSquid (5027)

@JackFly26 Cause I didn't know you could do that

LavernieChen (10)

@JackFly26 Yeah, just use len and it will print the number of chars. @DynamicSquid btw, how many chars does a line equal if we use more than one line?

DynamicSquid (5027)

@LavernieChen

Also, for this competition, 1 newline counts as 2 characters, so try to keep as few lines as possible!

MattDESTROYER (20)

@DynamicSquid For part 2, should part 1 example 2 output
possible tie or just tie? Also none of the examples included diagonals but I assume we have to account for those as well right? Lastly:

B R B
R B R
B R B

The center piece would be the winning move so the red piece placed on top would have happened after blue already won, would this be considered possible or not? It must get annoying answering so many questions, sorry :)

DynamicSquid (5027)

@MattDESTROYER Wdym by " For part 2, should part 1 example 2 output"?

Also yes, account for diagonals.

That's a good question. According to the criteria, that game is possible:

That means the difference between red and blue pieces can not be more than one, no piece can have an empty space underneath it (laws of gravity exist), and there is only one winner.

So you can just output

possible
blue

for that one (even tho it's impossible in real life, we'll pretend it is possible)

CodingEssence (136)

Determine the winner, if there is one, of a Connect 3 game. User input will be in the form of 9 characters (3 by 3 grid), either, R (red circle), B (blue circle), or . (empty space).

What do you mean by this (the bold)? (sorry if it's a silly qs, i don't understand)

EDIT: I think i got it:

So you mean by that the user inputs a grid of a finished game and we output if it's a tie, blue wins, or red wins?

That's basically the challenge for part 1?

And we don't need to specify what the user needs to input in our input. for example, can we just do this:

choice = input()
# The rest of the code

and not this:

choice = input('Grid layout')
# Or this
choice = input('Grid')

?

DynamicSquid (5027)

@CodingEssence Look at the examples. User input will be 3 lines, each line contains 3 characters, each separated by a space.

Also, the game might not be finished. It could be this:

. . .
. . .
. R B

In that case you would output tie.

And no, you don't need to specify what the user needs to input.

CodingEssence (136)

@DynamicSquid oooooh ok got it, thanks (and sorry again)

Nayoar (581)

Semicolons where used in place of a newline should count as 2 characters as well (and possibly other things, for example colon in python - for i in range(3):print(i) is valid)

Also, can we make two separate versions of the code for the two parts, or do they need to be a single script?

DynamicSquid (5027)

@Nayoar No, semicolons stay as one character.

Also, the two parts of the code should be in a single repl

Nayoar (581)

@DynamicSquid yes, I get that the two parts should be in the same repl... never mind though, I no longer need an answer to what I was trying to ask. Cool challenge btw

IMayBeMe (552)

Let’s go, I did a 1 line tic tac toe validation program so part 1 is pretty much done. Also the score website looks brilliant.

DynamicSquid (5027)

@IMayBeMe Ik, that's where I got the idea from :)

Whippingdot (681)

Hey can I submit this in like 1 hour. I want to do final checks and finish it and submit it by then. When will you create the post and do the final checks. Please try to give me time by 9 PM IST... 🙏

FlaminHotValdez (716)

God dammit I give up lmao I have like a 500+ char code for just part 1 oof

Whippingdot (681)

For part one, if the input is

BBB
RRR
...

we should output tie right? Or will you only give situations where one person wins or no-one wins. Cause I added a lot of characters in making it so that if two people win it says tie. Also, I have to keep both part 1 and part 2 in the same repl right? If so, which part should be the one executed when pressing the run button?

DynamicSquid (5027)

@Whippingdot For part 1, that will not be an input. For part 2, you have to output impossible since there are two winners.

Also yes, part 1 and part 2 have to be in the same repl. Just think of part 2 as a extension to part 1

Whippingdot (681)

Wait...should they be separate files or..? @DynamicSquid

DynamicSquid (5027)

@Whippingdot No, they're the same program. Task 2 is just an extension of Task 2

Whippingdot (681)

Then how do you grade task 1? Just because I don't know if you want to grade task 1 or not and you won't reply for 12 hours for now my main file will be part two and part one will be another file called part1.cpp. @DynamicSquid

Whippingdot (681)

Oh and also in C++ you got 537 characters in part 1 or 2?? Cause in part 1 I already got 568... 😲 @DynamicSquid

DynamicSquid (5027)

@Whippingdot Part 1 and Part 2 should be the same program. No need to make two separate files

Whippingdot (681)

OOOKKK basically part 2 is an addition to part 1 so part 1 isn't really needed and after you finish it part 2 is the only thing you need. Like you have to replace part 1 with part 2 / you have to add on to part 1 with part 2. @DynamicSquid

EricBrown (4)

I've got a working solution at 325 characters, but I cannot seem to publish my repl.

DynamicSquid (5027)

@EricBrown Just reply to this comment with the link :)

EricBrown (4)

@DynamicSquid Okay. I got it down to 241 characters & need to stop playing with it. There's a readme that explains how it works.

https://replit.com/join/bmctprucha-ericbrown

I have a python version too but it is over 300 characters.

I'm looking forward to next week's challenge! :)

DynamicSquid (5027)

@EricBrown Nice! However don't use the Join link cause anyone can click on that link and edit your repl. Just try to paste the URL instead :)

Aivoybia (26)

what if we use brainF... :(

Aivoybia (26)

@DynamicSquid how would the curve for that be though?
BrainF uses so many characters to do even hello world.

How would it work if you compare python with print hello world and brainf hello world?

Th3Coder (136)

@Aivoybia I tried it and believe me, it's insane to even make an if statement

CodingEssence (136)

Would we need to verify something like this?:

. . .
. . .
. . .
OldWizard209 (1638)

Hey, me once again. I was wondering, rather than just printing "tie", can I just let the program quit when no one wins? @DynamicSquid

Aivoybia (26)

@OldWizard209 @DynamicSquid Does the spelling need to be correct? like when someone ties just say ti or when someone wins they say playr one wins

P.S. I pinged you oldwizard cuz this is somewhat related to ur question

OldWizard209 (1638)

well spelling does matter. because if you just write ti, thats you saving characters while breaking a few rules. @Aivoybia

Aivoybia (26)

@OldWizard209 does it say you need to spell correctly lol

OldWizard209 (1638)

no but there is an output specification that you have to follow. @Aivoybia

DynamicSquid (5027)

@Aivoybia You have to output exactly as shown. If you only output "ti", I'll add an extra 2000 characters to your character count.

OldWizard209 (1638)

he might not be but you should know that he has all the power to do so @Aivoybia

Th3Coder (136)

@DynamicSquid so if I output "tiea" will you reduce 2000 characters?

JeffreyChen13 (59)

I don't get it @DynamicSquid, why are there new people on the leaderboard? They turned it late, I do not get this.

DynamicSquid (5027)

@JeffreyChen13 I only received two late submissions, and they were only a couple hours late, so I decided to be nice :)

OldWizard209 (1638)

Hey, I was not able to attend weekly challenge 1 because of health-related issues, but I want to participate in the weekly challenge 2, am I still eligible to participate? @DynamicSquid

AIDENSANDBAKKEN (2)

May we assume the input is in stdin at the start of the program's execution or do we have to wait for the user to input it?

JakeHu2020 (34)

I was like nooooooo when I didn't see javascript, but then I lit up when there was python. 106 chars:
https://replit.com/@JakeHu2020/DynamicSquids-challenge-1

DynamicSquid (5027)

@JakeHu2020 Where do you not see JS?

Python, Ruby, JS

Also you have to get input from the user. See examples for clarification

JakeHu2020 (34)

@DynamicSquid ok I'll restart with js :)

EdwardBentler (40)

So, part 1 is tic tac toe, and part 2 is tic tac toe with gravity?

DynamicSquid (5027)

@EdwardBentler No. In part 1, all the Connect 3 boards are guaranteed to be valid. If you also do part 2, the boards are not guaranteed to be valid, and it's up to you to validate them.

InvisibleOne (3226)

Are we allowed to do: exec("code") in python? It let's you put it all into one string with \n for new lines and run it all in a single line.

DynamicSquid (5027)

@InvisibleOne Yes. But be careful, exec("") is an 8 characters... so that could be a net gain or loss

MrVoo (102)

@InvisibleOne Adding all the newlines would do nothing since linebreaks are counted as two characters .-.

InvisibleOne (3226)

I know, but you can use exec for different commands that shortens your code.

Whippingdot (681)

How bad did I do?

Also why am I two days late again...

I haven't read the post yet so I will edit this comment to include my questions after reading

First edit: Wait you actually included elixir? Do you think it is useful learning that or nodejs is enough

DynamicSquid (5027)

@Whippingdot 7 is pretty good! Also, you can use any language you want, don't worry about the list too much

ch1ck3n (2388)

@Whippingdot dont worry i got 5

anrgy chicken noises

Whippingdot (681)

oh lol i wanna say something but it might hurt you so i am not gonna say something

just note that you are way better in coding than me... i am just smart ;) @ch1ck3n

Whippingdot (681)

I thought you were better at coding than me...how did you do worse xD @ch1ck3n

please don't ban me @DynamicSquid

FlaminHotValdez (716)

grouping all esolangs together is kinda unfair bc esolangs have diff lengths

DynamicSquid (5027)

@FlaminHotValdez ik, but like I said, I'll make changes to the list depending on what esolangs are used

FlaminHotValdez (716)

@DynamicSquid Whoa that was a fast response...

JackFly26 (114)

Should

. R .
R R R
B B B

output tie, blue, or impossible? It could feasibly be any depending on how the game is defined.

DynamicSquid (5027)

@JackFly26 If you're doing Part 1, then don't worry cause that will never be an outcome. If you're doing Part 2, output impossible.

DEANKASOZI (12)

im so confused what we are making for this weeks challenge, someone please explain

MrVoo (102)

@DEANKASOZI Im pretty sure its a connect 3 game validator with the least code possible (If I'm wrong please ping me Dynamic :>)

DEANKASOZI (12)

@DynamicSquid
I'm not exactly sure what we are doing for this week's challenge, are we making a connect 3 game with the least amount of code?

DynamicSquid (5027)

@DEANKASOZI Basically yes. Read the instructions for more clarification

DEANKASOZI (12)

@DynamicSquid
Oh ok, i was just making sure

MrVoo (102)

@DynamicSquid Wait, are we making a game or a validator... or both?

DynamicSquid (5027)

@MrVoo You're not making a playable game. For task 1, just output who won. For task 2, the board is not guaranteed to be valid, so check if it's valid, and if it is, output who won.

MrVoo (102)

@DynamicSquid You're* Okay, that makes a lot more sense

Th3Coder (136)

Hello, I'd like to ask a question!

I have a question about the 5 language groups you gave

  • C, C++
  • Java, C#
  • Python, Ruby, JS
  • Crystal, Elixir
  • Esolangs

Can you give the proportions of the length of each language group required?

E.g. if someone does it in Python with 500 characters how many characters would it take for someone to beat them using languages in other groups? (Sorry I'm bad at explaining XD)

Thanks!

DynamicSquid (5027)

@Th3Coder It's judged on a curve, so it depends on the submissions. I don't really know until I look at all of them :)

Th3Coder (136)

@DynamicSquid thanks! Btw I'm probably going to use BrainF or something

Edit: never mind, coding with BF is literally insane.

Th3Coder (136)

@DynamicSquid sorry for asking again, if I make a HTML-CSS-JS repl, will only the JS code be counted? This is for creativity points btw
Also the code has 444 characters so far and it's in JS, which is still kind of long XD

Thanks (again)!

DynamicSquid (5027)

@Th3Coder Yes, only the JS will be counted :)

Th3Coder (136)

@DynamicSquid YEAY! Thanks (again, again) :)

Th3Coder (136)

@DynamicSquid sorry for asking for the third time, but can I use the jQuery library? It will shorten the code even more, btw I'll submit soon! Thanks (again, again, again) :)

Th3Coder (136)

@DynamicSquid thanks! I published the repl :) jQuery doesn't work anyway

MrVoo (102)

Do we have to use R, B and . characters?

DynamicSquid (5027)

@MrVoo Yes. The input will be 9 characters (3 lines, 3 characters each), either R, B, or .

MrVoo (102)

@DynamicSquid So we type in either R, B or . 9 times and then the code checks who won the fake game?

LavernieChen (10)

@DynamicSquid I think I'm asking to many questions, sorry for that, but on your Part 2 example 2, shouldn't it be a possible and then red?

MattDESTROYER (20)

@LavernieChen Part 2 example 2:

. . .
. R R
B R B

There are three red but not in a row.

DynamicSquid (5027)

@MattDESTROYER Yes. That's why the output is:

possible
tie

@LavernieChen

LavernieChen (10)

@DynamicSquid Ok, so as long as it is not 3 in a row, it is tie.