Skip to main content
Minor edits
Source Link
Mathgeek
  • 587
  • 2
  • 7
1/                                     #Split the string into an array of chars
  {"_"=!},                             #Replace the prev array with one without underscores
          'P'%~                        #Split the array at the piper
               -1%                     #Reverse the second array (right side)
                                       #This has the function of making all correct mice
                                       #Face#face the same way, which makes for easier matching
                  +                    #Concatenate
                   2/                  #Split the array into groups of two
                                       #So#so we only an array of mouse-strings!
                     .                 #Duplicate our array, since we have to count twice
                      {"~o"=},,        #First count-find all valid mice
                               .       #Duplicate that count
                                @,     #Bring back that second array and count the mice
                                  \-   #Subtract (correct mice) from (all mice)
                                       #Which#which only leaves (correct mice) then (wrong mice)
1/                                     #Split string into an array of chars
  {"_"=!},                             #Replace the prev array with one without underscores
          'P'%~                        #Split the array at the piper
               -1%                     #Reverse the second array (right side)
                                       #This has the function of making all correct mice
                                       #Face the same way, which makes for easier matching
                  +                    #Concatenate
                   2/                  #Split the array into groups of two
                                       #So we only an array of mouse-strings!
                     .                 #Duplicate our array, since we have to count twice
                      {"~o"=},,        #First count-find all valid mice
                               .       #Duplicate that count
                                @,     #Bring back that second array and count the mice
                                  \-   #Subtract (correct mice) from (all mice)
                                       #Which only leaves (wrong mice)
1/                                     #Split the string into an array of chars
  {"_"=!},                             #Replace the prev array with one without underscores
          'P'%~                        #Split the array at the piper
               -1%                     #Reverse the second array (right side)
                                       #This has the function of making all correct mice
                                       #face the same way, which makes for easier matching
                  +                    #Concatenate
                   2/                  #Split the array into groups of two
                                       #so we only an array of mouse-strings!
                     .                 #Duplicate our array, since we have to count twice
                      {"~o"=},,        #First count all valid mice
                               .       #Duplicate that count
                                @,     #Bring back that second array and count the mice
                                  \-   #Subtract (correct mice) from (all mice)
                                       #which only leaves (correct mice) then (wrong mice)
Improved bytecount, added explanation
Source Link
Mathgeek
  • 587
  • 2
  • 7

GolfScript, 4646 bytes 36 bytes

1/.{"o"=},,\{"_"=!},"P"/~"o~"'P'%~-1%+2/.{"~o"=},\"~o"/,+2-.@\-@,\-

Significant improvement from my previous algorithm. Enough so that I'm not goingwilling to actually explain everything in depth right now, but the short of it is;

"Split the string into an array of chars, count the mice, then split the array in two, one before the piper and one after. Then count the number of mice in the correct direction, then subtract that from the original count."

This is the brute force method and can likely be very optimized.

1/                                     #Split string into an array of chars
  {"_"=!},                             #Replace the prev array with one without underscores
          'P'%~                        #Split the array at the piper
               -1%                     #Reverse the second array (right side)
                                       #This has the function of making all correct mice
                                       #Face the same way, which makes for easier matching
                  +                    #Concatenate
                   2/                  #Split the array into groups of two
                                       #So we only an array of mouse-strings!
                     .                 #Duplicate our array, since we have to count twice
                      {"~o"=},,        #First count-find all valid mice
                               .       #Duplicate that count
                                @,     #Bring back that second array and count the mice
                                  \-   #Subtract (correct mice) from (all mice)
                                       #Which only leaves (wrong mice)

GolfScript, 46 bytes

1/.{"o"=},,\{"_"=!},"P"/~"o~"/,\"~o"/,+2-.@\-\

I'm not going to explain everything in depth right now, but the short of it is;

"Split the string into an array of chars, count the mice, then split the array in two, one before the piper and one after. Then count the number of mice in the correct direction, then subtract that from the original count."

This is the brute force method and can likely be very optimized.

GolfScript, 46 bytes 36 bytes

1/{"_"=!},'P'%~-1%+2/.{"~o"=},,.@,\-

Significant improvement from my previous algorithm. Enough so that I'm willing to actually explain it.

1/                                     #Split string into an array of chars
  {"_"=!},                             #Replace the prev array with one without underscores
          'P'%~                        #Split the array at the piper
               -1%                     #Reverse the second array (right side)
                                       #This has the function of making all correct mice
                                       #Face the same way, which makes for easier matching
                  +                    #Concatenate
                   2/                  #Split the array into groups of two
                                       #So we only an array of mouse-strings!
                     .                 #Duplicate our array, since we have to count twice
                      {"~o"=},,        #First count-find all valid mice
                               .       #Duplicate that count
                                @,     #Bring back that second array and count the mice
                                  \-   #Subtract (correct mice) from (all mice)
                                       #Which only leaves (wrong mice)
Source Link
Mathgeek
  • 587
  • 2
  • 7

GolfScript, 46 bytes

1/.{"o"=},,\{"_"=!},"P"/~"o~"/,\"~o"/,+2-.@\-\

I'm not going to explain everything in depth right now, but the short of it is;

"Split the string into an array of chars, count the mice, then split the array in two, one before the piper and one after. Then count the number of mice in the correct direction, then subtract that from the original count."

This is the brute force method and can likely be very optimized.