[Jprogramming] monad vs. dyad
Roger Hui
rhui000 at shaw.ca
Thu Mar 22 18:57:31 HKT 2007
p2 in isolation can be better written as:
p2a=: ": -. at -:&(/:~) ":@+:
(+p2a)^:_ ]1
125874
p2b=: -. at -:&(/:~@":) +:
(+p2b)^:_ ]1
125874
----- Original Message -----
From: Roger Hui <rhui000 at shaw.ca>
Date: Thursday, March 22, 2007 3:45 am
Subject: Re: [Jprogramming] monad vs. dyad
> p2=: 1 < #@:~.@:(/:~@":"0)@:(*&1 2 )
> p3=: 1 < #@:~.@:(/:~@":"0)@:(*&1 2 3 )
> p4=: 1 < #@:~.@:(/:~@":"0)@:(*&1 2 3 4 )
> p5=: 1 < #@:~.@:(/:~@":"0)@:(*&1 2 3 4 5 )
> p6=: 1 < #@:~.@:(/:~@":"0)@:(*&1 2 3 4 5 6)
> f=: ((+p6)^:_)@((+p5)^:_)@((+p4)^:_)@((+p3)^:_)@((+p2)^:_)
>
> f 1
> 142857
>
> ping=: [ 1!:2&2^:(0=20000&|)
> (+p2)@ping^:_ ]1
> 20000
> 40000
> 60000
> 80000
> 100000
> 120000
> 125874
>
>
>
> ----- Original Message -----
> From: Geoff Canyon <geoffc at inspiredlogic.com>
> Date: Thursday, March 22, 2007 0:09 am
> Subject: Re: [Jprogramming] monad vs. dyad
>
> > 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?
More information about the Programming
mailing list