[Community Puzzle] Obsolete Programming

https://www.codingame.com/training/hard/obsolete-programming

Send your feedback or ask for help here!

Created by @Zorg1,validated by @dbdr,@JBM and @chouch.
If you have any issues, feel free to ping them.

I trolled hard this one in JS :smiley:
power to “eval()” function!

Then I must do in JS to check that :stuck_out_tongue:

2 Likes

I would add this simple test case, for nested IF.
Depending on the initial setup, should print always 2 values, without running out of stack.

        9 9  
        DEF X 
            IF 
                1 OUT
                IF 2 OUT ELS 3 OUT FI 
            ELS 
                4 OUT
                IF 5 OUT ELS 6 OUT FI 
            FI 
        END 
        X

Could we introduce test cases to have DEF in DEF, and DEF in IF ?

Ah yes, the statement have some undefined behaviours :slight_smile:

For me, in the “forth philosophy” you cannot have a DEF in a DEF (and the same for IF, because I have specified that IF can only occurs in a DEF), and you have only one scope (OK you can have vocabularies, but it’s another features).

In another hand if it is to test error case, I have not specified error cases, because in fact it is always painfull to implement, and the purpose of this puzzle was to be a simple introduction to a forth like language. OK in my solution I have error case, but it is because I need to develop test, and sorry, I can do errors.

My problem was to define a minimal and functional forth when I can code some non trivial test and validator (and in fact it is from where the fun come, coding the test ^^). And when I write this puzzle, I have some statement length limit (3k), even if the limit has been removed since by CG.

3 Likes

Why not. Actually the current test titled “nested IF” is a little complex

3 Likes

Without scope, you can’t prevent redefinition of a function, ultimately leading to this kind of things to happen :
DEF A DEF B A END B END

Hello,
I found something unclear in puzzle description :
For ADD, SUB, etc, the description says you are supposed to compute the last two numbers, but it appears we have to compute with the two top numbers.
Took me a while struggling with a calc sheet checking manually :sweat_smile:

Hi
my Python code works well with with the 10 tests but
there is something wrong with numbers 9(Hello Lucas) and 10(Integer square root)
when I submit it.
Any idea?

The difference between the test and the validator, for “Hello Lucas” for exemple is indentation.
In the validator the definition are on two lines, without indentation.

A END can be in the same line of the FI

4 Likes

Hello Zorg1
thanks for your help. I take into account what you told me,
so I changed my code a little bit and now my code works perfectly.
In fact I expected either DEF and END on one line of DEF on the beginning of
a line and END (alone) on another line.
Sincerely
LG

1 Like

I definitely loved this puzzle! Solving it felt like writing your own compiler for a primitive but fully functional programming language! ^^

Also it’s my first solved Hard puzzle! It wasn’t that much hard, but took me almost a day to get everything to work on each test case. (For example, test 07 “the Queen of functions” required me to erase space characters not only before but also after each line while parsing, which left me confused for a while until I dragged the mouse cursor over the text of input lines in std::cerr.)

You mentioned you had a lot of fun while writing the tests and validators, and I can see how :smiley:
Definitely going to try to upgrade the code to something a bit more interesting and functional :3

3 Likes

For some extra fun implement IN instruction that reads the next int from input.

Now we are ready for some obsolete code golf.
Temperatures code golf solved in 285 char

DEF ABS
DUP POS NOT
IF 0 SWP SUB FI
END
DEF READ
DUP
IF 1 SUB IN ROT CMP SWP READ FI
END
DEF LT
OVR OVR SWP SUB POS
END
DEF CMP
OVR ABS OVR ABS
LT IF POP POP ELS POP POP SWP FI
OVR OVR ADD NOT
IF DUP POS IF SWP FI FI
POP
END
IN
DUP DUP 9999 MUL
SWP
READ
SWP
OUT
2 Likes

Hi, I just came back to this one which I had left aside for some time, and found out what I was missing.
I had this statement wrong: “The operations (ADD, SUB, MUL, DIV, MOD) pop the last two numbers out of the stack and push the result back on top.” It’s actually the only sentence where you use “the last two numbers”, so I thought they referred to the two numbers in the bottom, versus the top. Sounds counter intuitive but that’s how I understood it.
If I may suggest an update to the text, maybe simply showing examples with 3 numbers instead of 2 could avoid this misunderstanding
Cheers, and thanks for the fun! :wink: