How to resolve the algorithm Quine step by step in the PowerBASIC programming language
How to resolve the algorithm Quine step by step in the PowerBASIC programming language
Table of Contents
Problem Statement
A quine is a self-referential program that can, without any external access, output its own source.
A quine (named after Willard Van Orman Quine) is also known as:
It is named after the philosopher and logician
who studied self-reference and quoting in natural language,
as for example in the paradox "'Yields falsehood when preceded by its quotation' yields falsehood when preceded by its quotation."
"Source" has one of two meanings. It can refer to the text-based program source.
For languages in which program source is represented as a data structure, "source" may refer to the data structure: quines in these languages fall into two categories: programs which print a textual representation of themselves, or expressions which evaluate to a data structure which is equivalent to that expression.
The usual way to code a quine works similarly to this paradox: The program consists of two identical parts, once as plain code and once quoted in some way (for example, as a character string, or a literal data structure). The plain code then accesses the quoted code and prints it out twice, once unquoted and once with the proper quotation marks added. Often, the plain code and the quoted code have to be nested.
Write a program that outputs its own source code in this way. If the language allows it, you may add a variant that accesses the code directly. You are not allowed to read any external files with the source code. The program should also contain some sort of self-reference, so constant expressions which return their own value which some top-level interpreter will print out. Empty programs producing no output are not allowed. There are several difficulties that one runs into when writing a quine, mostly dealing with quoting:
Next to the Quines presented here, many other versions can be found on the Quine page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Quine step by step in the PowerBASIC programming language
Source code in the powerbasic programming language
FUNCTION PBMAIN () AS LONG
REDIM s(1 TO DATACOUNT) AS STRING
o$ = READ$(1)
d$ = READ$(2)
FOR n& = 1 TO DATACOUNT
s(n&) = READ$(n&)
NEXT
OPEN o$ FOR OUTPUT AS 1
FOR n& = 3 TO DATACOUNT - 1
PRINT #1, s(n&)
NEXT
PRINT #1,
FOR n& = 1 TO DATACOUNT
PRINT #1, d$ & $DQ & s(n&) & $DQ
NEXT
PRINT #1, s(DATACOUNT)
CLOSE
DATA "output.src"
DATA " DATA "
DATA "FUNCTION PBMAIN () AS LONG"
DATA " REDIM s(1 TO DATACOUNT) AS STRING"
DATA " o$ = READ$(1)"
DATA " d$ = READ$(2)"
DATA " FOR n& = 1 TO DATACOUNT"
DATA " s(n&) = READ$(n&)"
DATA " NEXT"
DATA " OPEN o$ FOR OUTPUT AS 1"
DATA " FOR n& = 3 TO DATACOUNT - 1"
DATA " PRINT #1, s(n&)"
DATA " NEXT"
DATA " PRINT #1,"
DATA " FOR n& = 1 TO DATACOUNT"
DATA " PRINT #1, d$ & $DQ & s(n&) & $DQ"
DATA " NEXT"
DATA " PRINT #1, s(DATACOUNT)"
DATA " CLOSE"
DATA "END FUNCTION"
END FUNCTION
You may also check:How to resolve the algorithm Loops/Continue step by step in the R programming language
You may also check:How to resolve the algorithm Nested function step by step in the Lua programming language
You may also check:How to resolve the algorithm Fusc sequence step by step in the Tcl programming language
You may also check:How to resolve the algorithm Middle three digits step by step in the BASIC programming language
You may also check:How to resolve the algorithm Align columns step by step in the AArch64 Assembly programming language