Code Golf

by Marcel Veldhuizen 18. February 2013 14:13

Every now and then I just want to do something silly with code, like some code golf. Just for a moment to forget about best practices and write the shortest possible program to solve a problem.

Today I happened to run into one of those projects on my hard disk, which happened to be in C# (it's not exactly the tersest language there is, so it may be a little unusual). It's an exercise from an old Google Code Jam. The problem to be solved and some solutions can be found in this StackOverflow question, including my own. It measures 398 characters after removing insignificant whitespace, the longest solution between a host of different languages.

Today I realized that there was a slightly shorter solution than the one below, but perhaps you can come up with something even better?

namespace System
{
    class P
    {
        static void Main(string[]a)
        {
            int c = 0, n, m, d, l = 1;
            var f = IO.File.ReadAllLines(a[0]);

            while (c < int.Parse(f[0]))
            {
                var o = f[l++].Split(' ');
                n = int.Parse(o[0]);
                m = int.Parse(o[1]);
                var p = new Collections.Generic.HashSet<string>();

                while (n-- > 0)
                    p.Add(f[l++]);

                while (m-- > 0)
                    for (o = f[l++].Split('/'), d = 0; d++ < o.Length; )
                        if (p.Add(string.Join("/", o, 0, d)))
                            n++;

                Console.Write("Case #{0}: {1}\n", ++c, n);
            }
        }
    }
}

Tags: , ,

Coding4Fun

Comments (7) -

kashmir websites
1/13/2017 10:22:10 AM #

Very nice and informative post it help me lots in solving my problems

Reply

Tabatha United States
3/7/2017 2:59:33 AM #

I read this article fully regarding the resemblance of latest and preceding technologies, it's remarkable article.  Look into my page ...  Tabatha - http://?????.??/index.php?option=com_k2&view=item&id=29:about-the-company&limitstart=2400

Reply

viawebcloud
3/29/2017 4:52:10 PM #

Website Hosting offers. Try them out. Subscribe with viawebcloud. A point and click Control Panel. A 30-day money-return guarantee.

Reply

ngtdoha
3/31/2017 7:59:56 AM #

Restaurant Software in Qatar,Retail Software in Qatar,IT in Qatar,Printers in Qatar,POS in Qatar,HP POS in Qatar,Software in Qatar,Projectors in Qatar,
EPSON Projectors in Qatar,Networking in Qatar,Structured cabling in Qatar,Barcode Printer in Qatar,Barcode Scanner in Qatar,Barcode Scanner doha,Conference System doha,Barcode Printer doha,Restaurant Software doha,web design company doha,web development company doha,Scanner doha,Barcode Rolls doha,Hospital Management Solution doha,HP Cartridges doha,Retail Software doha, seo development company doha, ngt doha, website design bani hajer qatar, e commerce website design company bani hajer qatar, seo development company bani hajer qatar, web development company in bani hajer qatar, Computers Qatarbani hajer qatar, NGT Doha bani hajer qatar, Queue Management System bani hajer qatar, Software bani hajer qatar, Software in bani hajer qatar, Restaurant Software bani hajer qatar, HP POS  bani hajer qatar, Specktron POS bani hajer qatar, Ezee bani hajer qatar, Ezee Burrp bani hajer qatar, Retail Software bani hajer qatar, Raymedi, Point Of Sale bani hajer qatar, POS bani hajer qatar, Projectors bani hajer qatar, Scanner bani hajer qatar, Barcode Printer bani hajer qatar, Barcode Scanner bani hajer qatar, Digital Signage bani hajer qatar, Conference System bani hajer qatar, PDT bani hajer qatar, Thermal Rolls bani hajer qatar, Barcode Rolls bani hajer qatar, Networking bani hajer qatar, Restaurant POS bani hajer qatar, Asset Management Software bani hajer qatar, Customer Feedback Software bani hajer qatar, Website Designing bani hajer qatar, Digital Restaurant Menu in bani hajer qatar, HP bani hajer qatar, EPSON Bani Hajer bani hajer qatar, Samsung bani hajer qatar, TSC   bani hajer qatar, Zebra bani hajer qatar, DELL bani hajer qatar, Lenovo bani hajer qatar, Almoe bani hajer qatar, Care Well POS bani hajer qatar, Care Well bani hajer qatar, Emsysit bani hajer qatar, Emsys bani hajer qatar, Emsys POS bani hajer qatar, Alfanet bani hajer qatar, Whatsapp Gold bani hajer qatar, Hospital Management Solution bani hajer qatar, Hotel Management Solution bani hajer qatar, Software Development bani hajer qatar, Datalogic bani hajer qatar, Techno bani hajer qatar, Family Computers bani hajer qatar, Sofitel bani hajer qatar, Printek bani hajer qatar, Specktron bani hajer qatar, Interactive Boards, CISCO switches in Qatar, HP Cartridges in Qatar, touch panels, tv stands, woosim printers, rfid bani hajer qatar, NAS bani hajer qatar, QNAP bani hajer qatar, TELYHD bani hajer qatar, KONFTEL bani hajer qatar, NGT Doha bani hajer qatar, ngtdoha.com bani hajer qatar, Next Generation Technology Bani Hajer Qatar

Reply

Free Scipts PHP
4/5/2017 2:53:57 PM #

Thank you very helpful, visit also our website and get the free script PHP range with one click the link download the application for website

Reply

waqas
4/17/2017 6:32:08 AM #

You can download Any software Free of Cost and fast Includes Cracks etc just visit our site and Download.
http://directlyoutube.blogspot.com/

Reply

waqas
4/17/2017 6:33:33 AM #

You can download youtube rank software removin copyrighted video softwares just visit.
http://directlyoutube.blogspot.com/

Reply

Add comment

Marcel Veldhuizen

Software Architect by profession, mostly focused on Microsoft .NET technology.

Metal enthusiast; I love going to concerts :)

 

RecentPosts

Recent Tweets

Note: For Customization and Configuration, CheckOut Recent Tweets Documentation