Okay, got it. So here's my one line version:
(1+])^:(1<#@:~.@:(/:~@:":"0)@:((>:i.6)*]))^:(_)1
It works a treat, but I have two more questions ;-)
1. The goal is to find x such that 1x, 2x, 3x, 4x, 5x, and 6x are all
permutations of the same digits. That means that if 1x and 2x
_aren't_ permutations, there's no point testing the remaining four
values. Likewise if 1x and 2x are permutations but 3x isn't, etc.
The above code always checks all six values. Here it doesn't matter
because the problem is solved in a few seconds, but I want to learn:
is there a way to keep the tacit structure and at the same time short
circuit the process?
If the only way to do this is to break the code apart and write a
standard loop with conditionals, fine, but I wanted to ask before
doing that.
2. Again, it's not needed here, but if I wanted to report progress
along the way -- say every second spit out how far the process has
gone looking for an answer -- is that possible without switching to a
standard loop structure?
regards,
Geoff
On Mar 21, 2007, at 8:23 AM, Roger Hui wrote:
Sorry, there was a typo in the description.
It should be
z=. y
while. proposition z do. z=. f z end.
For example:
f=: 1 + 3 * ]
proposition=: 1e5&>
foo=: 3 : 0
z=. y
while. proposition z do. z=. f z end.
)
f^:proposition^:(_) 3
206671
foo 3
206671
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm