Hexagolf: Validagons
R, 184 bytes
Golfed, could probably be golfed by a few bytes
function(m){e=min;f=max;l=length;v=which(m!=" ",T);a=v[,1];n=l(v[a==1,2]);u=(v[a==e(a),2]);all(u==v[a==f(a),2])&all(c(e(d<-v[a==ceiling(f(v[,1])/2),2]),f(d))==c(u[1]-n+1,u[l(u)]+n-1))}
Ungolfed, very messy, more like half way golfed
f=function(m) {
v = which(m!=" ",T)
a = v[,1]
n = length(v[a==1,2])
u=(v[a==min(a),2])
c1 = all(u==v[a==max(a),2])
d = v[a==ceiling(max(v[,1])/2),2]
c2 = all(c(min(d), max(d))==c(u[1]-n+1,u[length(u)]+n-1))
c1 & c2
}
Since the input format is unspecified, Input needs to be specified in an R array format, looking something like this.
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] " " " " "5" " " "6" " " "7" " " " "
[2,] " " "8" " " "9" " " "0" " " "1" " "
[3,] "2" " " "3" " " "4" " " "5" " " "6"
[4,] " " "7" " " "8" " " "9" " " "0" " "
[5,] " " " " "1" " " "2" " " "3" " " " "
Here is a generator function that generates the input. The generator doesn't generate an object that is fed into hexagon check function, but rather the code specifying the array (effectively the same thing). So this should not count as parsing the text. Remember that I'm not inputting text, but rather an array structure.
generate = function(x) {
s = strsplit(strsplit(x, "\n")[[1]], "")
m = max(sapply(s, length))
dput(do.call(rbind, lapply(s, function(x) c(x, rep(" ", m-length(x))))))
}
For example, the generated code would be: structure(c(" ", " ", "2", " ", " ", " ", "8", " ", "7", " ", "5", " ", "3", " ", "1", " ", "9", " ", "8", " ", "6", " ", "4", " ", "2", " ", "0", " ", "9", " ", "7", " ", "5", " ", "3", " ",
"1", " ", "0", " ", " ", " ", "6", " ", " "), .Dim = c(5L, 9L
))
which is identical to array(c(" ", " ", "2", " ", " ", " ", "8", " ", "7", " ", "5", " ", "3", " ", "1", " ", "9", " ", "8", " ", "6", " ", "4", " ", "2", " ", "0", " ", "9", " ", "7", " ", "5", " ", "3", " ", "1", " ", "0", " ", " ", " ", "6", " ", " "), dim = c(5, 9))
Hopefully this input method is in compliance with the rules.
Here are the test cases
x1 =
" 5 6 7
8 9 0 1
2 3 4 5 6
7 8 9 0
1 2 3"
x2 =
" # _
+ + +
9 :"
x3 =
" t h i s
i s
a h
e x
a g
o n
! ! ! !"
x4 =" 5 6 7
8 9 0 1
2 3 4 5 6
7 8 9 0
1 2 3"
x5 = "r e c t a
n g l e s"
x6 = " h e l l o
w o r l d s
t h i s i s b
e t a d e c
a y n o w"
x7 =" *
* *
* * *"
x8 =" .....
.......
.........
.......
....."
Generate input arrays
sapply(mget(paste("x", 1:8, sep = "")), generate)
Test for hexagon
sapply(.Last.value , f)
x1 x2 x3 x4 x5 x6 x7 x8
TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE