439 questions
2
votes
1
answer
115
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 ...
3
votes
2
answers
164
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 ...
2
votes
2
answers
154
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:
|...
3
votes
2
answers
116
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 ...
1
vote
1
answer
153
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 ...
3
votes
2
answers
105
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 ...
5
votes
1
answer
181
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 ...
1
vote
3
answers
262
views
Print char of string uppercase if it is a vowel and lowercase if it is a consonant
I am trying to come up with a verb that will take a string as input
and printa character uppercase if it is a vowel i.e. (aeiou) or lowercase
if it is a consonant.
s=:'authority'
t=:<&>s
│a│...
0
votes
1
answer
117
views
How can I fix 'noun result was required' error in J?
I'm trying to do the 4th Advent of Code problem using J, and I've ran into lots of problems, but now I have a code that looks like this:
fn =. < 'D:/PyCharm/AOC/output4.txt'
data =. freads fn
...
2
votes
1
answer
224
views
Convert boxed array to normal array?
Suppose I have a boxed array like;
┌─┬─┬─┐
│1│2│3│
└─┴─┴─┘
how do I covert it to a normal array such as 1 2 3?
2
votes
1
answer
94
views
Replace atom in array of strings
Suppose I have an array of strings "31,793.1" "29,798.6" "30,455.7" "29,700.9"
How do I replace , with nothing to give me "31793.1" "29798.6"...
6
votes
2
answers
245
views
What is the "j" expression for the "maximum consecutive ones" problem?
In the paper "Combinatory Logic and Combinators in Array Languages" they give a solution in APL:
vec ← 1 1 0 1 1 1 0 0 0 1
⍝ split (partition) on zeroes
⊆⍨vec
┌───┬─────┬─┐
...
2
votes
1
answer
118
views
What does the dyad `=` do to boxed strings?
If x were a boxed string, I expect x=<'ABC' to compare the >x to 'ABC' to see if they are equal, but the following example shows that this is not the case. The J vocabulary document doesn't say ...
3
votes
1
answer
142
views
In j, how can I define a verb locally in one scope and pass it to a defined adverb?
I am getting an unexpected value error when I use a name to pass a verb as the argument to an adverb.
The adverb (integer binary search with predicate u and bounds x):
bsearch=: adverb define
r=. y ...
1
vote
1
answer
160
views
How to turn a table or matrix into a (flat) list in J
I know how to reshape a list into a table. But how do I turn a table into a list or uni- dimensional array.
my_list=:3 4 $i.12
0 1 2 3
4 5 6 7
8 9 10 11
And is it better to perform operations on ...
3
votes
2
answers
133
views
How to define selection using index function in J
Let's assume I have a following tensor t:
]m=: 100 + 4 4 $ i.16
100 101 102 103
104 105 106 107
108 109 110 111
112 113 114 115
]t=: (m ,: m+100) , m+200
100 101 102 103
104 105 106 107
108 109 ...
3
votes
1
answer
185
views
Find 4-neighbors using J
I'm trying to find the 4-neighbors of all 1's in a matrix of 0's and 1's using the J programming language. I have a method worked out, but am trying to find a method that is more compact.
To ...
2
votes
0
answers
116
views
where does j save the result of its last operation?
In python's repl, _ holds the value of the last operation.
Where is the value of the last operation saved in the j repl?
2
votes
1
answer
108
views
How to use arbitrary selector in interchange in J lang?
Let's assume we have a vector and matrix like below:
r =: 100 + 5 5 $ i.25
r
100 101 102 103 104
105 106 107 108 109
110 111 112 113 114
115 116 117 118 119
120 121 122 123 124
v =: 100 + 5 $...
3
votes
2
answers
119
views
different result once square root is added inside tacit
Very new to J. I love it but still far from fluent in it.
I have managed to hit an issue and I don't know why it is happening. If somebody could please explain why this is occuring I could learn more ...
3
votes
1
answer
146
views
Need help parsing the meaning of "i.~"
I'm trying to understand the solution for day 1 part 2: https://code.jsoftware.com/wiki/Essays/Advent_Of_Code#Part_2
PART2=: >: _1 i.~ +/\ 1 _1 mp '()'=/read'input'
I feel like I understand most ...
2
votes
1
answer
104
views
amend a subarray in place in j?
I've got two ways to amend a subarray in J but I don't like either of them.
(Imagine selecting a rectangle in a paint program and applying some arbitrary
operation to that rectangle in place.)
t =. ...
4
votes
4
answers
124
views
Get whole result when using J console
When using J console ijconsole I get only results up to some. For example,
ijconsole -js "a=. 3 3 5 6 " "echo 200 $ a" "exit''"
3 3 5 6 3 3 5 6 3 3 5 6 3 3 5 6 3 3 5 6 ...
4
votes
3
answers
1k
views
Write 4 : 'x&{.&.;: y' tacitly
Conor Hoekstra recently solved a Leetcode problem in APL https://youtu.be/QtvvQ7MdwKY The problem is to take the first x words from a character string y
In J, using &. (Under) and ;: (Words) I can ...
3
votes
1
answer
91
views
Amend with multiple indices per substitution in J
In J, how do you idiomatically amend an array when you have:
substitution0 multipleIndices0
...
substitutionN multipleIndicesN
(not to be confused with:
substitution0 multipartIndex0
...
...