# Make a package manager

It's time to make a more advanced program (rather than something simple, like printing some shape). You need a package manager for something, I guess.

First of all, if something wasn't defined, you are allowed to do anything, including destroying the computer (but please, don't, unless this will save your characters). After all, you will be using the package manager 100% correctly, so this won't happen. Who cares about security problems? It just has to be fast, like C programs.

The package manager should use STDIN and STDOUT as storage - that is, the database should be read from STDIN, and result database should be output to STDOUT, in true Unix style. The format of database is anything you want, as long you will be able to read it back.

The package manager shall support four commands. Typing unrecognized command is undefined, and anything can happen.

• init - outputs the empty database to be read by other commands. This shouldn't read the database state.
• install x y z - installs the programs x y z. If the program already exists, you can do anything
• remove x y z - removes the programs x y z. If the program doesn't exist, you can do anything.
• list - shows every program (with new line after every program). The list should be in alphabetical order. This mustn't output the database state.

The packages are only allowed to have lowercase ASCII letters (a-z). Anything else is undefined.

There is an example of example program:

$./lolmanager init > db$ ./lolmanager install cat dog < db > db2
$./lolmanager remove dog < db2 > db$ ./lolmanager list < db
cat
$./lolmanager install something else < db > db2$ ./lolmanager list < db2
cat
else
something
$ The shortest code wins. • "shows every program (with new line after every program). The list should be in alphabetical order. This shouldn't output the database state." So in effect, this means that separated by newlines, in alphabetical order, is a forbidden db state format? – nitro2k01 Dec 31 '13 at 17:20 • alphabetical order in the description and any order in the example seem to be different. – Howard Dec 31 '13 at 17:21 • @Howard: You catched me on a small mistake. I couldn't have decided whether list should be ordered or not (by accident). This should be fixed now, it's just a mistake while writing the task. – Konrad Borowski Dec 31 '13 at 17:22 • – Peter Taylor Jan 1 '14 at 11:22 ## 5 Answers ## GolfScript (23 chars) n%"#{ARGV*' '}"n/(;^$n*


My database format is the same as the list format.

I interpret the spec to allow assuming that the init command guarantees no input on stdin and no further command-line arguments, and that the list command guarantees no further command-line arguments. Then every command does exactly the same thing: xor the supplied database with the 2nd to nth command-line argument.

### GolfScript, 59 characters

[{;;[]}:it{|}:ll{-}:ve{;$n*}:st];~"#{ARGV*' '}"' '%(-2>~  Implemented the first idea which came into my mind. The database format is simply a GolfScript array representation. Install/remove also handle the case when a program is already installed. Explanation # Define four functions for later use ([...]; simply removes them from the stack): [ {;;[]}:it # init -> discard arguments, discard db, create empty db {|}:ll # install -> add arguments to db (if not already there) {-}:ve # remove -> remove all arguments from db {;$n*}:st          # list -> discard arguments, sort, join with newline
];

~                    # Parse db given on STDIN
"#{ARGV*' '}"' '%    # Parse command line arguments into array
(-2>                 # Take first argument (command) and the last two chars from it
~                    # Execute that command (i.e. "it" for "init", ...)


## Golf-Basic 84 for TI-84 Calculators, Character count: 84

:2_R:1_I:0_L:""_Str0iNdStr0l0iNgAdStr0g0lAiS@N=2:Str0+S_Str0@N=1:""_Str0g0


Hide the source code. Your teacher might think you're cheating :)

Output

?Init|db
?Install|db
?"CAT, DOG"
?List|db
CAT, DOG
?Remove|db
?"CAT, DOG"
?List|db

?Install|db
?"LOL"
?List|db
LOL

• 84 84 84 Too much 84 – CalculatorFeline Mar 14 '16 at 3:39
• @CatsAreFluffy They work on all in the early TI-8X series, notably TI-83s ;) – Timtech Mar 14 '16 at 18:23

## J (127 108)

Runs as a script (obviously). I could save some characters if I could assume it always receives an end-of-file even for init.

exit echo;,&LF&.>(LF cut stdin^:(-.A e.~<'init')''),(*/@(~:/~)#[)((/:{])@[)[@.('irl'i.{.>2}A)[3}.A=:ARGV


# Ruby, 102 bytes

c,*a=$*$/=?\0
puts c=~/it/?'':(i=STDIN.gets.split
case c
when/a/
a|i
when/v/
i-a
when/st/
i.sort
end)


Edit: Inspired by Howard, I replaced init, install, remove and list literals for some more general patterns: /it/, /a/, /v/ and /st/.

• Only remove has v, so you can shorten the pattern. – Konrad Borowski Dec 31 '13 at 20:57
• You're right, thanks! Also install is the only one containing a. – daniero Jan 1 '14 at 14:27
• Your program doesn't sort the values when you use list (I just tested it). – Konrad Borowski Jan 1 '14 at 19:13
• @GlitchMr I didn't read the rules properly I guess. Fixed (and shortened). – daniero Jan 1 '14 at 21:52
• And while shortening, you somehow managed to remove /v/` optimization ;-). – Konrad Borowski Jan 1 '14 at 21:56