18
Code that replicates itself(not recursion)
This thing called virus is crazy as hell, right? Like some dude out of nowhere got infected by COVID-19 virus. Now the world is going through this huge pandemic. That is due to their ability to replicate.
The situation is similar with digital virus aka computer virus. If somehow just one virus can enter your computer, in right condition it will create millions of copies of itself.
So what is a computer virus? A computer is just some code that has the ability to replicate itself. Code that can output itself is called Quine.
However a code that simply just reads itself is not a Quine.
#not a quine
print(open(__file__).read())
Code for a quine is made out of two parts:
- code used to do the printing
- data representing textual form of the code
Here's an example of quine in Python
q='q=%r;print (q%%q)';print (q%q)
#output: q='q=%r;print (q%%q)';print (q%q)
And in JS:
($=_=>`($=${$})()`)()
//output in console: ($=_=>`($=${$})()`)()
You can find more examples of quine by following these links: JavaScript Quines, Python Quines
That's all for now. Make sure you check out my other articles and YT tutorials.
18