diff --git a/2015/howe/.gitignore b/2015/howe/.gitignore index ffb16e793..aebcb1c75 100644 --- a/2015/howe/.gitignore +++ b/2015/howe/.gitignore @@ -1,2 +1,7 @@ +curds.tmp +makeholes +nuked.tmp prog prog.alt +war-and-peace.txt +whey.tmp diff --git a/2015/howe/Makefile b/2015/howe/Makefile index 25bf564f0..6c696ff1b 100644 --- a/2015/howe/Makefile +++ b/2015/howe/Makefile @@ -63,7 +63,7 @@ X11_INCDIR= /opt/X11/include # Common C compiler warnings to silence # #CSILENCE= -CSILENCE= -Wno-long-long -Wno-sign-compare +CSILENCE= -Wno-sign-compare # Common C compiler warning flags # @@ -76,7 +76,7 @@ CWARN= -Wall -Wextra -pedantic ${CSILENCE} # #CSTD= #CSTD= -ansi -CSTD= -std=gnu90 +CSTD= -std=gnu11 # Compiler bit architecture # @@ -101,8 +101,8 @@ CINCLUDE= #CINCLUDE= -include stdlib.h #CINCLUDE= -include stdio.h #CINCLUDE= -include stdlib.h -include stdio.h -#CINCLUDE= -I ${X11_INCDIR} -#CINCLUDE= -I ${HOMEBREW_PREFIX}/include/SDL2 +#CINCLUDE= -I ${X11_INCDIR} -I ${X11_INCDIR}/X11 +#CINCLUDE= `${SDL2_CONFIG} --cflags` # Optimization # @@ -126,7 +126,7 @@ CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT} LIBS= #LIBS= -lm #LIBS= -L ${X11_LIBDIR} -lX11 -#LIBS= -L ${HOMEBREW_PREFIX}/lib -lSDL +#LIBS= `${SDL2_CONFIG} --libs` # C compiler to use # @@ -165,7 +165,8 @@ ENTRY= howe PROG= prog # OBJ= ${PROG}.o -DATA= avgtime.sh prog-test.sh +CSRC= ${PROG}.o +DATA= spoiler/Makefile spoiler/err.h spoiler/prog.c TARGET= ${PROG} # ALT_OBJ= ${PROG}.alt.o @@ -186,14 +187,20 @@ all: data ${TARGET} ${PROG}: ${PROG}.c ${CC} ${CFLAGS} $< -o $@ ${LIBS} -${PROG}.alt: ${PROG}.alt.c - ${CC} ${CFLAGS} $< -o $@ ${LIBS} - # alternative executable # alt: data ${ALT_TARGET} @${TRUE} +${PROG}.alt: ${PROG}.alt.c + ${CC} ${CFLAGS} $< -o $@ ${LIBS} + +test: makeholes prog-test.sh ${TARGET} + ${SHELL} ./prog-test.sh + +makeholes: makeholes.c + ${CC} ${CFLAGS} $< -o $@ ${LIBS} + # data files # data: ${DATA} @@ -217,6 +224,7 @@ clean: clobber: clean ${RM} -f ${TARGET} ${ALT_TARGET} + ${RM} -f curds.tmp nuked.tmp war-and-peace.txt whey.tmp @-if [ -e sandwich ]; then \ ${RM} -f sandwich; \ echo 'ate sandwich'; \ @@ -328,4 +336,3 @@ pluto: charon @echo "dwarf is a type of planet" @echo "therefore, $@ is a planet" @echo "having lots of planets is good feature because supernovae can help ${MAKE} a lot of them" - diff --git a/2015/howe/README.md b/2015/howe/README.md index 8c61bff1b..1e71f7a7d 100644 --- a/2015/howe/README.md +++ b/2015/howe/README.md @@ -1,55 +1,64 @@ # Most Different -Anthony Howe -Montreal, Quebec, Canada - -Twitter: @SirWumpus + Anthony Howe + Montreal, Quebec, Canada + + Twitter: @SirWumpus -## To build: +# To build: - make all +```sh +make +``` -### To run +### To run: - ./prog file1 file2 +```sh +./prog file1 file2 - ./prog -d file1 file2 +./prog -d file1 file2 +``` ### Try: - ./prog prog.alt.c prog.c +```sh +./prog prog.alt.c prog.c - make test - ./prog -d ABXYEFCD.tmp ACDBECFD.tmp - ./prog ABXYEFCD.tmp ACDBECFD.tmp +make test +./prog -d ABXYEFCD.tmp ACDBECFD.tmp +./prog ABXYEFCD.tmp ACDBECFD.tmp - rm -f curds.tmp whey.tmp - cp /usr/share/man/man1/cc.1 curds.tmp - cp /usr/share/man/man1/cc.1 whey.tmp - chmod 666 whey.tmp - make makeholes - ./makeholes -n 1000 whey.tmp - ./prog curds.tmp whey.tmp - ./avgtime.sh 100 ./prog curds.tmp whey.tmp +rm -f curds.tmp whey.tmp +cp /usr/share/man/man1/cc.1 curds.tmp +cp /usr/share/man/man1/cc.1 whey.tmp +chmod 666 whey.tmp +make makeholes +./makeholes -n 1000 whey.tmp +./prog curds.tmp whey.tmp +./avgtime.sh 100 ./prog curds.tmp whey.tmp - # Assuming curl(1) installed, grab a really HUGE text file. - curl -L -o war-and-peace.txt http://www.gutenberg.org/ebooks/2600.txt.utf-8 - cp war-and-peace.txt nuked.tmp - ./makeholes -c'~' -n 1000 nuked.tmp - ./prog war-and-peace.txt nuked.tmp - ./avgtime.sh 100 ./prog war-and-peace.txt nuked.tmp +# Assuming curl(1) installed, grab a really HUGE text file. +curl -L -o war-and-peace.txt http://www.gutenberg.org/ebooks/2600.txt.utf-8 +cp war-and-peace.txt nuked.tmp +./makeholes -c'~' -n 1000 nuked.tmp +./prog war-and-peace.txt nuked.tmp +./avgtime.sh 100 ./prog war-and-peace.txt nuked.tmp +``` ### Alternate code -An alternate version of this entry, prog.alt.c, is provided. This alternate code does not use a 64 bit FNV hash. +An alternate version of this entry, `prog.alt.c`, is provided. +This alternate code does not use a 64 bit FNV hash. To compile this alternate version: - make alt +```sh +make alt +``` Use `prog.alt` as you would `prog` above. -### Selected Judges Remarks: +## Judges' comments: This is the best use of the FNV that we have seen in the IOCCC so far! The output, when used without -d, is compatible with POSIX diff and @@ -74,8 +83,8 @@ NOTE: Unlike the original entry source, prog.alt.c, prog.c uses a 64 bit FNV hash and fixes a function call warning. ## Author's comments: -Features --------- + +### Features * "An O(NP) Sequence Comparison Algorithm" by Wu, Manber, Myers, Miller. @@ -83,25 +92,19 @@ Features * Strokes one of the judge's ego (I couldn't email chocolate or curry). - -Description ------------ +### Description This is a functioning micro diff tool using an [O(NP) algorithm][Wu+89], compared to the older [O(ND) difference algorithm][Mye86] used by some versions of diff. Its output is based on the default diff(1) output described by POSIX and [The Open Group Base Specifications][SUSV7]. The output is suitable for use with patch(1). The -d option simply writes the edit distance between file1 and file2. - -Observations ------------- +### Observations The FNV1a hash is a little slow compared to the trival hash GNU Diff uses. I downloaded a plain text copy of "War And Peace" from Project Gutenberg, used ``makeholes.c`` to make 1000 random changes, then profiled and timed the program verses GNU Diff. The bottle neck appears to be in the file I/O and line hashing with an average +0.05s slower. Using a huge file like "War And Peace" for testing offsets the diff(1) optimised file I/O. There is no hash collision checking, partly because FNV1a appears to generate very [few collisions][HshCmp] and an assumption that localised collisions within a region of edits are highly unlikely. - -Support Files -------------- +### Support Files * ``prog-test.sh`` Basic test program verifies known test edit distances and patch support. @@ -111,9 +114,7 @@ Basic test program verifies known test edit distances and patch support. * ``makeholes.c`` Random edits (holes) made to a file in-place. - -References ----------- +### References Wu, Manber, Myers, and Miller; August 1989; "An O(NP) Sequence Comparison Algorithm"; @@ -160,11 +161,10 @@ Which hashing algorithm is best for uniqueness and speed? [HshCmp]: http://programmers.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed --------------------------------------------------------------------------------- -