441 questions
Score of 1
1 answer
86 views
Adding a comment in the middle of my verb randomly decides whether it works or not?
I'm making a CGOL game in J, here's the code to get the next state given the current one:
next =: 3 :0
res =. ,/ ({."1 pos) r"(0 0) ({:"1 pos)
(size,size) $ res
)
Which currently ...
Score of 0
1 answer
85 views
How to model this in J [closed]
The data is as follows:
price=:20
ages=:12 18 15 9 35 41 25 37 62 23 68 34
a) People below the 18 years get a 20% discount
b) People above 18 years but below 40 years get a 15% discount
c) People ...
Score of 3
1 answer
188 views
How to write an accumulative recursive function in J without looping
At the risk of asking a question with an obvious solution: if I have a function in J that takes two arguments and returns two arguments and I want to accumulate the answer's second argument and to use ...
Score of 2
2 answers
188 views
How to write a tacit tetration verb in J?
The tetration is an operation defined as an iterated exponentiation (e.g 2^^4 = 2^(2^(2^2)) = 65536)
I'm learning the J programming language and want to experiment with the ^: (power of verb) function ...
Score of 3
2 answers
189 views
Keep numbers which appear in both columns, in J lang
Given a table with two columns:
1 2
3 4
2 1
1 2
I'm trying to understand how to produce a list of only the numbers which appear in both columns.
E.g. 1, 1, 1, 2, 2, 2 in this example.
I can see Nub ...
Score of 2
0 answers
103 views
Need a more efficient sorted leaderboard prototype
Here is a leaderboard prototype for ranking on the left column and could be user indices on the right. The matrix stays sorted. It might get a lot of traffic. Typical size 100,000 and up.
(4 2 $0 342 ...
Score of 3
3 answers
220 views
Differentiation in J
I am a beginner learning J based on this book (2015 version). I was able to run all examples until this one from the calculus chapter:
^&3 d. 1
3&*@(^&2)
I get this error locally:
|...
Score of 2
1 answer
104 views
simplify tacit fork definition
I have the following tacit fork (intended to be used monadically):
F&.I G H&.I
i.e. the left and right verbs F and H of the fork get I applied with &. (under) before feeding the outputs to ...
Score of 3
2 answers
133 views
How to use local variables in nested verbs?
Perhaps there's no facility to do this in the J language, but when I write:
succession =: monad define
greg =. 1 2 3
tom =. {{ greg }}
tom y
)
and then call succession 'season 1', I get the ...
Score of 3
1 answer
91 views
How to reshape an array with an arbitrary size in one dimension?
How would you go about reshaping a length-N 1D array into an (N/2) x 2 array? In numpy, for example, you can use -1 in place of N/2 when reshaping:
>>> x = np.array([1,2,3,4])
>>> x....
Score of 1
1 answer
178 views
What does 'm' stand for in an inline function?
What's going on that makes this code work? It seems that using m in an anonymous verb (if that's what it's called) turns the verb into a postfix operator.
1 {{ 1 + m }}
2
If I replace the m with y ...
Score of 3
3 answers
185 views
Why is Insert (fold) right associative
I expected
-/ 1 2 3 4
_8 NB. ((1-2)-3)-4
but I got
-/ 1 2 3 4
_2 NB. 1-(2-(3-4))
I there a reason for this? How do I get the associativity that I was expecting? If there are relevant sections in the ...
Score of 3
2 answers
113 views
Alignment issue when printing formatted prime numbers in J language
I am a relatively new programmer in J-Lang and recently discovered its efficacy in Code Golfing, where it excels in scoring. I am currently working on a coding problem that involves printing all prime ...
Score of 2
1 answer
271 views
Can Prolog-like unification be expressed in a point free way?
Pattern matching can be implemented using a point free style, and there are many articles on the internet about it. I'm wondering if the more generalized case also holds, i.e. is it possible to ...
Score of 5
1 answer
187 views
How to unbox a list of boxed lists of differing lengths in J?
Given the following list of boxed lists of differing lengths…
┌──────────────┬───────────┬─────┬───┐
│0 2 3 4 7 9 11│9 7 4 3 2 1│1 2 3│3 1│
└──────────────┴───────────┴─────┴───┘
How can I create a ...