What general tips do you have for golfing in Keg? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Keg (e.g. "remove comments" is not an answer).
Please post one tip per answer.
Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It only takes a minute to sign up.Sign up to join this community
This is my biggest tip for anyone golfing in Keg: when writing programs, brackets used in loops or if-statements are automatically balanced if there are unclosed brackets.
Can be shortened to:
Can be shortened to:
In Keg, you can represent large constants using simply Unicode characters. Sometimes this is really hard to do, sometimes it is easy and can lead to creative solutions. And there is almost nothing to say about this; this is a canonical feature for golfed Keg programs.
Note that when the terms spaceful and spaceless are used, they refer to whether or not the string will place spaces between string compression codes when expanding.
I feel like I should take the time to explain what String Compression Codes are:
Every word within the Keg dictionary has a two byte code associated with it. These range from
00 through to
↫↫. When the uncompressor sees a string, it will go through and expand each SCC with it's corresponding word from the dictionary (for example,
Good). Even though all of the examples had uppercase letters, there are words starting with lower case letters.
The best and easiest way to find out what the required SCCs for programs is to navigate to
uncompress.py and run the program (preferably in some sort of terminal/something that isn't IDLE). "But that's a library, not a user-friendly program!", I hear you say. Well, when run by a user as a program, it will branch into
if __name__ == "__main__" and run a helpful session for golfing. If a word is in the dictionary, the corresponding SCC will be printed (single character SCCs start with
-1 will be printed. Here's an example session:
Enter a search term: Hello H% [43, 66] Enter a search term: world ⬥  Enter a search term: Keg -1 Enter a search term: keg ←z [130, 35] Enter a search term: Um -1 Enter a search term: Keg -1 Enter a search term: isn't 4🄂 [4, 239] Enter a search term: in -1 Enter a search term: the 0  Enter a search term: dictionary V¿ [57, 88]
Don't mind the fact that Keg isn't in the dictionary.