Go Self-reproducing programs (自重写)

Self-reproducing programs

The idea of self-reproducing programs dates back to the 1960s. My favorite statement of the problem is the one Ken Thompson gave in his 1983 Turing Award address:
In college, before video games, we would amuse ourselves by posing programming exercises. One of the favorites was to write the shortest self-reproducing program. Since this is an exercise divorced from reality, the usual vehicle was FORTRAN. Actually, FORTRAN was the language of choice for the same reason that three-legged races are popular.
More precisely stated, the problem is to write a source program that, when compiled and executed, will produce as output an exact copy of its source. If you have never done this, I urge you to try it on your own. The discovery of how to do it is a revelation that far surpasses any benefit obtained by being told how to do it. The part about “shortest” was just an incentive to demonstrate skill and determine a winner.
Spoiler alert! I agree: if you have never done this, I urge you to try it on your own. The internet makes it so easy to look things up that it’s refreshing to discover something yourself once in a while. Go ahead and spend a few days figuring out. This blog will still be here when you get back. (If you don’t mind the spoilers, the entire Turing award address is worth reading.)

code

/* Go quine */
package main

import "fmt"

func main() {
   
    fmt.Printf("%s%c%s%c\n", q, 0x60, q, 0x60)
}

var q = `/* Go quine */
package main

import "fmt"

func main() {
    fmt.Printf("%s%c%s%c\n", q, 0x60, q, 0x60)
}

var q = `

reference

https://research.swtch.com/zip

相关推荐

  1. Go Self-reproducing programs (自重

    2023-12-12 06:36:04       58 阅读
  2. 用stl一个自动打分比赛的案例

    2023-12-12 06:36:04       53 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-12 06:36:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-12 06:36:04       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-12 06:36:04       82 阅读
  4. Python语言-面向对象

    2023-12-12 06:36:04       91 阅读

热门阅读

  1. Matlab 对称轴探测(二维点集)

    2023-12-12 06:36:04       67 阅读
  2. Mr_HJ / form-generator项目文档学习与记录

    2023-12-12 06:36:04       49 阅读
  3. K8S学习指南(8)-k8s核心对象pod

    2023-12-12 06:36:04       62 阅读
  4. 新网站如何被搜索引擎迅速收录

    2023-12-12 06:36:04       60 阅读
  5. js-过滤制表符

    2023-12-12 06:36:04       65 阅读
  6. 《C++新经典设计模式》之第9章 命令模式

    2023-12-12 06:36:04       57 阅读