## ~jshholland/trybqn

trybqn/2016.bqn -rw-r--r-- 2.3 KiB
4e81c000Josh Holland use new ⋈ builtin 5 months ago
`                                                                                `
```1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53```
```# Write a function that takes a numeric array as its right argument and
# returns the mean (average) of the array.
Prob1 ⇐ +˝÷1⌈≠

# Write a function that takes a numeric vector as its right argument
# and returns the median of the array.
Prob2 ⇐ (+´÷≠) ∧⊏˜·(⌊≍⌈)2÷˜1-˜≠

# Write a function that takes a numeric vector or scalar as its right
# argument and returns the mode (that is, the most common value) of the
# array. If more than one number occurs the greatest number of times,
# return all such numbers.
Prob3 ⇐ ⊑¨·((⊢=⌈´)≠¨)⊸/⊐⊸⊔

# Write a function that takes vectors as its left and right arguments and
# returns them “meshed” into a single vector formed by alternately
# taking successive elements from each argument. The arguments do not
# have to be the same length.
# Prob4 ⇐ ⥊⍉∘≍ # works for same length only
Prob4 ⇐ ∾○(↕≠)⍋⊸⊏∾

# Write a function that takes a vector as its right argument and returns
# elements that occur only once in the vector.
Prob5 ⇐ (∊∧∊⌾⌽)⊸/

# Write a function that takes a vector of vectors as its right argument
# and returns it sorted by the length of each element. An element of
# the vector can be scalar or an empty vector.
Prob6 ⇐ (⍋≠¨)⊸⊏

# Write a function that takes a numeric vector and returns all elements
# that are divisible by 3 or 5.
Prob7 ⇐ (0⊸∊3‿5⊸|)˘⊸/

# Write a function that takes a numeric vector and returns a two element
# vector whose first element contains the values less than 0 (zero) in
# the vector and the second element contains all values greater than or
# equal to 0.
Prob8 ⇐ (≥⟜0∾2˙)⊸⊔

# Write a function that takes a character vector as its right argument
# and one or more characters as its left argument, where those characters
# are delimiters in the right argument. The function should return the
# delimited text as a vector of vectors.
Prob9 ⇐ (⊢-˜¬×+`)∘=⊔⊢

# Suppose you have a numeric vector that is the list of prices for a
# set of retail products. You also have a numeric vector that is the
# number ordered of each product. Write a function that takes as its
# right argument a vector of prices and as its left argument a numeric
# vector that indicates the number ordered and returns the total cost
# for the order.
Prob10 ⇐ +˝∘×⎉1‿∞
```