The puppy
utility takes a filename as input, and does exactly what you would expect a puppy to do: it shreds it!
How to shred
Rip out the pages with your teethSplit the input file on newlines.Tear up each page with your pawsFor each line (not including the linefeed), pick a random integern
such that2 <= n <= # of characters in the line
. Split the line inton
non-empty non-overlapping substrings of random length.Scatter the shreds all over the floorOutput each substring of each line to a unique random filename ([a-zA-Z0-9]
only, any consistent extension including none, length1 <= n <= 12
) in the current directory. Overwriting pre-existing files within the current directory (including the input file, if it is in the current directory) is acceptable, as long as it does not interfere with your submission running.
Clarifications
- There will never be an input where it is possible to use up all of the possible filenames.
- Files will consist of only printable ASCII (ordinals 32-127) and linefeeds, and will use UNIX/Linux-style line endings (LF, not the Windows-style CRLF).
- A single trailing newline in output files is acceptable as long as every output file has a trailing newline, but is not required. You may choose whether or not the input file contains a trailing newline.
- Each line in the input will contain at least 2 characters.
- The random values chosen must be chosen from a uniform random distribution on the given set of possible values.
If your language is unable to perform file I/O, you may instead take the input file's contents as input, and output pairs of strings representing the output filename and the text for that file. However, your submission will not be eligible for winning.
Example
Reference implementation:
#!/usr/bin/env python3
import random
import string
import sys
fname = sys.argv[1]
with open(fname) as f:
txt = f.read().rstrip().split('\n')
for line in txt:
n = random.randint(2, len(line))-1
idxs = [0]+random.sample(range(1, len(line)), n)+[len(line)]
idxs.sort()
splits = []
for i in range(0, len(idxs)-1):
splits.append(line[idxs[i]:idxs[i+1]])
ofnames = []
for s in splits:
flen = random.randint(1, 10)
ofname = ''
while ofname == '' or ofname in ofnames:
ofname = ''
for i in range(flen):
ofname += random.choice(string.ascii_letters+string.digits)
ofnames.append(ofname)
with open(ofname, 'w') as f:
f.write(s)
Example run:
$ cat bestsong.txt
Never gonna give you up
Never gonna let you down
Never gonna run around
And desert you!
$ puppy bestsong.txt
$ ls
8675309
a
bestsong.txt
cSdhg
Dq762
jq7t
ret865
rick4life
weu767g
xyzzy
$ cat 8675309
esert you!
$ cat a
Never gonna let you down
$ cat cSdhg
ive y
$ cat Dq762
And d
$ cat jq7t
Never gonna g
$ cat ret865
run arou
$ cat rick4life
Never gonna
$ cat weu767g
nd
$ cat xyzzy
ou up