Skip to content
Ta180m  /   Idiot-Code-Golf  /   Discussions #8  /  
  • Unwatch 1

    Notifications

    Get push notifications on iOS or Android.
  • Fork 0

Problem 7: Self-replication #8

Unanswered
Ta180m asked this question in Q&A
Problem 7: Self-replication #8
on Apr 21, 2021 · 3 answers · 1 reply

The classic coding golf problem: the quine. Write a program that produces itself as output!

Replies

3 suggested answers
·
1 reply

Ta180m
on Apr 21, 2021
Maintainer Author

Not very clever (except for the raw string trickery), but it works.

main(){char c[99]=R"(printf("main(){char c[99]=R\"("),printf("%s)\";",c),printf("%s",c);})";printf("main(){char c[99]=R\"("),printf("%s)\";",c),printf("%s",c);}
0 replies
@Ta180m

Ta180m
on Apr 21, 2021
Maintainer Author

A slightly more clever Bash script:

for f in *;do if [ -f "$f" ]&&[[ -n $(sed -n '/^for f in/p;q' "$f") ]];then cat "$f";fi;done
0 replies
@Ta180m

"Optimized" for size of source. Not optimized for anything else… including cleaning up after itself or basic error handling.

package main
import _ "embed"
import "os"
//go:embed main.go
var q []byte
func main(){f,_:=os.Open("main.go");f.Write(q)}
1 reply
@mpldr

https://github.com/Ta180m/Idiot-Code-Golf/blob/main/quine/main.go

@Ta180m
Select a reply ctrl .
Remember, contributions to this repository should follow our GitHub Community Guidelines.
Category
Change category
Q&A
Labels
None yet
2 participants
  • Lock conversation

    Lock conversation on this discussion

    • Other users can’t add new comments to this discussion.
    • You and other collaborators with access to this repository can still leave comments that others can see.
    • You can always unlock this discussion again in the future.
  • Transfer discussion
  • Pin discussion

    Configure pinned discussion

    Up to 4 discussions can be pinned and they will appear publicly at the top of the discussions page.

  • Create issue from discussion
  • Delete discussion?

    The discussion will be deleted permanently. You will not be able to restore the discussion or its comments

Loading complete