Skip to content
← Back to Community
Weekly Challenge #2!
Profile icon
h
has Hacker Plan
DynamicSquid

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
Profile icon
JackFly26

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

Profile icon
DynamicSquid

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

Profile icon
SilentFoxy78

@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?

Profile icon
DynamicSquid

@LavernieChen

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

Profile icon
SilentFoxy78

@DynamicSquid Ok Thanks!

Profile icon
MattDESTROYER

@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 :)

Profile icon
DynamicSquid

@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)

Profile icon
MattDESTROYER

@DynamicSquid Ok thanks :)

Profile icon
CyberPy

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')

?

Profile icon
DynamicSquid

@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.

Profile icon
CyberPy

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

Profile icon
ch1ck3n

so tic tac toe but the things drop

Profile icon
DynamicSquid

@ch1ck3n Yes lol

Profile icon
ch1ck3n

@DynamicSquid can i use dogescript

Profile icon
DynamicSquid
Profile icon
ch1ck3n

@DynamicSquid happy chicken noises

Profile icon
Nayoar

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?

Profile icon
IMayBeMe

@Nayoar agreed

Profile icon
DynamicSquid

@Nayoar No, semicolons stay as one character.

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

Profile icon
Nayoar

@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

Profile icon
DynamicSquid

@Nayoar Thanks!

Profile icon
IMayBeMe

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.

Profile icon
DynamicSquid

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

Profile icon
Whippingdot

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... 🙏

Profile icon
AaronClements

join my team @hjggfhhhghgfhg

Profile icon
FlaminHotValdez

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

Profile icon
Whippingdot

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?

Profile icon
DynamicSquid

@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

Profile icon
Whippingdot

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

Profile icon
DynamicSquid

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

Profile icon
Whippingdot

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

Profile icon
Whippingdot

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

Profile icon
DynamicSquid

@Whippingdot 537 in Part 2

Profile icon
DynamicSquid

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

Profile icon
Whippingdot

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

Profile icon
DynamicSquid
Profile icon
JakeHu2020
Profile icon
DynamicSquid

@JakeHu2020 I wouldn't do grid1 grid2 grid3, just leave it blank :)

Profile icon
JakeHu2020
Profile icon
EricBrown

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

Profile icon
DynamicSquid

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

Profile icon
EricBrown

@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! :)

Profile icon
DynamicSquid

@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 :)

Profile icon
EricBrown
Profile icon
Aivoybia

what if we use brainF... :(

Profile icon
DynamicSquid
Profile icon
Aivoybia

@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?

Profile icon
Th3Coder

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

Profile icon
DynamicSquid

@Aivoybia So don't use brainf :)

Profile icon
CyberPy

Would we need to verify something like this?:

. . . . . . . . .
Profile icon
DynamicSquid

@CodingEssence Yes, that would be a tie

Profile icon
CyberPy
Profile icon
OldWizard209

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

Profile icon
DynamicSquid
Profile icon
Aivoybia

@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

Profile icon
OldWizard209

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

Profile icon
Aivoybia

@OldWizard209 does it say you need to spell correctly lol

Profile icon
OldWizard209

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

Profile icon
DynamicSquid

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

Profile icon
Aivoybia

@DynamicSquid lol u serious?

Profile icon
OldWizard209

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

Profile icon
Th3Coder

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

Profile icon
CodingElf66

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

Profile icon
DynamicSquid

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

Profile icon
CodingElf66
Profile icon
OldWizard209

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

Profile icon
DynamicSquid

@OldWizard209 Ofc you can :D

Profile icon
OldWizard209

Thanks man @DynamicSquid

Profile icon
Aiden2207

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?

Profile icon
DynamicSquid

@AIDENSANDBAKKEN The user has to input it

Profile icon
JakeHu2020

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

Profile icon
DynamicSquid

@JakeHu2020 Where do you not see JS?

Python, Ruby, JS

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

Profile icon
JakeHu2020

@DynamicSquid ok I'll restart with js :)

Profile icon
EdwardBentler

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

Profile icon
DynamicSquid

@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.

Profile icon
InvisibleOne

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.

Profile icon
DynamicSquid

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

Profile icon
InvisibleOne
Profile icon
MrVoo

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

Profile icon
InvisibleOne

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

Profile icon
Whippingdot

How bad did I do?
image

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

Profile icon
DynamicSquid

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

Profile icon
Whippingdot

kk, thanks for replying @DynamicSquid

Profile icon
ch1ck3n

@Whippingdot dont worry i got 5

anrgy chicken noises

Profile icon
Whippingdot

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

Profile icon
ch1ck3n

@Whippingdot hurt me

hurt me

hurt me

Profile icon
Whippingdot

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

please don't ban me @DynamicSquid

Profile icon
ch1ck3n

@Whippingdot
:OOOOOOO

Profile icon
FlaminHotValdez

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

Profile icon
DynamicSquid

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

Profile icon
FlaminHotValdez

@DynamicSquid Whoa that was a fast response...

Profile icon
DynamicSquid
Profile icon
7outofBLIP

My last submission was not graded? https://replit.com/talk/share/Weekly1/142458

Profile icon
DynamicSquid

@7outofBLIP You have to publish it to Apps. I can grade it for you rn

Profile icon
7outofBLIP

@DynamicSquid oh sorry, will do next time

Profile icon
7outofBLIP
Profile icon
DynamicSquid

@7outofBLIP Graded. You should see your score

Profile icon
JackFly26

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.

Profile icon
DynamicSquid

@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.

Profile icon
JackFly26
Profile icon
GLXY-LGNDS-4

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

Profile icon
DynamicSquid

@DEANKASOZI What's confusing you?

Profile icon
MrVoo

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

Profile icon
GLXY-LGNDS-4

@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?

Profile icon
DynamicSquid

@DEANKASOZI Basically yes. Read the instructions for more clarification

Profile icon
GLXY-LGNDS-4

@DynamicSquid
Oh ok, i was just making sure

Profile icon
MrVoo

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

Profile icon
DynamicSquid

@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.

Profile icon
MrVoo

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

Profile icon
Th3Coder

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!

Profile icon
DynamicSquid

@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 :)

Profile icon
Th3Coder

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

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

Profile icon
Th3Coder

@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)!

Profile icon
DynamicSquid

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

Profile icon
Th3Coder

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

Profile icon
Th3Coder

@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) :)

Profile icon
DynamicSquid
Profile icon
Th3Coder

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

Profile icon
MrVoo

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

Profile icon
DynamicSquid

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

Profile icon
MrVoo

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

Profile icon
DynamicSquid

@MrVoo Yes

Profile icon
SilentFoxy78

@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?

Profile icon
MattDESTROYER

@LavernieChen Part 2 example 2:

. . . . R R B R B

There are three red but not in a row.

Profile icon
DynamicSquid

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

possible tie

@LavernieChen

Profile icon
SilentFoxy78

@MattDESTROYER so this is a tie?

Profile icon
SilentFoxy78

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

Profile icon
MrVoo

Is the score for last week out of 10?

Profile icon
DynamicSquid

@MrVoo yes

Profile icon
MattDESTROYER

@DynamicSquid Is the score for every challenge out of 10?

Profile icon
DynamicSquid
Profile icon
MattDESTROYER

@DynamicSquid Ok thanks :)