Skip to main content
edited body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

a 2D array of zeros and ones, where a 0 means empty and 1 means occupied

means that this:

enter image description here

looks like this:

0000000000
0010000101
1110001111
1111111110
1110111111

You want to know the height of the highest block. 3 in this case. Last time I played this game you also wanted to know when a row was filled so you could eliminate it. There is a simple calculation you can do that will answer both questions. Sum the rows.

0000000000 = 0 
0010000101 = 3 <= first non zero sum
1110001111 = 7  
1111111110 = 9 
1110111111 = 9 

First non zero from the top is the highest. Same calculation will tell you a row should be removed when it hits 10.

It's not fancy but who cares.? It's fast, it works, and it's easy to debug.

a 2D array of zeros and ones, where a 0 means empty and 1 means occupied

means that this:

enter image description here

looks like this:

0000000000
0010000101
1110001111
1111111110
1110111111

You want to know the height of the highest block. 3 in this case. Last time I played this game you also wanted to know when a row was filled so you could eliminate it. There is a simple calculation you can do that will answer both questions. Sum the rows.

0000000000 = 0 
0010000101 = 3 <= first non zero sum
1110001111 = 7  
1111111110 = 9 
1110111111 = 9 

First non zero from the top is the highest. Same calculation will tell you a row should be removed when it hits 10.

It's not fancy but who cares. It's fast, it works, and it's easy to debug.

a 2D array of zeros and ones, where a 0 means empty and 1 means occupied

means that this:

enter image description here

looks like this:

0000000000
0010000101
1110001111
1111111110
1110111111

You want to know the height of the highest block. 3 in this case. Last time I played this game you also wanted to know when a row was filled so you could eliminate it. There is a simple calculation you can do that will answer both questions. Sum the rows.

0000000000 = 0 
0010000101 = 3 <= first non zero sum
1110001111 = 7  
1111111110 = 9 
1110111111 = 9 

First non zero from the top is the highest. Same calculation will tell you a row should be removed when it hits 10.

It's not fancy but who cares? It's fast, it works, and it's easy to debug.

added 1 character in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

a 2D array of zeros and ones, where a 0 means empty and 1 means occupied

means that this:

enter image description here

looks like this:

0000000000
0010000101
1110001111
1111111110
1110111111

You want to know the height of the highest block. 43 in this case. Last time I played this game you also wanted to know when a row was filled so you could eliminate it. There is a simple calculation you can do that will answer both questions. Sum the rows.

0000000000 = 0 
0010000101 = 3 <= first non zero sum
1110001111 = 7  
1111111110 = 9 
1110111111 = 9 

First non zero from the top is the highest. Same calculation will tell you a row should be removed when it hits 10.

It's not fancy but who cares. It's fast, it works, and it's easy to debug.

a 2D array of zeros and ones, where a 0 means empty and 1 means occupied

means that this:

enter image description here

looks like this:

0000000000
0010000101
1110001111
1111111110
1110111111

You want to know the height of the highest block. 4 in this case. Last time I played this game you also wanted to know when a row was filled so you could eliminate it. There is a simple calculation you can do that will answer both questions. Sum the rows.

0000000000 0
0010000101 3
1110001111 7
1111111110 9
1110111111 9

First non zero from the top is the highest. Same calculation will tell you a row should be removed when it hits 10.

It's not fancy but who cares. It's fast, it works, and it's easy to debug.

a 2D array of zeros and ones, where a 0 means empty and 1 means occupied

means that this:

enter image description here

looks like this:

0000000000
0010000101
1110001111
1111111110
1110111111

You want to know the height of the highest block. 3 in this case. Last time I played this game you also wanted to know when a row was filled so you could eliminate it. There is a simple calculation you can do that will answer both questions. Sum the rows.

0000000000 = 0 
0010000101 = 3 <= first non zero sum
1110001111 = 7  
1111111110 = 9 
1110111111 = 9 

First non zero from the top is the highest. Same calculation will tell you a row should be removed when it hits 10.

It's not fancy but who cares. It's fast, it works, and it's easy to debug.

Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

a 2D array of zeros and ones, where a 0 means empty and 1 means occupied

means that this:

enter image description here

looks like this:

0000000000
0010000101
1110001111
1111111110
1110111111

You want to know the height of the highest block. 4 in this case. Last time I played this game you also wanted to know when a row was filled so you could eliminate it. There is a simple calculation you can do that will answer both questions. Sum the rows.

0000000000 0
0010000101 3
1110001111 7
1111111110 9
1110111111 9

First non zero from the top is the highest. Same calculation will tell you a row should be removed when it hits 10.

It's not fancy but who cares. It's fast, it works, and it's easy to debug.