My submission for the most outlandish/outrageous solution:
minors=: 1&(|:\.)"2^:2
det=: -/ .*
(<0 1) |: det minors (* =@/:) 3 1 4 1 5 9
180 540 135 540 108 60
As usual, when referring to minors, the obligatory Green Mug link:
http://www.jsoftware.com/jwiki/DavidMitchell
-
Unexpected bonus of "J thinking":
x=:1e6?@$10
ts=:6!:2,7!:2@]
100 ts '1 */\. x'
0.081586 4.19444e7
100 ts '((*/ .^ * %~)~:&0) x'
0.0448121 1.7828e7
(That's a factor of ~2, at least on my phone).
> On Mar 27, 2014, at 7:49 PM, Dan Bron wrote:
>
> ((*/ .^ * %~)~:&0)
---
t;>48 64 96 24
>>
>> -Dan
>>
>> - Original Message ---
>>
>> Subject: Re: [Jprogramming] J as an interviewing tool
>> From: Roger Hui
>> Date: Thu, 27 Mar 2014 12:44:59 -0700
>> To: Programming forum
>>
It's not what you know, it's who you know?
Still, if the reviewer is just being ornery you might as well have fun with
the situation... and then go elsewhere.
Oh, and here's a version that should be easy to translate into many other
languages:
(3*2*8),(4*2*8),(4*3*8),(4*3*2)
Thanks,
--
Raul
Unfortunately (as no doubt you are aware):
x=:5 5 6 5
1 */\. x
150 150 125 150
*/@-."1 0~ x
6 6 125 6
However, if we constrain our input to unique vectors, I'll note that we can
replace the =@i.@# in your original solution with simple, modest (monad) e. :
(-.e.x) */ .(^~) x
48 64 9
*/@-."1 0~ 4 3 2 8
48 64 96 24
*/@-."1 0~ 4 0 2 8
0 64 0 0
--
For information about J forums see http://www.jsoftware.com/forums.htm
(*/ % ]) 4 3 2 8
> >>48 64 96 24
> >>
> >> (*/@#~1-=@i.) 4 3 2 8
> >>48 64 96 24
> >>
> >> -Dan
> >>
> >> - Original Message ---
> >>
> >> Subject: Re: [Jprogramming] J as an interv
ar 27, 2014 at 4:10 PM, Dan Bron wrote:
>>
>> Oh, I like this game!
>>
>> (*/ % ]) 4 3 2 8
>>48 64 96 24
>>
>> (*/@#~1-=@i.) 4 3 2 8
>> 48 64 96 24
>>
>> -Dan
>>
>> - Original Message -
gt; -Dan
>
> - Original Message ---
>
> Subject: Re: [Jprogramming] J as an interviewing tool
>From: Roger Hui
>Date: Thu, 27 Mar 2014 12:44:59 -0700
> To: Programming forum
>
> Suppose you did not have the outfix operator, but still have array o
24
-Dan
- Original Message ---
Subject: Re: [Jprogramming] J as an interviewing tool
From: Roger Hui
Date: Thu, 27 Mar 2014 12:44:59 -0700
To: Programming forum
Suppose you did not have the outfix operator, but still have array ops.
x=: 4 3 2 8
I=: =i.#x
>
> -Dan
>
> - Original Message -----------
>
> Subject: Re: [Jprogramming] J as an interviewing tool
>From: Roger Hui
>Date: Thu, 27 Mar 2014 12:44:59 -0700
> To: Programming forum
>
> Suppose you did not have the outfix operator, but still have array ops.
>
>
Oh, I like this game!
(*/ % ]) 4 3 2 8
48 64 96 24
(*/@#~1-=@i.) 4 3 2 8
48 64 96 24
-Dan
- Original Message ---
Subject: Re: [Jprogramming] J as an interviewing tool
From: Roger Hui
Date: Thu, 27 Mar 2014 12:44:59 -0700
To
Just wanted to say...
Seriously blowing my mind here guys. I keep reconsidering
completely learning J when I see things like this.
As for an interviewing tool, well, I'm sure it would impress many.
On Thu, Mar 27, 2014 at 3:44 PM, Roger Hui wrote:
> Suppose you did not have the outfix ope
Suppose you did not have the outfix operator, but still have array ops.
x=: 4 3 2 8
I=: =i.#x
I
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
(-.I)*/ .(^~) x
48 64 96 24
On Thu, Mar 27, 2014 at 12:37 PM, Dan Bron wrote:
> A question on StackExchange [1]:
>
> "
>I was asked the following i
A question on StackExchange [1]:
"
I was asked the following interview question over the phone:
Given an array of integers, produce an array whose values
are the product of every other integer excluding the current index.
Example:
[4, 3, 2, 8] -> [3*2*8, 4*2*8, 4*3*8, 4*3*2] -
15 matches
Mail list logo