This thread is my subission for Reyweld's game

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
This thread is my subission for Reyweld's game
#7
RE: This thread is my subission for Reyweld's game
Code:
DEFINE PROCEDURE ''MINUS'' [M,N]:
BLOCK 0: BEGIN
    IF M < N, THEN:
    QUIT BLOCK 0;
    LOOP AT MOST M + 1 TIMES:
    BLOCK 1: BEGIN
        IF OUTPUT + N = M THEN:
        ABORT LOOP 1;
        OUTPUT ⇐ OUTPUT + 1;
    BLOCK 1: END;
BLOCK 0: END.

DEFINE PROCEDURE ''REMAINDER'' [M,N]:
BLOCK 0: BEGIN
    IF N = 0, THEN:
    QUIT BLOCK 0;
    LOOP AT MOST M + 1 TIMES:
    BLOCK 1: BEGIN
        IF OUTPUT * N > M, THEN:
        ABORT LOOP 1:
        CELL(0) ⇐ CELL(0) + 1;
    BLOCK 1: END;
    CELL(0) ⇐ MINUS [CELL(0),1];
    CELL(0) ⇐ CELL(0) * N;
    OUTPUT ⇐ MINUS [M,CELL(0)];
BLOCK 0: END.

DEFINE PROCEDURE ''PRIME?'' [N]:
BLOCK 0: BEGIN
    IF N = 0, THEN:
    QUIT BLOCK 0;
    CELL(0) ⇐ 2;
    LOOP AT MOST MINUS [N,2] TIMES:
    BLOCK 1: BEGIN
        IF REMAINDER [N,CELL(0)] = 0 THEN:
        QUIT BLOCK 0;
        CELL(0) ⇐ CELL(0) + 1;
    BLOCK 1: END
    OUTPUT ⇐ YES;
BLOCK 0: END.

DEFINE PROCEDURE ''GOLDBACH?'' [N]:
BLOCK 0: BEGIN
    CELL(0) ⇐ 2;
    LOOP AT MOST N TIMES:
    BLOCK 1: BEGIN
        IF {PRIME? [CELL(0)] AND PRIME? [MINUS [N,CELL(0)]]}, THEN:
        BLOCK 2: BEGIN
            OUTPUT ⇐ YES;
            QUIT BLOCK 0;
        BLOCK 2: END;
        CELL(0) ⇐ CELL(0) + 1;
    BLOCK 1: END;
BLOCK 0: END.
🐦🐙🐙[Image: nifOFwR.png]🐙🐙


Messages In This Thread
RE: This thread is my subission for Reyweld's game - by Kíeros - 12-12-2017, 04:29 AM