Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2048 Puzzle
#31
(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.  Tongue
Reply


Messages In This Thread
2048 Puzzle - by Dav - 10-17-2024, 02:19 AM
RE: 2048 Puzzle - by FellippeHeitor - 10-17-2024, 02:42 AM
RE: 2048 Puzzle - by Dav - 10-17-2024, 02:48 AM
RE: 2048 Puzzle - by FellippeHeitor - 10-17-2024, 03:17 AM
RE: 2048 Puzzle - by bplus - 10-17-2024, 09:16 AM
RE: 2048 Puzzle - by Dav - 10-17-2024, 01:01 PM
RE: 2048 Puzzle - by bplus - 10-17-2024, 03:36 PM
RE: 2048 Puzzle - by Dav - 10-17-2024, 04:19 PM
RE: 2048 Puzzle - by bplus - 10-17-2024, 04:26 PM
RE: 2048 Puzzle - by SMcNeill - 10-17-2024, 05:05 PM
RE: 2048 Puzzle - by bplus - 10-17-2024, 05:15 PM
RE: 2048 Puzzle - by SMcNeill - 10-17-2024, 05:28 PM
RE: 2048 Puzzle - by Dav - 10-17-2024, 10:46 PM
RE: 2048 Puzzle - by bplus - 10-18-2024, 12:48 AM
RE: 2048 Puzzle - by Dav - 10-18-2024, 11:49 AM
RE: 2048 Puzzle - by bplus - 10-18-2024, 01:51 PM
RE: 2048 Puzzle - by bplus - 10-18-2024, 09:59 PM
RE: 2048 Puzzle - by Dav - 10-20-2024, 10:44 PM
RE: 2048 Puzzle - by bplus - 10-20-2024, 11:32 PM
RE: 2048 Puzzle - by bplus - 10-21-2024, 09:18 AM
RE: 2048 Puzzle - by SMcNeill - 10-21-2024, 10:19 AM
RE: 2048 Puzzle - by bplus - 10-22-2024, 11:37 AM
RE: 2048 Puzzle - by SMcNeill - 10-22-2024, 02:27 PM
RE: 2048 Puzzle - by SMcNeill - 10-22-2024, 02:39 PM
RE: 2048 Puzzle - by bplus - 10-22-2024, 03:26 PM
RE: 2048 Puzzle - by SMcNeill - 10-22-2024, 03:49 PM
RE: 2048 Puzzle - by SMcNeill - 10-22-2024, 03:36 PM
RE: 2048 Puzzle - by bplus - 10-22-2024, 03:38 PM
RE: 2048 Puzzle - by bplus - 10-22-2024, 04:37 PM
RE: 2048 Puzzle - by SMcNeill - 10-22-2024, 08:18 PM
RE: 2048 Puzzle - by bplus - 10-22-2024, 04:47 PM
RE: 2048 Puzzle - by SMcNeill - 10-23-2024, 03:44 AM
RE: 2048 Puzzle - by bplus - 10-23-2024, 10:32 AM
RE: 2048 Puzzle - by bplus - 10-23-2024, 12:40 PM
RE: 2048 Puzzle - by SMcNeill - 10-23-2024, 01:51 PM
RE: 2048 Puzzle - by bplus - 10-23-2024, 05:00 PM
RE: 2048 Puzzle - by bplus - 10-24-2024, 06:42 PM
RE: 2048 Puzzle - by Dav - 10-25-2024, 07:32 PM
RE: 2048 Puzzle - by bplus - 10-26-2024, 12:34 PM
RE: 2048 Puzzle - by Dav - 10-26-2024, 01:21 PM
RE: 2048 Puzzle - by bplus - 10-26-2024, 01:33 PM
RE: 2048 Puzzle - by bplus - 10-27-2024, 01:39 AM
RE: 2048 Puzzle - by bplus - 10-27-2024, 10:08 AM



Users browsing this thread: 14 Guest(s)