Since the first weekend of October is drawing near, let's have our own Oktoberfest!


You and some other programmers have been hired by the local sausage guys in Munich, Germany. The sausage guys provide Oktoberfest with all the sausages the giant Volksfest needs. You manage to overhear your boss speaking to the other employees about why you and the others were hired without any previous sausage-related experience. You realize you were hired for your impeccable programming skills - and your boss apparently wants you to code a sausage analyzer.

This year around, the sausage guys have decided to increase the variety of sausages at Oktoberfest - but they have no idea of how much they've imported.


You need to help your boss figure out how much sausage of a certain kind they've actually imported. You will have to program a sausage analyzer which outputs the kind and number of every sausage the sausage guys have imported. Your boss has bought a special floppy drive for this occasion which, given a sausage, pipes it to stdin.


A number of sausages on stdin, each sausage separated by one space. Sausages are given on the following format:

Prinskorv (P)

| |
| |
| |

Salchichón (S)

| |
| |
| |
| |

Landjäger (L)

\ /
| |
| |
| |
| |
/ \

Kabanos (K)


Cotechino Modena (C)

|   |
|   |
|   |

Rød pølse (R)

| |
| |
| |
| |


The occurrences of a given sausage along with an identifier of which kind of sausage it is, separated by a space. The identifier is the first letter in the name of the sausage. Order is not important.

Output shall be written to stdout, trailing newlines and spaces are allowed.



 ^   ^   ^   ^  .
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
 v   v   v   v  |


4R 1K


\ /  ___   l   ¤   ¤
| | |   | | | | | | |
| | |   | | | | | | |
| | |   | | | | | | |
| | |___| | |  ¤   ¤
/ \        l


1L 1C 1S 2P


 l   ¤   l
| | | | | |
| | | | | |
| | | | | |
| |  ¤  | |
 l       l


2S 1P

The programmer with the shortest program in bytes gets paid by the sausage guys (wins)!

Sausage trivia

Prinskorv which directly translates to "prince-sausage" is a small Swedish sausage which is often sold in links. Usually fried in a frying pan and served with a generous helping of mustard.

Salchichón is a Spanish summer sausage often made with pork, although some recipes use other meats including ox, veal or horse. The meat and fat are chopped in thin bits, seasoned with salt, pepper, nutmeg, oregano, and garlic and then inserted in thick natural pork intestines.

Landjäger is a semi-dried sausage traditionally made in Southern Germany, Austria, Switzerland, and Alsace. It is popular as a snack food during activities such as hiking. It also has a history as soldier's food because it keeps without refrigeration and comes in single-meal portions.

Kabanos is a Polish long thin dry sausage made of pork or kosher turkey. They are smoky in flavour, and can be soft or very dry in texture depending on freshness. Kabanosy are often seasoned only with pepper. Unlike other meats, these sausages are typically eaten alone as an appetiser and, except when kosher, often served with cheese.

Cotechino Modena
Cotechino Modena or Cotechino di Modena is a fresh sausage made from pork, fatback, and pork rind, and comes from Modena, Italy, where it has PGI status. Cotechino is often served with lentils or cannellini beans with a sauce alongside mashed potatoes, especially around the New Year.

Rød pølse
Rød pølse (red sausage) is a type of brightly red, boiled pork sausage very common in Denmark. Since hot dog stands are ubiquitous in Denmark, some people regard røde pølser as one of the national dishes.

All sausage information shamelessly copied from Wikipedia

  • 32
    \$\begingroup\$ You are writing an Oktoberfest-themed challenge about sausages, and it doesn't include Weißwurst? -1 \$\endgroup\$ Oct 1, 2015 at 18:11
  • 3
    \$\begingroup\$ I blame those dastardly sausage guys! \$\endgroup\$ Oct 1, 2015 at 18:18
  • 31
    \$\begingroup\$ Why did you put the sausage information in a spoiler tag? Is that to keep it from going bad? \$\endgroup\$
    – Alex A.
    Oct 1, 2015 at 19:43
  • 10
    \$\begingroup\$ @MartinBüttner Well I guess you could say...that was the wurst idea ever! \$\endgroup\$
    – DankMemes
    Oct 1, 2015 at 23:42
  • 2
    \$\begingroup\$ Trailing spaces are allowed. I think I meant to write trailing spaces instead of trailing newlines.. Now both are allowed! \$\endgroup\$ Oct 2, 2015 at 5:17

9 Answers 9


Pyth, 36 34 32 30 bytes


Saved yet another 2 bytes thanks to...guess who? :D

Ignores all the input except for the first line, removes all the /s and spaces, translates it to the target identifiers, sorts it, uses run-length encoding, and prints the result.

Live demo.

32-byte version


Live demo.

Saved another 2 bytes thanks to @Jakube!

34-byte version


Live demo.

Saved 2 bytes thanks to @Jakube!

36-byte version


Live demo.

  • 6
    \$\begingroup\$ I gave you a +1 because I love Kirby \$\endgroup\$
    – Nacht
    Oct 2, 2015 at 1:04
  • 6
    \$\begingroup\$ I didn't give you a +1 because you're at exactly 4k rep :) \$\endgroup\$ Oct 2, 2015 at 2:37
  • \$\begingroup\$ I gave you a -1 to get you back to exactly 4k :D \$\endgroup\$
    – Beta Decay
    Oct 2, 2015 at 6:34
  • 1
    \$\begingroup\$ Another two bytes ;-) hM-czd\\ is the same as -hMfTczd\\ \$\endgroup\$
    – Jakube
    Oct 2, 2015 at 8:37
  • 1
    \$\begingroup\$ @sweerpotato See here. The ¤ is two bytes. \$\endgroup\$ Oct 28, 2015 at 20:21

Pyth, 30 bytes


Try it online: Demonstration or Test Suite


As all other participants I only look at the first line of the input. Let's say the first line of the input is \ / ___ l ¤ ¤ ____.

At first I split by spaces, which gives me the list

['\\', '/', '', '___', '', '', 'l', '', '', '¤', '', '', '¤', '', '___']

Now we want to get ride of '/'s and ''s and sort the remaining thing.

['\\', '___', '___', 'l', '¤', '¤']

Now I can run-length-encode it.

[[1, '\\'], [2, '___'], [1, 'l'], [2, '¤']]

As it turns out, the order (ascii-value) of these chars or of the string '___' can be mapped nicely to the numbers [0, 1, 2, 3, 4, 5].

char/string |  l   .   \    ___    ^   ¤  
value       | 108  46  92 6250335  94 164  
value%45    |  18   1   2      15   4  29    
(value%45)%6|   0   1   2       3   4   5     

And this can be used to map them directly to the letters SKLCRP.

                        czd     split the input string at spaces
                       -   \/   remove "/"s (and also ""s)
                      S         sort
                     r       8  run-length-encode
  m                             map each pair d of ^ to:
   +hd                            d[0] + 
                Ced               convert d[1] to a number
               %   45             mod 45
      @"SKLCRP"                   take the ^th element in the string (mod 6)
jd                              join by spaces

Javascript (ES6), 105

a=>[...'¤l/._^'].map((g,h)=>(f=(a.split(g).length-1)/'222261'[h],f?f+'PSLKCR'[h]:0)).filter(b=>b).join` `

It's pretty simple but here's an explanation anyway:

  // list of all unique characters of the sausages
  [...'¤l/._^'].map((sausage_char, index)=>(
    // find all occurrences of the character in the string
    occurrences = (input.split(sausage_char).length - 1)
      / '222261'[index], // divide by the number of that character in its sausage
      // when dividing and multiplying by numbers in strings, JS automatically casts them
    occurrences ? // is there anything for this sausage?
      occurrences + 'PSLKCR'[index] : // add the sausage's letter and count
      0 // return 0 so it can be filtered out
  // filter out the 0s
  // return a space-separated string
  .join` `
  • 3
    \$\begingroup\$ Very clever! Using ES7's array comprehensions to golf this version, I got 91: a=>(h=-1,[for(g of'¤l/._^')if(f=(a.split(g).length-1)/'222261'[++h])f+'PSLKCR'[h]].join` `) If only I could simplify the declaration of h... \$\endgroup\$ Oct 2, 2015 at 2:57
  • \$\begingroup\$ @ETHproductions cool! I should learn ES7 \$\endgroup\$
    – DankMemes
    Oct 2, 2015 at 11:43

CJam, 38 35 33 bytes

l'_%'C*"l¤\^./""SPLRK "erS-$e`S*

Test it here.


The first line of each type of sausage is unique, and since the sausages are aligned at the top, it's sufficient to count the relevant characters in that first line. Two types require special treatment:

  • Landjäger (L) have both \ and /. We want to get rid of one of them, then we can count the other one like all the other characters.
  • Cotechino Modena (C) have three underscores, so we need to divide the underscore count by 3. However, it's actually shorter to treat underscores individually by simply replacing runs of them in the input (which will always belong to only one sausage) with the target character C right away.

Now for the actual code:

l         e# Read one line from STDIN.
'_%       e# Split on runs of underscores.
'C*       e# Join back together by C's.
"l¤\^./"  e# Push a string with characters corresponding to each type, and a slash.
"SPLRK "  e# Push a string with the corresponding letters and a space.
er        e# Transliterate, turning each identifying character into the correct
          e# letter and all slashes into spaces.
S-        e# Remove spaces (which also gets rid of what used to be slashes).
$         e# Sort the string to group each letter.
e`        e# Run-length encode.
S*        e# Join by spaces.
  • \$\begingroup\$ Whatever you do, don't forget to Splurk. \$\endgroup\$ Oct 2, 2015 at 15:42

Mathematica 116

Some bytes could probably shaved off, but nothing to approach the golfing languages.

Row[Row/@Reverse/@Tally@ImportString[#,"Table"][[1]]/.{"¤"->"P","l"->"S","/"->"L","___"->"C","."->"K","^"->"R"}," "] &

ImportString[#,"Table"][[1]] returns a list of space-separated strings appearing in the top line of the input. The string may include any of the elements in the list, {"¤","l","/","___",".","^"}, including repeats. Each element is associated with a unique type of sausage.

Tally counts the number of times each such string appears.

/.{"¤"->"P","l"->"S",... replaces ¤ with P, l with S and so on.

Reverse places each tally before the item it is associated with.

The two Rows format the output.



Assuming that trailing spaces are allowed (yep they are), here is a MATLAB anonymous function:

@(a)arrayfun(@(p,m)fprintf([(m>32&&p)*'%d%c ' ''],p,m),histc(strtok(strrep(a,'___','_'),10),'./\^_l¤'),'K LRCSP')

And an explanation:

@(a) %Anonymous function, with an input a
    arrayfun(@(p,m) %Loop through the two input arrays (see later)
                   fprintf( %Print to console
                           [(m>32&&p)*'%d%c ' ''] %Essentially this means if p>0 and m>' ', print an integer followed by a char, then a space
                                                 ,p,m) %The values from the array input is what is getting printed
                                                      ,histc( %Make an array of how many times 
                                                                       strtok(strrep(a,'___','_'),10), %Keep only the first line (as that is where the interesting bit is) and also replace ___ with _ for the 'C'
                                                             './\^_l¤'), %these inputs appear (which will be passed in turn as the 'p' variable to cellfun)
                                                                        'K LRCSP' %These are the characters to be printed with the count representing each sausage (it will be placed in the 'm' input of arrayfun)

Appears to work correctly. Still has the trailing space, but now handles all sausages correctly.


Perl, 84 77 bytes

Someone could probably shave a bit off of this...

84 bytes

($s=<>)=~y|_^\.l\\¤|CRKSLP|d;$$_++for split//,$s;$C/=3;for(A..Z){print"$$_$_ "if$$_}

77 bytes

$$_++for split//,<>=~y|_^\.l\\¤|CRKSLP|dr;$C/=3;for(A..Z){print"$$_$_ "if$$_}


Take first line of STDIN, transliterate values into letter codes, delete extra garbage. The d modifier shouldn't really be necessary, but I ran into weird unicode issues on the ¤ character without it.

Use symbolic reference to create and/or increment variable for each character found.

$$_++ for split //, <> =~ y|_^\.l\\¤|CRKSLP|dr;

Divide C variable by 3, due to triple-underscore

$C /= 3;

Loop through alphabet and print single-letter capital variables along with letter if they have a value greater than zero

for (A..Z) {
    print "$$_$_ " if $$_;

Test result: http://ideone.com/alpUlI

Edit: Chop 7 bytes by having transliterate pass anonymous return value directly into split.


Perl, 172 bytes

Daresay more can be sliced off this sausage still, but here's a starter for ten.

$a=<>;$a=~s/¤/h/g;$a=~s/_+/_/g;$a=~s/(\/| |\n)//g;$a=~s/\\/x/g;$h{$_}++ for split(//,$a);foreach (sort keys %h){print $h{$_};$_=~tr/^.hlx_/RKPSLC/;print "$_ ";}print "\n"

Ungolfed version

$a=<>;              # get 1st line
$a=~s/¤/h/g;        # convert ¤ to h, avoid unicode hassles
$a=~s/_+/_/g;       # multiple consecutive _ to single _
$a=~s/(\/| |\n)//g; # strip / and spaces
$a=~s/\\/x/g;       # convert \\ to x to avoid regexp hassles

# build hash that counts occurences of character
$h{$_}++ for split(//,$a);

# print the answers
foreach (sort keys %h) {
 print $h{$_};
 print "$_ ";
print "\n";

Test results

$ perl meaty.pl <test1.txt
1K 4R
$ perl meaty.pl <test2.txt
1C 2P 1S 1L
$ perl meaty.pl <test3.txt
1P 2S

Python 3, 120 bytes

I'm pretty sure you can shorten this, but there wasn't already a Python solution so here we go:

a={z:x.count(y)for y,z in zip('¤l/.^_','PSLKRC')}
print(' '.join(str(a[x])+x for x in a if a[x]))


It's pretty simple, some might even say readable, but here's a short explanation anyway:

First one line of input is read, since each sausage can be determined from just the first line.

Now a={z:x.count(y)for y,z in zip('¤l/.^_','PSLKRC')} is a dictionary comprehension that maps the identifier of each type of sausage (z) to the count of each type of sausage (x.count(y), where y is the sausage defining character).

We then divide the count of Cotechino Modena (C) sausages by 3 because of the triple underscore.

Finally we print out the result: print(' '.join(str(a[x])+x for x in a if a[x])). This creates the output count of each sausage one at a time, but only if that sausage was seen at least once (a[x] is not zero => Truthy). Each count string is joined by a space and printed out.

  • \$\begingroup\$ print ’a[x]’+' '+a[x] for ... Should work (not tested) and saves 5 bytes. With ’ being a backtick. \$\endgroup\$
    – agtoever
    Oct 4, 2015 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.