Computer Science Canada DWITE#5 (in turing) |
Author: | A.J [ Sun Feb 17, 2008 3:07 pm ] |
Post subject: | DWITE#5 (in turing) |
Can someone tell me what's wrong with this. (it doesn't work for the 4th test case, even though I am dropping the pieces from way above the 'ground') I couldn't add comments since I didn't have time tell me if you do not understand any part of my code thx (I also attached the test case) |
Author: | A.J [ Sat Mar 08, 2008 4:29 pm ] |
Post subject: | Re: DWITE#5 (in turing) |
GUYS I REAlly need help with this question!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
Author: | zylum [ Tue Mar 11, 2008 6:06 am ] | ||
Post subject: | RE:DWITE#5 (in turing) | ||
Your code is somewhat hard to follow especially with the lack of comments. Thus I wont find the error in your code and instead will post my solution to give you some ideas as how to improve your solution. It is heavy on bitwise operators so you may want to read the tutorial on the subject. If you clean up your code a bit and comment it, I will be glad to take a look at it
|
Author: | A.J [ Tue Mar 11, 2008 9:44 am ] | ||||
Post subject: | Re: DWITE#5 (in turing) | ||||
SO many bitwise operators for my head..........looks like a good solution though (like I would know ) I'll look them up at the Turing Walkthrough, but I don't get how:
checks for overlap, and how
inserts. sry, but I am a noob to bitwise operators and their uses. |
Author: | zylum [ Tue Mar 11, 2008 4:47 pm ] |
Post subject: | RE:DWITE#5 (in turing) |
Well the |= and xor= are basically what you would expect (work the same as +=). ret initially starts as false. Due to ors nature, if the expression to the right ever evaluates to true, then ret will be true for the remainder of the loop and thus return whether or not the expression evaluates to true at least once. If it does evaluate to true then there was an overlap.. b(i + y) is the row of the board we are checking and p(r, i) is the row and rotation of the piece we are checking. We shift the piece to the left by the appropriate number to get it in the proper position and 'and' it with the board column. If any bit in the board row is 'high' and the corresponding bit in piece is 'high' then the corresponding bit in the value of the expression will be high, thus making the expression non-zero and resulting as true. This is a somewhat long topic. For a more detailed description, check out the tutorial. |
Author: | A.J [ Tue Mar 11, 2008 6:09 pm ] | ||||
Post subject: | Re: DWITE#5 (in turing) | ||||
thnx. i read through the tutorial and I understand most of what you are doing. Thank you so much . I still don't get one part:
why 65535? and could you just give a BRIEF (don't want to waste your time) explanation on how the following works:
you the greatest zylum! |
Author: | zylum [ Tue Mar 11, 2008 11:33 pm ] |
Post subject: | RE:DWITE#5 (in turing) |
65535 in binary is 16 ones so that represents a full row. 57351 is 3 ones followed by 10 zeroes and another 3 ones. When i is > 5 then 13-i is the 6th row of the board (not including the bottom full row) and we can start reading in values of the board from the test data. Each test data row consists of 10 columns, so we iterate through them and or in a 1 when we encounter a '#'. We place the 1 in the appropriate position by shifting it. |
Author: | A.J [ Tue Mar 11, 2008 11:45 pm ] |
Post subject: | Re: DWITE#5 (in turing) |
thnx a lot! |