Challenge about advacado

Pyth, 59 51 bytes

*Ksm/.s.s.sd\ \#\ \ fq4l:T"#+"4.z13+-/s.sR\ .zdK*2K

Try it here!

Outputs the time to juic the advacado (totally correct english) first and on the next line the amount of juic.

Explanation

Code - Overview

*Ksm/.s.s.sd\ \#\ \ fq4l:T"#+"4.z13+-/s.sR\ .zdK*2K # .z=list of all input lines

                    fq4l:T"#+"4.z                   # Get the pit-lines
   m/.s.s.sd\ \#\ \                                 # Map the pit-lines to the whitespace amount
 Ks                                                 # Sum the amount of pit-spaces and assign to K
*                                13                 # Print the juic time
                                     /s.sR\ .zd     # Count all whitespaces in the advacado
                                    -          K    # Subtract the pit size from it
                                   +            *2K # Do the Rest of the amount calcluation and print it


Detailed explanations of the size calculation parts see below.

Getting the advacado size

Let's look at this one:

    ###### 
   #      #
   # #### #
  #  #  # #
  ## #### #
   #      #
    ######

First the leading and trailing whitespaces get removed. After that we wrap everything in one line, which results in this string:

#######      ## #### ##  #  # ### #### ##      #######

This contains all whitespaces in the advacado, so we just have to count them (the advacado will always be convex, so this works for all valid inputs). This number still contains the spaces in the pit, but for the juic amount calculation we only need the spaces in the fruit without the pit-spaces. So we need to calculate them too.

The code for that explained in detail:

/s.sR\ .zd   # .z=list of all input lines

  .sR\ .z    # strip spaces from every input line
 s           # Concatenate all lines
/        d   # Count all spaces

Getting the pit size

This is a bit trickier. First we remove the lines which don't contribute to the pit size. This is done by filtering out all lines that have less than 4 groups of hashes (using the regex #+ and counting its matches). In the example above only one line will survive this process:

  #  #--# #

The spaces I marked with a - here are the ones we need to count. So we just strip spaces, then hashes and then spaces again which leaves us with this:

#  #

There we just have to count the spaces. We do all that for every line which survived the filtering process, sum everything and we are done. The rest is trivial math.

The code for that explained in detail:

sm/.s.s.sd\ \#\ \ fq4l:T"#+"4.z   # .z=list of all input lines

                  f          .z   # filter the input
                     l:T"#+"4     # length of the matches for the regex `#+`
                   q4             # if there are 4 groups of hashes its a pit line
 m                                # map the pit lines to...
  /             \                 # The occurences of spaces in..
   .s.s.sd\ \#\                   # ...the stripped pit line (see explanation above)
s                                 # Sum all amounts of spaces in the pits


Retina, 70

  • 25 bytes saved thanks to @FryAmTheEggman and @randomra
T` `i`(?<=# +#+) *(?=#+ +#)
T` `f`# +#
i
13$*iff
((i)|(f)|\W)+
$#2 $#3

Try it online.


Python, 141 119 bytes

import sys
s=str.strip;l=len;o=i=0
for x in sys.stdin:x=s(s(x),'#');y=s(x);o+=l(x)-l(y);i+=l(s(y,'#'))
print o+2*i,13*i