📜 ⬆️ ⬇️

If ... else conditions

image
Good day Habraludi!

Today is a great day for me.
In questions, I wrote about brief help for newbies and professionals, I thought that I would quickly plunge into the language, do good for everyone and go on exploring my Perl .
But as always, everything went wrong ...

When I was studying, I had a small notebook, a chair in the kitchen and a printed ASCII code plate. Each new step was for me, as a new record, a new height.

Sometimes I ran BrainfuckIDE on my computer and experimented. The experiments were quite fruitful, and after 5-6 hours I studied it thoroughly. He remembered all the algorithms of addition, subtraction, displacement, copying, division and multiplication. Elementary addition, subtraction and movement I spied on some of the sites, I thought of the rest myself.

Then posferfil looked on the Internet and saw that it turns out you can do the conditions (it was a surprise to me). Main question: How?
')
Without becoming to study and print the algorithm into my brain, I sat in a corner with a notebook and began to think.
I thought to the effect of complete abstraction from this world. It took two notebooks in which I tried a bunch of different options, moved, copied, tried to compare something, vague ideas when they were implemented on a piece of paper, led to the next chaos in my head by the end.

Having set a goal to write a program that will compare the entered number with a well-known one, and display the result (equal or not equal), I sat for two days with little rest (only sleep, food, toilet and dota) and imagined how to implement it, so intricate beautiful language.

I went to bed late enough (10 am), I could not fall asleep when such things were spinning in my head.

Waking up in the evening, I took the unfinished second notebook and started writing, to be honest, I do not understand how I came to such an algorithm, but on a piece of paper after 2 hours it seemed to be working. He sat down for the netbook, on the stationary at this time was put a new axis.
I started to rewrite from the leaflet, it turned out I did not take into account a lot of questions and pitfalls, but the algorithm still seemed to be correct.
At the computer, debugging it took no more than an hour, when suddenly, before my eyes, the program woke up, working exactly as I wanted.
Inexpressible feeling, the feeling that you discovered the planet. My first words were: " B * la Well, finally!". Having a little debugged, removed a bunch of + and -, replacing them with cycles, everything worked like a fairy tale.

Don't throw tomatoes and rotten eggs much, but I will try to take a chance and give the code that I wrote. See:
,[>+>+<<-]>>[<<+>>-] #     1  +++++ +++++[<----->-]<--- #    ascii      >>+>>+<<<< #    [ #   n != 5 [-]+++++ +++++[>+++++<-]>+++. #  5 [-]<++++++++[>++++<-]>. #   [-]<++++++++[>++++<-]>+. #    [-]<++++++++++[>++++++<-]>+. #    [-]<++++++++[>++++<-]>.<<. #     n >>>>>-<<-] #  ,       >>[ #  ,     [-]+++++ +++++[>+++++<-]>+++. [-]<++++++++[>++++<-]>. [-]<++++++++++[>++++++<-]>+. [-]<++++++++[>++++<-]>.<<<<. >>>>>-] 


As you can see, the main idea is that the cycle be executed if and only if the remainder of the difference of the numbers n and ascii of the code of the number with which they are compared! = 0.

I think this will be a fairly good example for beginners, and from you Dear gurus and ninjas of this language, I ask for advice and possibly criticism.

More interested in questions:

Source: https://habr.com/ru/post/140152/


All Articles