6 kyu

File Size Trouble!

Description:

Purely optional backstory:

Israel's top secret agent, mxdavis, has a mission to complete. Unfortunately, it requires a special set of skills that she hasn't found the time to acquire. She needs to Learn how to accomplish this task in a very short amount of time, so that when she's in the field she can React appropriately.

Can you help her?

Additionally, our intrepid spy, mxdavis, unfortunately dropped her agency-issued next-gen mobile device and the data drive she's supposed to be decrypting in her Matzo-ball soup. As a result, she is using some old, proprietary hardware, so we'll have to think a little bit about efficiency. Nothing crazy, but we can't get away with brute-forcing absolutely everything on a 1997 Power Mac 9700 prototype, no matter how fast its 604ev's "Mach V" moniker might sound.

She's sorting through the data files, but they're a little bit jumbled now! She needs to know whether or not there's enough space on her government-issued thumb drive. Don't worry about decrypting things once everything's sorted out, she's taken care of that.

Instructions:

0.) The thumb drive she's using is represented by the argument size in the function. It's always a whole number measured in GB.

1.) Because of the Matzo-ball soup SNAFU, the list of file sizes on the hard drive she's trying to copy from is messed up and encased in blocks of random text. You'll have to find and add them to the list of file sizes. File sizes can be in bytes, KB, MB or GB (not TB or bits). Sizes will never be negative or a decimal, and the only valid format looks like: 768 MB, 740281 bytes, 22 GB, etc.

2.) One KB is defined as 1024 bytes, not 1000. (Technically this is a KiB.)

3.) Because of the nature of the agency back in 1997, the computer she's using always feels the need to check for primes. You only need to check to see that the number as found in the string (be it in MB, KB, bytes or GB) is not prime; it doesn't matter if it's prime once converted to bytes if you're choosing to do so. If it is prime, it won't be counted as part of the total size of the file transfer, but we do need to keep track of it.

4.) Additionally, due to the wonky file system of the special thumb drive she's copying to, files smaller than one sector (1280 bytes) should be ignored. This won't invalidate anything, but if this number is prime, it needs to be added to the list of primes in addition to incrementing the number of dropped files.

5.) Sample tests will be short, but full tests are pretty long. You'll need a reasonably efficient algorithm to get primes done in time; nothing too crazy, but don't do exponentially more work than you have to (hint).

6.) Return an array in the following format: [ [array of all valid file sizes as they were found], [array of unique primes, sorted descending], number of files discarded for being < 1280 bytes, true/false depending on whether the files she wants to transfer will fit] ].

Examples:

Input: fileTransfer("1024 MB  16 KB  8 bytes  7 MB  13 GB  44102 bytes", 64)
Output: [ ["1024 MB", "16 KB", "44102 bytes"], [13,7], 1, true ]

Input: fileTransfer("52 GB  161 KB  8206 bytes  2704 MB  12 GB  98102 bytes", 64)
Output: [['52 GB', '161 KB', '8206 bytes', '2704 MB', '12 GB', '98102 bytes'], [], 0,false]

More realistic, less readable Input: fileTransfer("asl.$lf we102 MBks&(0 23k604 KB,11 MB9ywu2 GB7 bytes9tb23 GBkbie2o3kled,dl waer 6sx jer 68 MB", 128)
Output: [ ["102 MB", "604 KB", "68 MB"], [23, 11, 2], 1, true]
Strings
Arrays
Regular Expressions
Algorithms

Stats:

CreatedNov 22, 2017
PublishedNov 26, 2017
Warriors Trained225
Total Skips16
Total Code Submissions681
Total Times Completed46
JavaScript Completions46
Total Stars6
% of votes with a positive feedback rating80% of 25
Total "Very Satisfied" Votes16
Total "Somewhat Satisfied" Votes8
Total "Not Satisfied" Votes1
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Firefly2002 Avatar
  • user8436785 Avatar
Ad