Files
ioccc/2019/karns/README.md
T
Cody Boone Ferguson 0791a31fc7 Fix 2019/karns
A strange problem is that although it worked with macOS and linux for me
numerous times in the past it stopped working under both. I went to try
and figure it out but when disabling the optimiser for debug symbols the
problem vanished. Changing it back to -O3 and the problem reappeared
both with macOS and linux. Thus it appears that the entry should not
have -O level > 0. I'm not sure if this is the same issue the author
reported where it sometimes segfaults but I did not try and figure it
out either (in any event the crash disappeared when -O0 was specified so
it'd be harder to debug).

Added to .gitignore the file the author noted the program is called (as
the command he gives creates). To make it easier I just made it a
symlink to prog.

Fixed formatting in README.md.
2023-04-03 09:57:21 -07:00

3.2 KiB

Most in need of whitespace

Joshua Karns
Twitter: @jkarnss

To build:

make

To run:

./prog < textfile_that_fits_on_the_screen

Cody Boone Ferguson reported that with -O level > 0 this program segfaults (sometimes?). He's not sure why as it worked fine before on the same systems tested but -O0 appears to fix the problem in both macOS and linux. Perhaps this is the problem that the author reported where it sometimes segfaults but Cody did not try debugging it. Thank you Cody for your assistance!

Try:

./prog < README.md

./prog < prog.c

./prog < maze

The last two can be done in a sequence, first showing the respective files at the terminal, like:

./demo.sh

Judges' comments:

If you typically get lost in mazes, watching this program run might -- or might not, YMMV -- teach you how to find your way in a maze. The algorithm is well-known but the drawing is amazing!

Before running, make sure that your terminal can accommodate the whole file. Before running "make test", make it about 120x40 to be safe, ensuring that you see the @ sign as well as the exclamation mark.

...Oh, and the first M in YMMV stands for "mazing".

A puzzle for the reader: Can you change the program to consider a diagonal movement as one step?

Author's comments:

The Program:

This program is pretty simple! It performs a breadth first search on the specified graph. The graph can be any ascii text file that has an 'at' character, which is going to be the starting location, and a '!' character which will be the destination.

The nodes on this graph that are spaces are connected with any directly adjacent nodes that are also spaces. Nodes that aren't spaces are not connected with anything.

Compiling and Running:

This program usually compiles under both GCC and clang. Build with:

$(CC) -std=c99 -o tbfs prog.c

where $(CC) is cc, gcc, clang, or some other c compiler.

You can then run it with:

cat <input file> | ./tbfs

Examples:

./tbfs < maze 
./tbfs < prog.c

Issues

  • The program must be ran in a terminal that supports ANSI escape codes for moving the cursor and changing colors.
  • Segfaults happen sometimes.
  • I don't know what memory management there is, if any.
  • The program will not compile by an ANSI C compiler: it uses for loops, and it uses C++ style comments. It should compile cleanly using a C99 standard.
  • Breadth first search is slow (and very slow on certain maps), but my A star version of this program is too big.
  • Lots of extra whitespace may be needed if you want to feed in an arbitrary file.
  • It fails to compile on GCC sometimes (according to a friend of mine, I've not encountered this myself).
  • The program could be obfuscated much further.
  • The program contains some unused code and data.

This file is Copyright (c) 2023 by Landon Curt Noll. All Rights Reserved. You are free to share and adapt this file under the terms of this license:

Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)

For more information, see: https://creativecommons.org/licenses/by-sa/4.0/