You are looking down at a map of a 5x5 block area of a city where each block is occupied by one skyscraper. Call the heights 1, 2, 3, 4 and 5 (say they are in 10-story increments). Each row has one of each height and each column also has one of each height.
Considering that when viewed from outside the row or column, the nearer buildings of taller height hide those behind them that are of shorter height, numbers have been placed in the yellow areas pointing to a given row or column. Each number represents the number of buildings that can be seen from that vantage point when looking at the row or column in question.
Fill in each block's height.
From Mensa Puzzle Calendar 2019 by Fraser Simpson, Workman Publishing, New York. Puzzle for December 9.
There are 10 different types of streets that have 4 buildings visible when viewed from the left end
21345, 23145, 23415, 23451, 13245, 13425, 13452, 12435, 12453, 12354.
There are only 2 streets that have 3 visible when viewed from both ends:
12534 and 34521
But there are 35 street that have 3 visible from the left!
I was able to figure all the possible arrangements for the first two groups, but choosing the right 3-streets proved onerous for me, so I wrote a program.
lord@rabbit-3 ~ % city
success!
4 5 3 1 2
1 2 4 5 3
3 4 5 2 1
2 3 1 4 5
5 1 2 3 4
program city
implicit none
integer i(5),i1,i2,i3,i4,i5,j3(5,35),jn3(5,35),j33(5,2),j4(5,10),
1 jc3,jc33,jc4,v,vv,j,jb,kk,k,k2,a,b,c,d,e,f,n(5,5),ksec,kfir,
2 kcol,kkcol,kkrow
equivalence (i1,i(1)),(i2,i(2)),(i3,i(3)),(i4,i(4)),(i5,i(5))
data jc3,jc33,jc4/3*0/,j33/1,2,5,4,3,3,4,5,2,1/
do 1 i1=1,5
c print*,'i1 = ',i1
do 2 i2=1,5
c print*,'i1, i2 = ',i1,i2
if(i1.eq.i2)go to 2
do 3 i3=1,5
if(i1.eq.i3.or.i2.eq.i3)go to 3
do 4 i4=1,5
if(i1.eq.i4.or.i2.eq.i4.or.i3.eq.i4)go to 4
do 5 i5=1,5
if(i1.eq.i5.or.i2.eq.i5.or.i3.eq.i5.or.i4.eq.i5)go to 5
v=1
do j=2,5
do jb=1,j-1
if(i(j).lt.i(jb))go to 6
enddo
v=v+1
6 enddo
c
c find the 3 streets j3, the backward 3 streets 3nj, double 3 st.s j33
c and the 4 streets j4
c
if(v.eq.3)then
jc3=jc3+1
do k=1,5
j3(k,jc3)=i(k)
jn3(k,jc3)=i(6-k)
enddo
endif
if(v.eq.4)then
jc4=jc4+1
do k=1,5
j4(k,jc4)=i(k)
enddo
endif
5 enddo
4 enddo
3 enddo
2 enddo
1 enddo
do 101 a=1,10
do 102 b=1,2
do 103 c=1,10
if(a.eq.c)go to 103
do 104 d=1,10
do 105 e=1,35
do 106 f=1,35
if ( (jn3(4,f).eq.j3(5,e)).and.
2 (j4(2,a).eq.j4(4,d)).and.
3 (j4(4,a).eq.j3(4,e)).and.
4 (j33(2,b).eq.j4(3,d)).and.
5 (j33(4,b).eq.j3(3,e)).and.
6 (j4(2,c).eq.j4(2,d)).and.
7 (j4(4,c).eq.j3(2,e)) ) then
do kk=1,5
n(1,kk)=jn3(kk,f)
n(2,kk)=j4(kk,a)
n(3,kk)=j33(kk,b)
n(4,kk)=j4(kk,c)
enddo
n(5,1)=15-(n(1,1)+n(2,1)+n(3,1)+n(4,1))
n(5,2)=j4(1,d)
n(5,3)=15-(n(1,3)+n(2,3)+n(3,3)+n(4,3))
n(5,4)=j3(1,e)
n(5,5)=15-(n(1,5)+n(2,5)+n(3,5)+n(4,5))
do ksec=2,5
do kfir=1,ksec-1
do kcol=1,5
if (n(kfir,kcol).eq.n(ksec,kcol))go to 400
enddo
enddo
enddo
print*,'success!'
print*
print 50,((n(kkrow,kkcol),kkcol=1,5),kkrow=1,5)
50 format(5(i1,1x))
400 continue
endif
106 enddo
105 enddo
104 enddo
103 enddo
102 enddo
101 enddo
end
Edited on January 27, 2020, 10:53 am