Skip to content

Instantly share code, notes, and snippets.

@stek29
Created October 6, 2021 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stek29/8803a8b002dd1c8f7ff0c185f3306f96 to your computer and use it in GitHub Desktop.
Save stek29/8803a8b002dd1c8f7ff0c185f3306f96 to your computer and use it in GitHub Desktop.
simple Quine program ¯\_(ツ)_/¯
func quine() {
var s = """
func quine() {
var s = MEGIC
let slash = "\\\\"
let s1 = "\\n "
let s2 = "\\"\\"\\""
var sInd = s.replacingOccurrences(of: "\\n", with: s1)
sInd = sInd.replacingOccurrences(of: slash, with: slash + slash)
sInd = s2 + s1 + sInd + s1 + s2
if let r = s.range(of: "MEGIC") {
s = s.replacingCharacters(in: r, with: sInd)
}
print(s)
}
"""
let slash = "\\"
let s1 = "\n "
let s2 = "\"\"\""
var sInd = s.replacingOccurrences(of: "\n", with: s1)
sInd = sInd.replacingOccurrences(of: slash, with: slash + slash)
sInd = s2 + s1 + sInd + s1 + s2
if let r = s.range(of: "MEGIC") {
s = s.replacingCharacters(in: r, with: sInd)
}
print(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment