3 ms·
Since J allow you to write short code, here are three example in J. The first use iota1000, the second a random permutation, and the third use matrix notation
by iotasilly 1y ago
Since J allow you to write short code, here are three example in J. The first use iota1000, the second a random permutation, and the third use matrix notation to create a little guessing game.
Example 1: Find the missing number
xor =: (16 + 2b0110) b.
iota1000 =: (i. 1000)
missingNumber =: (xor/ iota1000) xor (xor/ iota1000 -. 129)
echo 'The missing number is ' , ": missingNumber
This print 'The missing number is 129'
Example 2: Using a random permutation, find the missing number.
permuted =: (1000 ? 1000)
missingNumber = (xor/ permuted) xor (xor/ permuted -. ? 1000)
Example 3: find the missing number in this matrix.
_ (< 2 2) } 5 5 $ (25 ? 25)
12 9 1 20 19
6 18 3 4 8
24 7 _ 15 23
11 21 10 2 5
0 16 17 22 14
Final test: repeat 10 times the example 3 (random matrices) and collect the time it takes you to solve it in a list of times, then compute the linear regression best fit by
times %. (1 ,. i. 10)
Did you get better at solving it by playing more times?
I am not affiliated with J, but in case you want to try some J code there is a playground: https://jsoftware.github.io/j-playground/bin/html2/ https://jsoftware.github.io/j-playground/bin/html2/
Edited: It seems I am procrastinating a lot about something I have to do but don't want to.
- Pompidou 1y agothe top comment trick [ n, 1, n + 1, 0 ][n % 4] can be implemented in J as following : f =: ]`1:`>:`0:@.(4&|)"0 Then: (,. ; #: ; [: #: f) i.16 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 2 0 0 1 0 0 0 1 1 3 0 0 1 1 0 0 0 0 4 0 1 0 0 0 1 0 0 5 0 1 0 1 0 0 0 1 6 0 1 1 0 0 1 1 1 7 0 1 1 1 0 0 0 0 8 1 0 0 0 1 0 0 0 9 1 0 0 1 0 0 0 1 ....
- betasilly 1y agoHello fellow J programmer. In statistic you can estimate the population size by coloring fishes that you put in a lake and some time later you fish in that lake, the proportion of colored fishes allow you to estimate the size of the population. Four month ago I posted some J identities [1] and you were the only one which commented, that means that in this capture I only got one fish and it was the colored fish. This imply that there must be very few J programmers HN, or more precisely, very few of them that post J related material. The parent's comment (also mine) has a style that was designed not to scare non J programmers. One should also consider that some people dislike J code so downvotes are the usual result except when the post provides some additional insight. Finally, thank you for this small J lesson, is a pleasure to find here fellow J programmers. [1] https://news.ycombinator.com/item?id=42859077 https://news.ycombinator.com/item?id=42859077