Skip to main content
View on YouTube to comment and like!

Syntax Video

The Hardest Reverse Clash of Code Yet

Chapter 1 00:00

Transcript

Welcome to Clash of Code, where today we're all going to be competing to solve these JavaScript problems, but with a catch. So, we are not given any sort of problem description. All we can see are the inputs and the outputs, and we have to figure out what code to write to make that happen. Is everyone ready?

No. Absolutely not. Not at all. Let's do it. Let's do it. Okay, here we go. Clash now. Input 3 4. Expected output 2 1 16. So two twos and two eights. Okay. So the first one is going to be x. Second one is going to be y. Um and we just basically need to answer is equal to x * x.

Do we multiply and then reverse? So 3 * 4 is 12, reversed is 21, 2 * 8 is 16. What What is the pattern here? Shoot. What is the dang pattern? You're not just multiplying numbers together. What is the pattern here, folks? I am dumb right now. I'm officially dumb. Oh, it's giving us a hint here. So, the X and the Y are what it's read the variables in as. So, if X is 27, what the heck? So, if Yeah. So, if X is 27 and Y is 26, we want 891. Are we going to have to do some sort of like distance formula?

No, that's not it. Okay, the first one expected 21. Three threes is nine. Four fours is 16. What is it? I was wrong about that. Obviously, you can't just multiply these together. But like, if we were to just say 7 * y to get something on paper here, um, and we play all test cases, it's obviously going to fail. And if we have that, what else could it be, though? If x is 2 and y is 8, distance formula would require like two points.

If we find the distance between that and the origin, it's not 20, is it? No. 27 8.91. Okay. We do test case number two. Expected 16 found 20. Is that test number two? Okay. Expected 16. So, what is the difference here? It's four. Um, the other one had a difference of not four. What is the commonality here? Is it the area of a triangle? How do you find the area of a triangle?

Uh, a square + b square= c^2. I have no idea. Absolutely no idea. Maybe I'm overthinking this. I'm going to look at their us their other test cases. Can we see these? So, it is 2727 plus x * y. Play all test cases. Boom. Submit.

I win. I'm the best. 100%. These guys don't understand problem solving. My intuition and pattern matching skills are unmatched. This is not even programming though. This is just stupid little Oh, can you tell what these numbers have in common?

So, if we do 0 to the power of 8, that is zero. If we do 3 to the power of four, that is not legitimately. I'm I'm just staring at this in this like I'm I'm missing something very obvious and I feel like um I'll just accept the L on this one.

I'm sorry. My brain has decided to not do this today. This is so simple and I'm I'm just losing it. So we we add is it to the power of the two and then multiply it by the first one. No. Is that it? Has nothing to do with that. You guys like Mountain Dew?

Like I don't know how Wes got that stuff. We don't got a lot of weird pops in Canada, but this one I fly on this one. I love this stuff. I'm all jacked up on Mountain Dew. We can end up I don't have an answer to this. My brain just flat out didn't come up with it. Sorry. This is the stupidest one ever, but we have to leave it in.

Yeah, cuz I'm like, is it distance formula? Like, do I get the square root? Like, what are they? Yeah, it was simply just the first number multiplied by itself and then the first number multiplied by the second number. How did you figure that out? I brought up open my calculator and I thought it was the the two just basically the to the power of two of each of them, but then I was short a little bit and I u my like pattern matching skills are unmatched. So I immediately noticed that it was off by a certain amount and I said, "hm, that's suspicious." And then I just changed it to the X to a Y. All right, let's do it again.

Again. Clash now. All right, so 101 expected output zero. 669 expected output 9. What the hell? 278 is the lowest. This is the highest. And this is the lowest. And this is the highest.

278 890. Okay. So I think it's the second two. First two. the first one minus the second one. Jeez, what is going on here? Oh no, we want to basically just want to count them and find the one that exists more than once. Oh, I'm regretting this. I'm stressing out. This is the thing is so people are screaming at us right now being like, "It's so easy. Just do this." We're stressed cuz we want to win cuz CJ's cheating. Gosh, this is stupid. It's the highest sometimes unless it if if it's nine. If it's nine, it's the highest.

Okay, let's say if a equ= 9 or b = 9. Oh, this is so stupid. Yeah. 9 - 6 is 3. 3 * 6 is not 9. That's That's dumb of me to say that. So, is it the first minus the 2? Yeah, I'm just going to like throw calculations at this. So, can we do a minus b that whole thing time? But if this is zero then it becomes one.

Let's just let's see what we got here. Values play all test. Play test case. Oh my gosh. Rest parameter must be last formal. Oh wait, we got to return an object from that. That's why. Okay, this solves some of them.

But it doesn't solve the first one. So if we do 1 minus 0, are we taking the min of the pairs or the max of the pairs? No. If a is lower than b, then a is currently the lowest. Then likewise, we'll do another if. This is some like leak code stupid. If a is also lower than c, uh then again it's the same.

else we're going to have if B is lower than C, then lowest is equal to B. Else lowest is equal to C. This is the dumbest league code I've ever written in my entire life. Play all test cases. And it failed. Uh, found nothing. How did you find nothing? Oh.

Oh, then we got to return. No. All right, screw this. You know what? I am going to just cheat cuz CJ is cheating. CJ is cheating. So if A is equal to B then console.log C. Otherwise if A is equal to C, console.log B and then else console.log A. This is the stupidest way ever. Does that work? Play all test cases. Boom.

Submit. I still won. Oh, I was so stressed out. I was so stressed out. The The way I normally would do that, I was to just count the instances of that value in there and then I would sort and just return the one that has the least amount of instances. That was sometimes with these things you just got to do the down and dirty one.

So the input the max of the last two nine but and the min of the second. Well, they they haven't even figured out they haven't even figured out what the math the challenge is. They're math talking about expected nothing. Expected nothing. Expected.

Is it just the maximum? Oh, because I'm outputting two things. Cuz then we lose the zero. Oh, that's stupid. Uh oh. This needs to be This is the dumbest leak code I've ever written in my entire life. I feel better for having challenges, let alone apologizing to every person on the planet who has watched me write this. Okay, that didn't work for this one. No, because No, cuz then you get nine.

Congratulations. Did Scott figure it out? Okay, I got 50%. I think I can get 50%. I'm just going to submit this one. Oh, Scott was I give up. You guys are not understanding the problem again. No, I didn't understand the problem again. So the problem was return the number that didn't exist twice.

Really? Oh [ __ ] Okay. So I was like I wrote a reduce to like add up instances and then I like was I panicked and just did an if statement. Okay. I cheed mine. I just straight up cheesed it and obviously that didn't work.

Wait, what's cheese? I just wrote a bunch of if statements to get the test cases to pass. you guys. All right. Redemption. Redemption. Have you guys tried Mountain Dew? We're sponsored by Mountain Dew, but also Sentry at centry.io/sintax.

You should definitely use Sentry, so you don't need to drink as much Mountain Dew as I do. Is that enough? What was that? That was not a very good ad placement. So, I would like to tell you that Sentry is very good at fixing your code, finding the bugs, finding errors, performance things, whatever is going wrong, using AI to fix it, using yourself to fix it, using a playback to figure out what the hell went on. Check it out. centry.io/intentex.

All right. Should I give these guys like a head start? All right. So, A B CDE E F B D F A B. So basically just only return things that are not vowels, but if there is a space, return things. Uhoh. All right, I can do this. It's every every other letter. Okay, easy.

Remove the characters at even indices. Oh, it literally tells us what the thing is. R E M. Oh, yeah. Okay. So, basically read the line um and then const result is equal to dotsplit. What we want to do is we want to spread this out. So let uh words equal and we're going to spread I mean there's so many other ways to do this. That's fine. Have a for loop uh while it's less than the length i ++ uh if i is odd log the letter but we don't want to log it. We want to build it up. So we'll have a result string at that index and then log out the result.

Do I need this? So I 0 1 2 3. It's Oh, the call. It's the callback function. What am I doing? God dang it. I'm trying to go fast. L, I call back function. Uh, if I is even or odd. If I modulo 2 and then console.log log l play all test cases failed. Okay.

So s do map the character and the index. So basically we're going to say if the index is even so if it's cleanly divisible by two that's not going to give me the first one. S. a function.

Oh, words. Words. Okay. Output stream. It uh I should be collecting them. So, let C for collect is equal to an empty string. Instead of console logging here, we're going to do C += L and then at the end of it, console.log return the character otherwise return nothing. And then we will filter with a boolean. and console.blog result play all test cases. Boom boom boom boom submit. Eat my short nothing% dot messing up.

So it turns out that the secret to winning one of these is to just complete dodge the first two of them. A B CDE E. Oh, I'm on two. If it's not even, that's not equal Z. Play all test cases. Here we go. Submit.

Boom. Scott beat me. No. One second. One second off of Wes. Scott, you did it. Yeah. And Wes, you beat me by You beat me by one second, Wes. Oh, man. I was going I thought I would have all the time in the world. So, let's see Scott's code. I did Oh, I just spread those words out. I spread them out and then I just did a for each and then I uh pushed the odd characters into a new string. Stupid, but it works.

It was fast. That's good. It took me forever to figure out how to figure out if a number is odd. U Oh, today's not my day. No, which is so funny cuz it's something that's like it's like 101 and it's just something you never do. That was quick though, Scott. You're you're fast with your messy for loops. I'll give you that.

Yeah, I don't know about that. All right. Should we do one more? Yeah, might as well. My god, I am so stressed to the gills right now. Okay. Expected answer nine. Expected answer 10. Expected answer 25, 27. We get a one, we get a three, we get a zero, we get a nine. We get a one, we get a three, we get a one, we get a 10.

That's a bit of a hint cuz it's like do this and then one more than that. Input 1 13 0 9 1 1 3 is 10. What the hell? Three. What? Um, Scott, let's go. We have AB.

So each one is an AB. So each line we have ignore the first one. If I is equal to zero, then ignore it. Else, see, this is how I program. I just kind of think even if it's not optimized here. Okay. And then with multiple lines, we're getting multiple outputs. So I do think it's like raised to the power of because five raised to the power of three. No, that would would that be? No.

Yes. Oh man. Autogenerated code below help aims to help you parse the standard input according to the problem statement. console.log log a b expected 9. What the hell is 30?

If it's not the first one, we want a * a + b. console.log that. Okay. Failed. Found nothing. Oh, console. You got to do that to see what's going on here. This doesn't make any sense. You know what?

You know what we're going to do? How can we get 25 out of these? I mean, I think maybe we focus on these two cuz this is one more than the previous. So, why is it one more than the previous? If I is equal to zero, then do nothing. Otherwise, do this. But I is the the very first one. Huh? If um if I is equal to zero, then do nothing otherwise console log A plus A. Okay. Well, let's just play all test cases here. Success.

Success. Success. Whatever. It worked. Scott figured it out. What the heck? Why did it work? I don't know. How does he do it? Why don't I know why it worked? Cuz I didn't have time to look at it, folks. We're just typing code as fast as humanly possible. So, do we save the previous one?

Oh my gosh. I just asked chat GPT and it's it's giving me no JS code with files. File system. No chance. All right. I have no idea. 5 * 3 is 15 + 0 is not 25. I think I do have a feeling that the last digit is always added onto the previous.

Please help me. Chat GPT I got these inputs. Wes get it. He got it probably in some weird way. He cheated and he beat me by an hour. How long do I give up over almost 2 minutes? Only been in here for 2 minutes. I'm going to Scott try to figure it out.

I got that math part of it really quick. But I was thinking that you had to ignore the first row. You ignore the first row and then do the second row or is that not accurate? Is it just the I don't know. I cheated. How do you say not math questions? Yeah, right. Yeah, no kidding.

Give me like an array map filter sort. No, cuz this is just like what is the equation and who can write that equation fast enough? Yeah. Yeah. So, previous A * A plus B. All right, I give up. All right, I gave up. And that was bad. I cheated. What did you do?

I I just screenshotted it. I was so mad that I just screenshot it and put it in chat GBT. I was like, I don't I no pattern I'm seeing here. And pattern matching skills are unmatched. I got the the equation part quickly, but I was thinking you had to ignore the first line. So I did this like if the index is equal to zero, then then do it or don't. And then I was like, well, fine. Let me just output the console log in here outside of the loop to debug it and then all the test cases pass. And I was like, okay, fine.

Yeah. Well, I yeah, I didn't realize till the end that the the first number is the number of lines that it will read in. So that's what in that's why it's ignored because there is a read line to give you in. After that it's AB for each one. All right, last one. Let's do it. I got to win this one. I started off so strong and here I am cheating. I'm ashamed of myself.

I got to win this one just because Wes is getting real cocky on his Mountain Dew clash. Now a dash b uh uppercase lower and lowerase. Okay, how do you tell if something is uppercase map over each character and if that character is equal to that character to uppercase uh then we'll do it to lowerase otherwise we'll do it to uppercase.

So you're inverting those you're inverting these okay if it's lower to upper if it's upper to lower. Okay, so we have the string. We're going to do str. Okay, so we will split it and then we will map over each character. If the character is uppercase, uh let's just do this const bet is equal to should am I going to type up the entire alphabet?

Spread it to an array and then do a for each. No, we're going to do a uh map and we're going to say each character each character and we're going to do how do you check if something's uppercase? Uh uh reax is uppercase JavaScript. How do you do check to see if something is uppercase or not? B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z. So that gives us an array. Join it back all together on a string and print it all out. Done.

These are my kinds of challenges. I can do this. I I I can I can iterate and format. I can't figure out weird patterns. Oh, this is stupid. You could check to see. Yeah, that's stupid. You could say character if Cer. So, if it is, this is so dumb. Uh, is this really the way to do it?

Going to return using reax. Maybe too lowerase.

Oh, join with a comma. I don't want to join with a comma. What was I doing? Boom. Beat him at his own game even though CJ beat me. Why is it not lowercasing it? I'm just going to missubmit. Damn it. Yeah. So, mine iterates over each character. If that character is equal to itself uppercase, yeah, then we lowerase it. Otherwise, we uppercase it and join it back all together.

I wrote the whole alphabet in uppercase. I I thought rejax right away, but I actually had to Google the rejax syntax to be sure of it because I like I'm just I hate rejax. What an upset. Yeah. Wow, that was embarrassing. in that sect.

Quote it with credit and a link. Quoting Syntax