Brain Fork - Optimization - Puzzle discussion

Dans le 3ème jeu de test, Bilbo épelle ce message:
Failure: Bilbo spelled: VTAS UHKAPR SJGLHHES OWPHISI VOQJ

Tu dois renvoyer un code en BrainFuck, ce code doit répéter ce qu’écrit Bilbo.

Oui çà j’avais compris, mais en fait j’ai mal du lire les règles du jeu (hernie cervicale depuis 2 mois déjà :-() Merci pour tes contributions toujours agréables :slight_smile:

Bilbo ne peut inscrire qu’une lettre donnée sur une rune, mais il peut activer plusieurs fois une rune donnée. Bilbo doit inscrire les lettres du messages sur les 30 runes du parcours puis les épeler en effectuant le moins d’actions possible :wink:

Cool fini en 8880 instructions, reste plus qu’à optimiser le code brainf**k (avec des boucles?)

Oui, avec les boucles.
Mes programmes en BrainFuck n’utilisent pas les boucles. Je ne sais même plus à combien j’en suis.

1 Like

Bon j’ai utilisé les boucles pour me déplacer sur des cases vides, gagné 200 instructions, mais dernier jeu de test plafonne à 4000 :frowning:, et total des tests à 8688

Started, and failed with 15k, thought about how could i move around to the nearest rune with a closer letter. finally got it. down to 7500. started messing with regex and just resetting spaces. got that to work with a lower number, and got a score of 6000 but the final test fails, because it’s limited to how many rotations. so even though i have loops that lower the text length, they lengthen the steps. seems less optimal to me. Optimization should be least steps, not least characters. seems sort of backwards. We all know loops can be worse for optimization, but this is sort of a “shortest” challenge, over a “fastest” challenge.

Try resetting with - instead of +, it makes a difference for the last validator.
Also try different patterns to initialize the runes, the pattern THETHETHE… works very well for some validators :slight_smile:

1 Like

Hello,
I made a code that seems to be working fine for the 9th first tests, but then for others tests I have this error : (traducted from french so maybe not 100% accurate)
“Warning: your code did not read all the data available from standard input before writing to standard output. This causes desynchronization which can lead to unexpected behavior.”

I tried something with the 11th test (letter B repeated 70 times), if I put this at the beginning it doesn’t work :
magic_phrase = input()

If I put this, it works :
magic_phrase = “B” * 70

but the weirder part is if I put this, it doesn’t work anymore !
magic_phrase = input()
magic_phrase = “B” * 70

Just calling input() seems to be creating the bug.
I don’t know if I’m allowed to post my entire code to facilitate the resolution of this issue, let me know.

@Timothee1997 Usually when you get a “Warning”, it means your code is too slow. Especially if you pass the other cases without problems. If I remember this puzzle well, the last problem is a long magic_phrase. I think your code could use some cleanup/improvements, and that your inputs are fine. I wrote my solution in Python and I have no problems (ranked 143th).

It’s something that often happens in multiplayer games when there are so many units that your calculations take a bit too long. There is always a bug hidden somewhere. Could be an algorithm working in O(n²) when something cleaner and simpler would work.

1 Like

@Timothee1997 Your code must not be calling input() >,< what kind of magic did you do hehe ,
In this puzzle there is only 1 line coming ~
This error comes in when you don’t read stdin.

One easy way to figure it out is to comment #magic_phrase = input() on the default code
Then you will see your error msg~

1 Like

@KiwiTae @logiqub I finally resolved the bug by removing some of my error prints. I still don’t know why it caused an issue, the logic and the code are good, the code is not too slow. The only thing I can think of is that wrting too many things on the standard error create a problem with the standard entry which is kind of black magic ^^
Anyway thanks for your help :wink:

@Timothee1997 I am glad you were able to solve it. :smiley:

Interesting puzzle, but I think there is a bug somewhere. Adding this line makes me fail test 14, which is 26 times 'BALROG -

print (‘phrase:’, self.magic_phrase[::-1], file=sys.stderr, flush=True)

It’s hard to help you if you don’t provide more details.
What is the error message ?

Just to be sure, you imported sys and magic_phrase is an attribute/property that has a type you can actually slice like str or list ?

didn’t give me an error on the code; just failed the test. If I take the print line out, the code runs fine and passes all tests. no biggie; just weird.

I have a question regarding this puzzle. How come the score of each test does not correspond to the length of the printed sequence but is sometimes longer?

The puzzle statement states:

Your score is computed from the number of characters you send to Blub and only if the test case is passed.

Continuing the discussion from Brain Fork - Optimization - Puzzle discussion:

Really? I am using python. The 2 last lines of my code are:

debug(f'Total order size: {len(orders)}')
print(orders)

And for certain tests, for example test 24, I got :
[DEBUG] Total order size: 2295
Whereas the test score is 2805 (2805 steps)
All my test pass but with the longest tests, there is always a difference between the length of what I print and the number of steps being executed (which is always bigger).