• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Comment How To Add Malicious Code To Your Programs, Abl Ackermann's Function

Cecil

17+ years progress programming and still learning.
#1
The ABL Ackermann's function

So, if you have a client(s) that are behind on payments, stick this code in your programs. It will either 'error' or slow down the system. NOTE: Don't do this.

Inspired by this YouTube video:

ABL Dojo:
ABL Dojo

Code:
/* int ack(m,n) */
/* int m,n; */
/* { */
/* int ans; */
/* if (m == 0) ans = n+1; */
/* else if (n == 0) ans = ack(m-1,1); */
/* else ans = ack(m-1, ack(m,n-1)); */
/* return (ans); */
/* } */

function ack return int64(input m as int64,
                            input n as int64):
                           
    define variable answer as int64 no-undo.                          
       
    case true:
        when m eq 0 then
            answer = n + 1.
        when n eq 0 then
            answer = ack(m - 1, 1).
        otherwise
        answer = ack(m - 1, ack( m , n - 1)).
    end case.
                       
    return int64.            
                           
end function.    

ack(random(0,9) , random(0,9) ).
 
Last edited:

Cecil

17+ years progress programming and still learning.
#3
Is the link broken or is that the code breaks the Dojo?

Code:
SYSTEM ERROR: -s exceeded. Raising STOP condition and attempting to write stack trace to file 'procore'. Consider increasing -s startup parameter. (5635)
SYSTEM ERROR: -s exceeded. Raising STOP condition and attempting to write stack trace to file 'procore'. Consider increasing -s startup parameter. (5635)
SYSTEM ERROR: -s exceeded. Raising STOP condition and attempting to write stack trace to file 'procore'. Consider increasing -s startup parameter. (5635)
SYSTEM ERROR: -s exceeded. Raising STOP condition and attempting to write stack trace to file 'procore'. Consider increasing -s startup parameter. (5635)
SYSTEM ERROR: -s exceeded. Raising STOP condition and attempting to write stack trace to file 'procore'. Consider increasing -s startup parameter. (5635)
SYSTEM ERROR: stkpush: stack overflow. Increase the -s parameter. (279)
** Save file named core for analysis by Progress Software Corporation. (439)
 

Cecil

17+ years progress programming and still learning.
#5
Kept telling me unable to run, even a blank piece of code failed.
"Bonkers"

Did a bit of investigation on the AJAX request and the server is returning the following.:

Code:
<h1>(HTTP code 500) server error - Unable to find a node that satisfies the following conditions
[available container slots]
 </h1>
 

Smud

New Member
#6
yep you will need some serious stack space to go beyond 1 TO 3 (and helps if you get the syntax right ;-)

Code:
function ack RETURNS INT64 (INPUT m as int64,INPUT n as int64):
                          
    define variable answer as int64 no-undo.                        
      
    case true:
        when m eq 0 then
            answer = n + 1.
        when n eq 0 then
            answer = ack(m - 1, 1).
        otherwise
        answer = ack(m - 1, ack( m , n - 1)).
    end case.
                      
    return answer.          
                          
end function.

DEFINE VARIABLE I AS INT64 NO-UNDO.
DEFINE VARIABLE J AS INT64 NO-UNDO.
DEFINE VARIABLE K AS INT64 NO-UNDO.

REPEAT I = 1 TO 3:
    REPEAT J = 1 TO 3:
        K = ack(I,J).
        DISPLAY "Ackermann(" I "," J ") is" K WITH NO-LABELS.
    END.
END.
 
Last edited by a moderator:

Smud

New Member
#7
Been itching to have a go at a non-recursive version of this function but not had the time till now. Could not find a version that was either "right" or one I could understand but this article gives you enough hints on how its done;

https://www.saylor.org/site/wp-content/uploads/2013/04/Ackermann-Function.pdf

Not that I believe my code below is perfect. Anyway still not worth trying to calculate Ack(4,2) as its an integer of 19,729 decimal digits (as per the site above) and you will get a different error to "stack overflow";

Code:
function ack RETURNS INT64 (INPUT m as int64,INPUT n as int64):
                        
    define variable answer as int64 no-undo.                        
    
    case true:
        when m eq 0 then
            answer = n + 1.
        when n eq 0 then
            answer = ack(m - 1, 1).
        otherwise
        answer = ack(m - 1, ack( m , n - 1)).
    end case.
                    
    return answer.          
                        
end function.
 
DEFINE VARIABLE I AS INT64 NO-UNDO. /* loop var 1 */
DEFINE VARIABLE J AS INT64 NO-UNDO. /* loop var 2 */
DEFINE VARIABLE K AS INT64 NO-UNDO. /* recusive calculation */
DEFINE VARIABLE H AS INT64 NO-UNDO. /* non-recursive calc */
 
DEFINE VARIABLE X AS INT64 NO-UNDO. /* working var */
DEFINE VARIABLE Y AS INT64 NO-UNDO. /* working var */
DEFINE VARIABLE S AS INT64 NO-UNDO. /* stack pointer */
/* define the stack as a temp-table */
DEFINE TEMP-TABLE ttStackAck NO-UNDO
    FIELD tvptr AS INT64
    FIELD tvval AS INT64
  INDEX tiStack tvptr.
/* initialise the Stack pointer S */
S = 0.
REPEAT I = 1 TO 3:
    REPEAT J = 1 TO 3:
        K = ack(I,J). /* recursive function call */
        
        /* now non-recursive - prime the stack */
        S = 0.  /* could also empty the temp-table as well */
        RUN pushack (INPUT I).
        RUN pushack (INPUT J).
        REPEAT:
            RUN popack(OUTPUT Y).
            RUN popack(OUTPUT X).
            IF X = ? THEN LEAVE. /* stack empty - so answer in Y */
            IF X = 0 THEN DO:
                RUN pushack(INPUT Y + 1).
                NEXT.
            END.
            IF Y = 0 THEN DO:
                RUN pushack(INPUT X - 1).
                RUN pushack(INPUT 1).
                NEXT.
            END.
            /* else */
            RUN pushack(INPUT X - 1).
            RUN pushack(INPUT X).
            RUN pushack(INPUT Y - 1).
        END.
        H = Y.  /* last value off stack is the answer */
        DISPLAY "Ackermann(" I "," J ") is" K SKIP(1)
            " and non-recursive calculation is" H WITH NO-LABELS.
    END.
END.
PROCEDURE pushack:
    DEFINE INPUT PARAMETER ipAck AS INT64 NO-UNDO.
    S = S + 1.
    FIND ttStackAck WHERE ttStackAck.tvptr = S NO-ERROR.
    IF NOT AVAILABLE(ttStackAck) THEN DO:
      CREATE ttStackAck.
      ASSIGN ttStackAck.tvptr = S.
    END.
    ASSIGN ttStackAck.tvval = ipAck.
RETURN.
END PROCEDURE.
PROCEDURE popack:
    DEFINE OUTPUT PARAMETER opAck AS INT64 NO-UNDO.
    ASSIGN opAck = ?.  /* assumes no-find is empty stack */
    /* but S = 0 would also mean an empty stack if all is working */
    FIND ttStackAck WHERE ttStackAck.tvptr = S NO-ERROR.
    IF AVAILABLE(ttStackAck) THEN
        ASSIGN opAck = ttStackAck.tvval.
    S = S - 1.
RETURN.
END PROCEDURE.
 
Last edited by a moderator: