1 Replies - 350 Views - Last Post: 14 August 2018 - 08:07 PM Rate Topic: -----

#1 nymphic   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-August 18

Whats the issue with this pseudo-code and how would you fix it?

Posted 14 August 2018 - 07:54 PM

indentation does not matter in this code, ":=" denotes the substitution, and "=" is the equal comparator.

========
Initial state of an array "a":

[[2, NULL, 2, NULL], 
 [2, NULL, 2, NULL], 
 [NULL, NULL, NULL, NULL], 
 [NULL, NULL, NULL, NULL]]


========
Main function:

FUNCTION foo()
    FOR y := 0 to 3 
        FOR x := 0 to 3
            IF a[x+1][y] != NULL
                IF a[x+1][y] = a[x][y]
                    a[x][y] := a[x][y]*2
                    a[x+1][y] := NULL
                END IF
                IF a[x][y] = NULL
                    a[x][y] := a[x+1][y]
                    a[x+1][y] := NULL
                END IF
            END IF
        END FOR
   END FOR
END FUNCTION
:code:

This post has been edited by modi123_1: 16 August 2018 - 06:36 AM
Reason for edit:: In the future, please highlight the text that is code and click the [code] button in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: Whats the issue with this pseudo-code and how would you fix it?

#2 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 11426
  • View blog
  • Posts: 19,482
  • Joined: 19-March 11

Re: Whats the issue with this pseudo-code and how would you fix it?

Posted 14 August 2018 - 08:07 PM

Well, what gives you the idea that anything's wrong with it?
What's it meant to do, for a start?

Tell you what, it's your homework, why don't you start working it out and we'll throw in a suggestion here and there, a little "hot" and "cold" to guide you along. Fair?
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1