Coding Games and Programming Challenges to Code Better
Send your feedback or ask for help here!
Created by @JDOnline,validated by @Eulero314,@JeZzElLutin and @TAFITA_Julis.
If you have any issues, feel free to ping them.
Coding Games and Programming Challenges to Code Better
Send your feedback or ask for help here!
Created by @JDOnline,validated by @Eulero314,@JeZzElLutin and @TAFITA_Julis.
If you have any issues, feel free to ping them.
Thanks for this great, great puzzle!
My solution fails the remote test 4 âUnknown varâ. Is this test similar to the corresponding local test? I cannot think of edge cases, except if a procedure has the same name, but that case is not specified in the puzzle instructions. Or a name that is a keyword or not an identifier.
The output could have included line numbers (and variable/procedure names?) to make the result easier to debug and to read.
The puzzle states: âAll math and comparison operations work from left to right (e.g. there wonât be cases like 2 + 7 * 9).â. I find this strange, because the â2+7*9â expression is correctly processed by the grammar, and I would expect a hard puzzle with mathematical expressions and parentheses to require operator priority.
var i;
i:=2+7*9
.
jmp 0, 1
int 0, 4
lit 0, 2
lit 0, 7
lit 0, 9
opr 0, 4 <-- *
opr 0, 2 <-- +
sto 0, 3
opr 0, 0
Validator 4 still features one unknown variable (not procedure), but thereâs one known variable at the same time. Hope this will help you find out what the issue of your code may be.
For operator priority, Iâll let the author answer your question. What I do know is that the statement has almost reached the upper limit of 5000 characters, and itâs difficult to squeeze in more characters to state the operator precedence applicable to PL/0 (as all operators need to be mentioned, not just + - * /), if harder cases have to be included.
Thanks! I sometime raised âInvalid exprâ instead of âUnknown varâ and did not write the right line number.
Hi,
Thanks for the great puzzle!
For begin ⌠end blocks, it seems to me that the last statement should not be followed by a ; but directly by âendâ.
The examples do that if begin ⌠end is on single lines, but they have a ; after the last statement if the end is on a new line.
This does not correspond to the grammar or the examples on PL/0 - Wikipedia.
I had to relax my parser to allow handling these cases to pass the test vectors.
I have a second issue, maybe related, maybe not: I pass all test vectors, but when submitting the â; missing validatorâ fails. Did anyone else have an issue like that?
Hi,
You are totally right ! The PL/0 grammar does not require â;â when followed by âendâ. My implementation was too permissive on that.
I updated the puzzle validators to correctly enforce the grammar.
Thanks for your support.
I think these test cases still have a ; to many before âendâ:
02: Line 13
03: Line 14
15: Line 1
As well as the validators 02 & 12.
I found the bug I had for validator 05 ![]()
I indeed found 2 cases not updated but all others were not wrong based on what I saw
?
What is your issue with validator 05 ?
Could someone kindly explain what exactly is wrong with the expression in test case 6?
Input:
5
const k = 10;
var i;
begin
i := ( 2 * k * -5 ) / 3
end.
Output:
Line 4: Invalid expr
Thanks!
After the multiplication operator * you need a factor. But for a factor to be a number, it has to be a non-negative integer.
Ah, I see now. Thanks!
Very nice one, even if a bit time-consuming ![]()
As is often the case with these complex problems, it is hard to have a very good test coverage both in Tests and Validators. As it happens, I was happy to be able to access the validators, because I had 4 of them failing ! In case others stumble on the same rocks :
., so that the lexer would fail early, and not catch another (obviously earlier) error.Also Test #15 is still incorrect (according to the grammar), with an illegal ; before an end.
Nice puzzle!
Could be a great one, BUT⌠a bit disapointing though⌠that a given test case (#15) does not comply to the syntax (some other fellow pointed that out)âŚ
Had the same troubles. Note: Seems that a solution not even testing the final â.â passes anywayâŚ
PS: Time consuming you say⌠my wife thanks the author !!
Thanks you for spotting this as indeed I totally missed it ! So, I updated the validators to add the missing final . and I also removed the extra ; to fully comply to the grammar.
If you liked it, I am also submitting a new part for the PL/0 executor which is quite nice as well and if this one is accepted I will submit a PL/0 debugger puzzle.
Thanks again for your help.
This still happens on Validator 12: Odd or Neg validator.
Also, this puzzle was very fun to solve.
Thank you for reporting the issue. Itâs now fixed.