Keith and Dawg 4 Solution

By: Jason Yang

Flag: 2313842

This program is written in lolcode.

The compiler can be built from this repo: https://github.com/justinmeza/lci

The language specification for lolcode can be found here: https://github.com/justinmeza/lolcode-spec/blob/master/v1.2/lolcode-spec-v1.2.md

HAI marks the beginning of the program, while the final line, KTHXBYE marks the end of the program.

Lines 9 through 31 define a “class” called TABLE. The next line (32) I HAS A TABLES ITZ LIEK A TABLE creates a new instance of TABLE called TABLES. The function of this variable is explained later. Moving on…

Similarly, lines 34 through 43 define a class called MATH, which is then instantiated in the next line (44). The function of this class is pretty obvious (do math things).

Again, lines 46 through 79 define a class called PILE, which is instantiated in line 101 as a variable called PIN. We’ll be skipping lines 81-99 for now (we’ll come back to it later). The class PILE has various functions defined through the following syntax:

HOW IZ I [METHOD NAME] YR [ARGUMENTS]

The methods are: PUSHIN(ITEM), POPPIN(), GETTIN(INDEX), and SIZIN. Clearly, this class is a stack (get it? It’s a pile!), where PUSHIN() pushes an object, POPPIN() pops an object, GETTIN() gets the object at an index, and SIZIN() returns the size of the stack.

Following the creation of the variable PIN, the user is prompted for the first number. Using the following syntax:

[OBJECT] IZ [METHOD NAME] YR [ARGUMENTS] MKAY

the variable PIN pushes the first number. This process is repeated for the 2nd and 3rd numbers, creating a stack PIN with 3 numbers. A boolean variable LOCK is then initialized, and set to the return of the method CHECKIN() when passing PIN as the argument. CHECKIN() was defined in lines 81-99, which we previously skipped.

The method CHECKIN() creates a boolean C which is initialized to true. A series of 3 if statements are tested (one for each number in the stack), and if any fail, C is set to false. The method then returns C.

The first if statement is just math and can be rewritten in pseudocode as follows:

if ( (((int) P.get(0)) - 3) * 15 + 43 == (16807 / 7) / 7 )

Thus, the first number must satisfy the equation

(P.get(0) - 3) * 15 + 43 = 16807 / 7 / 7
P.get(0) = 23

The second if statement uses the MATH class to do some math with the POWERIN method (which is not a power method btw). The POWERIN method can be rewritten as follows:

function POWERIN(abc, def){
    int index = 0;
    int num = abc;
    while (index = 0; index < def; index++){
        num *= index + 1;
    }
    return num;
}

This evaluates to:

num = abc * (def / abc)!

Going back to the second if statement, the condition is essentially:

if ( MATHS.POWERIN(P.get(0), P.get(1) / P.get(0)) == 16560 )

Recall that P.get(0) must equal 23. Therefore:

23 * (P.get(1) / 23)! = 16560
P.get(1) = 138

Finally, for the third if statement, the class TABLES is used, specifically the method CAT. This method takes an argument NUM. First, a numerical variable CAT3864 is created and defined as CAT2 / NUM. CAT2 is defined as 672 at the beginning of the TABLE definition (before the method definition). The next line uses the SRS keyword. SRS [IDENTIFIER] returns the variable with the name [IDENTIFIER]. This line also uses SMOOSH, which concatenates strings. So, the variable KIT (which equals 92) is multiplied to NUM which is then appended to the string CAT, and the variable of that name is found. The only variable with remotely that kind of name (CAT followed by a number) was just created, CAT3864. So, in order to not get a syntax error, NUM must equal

NUM = 3864 / 92 = 42

The next line basically does the same thing (concatenate and find variables of a certain name), which eventually evaluates to the variable A59CAT0. Remember, A59CAT0 was set to CAT3864, which equals CAT2 / NUM, so ultimately, the method CAT returns

672 / 42 = 16

This is returned to the third if statement, which checks:

if ( TABLES.CAT(P.get(2)) == 16 )

which returns true. So,

P.get(2) = 42

Now, when the correct three numbers are entered, the method CHECKIN returns true. The boolean LOCK is then set to true, leading to the message confirming the correct entry of numbers and revealing the flag, which is the concatenation of the three numbers in order:

2313842
KTHXBYE.

results matching ""

    No results matching ""