10-22-2024, 08:18 PM
(10-22-2024, 04:37 PM)bplus Wrote: That is one line of code for which I'd gladly exchange the 3 easier to understand lines from which it came.
I wouldn't take it even if I was at 66 lines and was trying to get to 64.
But now you're changing the rules of the exercise. Which do you want -- Readable Code, or least Lines Of Code? Those two things are usually mutually exclusive. Same for efficiency -- do you want the most efficient program, or the shortest program? Smallest executable? Least memory usage? Fastest processing?
Usually, people would focus on "I want readable code that works", without much concern over the other things. But once you zoom in on "I want the least amount of lines of code for this program, as possible, so that it still works," you change the style completely.
If we're going for readability, then I'd go for the following for those lines:
Code: (Select All)
If y < 3 _ANDALSO B(y * 4 + x) = B((y + 1) * 4 + x) Then 10 ' == a move left goto 10 ==
If x < 3 _ANDALSO B(y * 4 + x) = B(y * 4 + (x + 1)) Then 10
IF THEN IF just doesn't seem like that readable or efficient of a set of code to me. A single line IF THEN seems better, and there's no one who should ever obect to it and say something like, "It's just cramming multiple IF statements on one line to reduce line count!"
It's a valid code restructure which reduces lines of code. We go from what is basically multiple line statements packed together:
If y < 3 Then
If B(y * 4 + x) = B((y + 1) * 4 + x) Then
Goto 10 ' == a move left goto 10 ==
End If
End If
To a single line statement:
If y < 3 _ANDALSO B(y * 4 + x) = B((y + 1) * 4 + x) Then
Goto 10 ' == a move left goto 10 ==
End If
But, for pure reduction of lines of code?
One single line, which combines all that logic together, such as what I posted above, is what you want.
It honestly just sounds like the goalpost has shifted and the game has changed in the middle of playing it. No longer is it an exercise to reduce the code down to the smallest number of lines of code. It's now about having it look pretty, fit on a screen of no more than 100 characters in width, making it readable, and then reducing the line count down until it's a cutely acceptable number like 64.