Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Background

You are working as a programmer for a car sales company. Your task for this week is to program an XML parser that takes in data about available models from different car manufacturers, and pretty-prints information about the newest models. Luckily for you, the testing department has provided only one test case! The faster you can write code that passes it, the more time you have for procrastination during the rest of the week.

Input

Your input is exactly this piece of XML data, supplied by the testing department. It contains data about some car manufacturers, their series of cars, and the models in these series. You may assume a trailing newline.

<?xml version="1.0" ?>
<products>
  <manufacturer name="Test Manufacturer 1">
    <series title="Supercar" code="S1">
      <model>
        <name>Road Czar</name>
        <code>C</code>
        <year>2011</year>
      </model>
      <model>
        <name>Ubervehicle</name>
        <code>U</code>
        <year>2013</year>
      </model>
      <model>
        <name>Incredibulus</name>
        <code>I</code>
        <year>2015</year>
      </model>
      <model>
        <name>Model 1</name>
        <code>01</code>
        <year>2010</year>
      </model>
    </series>
    <series title="Test series 22" code="Test">
      <model>
        <name>Test model asdafds</name>
        <code>TT</code>
        <year>2014</year>
      </model>
    </series>
  </manufacturer>
  <manufacturer name="Car Corporation">
    <series title="Corporation Car" code="CC">
      <model>
        <name>First and Only Model</name>
        <code>FOM</code>
        <year>2012</year>
      </model>
    </series>
  </manufacturer>
  <manufacturer name="Second Test Manufacturer">
    <series title="AAAAAAAAAAAAAA" code="D">
      <model>
        <name>Some older model</name>
        <code>O</code>
        <year>2011</year>
      </model>
      <model>
        <name>The newest model</name>
        <code>N</code>
        <year>2014</year>
      </model>
    </series>
    <series title="BBBBBBBBBBBBBBB" code="asdf">
      <model>
        <name>Another newest model here</name>
        <code>TT</code>
        <year>2015</year>
      </model>
    </series>
  </manufacturer>
</products>

Output

Your output is this string. It lists the car manufacturers in alphabetical order, followed by a colon and the number of series they make. Under each manufacturer, it lists the series name, model name, and code of each of their models, starting from the newest and going backward by year. Trailing whitespace and line breaks are acceptable, as long as your output looks similar to this when printed.

Car Corporation: 1 series
  Corporation Car, First and Only Model (CC-FOM)
Second Test Manufacturer: 2 series
  BBBBBBBBBBBBBBB, Another newest model here (asdf-TT)
  AAAAAAAAAAAAAA, The newest model (D-N)
  AAAAAAAAAAAAAA, Some older model (D-O)
Test Manufacturer 1: 2 series
  Supercar, Incredibulus (S1-I)
  Test series 22, Test model asdafds (Test-TT)
  Supercar, Ubervehicle (S1-U)
  Supercar, Road Czar (S1-C)
  Supercar, Model 1 (S1-01)

Rules and Scoring

You may write either a function or full program. The lowest byte count wins, and standard loopholes are disallowed.

Note that the input is fixed: you don't need to support any other inputs than the one given here. Your program is allowed to return nonsense or even crash if the input is modified in any way. You may also ignore the input and hard-code the output, if desired. However, you may not use XML or HTML parser libraries or built-ins.

share|improve this question
    
Would an HTML parser be allowed or would that be bending the rules? –  vihan 16 hours ago
7  
I never want to buy a car from this company. –  kirbyfan64sos 16 hours ago
1  
@vihan I'll (rather arbitrarily) decide that HTML parsers are not allowed either, since the two formats are so similar. –  Zgarb 16 hours ago

2 Answers 2

Bubblegum, 227 bytes

0000000: 6d 50 35 76 03 31 10 ed f7 14 bf 33 63 e9 ce 31 33 1f  mP5v.1.....3c..13.
0000012: 40 5e cd 9a 25 3f 41 e8 f4 59 49 21 c3 74 43 9f 5a 4c  @^..%?A..YI!.tC.ZL
0000024: a1 25 d5 55 2a 66 0e 52 34 50 83 26 75 20 1d e1 ff 1c  .%.U*f.R4P.&u ....
0000036: e9 5d 11 dd 83 d2 06 4c 70 cc c4 f9 03 13 c9 e9 8c 6c  .].....Lp........l
0000048: ab 55 ea ce 26 b9 68 45 b1 4c 57 6b 4a 6f 26 4c d8 84  .U..&.hE.LWkJo&L..
000005a: c5 c6 2a 52 0d d4 ff 30 5f 6e ab 88 a6 90 66 4f 0a 82  ..*R...0_n....fO..
000006c: de dc e3 c5 63 a6 03 42 96 69 9e 94 d6 eb 5c 04 34 6f  ....c..B.i....\.4o
000007e: aa 88 f5 9e 6e 3f b2 ed d2 f4 d9 e1 4a 5e 08 f2 cc 49  ....n?......J^...I
0000090: fd 1d ce 72 d1 83 48 d4 6e 64 ae ec 95 54 ec 3c 0f 44  ...r..H.nd...T.<.D
00000a2: ac 88 1f b6 f6 6c 35 b2 ab 5a 69 e0 68 fc 7f b8 46 bd  .....l5..Zi.h...F.
00000b4: 9e ea f9 53 92 aa 66 09 4f 6f dd cc c9 bf 81 db 6c 49  ...S..f.Oo......lI
00000c6: bd d2 fe 10 9f c9 a3 6d 6e d7 4b c9 38 5a 9f 4c f9 65  .......mn.K.8Z.L.e
00000d8: eb 76 19 f2 ae f9 55 b5 96 fb 02                       .v....U....

This isn't very competitive, but I just couldn't resist to post my first Bubblegum answer to an actual challenge.

The code completely ignores the input. Compression has been done with zopfli, which uses the DEFLATE format but obtains a much better ratio than (g)zip.

share|improve this answer

CJam, 109 107 bytes

"rzn ¸À¨ 4T\$D"S/q"<>"'"er'"/
f{\:i2/_E5bf.+.+\ff=)1<_s,9/+":  series
"2/.+\"  ,  ()
-"2/Z4e\f.\}

Note that four of the characters in the string at the beginning are unprintable.

Try it online in the CJam interpreter.

share|improve this answer
    
Please let me know if the permalink doesn't work in some browser. –  Dennis 16 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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