Your task is to find the length of the coastline of a map of islands provided in
an ASCII map. The input map will consist of 1 or more #
characters that
indicate land, and spaces which indicate water. The coastline is considered to
be any edge between land and water, including inland lakes and islands.
Your solution should be a complete program that reads in a file, a string or an array of strings, and outputs a single integer to the screen or stdout. Each input line may have leading or trailing space, and zero or more hash characters. The borders of the map are assumed to be space (water).
Lines may be of different lengths.
Examples:
Input:
##
##
Output: 8
Input:
### ###
##### #
##
Output: 26
Input:
#####
# #
# # #
# #
#####
Output: 36
This is code golf, so the smallest byte count wins.