Edit Rename Changes History Upload Download Back to Top

Vier-Neun Puzzle

This puzzle was originally posted on a mailing list for the Icon 
programming language.  Thought members of this group might also 
want to give it a shot. 
VIER and NEUN represent 4-digit squares, each letter denoting a 
distinct digit. You are asked to find the value of each, given the 
further requirement that each uniquely determines the other. 
The "further requirement" means that of the numerous pairs of 
answers, choose the one in which each number only appears once 
in all of the pairs. 
Steve Graham 

| squares neuns pairs tallies results | 
squares := (1000 sqrt ceiling to: 9999 sqrt truncated) 
               collect: [ :n | n squared printString ]. 
neuns := squares select: [ :string | 
               string first == string last 
                   and: [string asSet size==3]]. 
pairs := OrderedCollection new. 
tallies := Bag new. 
squares do: [ :square | 
    neuns do: [ :neun | 
        ((square at: 3 )==(neun at: 2) 
            and: [(square,neun) asSet size = 6]) 
                ifTrue: [ 
                    pairs add: square -> neun. 
                    tallies add: square; add: neun ]]]. 
results := pairs select: [ :pair | 
                (tallies occurrencesOf: pair key) == 1 
                    and: [(tallies occurrencesOf: pair value) == 1]] 



Edit Rename Changes History Upload Download Back to Top