Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 806723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:17:23+00:00 2026-05-15T00:17:23+00:00

Last year (2009), the Google Code Jam featured an interesting problem as the first

  • 0

Last year (2009), the Google Code Jam featured an interesting problem as the first problem in Round 1B: Decision Tree

As the problem seemed tailored for Lisp-like languages, we spontaneously had an exciting codegolf here on SO, in which a few languages managed to solve the problem in fewer characters than any Lisp variety, using quite a number of different techniques.

This year’s Round 1B Problem A (File Fix-it) also seems tailored for a particular family of languages, Unix shell scripts. So continuing the “1B-A tradition” would be appropriate. :p But which language will end up with the shortest code? Let us codegolf and see!

Problem description (adapted from official page):

You are given T test cases. Each test case contains N lines that list the full path of all directories currently existing on your computer. For example:

/home
/home/awesome
/home/awesome/wheeeeeee
/home/awesome/wheeeeeee/codegolfrocks
/home/thecakeisalie

Next, you are given M lines that list the full path of directories you would like to create. They are in the same format as the previous examples. You can create a directory using the mkdir command, but you can only do so if the parent directory already exists. For example, to create the directories /pyonpyon/fumufumu/yeahyeah and /pyonpyon/fumufumu/yeahyeahyeah, you would need to use mkdir four times:

mkdir /pyonpyon
mkdir /pyonpyon/fumufumu
mkdir /pyonpyon/fumufumu/yeahyeah
mkdir /pyonpyon/fumufumu/yeahyeahyeah

For each test case, return the number of times you have to call mkdir to create all the directories you would like to create.

Input

Input consists of a text file whose first line contains the integer T, the number of test cases. The rest of the file contains the test cases.

Each test case begins with a line containing the integers N and M, separated by a space.

The next N lines contain the path of each directory currently existing on your computer (not including the root directory /). This is a concatenation of one or more non-empty lowercase alphanumeric strings, each preceded by a single /.

The following M lines contain the path of each directory you would like to create.

Output

For each case, print one line containing Case #X: Y, where X is the case number and Y is the solution.

Limits

1 ≤ T ≤ 100.

0 ≤ N ≤ 100.

1 ≤ M ≤ 100.

Each path contains at most 100 characters.

Every path appears only once in the list of directories already on your computer, or in the list of desired directories. However, a path may appear on both lists, as in example case #3 below.

If a directory is in the list of directories already on your computer, its parent directory will also be listed, with the exception of the root directory /.

The input file is at most 100,000 bytes long.

Example

Larger sample test cases may be downloaded here.

Input:

3
0 2
/home/sparkle/pyon
/home/sparkle/cakes
1 3
/z
/z/y
/z/x
/y/y
2 1
/moo
/moo/wheeeee
/moo

Output:

Case #1: 4
Case #2: 4
Case #3: 0

Code Golf

Please post your shortest code in any language that solves this problem. Input and output may be handled via stdin and stdout or by other files of your choice. Please include a disclaimer if your code has the potential to modify or delete existing files when executed.

Winner will be the shortest solution (by byte count) in a language with an implementation existing prior to the start of Round 1B 2010. So while you are free to use a language you’ve just made up in order to submit a 0-byte solution, it won’t count, and you’ll probably get downvotes. ^_^

Standings

  • 65 GolfScript
  • 100 Perl
  • 121 AWK (not including interpreter options)
  • 128 Bash
  • 144 Ruby
  • 145 Python
  • 158 PyonScript
  • 159 J
  • 172 Lua
  • 182 PostScript
  • 189 Scala
  • 218 Haskell
  • 284 Java
  • 398 C#
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:17:24+00:00Added an answer on May 15, 2026 at 12:17 am

    Golfscript, 74 69 65

    Now on a single line!
    This solution is 63 characters, but will not run in a reasonable amount of time for test cases with thousands of paths (over 8 minutes), so I have opted to not count it.

    n%(~,{'Case #'\)@': '\(~1$+@[]@{\('/':!%@\{[n!++:!]|}/}*,@-n@}/
    

    The faster 65 character solution:

    n%(~,{'Case #'\)@': '\(~1$+@[]@{\('/':!%@\{[n!++:!]+}/.&}*,@-n@}/
    

    Kudos to marcog for the algorithm!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First a little intro: Last year i wrote this http://dragan.yourtree.org/code/canvas-3d-graph/ Now, i want to
How can I get last year's start and end date using PHP code? Is
Last year, in 2009 GSoC, I participated with an organization called Winlibre. The basic
Last year I saw some source code (C++) where its author declares static function
In the last year and a bit of working on my team's code base
Last year I developed a data access service for our project using Entity Framework
Last year, I made an application in Java using PDFBox to get the raw
For the last year or so I have followed the idea that if a
I am in the last year of undergraduate degree and i am stumped by
Following up on my last year's question on documentation, I now want to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.