在 Quine 部落格系列之前的冒險中,我們探索如何編寫我們自己的 Quine 和內含子。今天我們將了解 QuineRelays 是什麼以及如何利用 Introns 來創建它們。
想像一圈程序,每個程式都用不同的語言寫。該循環中的每個程式都有一個目的:列印序列中下一個程式的原始程式碼。最後一個程式透過列印第一個程式的原始碼來關閉循環。
本質上,QuineRelays 是一組 n 個程序,採用 n 種不同的語言,例如:
- 每個程式都會輸出下一個程式的原始碼。
- 最後一個程式輸出第一個程式的原始碼。 這裡考慮循環鍊錶。最後一個例子令人震驚!
讓我們來看一些例子來更好地理解這個概念。
二階繼電器
這個二階 QuineRelay 有一個 JavaScript 程序,可以列印 Python 程序,然後再列印回原始 JavaScript 程式。這是一對動態的自我複製組合。
JavaScript → Python ⥀
JavaScript:線上嘗試!
console.log((q=_=>`print(${JSON.stringify(`console.log((q=${q+[]})())`)})`)())
Python:線上嘗試!
print("console.log((q=_=>`print(${JSON.stringify(`console.log((q=${q+[]})())`)})`)())")
三階繼電器
使用三階 QuineRelay 會讓事情變得更有趣。這個從 Haskell 程式開始,輸出 Python 程序,Python 程式輸出 Ruby 程序,最後 Ruby 程式循環回原始 Haskell 程式。
Haskell → Python2 → Ruby ⥀
Haskell:線上嘗試!
q a b c=putStrLn $ b ++ [toEnum 10,'q','('] ++ show b ++ [','] ++ show c ++ [','] ++ show a ++ [')'] main=q "q a b c=putStrLn $ b ++ [toEnum 10,'q','('] ++ show b ++ [','] ++ show c ++ [','] ++ show a ++ [')']" "def q(a,b,c):print b+chr(10)+'q('+repr(b)+','+repr(c)+','+repr(a)+')'" "def e(x) return 34.chr+x+34.chr end;def q(a,b,c) print b+10.chr+'main=q '+e(b)+' '+e(c)+' '+e(a)+' '+10.chr end"
Python2:線上嘗試!
def q(a,b,c):print b+chr(10)+'q('+repr(b)+','+repr(c)+','+repr(a)+')' q("def q(a,b,c):print b+chr(10)+'q('+repr(b)+','+repr(c)+','+repr(a)+')'","def e(x) return 34.chr+x+34.chr end;def q(a,b,c) print b+10.chr+'main=q '+e(b)+' '+e(c)+' '+e(a)+' '+10.chr end","q a b c=putStrLn $ b ++ [toEnum 10,'q','('] ++ show b ++ [','] ++ show c ++ [','] ++ show a ++ [')']")
Ruby:線上嘗試!
def e(x) return 34.chr+x+34.chr end;def q(a,b,c) print b+10.chr+'main=q '+e(b)+' '+e(c)+' '+e(a)+' '+10.chr end q("def e(x) return 34.chr+x+34.chr end;def q(a,b,c) print b+10.chr+'main=q '+e(b)+' '+e(c)+' '+e(a)+' '+10.chr end","q a b c=putStrLn $ b ++ [toEnum 10,'q','('] ++ show b ++ [','] ++ show c ++ [','] ++ show a ++ [')']","def q(a,b,c):print b+chr(10)+'q('+repr(b)+','+repr(c)+','+repr(a)+')'")
4階繼電器
這是一個四階 QuineRelay:Ruby → Java → C# → Python ⥀
GitHub
不同文化之間有一些共同的象徵意義。其中之一是銜尾蛇,它在埃及、希臘、羅馬、印度教、西伯利亞、挪威、非洲和南美洲神話中都有提及。銜尾蛇是一個古老的符號,描繪了一條蛇或龍吞噬自己的尾巴,代表著創造和毀滅的永恆循環。
在北歐神話中,耶夢加得是一條巨蛇,是洛基和女巨人安格爾博達的中間的孩子。奧丁將耶夢加得扔進米德加德(人類王國)周圍的海洋中,這條蛇在那裡變得如此巨大,以至於它包圍了世界並抓住了自己的尾巴。由於它圍繞著米德加德(地球),因此被稱為世界之蛇 - 銜尾蛇。耶夢加得釋放尾巴是諸神黃昏(世界的最後之戰)開始的標誌之一。
Quine 中繼非常巧妙地體現了這種象徵意義,因為循環中的每個程序都會產生下一個程序,最後才會重生,因此被暱稱為 Ouroboros 程序。
128階階尾蛇繼電器
請坐在座位上。這是一輛 128 階 Ouroboros QuineRelay。是的,你沒看錯。 128! ! !
Ruby → Rust → Scala → ...(其他 120 個)... → Python → R → Ratfor → rc → REXX ⥀
GitHub
好像這還不夠令人印象深刻,它還包括一個復活節彩蛋。縮小後的原始 Ruby 代碼包含一條 Ouroboros 龍!
寫你自己的 QuineRelay
讓我們啟動先前編寫的Python內含子,試著將其變成二階QuineRelay。
Python Intron:線上嘗試!
intron = 'wubbalubbadubdub' data = "print('intron =', repr(intron)); print('data =', repr(data)); print(data)" print('intron =', repr(intron)); print('data =', repr(data)); print(data)
利用內含子的魔力,我們現在可以輕鬆地將不同語言的同級奎因的代碼部分放入內含子中。產生以下形式的程式:
Python:
intron = "code part of sibling" data = "code part of self" print('intron =', repr(intron)); print('data =', repr(data)); print(data)
因為,每個變數只是充當不同奎因的數據。讓我們將 data 和 intron 分別重新命名為 d1 和 d2。
Python:
d1 = "code part of self" d2 = "code part of sibling" print('d1 =', repr(d1)); print('d2 =', repr(d2)); print(d1)
現在,d2充當內含子,但上面的程式仍然嘗試列印self的程式碼部分。為了讓它列印下一個的原始碼,讓我們在最後列印(d2)而不是列印(d1)。
Python:
d1 = "code part of self" d2 = "code part of sibling" print('d1 =', repr(d1)); print('d2 =', repr(d2)); print(d2)
我們已經知道 d1 的內容只是第 3 行的副本。但是我們還沒有 d2 的內容。
比如說,我們想用 JavaScript 建立一個 QuineRelay。我們用 JS 寫一個類似的內含子。
JavaScript:
d1 = "code part of sibling" d2 = "code part of self" console.log(`d1 = ${JSON.stringify(d1)}`); console.log(`d2 = ${JSON.stringify(d2)}`); console.log(d1);
現在,上面 JS 內含子的第 3 行,就是我們想要的兄弟程式的 程式碼!
將彼此的代碼貼為對方的內含子。
筆記。我們需要在 js 中加入 d1 + '' 以避免一些引用不符
Python: Try it online!
d1 = "print('d1 =', repr(d1)); print('d2 =', repr(d2)); print(d2)" d2 = "console.log(`d1 = ${JSON.stringify(d1)}`); console.log(`d2 = ${JSON.stringify(d2)}`); console.log(d1 + '');" print('d1 =', repr(d1)); print('d2 =', repr(d2)); print(d2)
JavaScript: Try it online!
d1 = "print('d1 =', repr(d1)); print('d2 =', repr(d2)); print(d2)" d2 = "console.log(`d1 = ${JSON.stringify(d1)}`); console.log(`d2 = ${JSON.stringify(d2)}`); console.log(d1 + '');" console.log(`d1 = ${JSON.stringify(d1)}`); console.log(`d2 = ${JSON.stringify(d2)}`); console.log(d1 + '');
There you go. It's a proper 2nd order QuineRelay! A Python program, that prints a JavaScript program, that prints the original Python program back in a cycle.
Creating a QuineRelay is an exercise in creative coding and understanding how different languages represent and manipulate strings. It involves weaving together introns from various programs, each containing the code to replicate its next neighbour.
At its core, an nth-order relay is a game of n clever ways to escape quotes across n programming languages.
Stay tuned for the next post on MultiQuine!
Sources and references:
- Ouroboros programs, wiki page.
- A Third Order Quine in Three Languages, blog by sigfpe.
- Chain Quine, GitHub repo by Ibragimov Ruslan.
- 128 Quine Relay, GitHub repo by Yusuke Endoh.
- QuineRelay: Birth of the Quine serpent, self-referencing blog where a word in each n-order example hyperlinks to the next, cyclically. (May not work in dev.to; checkout the canonical blog)
- Jörmungandr, wiki page.
- Ouroboros, wiki page.
- Art of Code, talk by Dylan Beattie
以上是QuineRelay:奎因蛇的誕生的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通過使用pyenv、venv和Anaconda來管理不同的Python版本。 1)使用pyenv管理多個Python版本:安裝pyenv,設置全局和本地版本。 2)使用venv創建虛擬環境以隔離項目依賴。 3)使用Anaconda管理數據科學項目中的Python版本。 4)保留系統Python用於系統級任務。通過這些工具和策略,你可以有效地管理不同版本的Python,確保項目順利運行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基於基於duetoc的iMplation,2)2)他們的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造

數組的同質性對性能的影響是雙重的:1)同質性允許編譯器優化內存訪問,提高性能;2)但限制了類型多樣性,可能導致效率低下。總之,選擇合適的數據結構至關重要。

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,內存效率段

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 Linux新版
SublimeText3 Linux最新版

記事本++7.3.1
好用且免費的程式碼編輯器

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中