Coding Battles - Clash of Code
Вставка
- Опубліковано 19 сер 2024
- Coding battles are a fun way to practice coding, especially if you are learning a new language. It's also a good mental workout to keep that noggin sharp.
Clash of Code:
🕹 www.codingame....
Cracking the Coding Interview (my favorite coding interview prep book):
📼 amzn.to/2EHHQ3D (the new 6th edition one)
Cracking the Coding Interview - Video with Danny:
📼 vimeo.com/1140...
Join our Discord community:
💬 / discord
Connect with me:
🐦 Twitter - / elliotwaite
📷 Instagram - / elliotwaite
👱 Facebook - / elliotwaite
💼 LinkedIn - / elliotwaite
Music:
🎵 • Video
🎵 • Video
🎵 • Video
🎵 • ksolis - Nobody Else
A MISTAKE I MADE IN THE VIDEO:
In clash 4 (Shortest Mode), num is strange if: x^x + x = num, and num's constraints were: 0 < num < 2^32, so to find the range of x, I needed to solve this equation: 0 < x^x + x < 2^32, but when I tried to solve it in my head, I actually solved this equation: 0 < x^2 + x < 2^32, so my upper bound for x was way too high (noob error, shame 😔). What I should have done instead was enter something like "x^x+x = 2^32" into WolframAlpha to realize that x < 9.74309. So I really only had to check against values of x in the range 1 to 9. This also means I could have removed the "if not n%x" part that was only added to make it so I didn't run into the computation time limit because I was checking so many different values. So a better solution would have been "print(any(x**x+x==n for x in range(10)))".
@anas6733 Thanks for the suggestion. I've made this the pinned comment.
i think the short code mode should be replaced by something more usefull like fastest execution time
That'd be a cool mode, but Python might not be the best language choice for that one.
@@elliotwaite The current meta heavily favors script languages like Javascript and Python, because of short code and versatile std libraries. But I prefer to write C++ code, which will be way longer in most cases:(
@@ep9017 ah, yeah, adding the fastest execution mode might help balance out the advantage scripting languages currently have.
They have to add assembly then
@@jamesmathai1138 indeed.
I should have just written "print(min(m, n))" for that first one. I went old school with that if-else statement.
You noticed that after 2 years? 😂
@@faisalalamri4091, I noticed it a while ago, but it wasn't until recently that I thought "maybe if I at least leave a comment letting people know that I'm aware of the mistake, I'll look less stupid." But from your reply, it seems my comment may have had the opposite effect.
But this is probably a good thing since I think I have an irrational fear of others thinking I am unintelligent, and I think that holds me back from taking more of the risks in life that would actually benefit me the most. So perhaps the stupider I look the better to some extent. Exposure therapy.
Another mistake is at 5:08 where I actually only needed to go up through 9 if only checking integers since 10^10 + 10 is already greater than 2^32. Also, I'm not sure why I assumed that x had to be an integer since that didn't seem to be stated in the problem. And if x could be any real number, then all of the numbers between 0 and 2^32 would qualify as "strange" since they all exist in the range of the function f(x) = x^x + x. So I'm still not sure what happened with that one.
@@elliotwaite Why are you not doing Clash of Code anymore now?
@@munyoudoumpav180, mostly because I felt like there were more productive things I could be doing with my time, like writing code that would go towards building something that I or others would actually use.
It really worked for me after I look and try some tutorials, yours is the one that worked. Owe you a lot.
Glad to hear it helped.
made it into an arp using the default soft envelope generator and a bunch or other weird stuff I didn’t even know existed. Called it pants
that's pretty cool!
thanks for sharing
Works at its best
May I ask? For shortest mode, it is unfair as other language are presumably longer to execute a certain task such as printing, Java took multiple characters but Python only needed few. Do you acknowledge this?
The shortest possible solutions will be different between languages, so it's not fair between languages, but all users can switch to whatever language they think is best for the task. So I guess it depends on how you want to define fair.
C programmers: 👁👄👁
idk if I just suck at coding or what I can build responsive webpage but I tried playing this game and I just suck
I used to suck at code battles too before practicing. It's probably just a different skill set. There are a lot of different ways to be good at coding.
Elliot Waite lol thanks for making me feel better I was just concerned that I won’t be able to get a job because I can’t make a mans faces
@@Haloking1212 lol
Shortest code puts other languages at a disadvantage, compared to Python.
Yep.
Would be nice if you could set which Clash modes you'll play in user settings. Fastest and reverse are fine, but for shortest mode, I just quit the clash. Pointless vs. Python and JS script kiddies, Ruby coders, et al.
Without this, the least CodinGame could do is to define aliases for common functions. I use F#, so instead of the ridiculous "System.Console.In.ReadLine" (which should be "System.Console.ReadLine" anyway), just define something like "let rl = System.Console.ReadLine". It's a lot fairer vs. stuff like "input" and "gets".
That's a good suggestion, especially for people using the game to learn a specific language that might not be as concise as others. It might be a good idea to mention this suggestion to them on their forum: www.codingame.com/forum
I noticed a few threads already discussing the frustrations of shortest mode:
www.codingame.com/forum/t/clash-of-code-shortest-improvement/2765
www.codingame.com/forum/t/clash-of-code-best-performance-instead-of-shortest/892
www.codingame.com/forum/t/clash-of-code-shortest-mode-improvement-for-java/2926
Probably the best app from you..
thanks,Elliote
great video
good work and thank you so much, Greetings from Egypt
Thanks! Greetings.
The strange numbers solutions were...strange.
You did it correctly, but for some reason you looped to the square root of 2^32 as if the check was x^2+x=num rather than x^x. (Seems it would be enough to loop 1 to 9.)
Even stranger was that the guy you checked did exactly that - i*i+i instead of i**i+i - and got 80% score.
Or I misunderstood something.
You are correct, I only needed check the numbers 1 to 9. I think I was trying to go to fast and made the noob error of thinking the square root of x^x was x (kind of embarrassing). Also, if only using "range(10)" I wouldn't have needed the extra "if not n%x" which I only added to not run into the computation time limit. So a better solutions would have been "print(any(x**x+x==n for x in range(10)))". Thanks for pointing that out.
I'm not sure how that solution I checked from the other user got 80% when his answer was checking against the wrong equation, but I guess his answer also worked for some of the test cases.
Cool
Really enjoyed the video. Good one,
thanks for the info really helped alot. i rather learn about tNice tutorials than school
I'm glad you liked it.
is there a mode where they force coders to code with the same language; like java vs java coders. because some languages have shorter syntax than others and thats no fair if a coder code in a shorter syntax language vs a coder with long syntax language
I don't think they have that mode, but you're right about that.
Does anyone here feel as lost as i am?
I'm somewhat disappointed with the shortest mode. I always thought that making shorter code is not always better, and that a good code is one that is well understood. Making code shorter by being more cryptic is bad practice.
Yep, to me shortest mode is less about developing good habits and more about exploring what's possible with the syntax of whichever language you choose (and unfortunately, which language you chose makes a big difference on your potential best score). I'm not sure how well exploring the possibilities of a syntax translates to being a better coder, but I find it an interesting challenge sometimes. But that mode seems to be the most controversial, with some people suggesting there should be an option to only compete against users using the same language, and others suggesting there should be an option to not have to play that mode at all.
For the life of me, i don't understand the Test1, Test2... Test5 cases. What are those for?? Either your code works, or not. Why are there 5 tests? Because of this i only get 20%, i have no clue what to do with the other 4.
Each of the tests is supposed to represent an input value and an expected output value. For example, if the challenge was to write a function that would return the absolute cube of the input, then to check if you programmed it correctly there would be a set of tests, for example:
Test 1: (input 1, output 1)
Test 2: (input 2, output 8)
Test 3: (input -1, output 1)
Test 4: (input -300, output 27000000)
So if you don't have the correct solution, you might pass some of the tests but fail on others. For example, "f(x): return x * x" would pass 1 and 3, but fail 2 and 4. And "f(x): x * x * x" would pass 1 and 2, but fail 3 and 4. While "def f(x): return abs(x * x * x)" would pass all of them, and be considered correct according to those tests.
Checking a solution against a set of tests is much easier than trying to reverse engineer your code to determine if it is actually correct. Some programming languages make this easier by being able to be provably correct, but most programming languages are too flexible to be able to do this efficiently, if at all in some cases.
Also, the reason the game doesn't tell you what the test cases actually are, is that if you knew them, you could use them to cheat. For example, given the test cases above, you could just make this your answer:
def f(x):
if x == 1 or x == -1:
return 1
if x == 2:
return 8
if x == -300:
return 27000000
And according to the tests, it would be accepted as correct.
Usually the tests are ordered in a way such that the simple general cases are tested first, and then the later ones are more difficult, such as edge cases or ones that would take too much time or memory to computer if you used an inefficient algorightm.
Hope that helps.
Piedm
i really love this vedio.
Thanks!
excellent video
Thanks
hello why is clash of code a scheduled event now?
I don't know. This is the first I've heard of this.
Most of the challanges are made to be convenient solvable with python its often faster written and easy to find a "one line of code" solution with python. other languages look bad next to it... this ist just stupid xD
Does anyone know why some solutions don't get 100% ? What is the criters to get the maximum ?
100% means your program returned the correct answer for all the testcases. Your program also has to return those correct answers within the allowed time limit. Sometimes your solution will work for most inputs, but will fail or take too long on certain edge cases, causing you to not get 100%. Usually the earlier testcases check against more common inputs and the later testcases check against more edge case inputs. As long as your solution passes all the testcases before you submit it, you should get 100%.
@@elliotwaite All right thanks :)
@elliotwaite can you please mentor me to get into google?
Hey, Thomas. For now, I think the best thing I can do is point you to the resources that I found most helpful in preparing for the Google interview. Also, I don't think I'm the best resource for giving advice on how to get to the interview stage since I did it by stumbling upon one of Google's secret online coding challenges and solving enough of the problems on there to get contacted by a recruiter, which isn't a reliably repeatable strategy. But once I got to the interview stage, these were the resources that I found most helpful in preparing for the interview.
For learning about data structures and algorithms (which most of the coding questions were about) this playlist was my favorite resource:
MIT 6.006 Introduction to Algorithms, Fall 2011
ua-cam.com/video/HtSuA80QTyo/v-deo.html
I also found it really helpful to practice solving coding problems on a whiteboard, especially the types of problems in Cracking the Coding Interview (link in the description) and on the ones on interviewcake.com.
It also helped to become very familiar with the programming language I was going to be writing up my coding solutions in. Currently, I'm most comfortable with Python, but back then I was more comfortable with JavaScript, so before taking the interview in JavaScript, I read a lot of the JS documentation on MDN and took this online course which covered a lot of the advanced parts of Javascript: www.udemy.com/understand-javascript/
Also, doing the coding challenges on a whiteboard where you don't have any IDE auto suggestions and where you have to remember all the functions and the correct syntax by heart helps to become more familiar with the language you'll be using.
It also helped to learn about systems building, and get some general understanding of the different infrastructure options you have when building web-based applications, and knowing when you'd want to make certain system design decisions vs others depending on the requirements of an application, and knowing the different tradeoffs that you have to make as you scale an application from a few daily users to millions. Some of the questions I got during the interview were related to systems design.
I also found it valuable to do some general research on how the internet works and how computers work to fill in some of the gaps in my knowledge.
Hope that helps.
Hello Elliot Waite thank you very much four your detailed response. I really do appreciate it!
coool!
I don't get the instructions on your site at all. It's like it's made only for pro codders, not for beginners.
I'm just a user of that site like yourself. If you want to reach out to the people that run the site, their UA-cam channel is here: ua-cam.com/users/Codingame
@@elliotwaite
Ok, thanks for the video.
Is this game for noobs..like me??
Yes, it's noob friendly. Whenever you can't figure out how to do something, you can look at how your opponents solved it. It's a good learning cycle, try to solve something on your own then look at others solutions.
@@elliotwaite sweet..because I'm starting from rock bottom....like bottom bottom
@@seniorpz1969 If you are starting from the bottom bottom, it might be better to follow some type of course such as a youtube playlist or a book that will lead you through the learning process in a more organized way, starting with the fundamentals and building up from there. You can learn by playing this game, but it will probably not be in an organized way, so it might not be as fast or as thorough of a process.
@@elliotwaite ok, i'll try that. thanks!
Python, really? This kind of exercises encourage really bad practices. Readability and performance should be the two main factors you should take into consideration when programming this kind of snippets, not how short or obfuscated is the code or how fast you can program, that's just stupid. Do we want programmers to be professional or to be sloppy?
I agree that it is probably not the best way to practice the main skills in programming (like readability, performant code, etc.), but I did find it beneficial in the following ways:
* "Shortest" mode made me think about all the different ways that something could be accomplished in that language, which seemed like a good exercise.
* "Shortest" mode also helped me learn about uncommon features of a language since I would see someone else's solution that used a part of the language I hadn't used before, and then I'd go learn about it.
* "Fastest" mode seemed to help me practice problem solving under time pressure. I'm not sure how beneficial this is because in most coding situations there isn't that level of time pressure, but it still felt like a good brain and coding exercise.
* "Fastest" mode also helped me memorize more of Python's built-in functions since looking up any documentation was slow.
* "Reverse" mode seemed like general pattern recognition and brain training, and then also coding practice cause I'd have to translate my thoughts into code.
That was just my personal experience with playing the game.
this website is absolutely not for Beginners even though it advertises for, descriptions are very very complicated
garbage
you dont ever understand what you asked for
Probably the best app from you..
Does anyone here feel as lost as i am?