Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

###sh+bzip2, 2*364106 = 728212

sh+bzip2, 2*364106 = 728212

###sh+bzip2, 2*364106 = 728212

sh+bzip2, 2*364106 = 728212

whale2.txt compresses much better; fixed bugs
Source Link
Joshua
  • 3.5k
  • 1
  • 22
  • 25

###sh+bzip2, 2*381249 + 02*364106 = 762498728212

(削除) 2*381249 +たす 0 = 762498 (削除ここまで)

dd if=0ドル bs=1 skip=37|bunzip2&execskip=49|bunzip2&exec catcat>/dev/null

followed by the bzip2-compressed whalewhale2.txt with the first byte missing

Builder script:

#!/bin/sh
if [ $# -ne 3 ]
then
 echo "Usage 0ドル gen.sh datafile output.sh"
 exit 1
fi
cat 1ドル > 3ドル
dd ibs=1 if=2ドル skip=1 | bzip2 -9 >> 3ドル
chmod +x 3ドル

I/O test harness (tcc; cut off first line for gcc). This test harness can be used by anybody on a suitable platform that submits a complete program that expects read/write I/O. It uses byte-at-a-time I/O to avoid cheating. Child program must flush output after every byte to avoid blocking.

#!/usr/bin/tcc -run
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char **argv)
{
 volatile int result;
 int readfd[2];
 int writefd[2];
 int cppid;
 int bytecount;
 char c1, c2, c3;
 if (argc != 2) {
 printf("write X approximately -- service host\n");
 printf("Usage: %s serviceprocessbinary < source.txt\n", argv[0]);
 return 1;
 }
 /* Start service process */
 if (pipe(readfd)) {
 perror("pipe()");
 return 3;
 }
 if (pipe(writefd)) {
 perror("pipe()");
 return 3;
 }
 result = 0;
 if (!(cppid = vfork())) {
 char *argtable[3];
 argtable[0] = argv[1];
 argtable[1] = NULL;
 dup2(readfd[0], 0);
 dup2(writefd[1], 1);
 close(readfd[1]);
 close(writefd[0]);
 close(readfd[0]);
 close(writefd[1]);
 execvp(argv[1], argtable);
 if (errno == ENOEXEC) {
 argtable[0] = "/bin/sh";
 argtable[1] = argv[1];
 argtable[2] = NULL;
 /* old standard -- what isn't an executable
 * can be exec'd as a /bin/sh script */
 execvp("/bin/sh", argtable);
 result = ENOEXEC;
 } else {
 result = errno;
 }
 _exit(3);
 } else if (cppid < 0) {
 perror("vfork()");
 return 3;
 }
 if (result) {
 errno = result;
 perror("execvp()");
 return 3;
 }
 close(readfd[0]);
 close(writefd[1]);
 /* check results */
 read(0, &c2, 1);
 bytecount = 1;
 errno = 0;
 while (read(0, &c1, 1) > 0) {
 write(readfd[1], &c2, 1);
 if (read(writefd[0], &c3, 1) <= 0) {
 printf("%d errors (%d bytes)\n", result, bytecount);
 if (errno == 0)
 fprintf(stderr, "pipe: unexpected EOF\n");
 else
 perror("pipe");
 return 3;
 }
 if (c3 != c1)
 ++result;
 c2 = c1;
 ++bytecount;
 }
 printf("%d errors (%d bytes)\n", result, bytecount);
 return 0;
}

###sh+bzip2, 2*381249 + 0 = 762498

dd if=0ドル bs=1 skip=37|bunzip2&exec cat

followed by the bzip2-compressed whale.txt

###sh+bzip2, 2*364106 = 728212

(削除) 2*381249 +たす 0 = 762498 (削除ここまで)

dd if=0ドル bs=1 skip=49|bunzip2&exec cat>/dev/null

followed by the bzip2-compressed whale2.txt with the first byte missing

Builder script:

#!/bin/sh
if [ $# -ne 3 ]
then
 echo "Usage 0ドル gen.sh datafile output.sh"
 exit 1
fi
cat 1ドル > 3ドル
dd ibs=1 if=2ドル skip=1 | bzip2 -9 >> 3ドル
chmod +x 3ドル

I/O test harness (tcc; cut off first line for gcc). This test harness can be used by anybody on a suitable platform that submits a complete program that expects read/write I/O. It uses byte-at-a-time I/O to avoid cheating. Child program must flush output after every byte to avoid blocking.

#!/usr/bin/tcc -run
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char **argv)
{
 volatile int result;
 int readfd[2];
 int writefd[2];
 int cppid;
 int bytecount;
 char c1, c2, c3;
 if (argc != 2) {
 printf("write X approximately -- service host\n");
 printf("Usage: %s serviceprocessbinary < source.txt\n", argv[0]);
 return 1;
 }
 /* Start service process */
 if (pipe(readfd)) {
 perror("pipe()");
 return 3;
 }
 if (pipe(writefd)) {
 perror("pipe()");
 return 3;
 }
 result = 0;
 if (!(cppid = vfork())) {
 char *argtable[3];
 argtable[0] = argv[1];
 argtable[1] = NULL;
 dup2(readfd[0], 0);
 dup2(writefd[1], 1);
 close(readfd[1]);
 close(writefd[0]);
 close(readfd[0]);
 close(writefd[1]);
 execvp(argv[1], argtable);
 if (errno == ENOEXEC) {
 argtable[0] = "/bin/sh";
 argtable[1] = argv[1];
 argtable[2] = NULL;
 /* old standard -- what isn't an executable
 * can be exec'd as a /bin/sh script */
 execvp("/bin/sh", argtable);
 result = ENOEXEC;
 } else {
 result = errno;
 }
 _exit(3);
 } else if (cppid < 0) {
 perror("vfork()");
 return 3;
 }
 if (result) {
 errno = result;
 perror("execvp()");
 return 3;
 }
 close(readfd[0]);
 close(writefd[1]);
 /* check results */
 read(0, &c2, 1);
 bytecount = 1;
 errno = 0;
 while (read(0, &c1, 1) > 0) {
 write(readfd[1], &c2, 1);
 if (read(writefd[0], &c3, 1) <= 0) {
 printf("%d errors (%d bytes)\n", result, bytecount);
 if (errno == 0)
 fprintf(stderr, "pipe: unexpected EOF\n");
 else
 perror("pipe");
 return 3;
 }
 if (c3 != c1)
 ++result;
 c2 = c1;
 ++bytecount;
 }
 printf("%d errors (%d bytes)\n", result, bytecount);
 return 0;
}
Source Link
Joshua
  • 3.5k
  • 1
  • 22
  • 25

###sh+bzip2, 2*381249 +たす 0 = 762498

dd if=0ドル bs=1 skip=37|bunzip2&exec cat

followed by the bzip2-compressed whale.txt

Ignores its input; outputs the correct answer. This provides a baseline on one end; daniero provides a baseline on the other end.

AltStyle によって変換されたページ (->オリジナル) /