CodeFights Ep. 2 - Bad Little Johnny (Head-to-Head)

The Art of Coding: A Journey Through Glitches and Recovery

It's Christmas time at the North Pole, and everyone is excited to share their festive spirit with each other. However, the internet traffic is very expensive, so instead of sending actual images, Santa decides to draw a tree using only asterisks. This means that his friends will have to look at a string of asterisks to see the Christmas tree. In this task, we are asked to write a program that can generate these trees following a specific specification and some initial parameters.

The problem requires us to define a line as a horizontal group of asterisks and a level as a collection of asterisks stacked one on top of the other, forming the crown of the tree. The trees are perfectly symmetric, so all the middle asterisks of the lines lie on the center of the tree. Each line at a given level can be created by repeating a pattern of asterisks, with the number of repetitions determined by the level and height of the tree.

The specification for the tree is as follows: each line should have the same height, and the middle asterisk of each line should be on the center of the tree. This means that if we want to create a tree with a certain level and height, we can use the following pattern to generate it. We start by creating a horizontal group of asterisks for the crown of the tree, followed by a series of vertical groups of asterisks that form the levels of the tree.

The key to solving this problem is understanding how the trees are constructed and recognizing the pattern in which they are created. By following this pattern, we can create any number of trees with different heights and levels, all while maintaining the symmetry and structure required by the specification.

However, as we delve deeper into the world of coding, we may encounter problems that require us to recover from mistakes or unexpected behavior. In such cases, we must be able to think creatively and come up with solutions that can handle these issues. One such problem is "curved spaces," which seems to be a reference to the use of asterisks in creating trees.

After some experimentation, it appears that using max spaces minus one may provide a solution to this problem. By understanding how the trees are constructed and applying this pattern, we can create trees with curved shapes that still meet the requirements of the specification. However, the problem is not without its challenges, and we must be prepared to deal with unexpected behavior and errors.

Moving on to the next task, we come across a problem involving a boy who was denied candy by his mother. To make matters worse, he has a habit of turning everything you say upside down, including false statements becoming true and vice versa. This means that if we want to determine what the boy will say about a statement, we must first establish whether the statement is true or false.

Fortunately, this problem is relatively easy to solve, as we can simply return "true" for the statement if it is given as false, and return "false" otherwise. By applying this simple rule, we can determine what the boy will say about any given statement, making it an easy and straightforward task.

In conclusion, coding can be a challenging and rewarding experience, but it also requires patience, persistence, and creativity. Whether dealing with complex problems or simple ones like the latter, there is always room for growth and improvement. By mastering these skills and staying adaptable, we can overcome even the most daunting challenges and create solutions that amaze and delight.

In our journey through coding, we have encountered a variety of problems, each with its unique requirements and specifications. From creating Christmas trees using asterisks to dealing with the quirks of a boy who turns everything upside down, every challenge presents an opportunity for growth and learning. By embracing these challenges and pushing ourselves to solve them, we can become better coders and developers, capable of tackling even the most complex problems.

As we continue on this journey, it is essential to remember that coding is not just about solving problems; it's also about having fun and being creative. Whether working individually or in teams, coding allows us to express ourselves and bring our ideas to life. So let's keep pushing forward, stay curious, and enjoy the ride.

"WEBVTTKind: captionsLanguage: enwhat's up beautiful people welcome to another episode of code fights too with Kazi from clever programmer tom where you learned to code smarter so let's get this episode started we're gonna go ahead to head pick somebody to fight quick let's fight and let's get going alright dark can dark on let's go his language of choice is Java let's see if we can take him down with Python alright so we have a problem is power so essentially is this a power can you get this number by doing a ^ beat for 72 no you can't there's no power and you can't take any integer and raise it to some integer power it gets 72 if you do five cubes you could get 125 okay so you're checking if any a ^ B gives you this dunyah - there's not gonna be too much stuff that we're doing here this is a bug fix remember the first one is a bug fix so let's fix this bug and let's keep going let's hit start coding alright sometimes these books seem really annoying to fix sometimes not really so let's let's see if we can fix this one easily generally for bug fixes there you're not supposed to change anything you're supposed to keep it the same you just change one line you don't really add new lines let's check out these sample test cases you guys sometimes might not see the sample test cases cuz my face might be blocking it it might be behind me let me just run this so what I was expecting true and Trent false mmm looks like really like flip if n is equal to one return true I think this one I should change it to false let's see what happens it says you made too many changes oh no too many changes I made only one change you guys too many changes what is this constraint what does this even mean well what did you tell us how to solve it come on code fights where are my rules rules there's one bug on one line of the code find it fix it hit submit okay one bug on one line when I do it it says too many changes what does that even mean let me refresh it maybe there's some bug let me try it again false too many changes how about not true which is the same thing as false haha what is this what does that mean too many changes I'm making a change to only one line okay guys this is boring let's let's just skip it alright I'm just gonna skip it next I don't care down yep geez okay it looks like that person skipped it too so it looks like that problem was actually glitched so we're gonna just ignore that one okay problem two each strip each tree has a crown so it looks like this here's the formal definition of how the tree should be built before you read it the elf highly recommends looking first at the examples to follow okay so to share his let's just read the problem it's Christmas time to share his Christmas spirit all his friends on Christmas elf decided to send each of them a Christmas email with a nice Christmas tree unfortunately internet traffic is very expensive in the North Pole so instead of sending an actual image he decided to draw the tree using only asterisk okay weird but sure he has given you this bag see below in your task is to write a program that would generate trees following the spec and some initial parameters a Sri has a crown that looks as follows okay define the line as a horizontal group of asterisks and a level as as a collection of level height line stacked one on top of the other below the crown there are level number levels the trees perfectly symmetric so all the middle asterisks of the lines lie on the center of the tree okay each line to the same level wow these are some jacked trees huh so if you give the Christmas tree level num level height it makes the tree like this all right cool the crown level one the foot okay a lot of stuff going on here now the thing is we might not even have to understand the problem because there might be a recovery that we have to do so what is curved spaces hmm what the heck is curved spaces let's try max spaces minus one let's see if that yields the answer to be honest code fights you gotta get rid of these problems these problems are just bad though the ones with recovery and stuff just add problems where you have to solve them all right so weird having to do bug fix it's not really testing your coding skills alright so I'm essentially just trying to do some pattern matching here but let me see if I have to get smarter so I'm getting the wrong answer I'm off by off by what okay my face might be hiding the test cases but trust me the test cases are you know are there I'm looking at the test cases what the heck is going on here that's pretty much what we made max faces plus-one maybe it's min spaces I don't even know if men's faces the thing probably not that's not cur spaces is defined up here not exactly sure how good to file it find it down here max spaces - one was the closest we came like the two trees look exactly the same our output and expected output literally look pretty close actually not no no they definitely look a hundred percent the same but for whatever reason it's over not correct maybe a bug maybe next down vote let's skip this one - lets get to the next one okay this one will probably be a fun funner one because we actually get to write code rather than just bug fix this so let's get to it little boys mother didn't buy him a candy so now he's sulky and moody he turns everything you say upside down if you say that something is true heel sits false and vice versa find out what the boy will say about the statement you're about to make so the statement is false the output should be true if the statement should not but should be false what the hell just happened it just went from like these ridiculously hard and problematic and bugged out problems you know one-line solutions or whatever to just the easiest thing in the world like this is gonna be literally returned not whatever that was given it's gonna be like a is gonna take a second it's gonna come down to this look around if I write the solution that is faster than the other guy I went so the solution is gonna be return not something return not statement check the solution done yeah all right now we got to see if we did it faster than this guy because if we did we win now I'm gonna vote it down like what is this we know it's the easiest thing in the world all right guys that was awesome we killed it as you can see we were clearly better we outsmarted the other guy 100% and those great oh we we want okay doesn't it feel good to win this it was very hard-fought thank you guys for being there I appreciate you and if you liked it comment in the video below and I'll see you guys in the next videowhat's up beautiful people welcome to another episode of code fights too with Kazi from clever programmer tom where you learned to code smarter so let's get this episode started we're gonna go ahead to head pick somebody to fight quick let's fight and let's get going alright dark can dark on let's go his language of choice is Java let's see if we can take him down with Python alright so we have a problem is power so essentially is this a power can you get this number by doing a ^ beat for 72 no you can't there's no power and you can't take any integer and raise it to some integer power it gets 72 if you do five cubes you could get 125 okay so you're checking if any a ^ B gives you this dunyah - there's not gonna be too much stuff that we're doing here this is a bug fix remember the first one is a bug fix so let's fix this bug and let's keep going let's hit start coding alright sometimes these books seem really annoying to fix sometimes not really so let's let's see if we can fix this one easily generally for bug fixes there you're not supposed to change anything you're supposed to keep it the same you just change one line you don't really add new lines let's check out these sample test cases you guys sometimes might not see the sample test cases cuz my face might be blocking it it might be behind me let me just run this so what I was expecting true and Trent false mmm looks like really like flip if n is equal to one return true I think this one I should change it to false let's see what happens it says you made too many changes oh no too many changes I made only one change you guys too many changes what is this constraint what does this even mean well what did you tell us how to solve it come on code fights where are my rules rules there's one bug on one line of the code find it fix it hit submit okay one bug on one line when I do it it says too many changes what does that even mean let me refresh it maybe there's some bug let me try it again false too many changes how about not true which is the same thing as false haha what is this what does that mean too many changes I'm making a change to only one line okay guys this is boring let's let's just skip it alright I'm just gonna skip it next I don't care down yep geez okay it looks like that person skipped it too so it looks like that problem was actually glitched so we're gonna just ignore that one okay problem two each strip each tree has a crown so it looks like this here's the formal definition of how the tree should be built before you read it the elf highly recommends looking first at the examples to follow okay so to share his let's just read the problem it's Christmas time to share his Christmas spirit all his friends on Christmas elf decided to send each of them a Christmas email with a nice Christmas tree unfortunately internet traffic is very expensive in the North Pole so instead of sending an actual image he decided to draw the tree using only asterisk okay weird but sure he has given you this bag see below in your task is to write a program that would generate trees following the spec and some initial parameters a Sri has a crown that looks as follows okay define the line as a horizontal group of asterisks and a level as as a collection of level height line stacked one on top of the other below the crown there are level number levels the trees perfectly symmetric so all the middle asterisks of the lines lie on the center of the tree okay each line to the same level wow these are some jacked trees huh so if you give the Christmas tree level num level height it makes the tree like this all right cool the crown level one the foot okay a lot of stuff going on here now the thing is we might not even have to understand the problem because there might be a recovery that we have to do so what is curved spaces hmm what the heck is curved spaces let's try max spaces minus one let's see if that yields the answer to be honest code fights you gotta get rid of these problems these problems are just bad though the ones with recovery and stuff just add problems where you have to solve them all right so weird having to do bug fix it's not really testing your coding skills alright so I'm essentially just trying to do some pattern matching here but let me see if I have to get smarter so I'm getting the wrong answer I'm off by off by what okay my face might be hiding the test cases but trust me the test cases are you know are there I'm looking at the test cases what the heck is going on here that's pretty much what we made max faces plus-one maybe it's min spaces I don't even know if men's faces the thing probably not that's not cur spaces is defined up here not exactly sure how good to file it find it down here max spaces - one was the closest we came like the two trees look exactly the same our output and expected output literally look pretty close actually not no no they definitely look a hundred percent the same but for whatever reason it's over not correct maybe a bug maybe next down vote let's skip this one - lets get to the next one okay this one will probably be a fun funner one because we actually get to write code rather than just bug fix this so let's get to it little boys mother didn't buy him a candy so now he's sulky and moody he turns everything you say upside down if you say that something is true heel sits false and vice versa find out what the boy will say about the statement you're about to make so the statement is false the output should be true if the statement should not but should be false what the hell just happened it just went from like these ridiculously hard and problematic and bugged out problems you know one-line solutions or whatever to just the easiest thing in the world like this is gonna be literally returned not whatever that was given it's gonna be like a is gonna take a second it's gonna come down to this look around if I write the solution that is faster than the other guy I went so the solution is gonna be return not something return not statement check the solution done yeah all right now we got to see if we did it faster than this guy because if we did we win now I'm gonna vote it down like what is this we know it's the easiest thing in the world all right guys that was awesome we killed it as you can see we were clearly better we outsmarted the other guy 100% and those great oh we we want okay doesn't it feel good to win this it was very hard-fought thank you guys for being there I appreciate you and if you liked it comment in the video below and I'll see you guys in the next video\n"