Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 22, 2021 04:57 am GMT

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.
Computer virus

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 quineprint(open(__file__).read())

Code for a quine is made out of two parts:

  1. code used to do the printing
  2. 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.

.ltag__user__id__728097 .follow-action-button { background-color: #000000 !important; color: #ffffff !important; border-color: #000000 !important; }
0shuvo0 image





Original Link: https://dev.to/0shuvo0/code-that-replicates-itselfnot-recursion-4chf

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To