filefixit
``` ```
% filefixit.pi (in Picat)
% by M. Bionchik (edited by N.F.Z.), July, 2015
% Round 1B 2010
% Problem A. File Fix-it
%
% to use: picat filefixit < input_file > output_file

import util.   % using split/2

main =>
foreach(TC in 1..T)
do_case(TC)
end.

do_case(TC) =>
N = to_int(NToken),
M = to_int(MToken),

RootDir = new_map(),    % root directory tree:
% string -> map(string -> map)...
foreach(_ in 1..N)
_ = mkdir(RootDir, split(Dir,"/"), 0)  % path into subdirectories
end,

Mkdirs = 0,             % counter for mkdir commands
foreach(I in 1..M)
Mkdirs := Mkdirs + mkdir(RootDir, split(Dir,"/"), 0)
end,

writef("Case #%w: %w%n", TC, Mkdirs).

%% mkdir:  create a given directory (as well as directories in its path, if
%%         needed) in the current directory tree and return number of mkdir
%%         commands used
mkdir(_Parent, [], Acc) = Acc.
mkdir(Parent, [Dir|Dirs], Acc) = Res, Parent.has_key(Dir) =>
Res = mkdir(Parent.get(Dir), Dirs, Acc).
mkdir(Parent, [Dir|Dirs], Acc) = Res =>
M = new_map(),
Parent.put(Dir, M),
Res = mkdir(M, Dirs, Acc+1).

``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.60525596,"math_prob":0.9578977,"size":1194,"snap":"2019-13-2019-22","text_gpt3_token_len":396,"char_repetition_ratio":0.11092437,"word_repetition_ratio":0.0,"special_character_ratio":0.36348408,"punctuation_ratio":0.27058825,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98373437,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-03-25T08:48:59Z\",\"WARC-Record-ID\":\"<urn:uuid:001da641-ba4a-418b-a3ba-f61052735376>\",\"Content-Length\":\"6532\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c7966da7-648a-48f9-bd8d-4abb12d531b8>\",\"WARC-Concurrent-To\":\"<urn:uuid:1feb2d2f-965c-4843-94cd-8bb52fd8cf15>\",\"WARC-IP-Address\":\"64.71.35.59\",\"WARC-Target-URI\":\"http://picat-lang.org/gcj/filefixit.html\",\"WARC-Payload-Digest\":\"sha1:NXC3E3ILZQ25M2JZOVW7ZWXGNEZVNUXE\",\"WARC-Block-Digest\":\"sha1:52TYYDCXT5NVASLETC3ABMY5ZS67LI5L\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-13/CC-MAIN-2019-13_segments_1552912203842.71_warc_CC-MAIN-20190325072024-20190325094024-00064.warc.gz\"}"}