## ~jshholland/trybqn

trybqn/2014.bqn -rw-r--r-- 2.5 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
54```
```# Write a dfn that takes the length of the legs of a triangle as its
# left argument, and the length of the hypotenuse as its right argument
# and returns 1 if the triangle is a right triangle, 0 otherwise.
Prob1 ⇐ =○(+´×˜∘⥊)

# Write a dfn which takes a character vector and removes the interior
# vowels from each word.
vowels ← "AEIOUaeiou"
Prob2 ⇐ (¬∘∊⟜vowels ∨ ·¬·(«∧»)' '⊸≠)⊸/

# Write a dfn that takes an integer right argument and returns that
# number of terms in the Fibonacci sequence.
Prob3 ⇐ {{𝕩 ∾ +´ ¯2↑1‿0∾𝕩}⍟𝕩 ⟨⟩}

# Write a dfn that removes extraneous (leading, trailing, and multiple)
# spaces from a character vector.
Prob4 ⇐ ¬∘(∧` ∨ ∧`⌾⌽ ∨ «⊸∧) ∘ =⟜' '⊸/

# A palindrome is a word or phrase whose letters read the same forwards
# and backwards. Write a dfn which returns a 1 if its character vector
# argument is a palindrome, 0 otherwise. For simplicity’s sake, you
# may assume that the vector is all one case.
letters ← ∾˝"Aa"+⌜↕26
Prob5 ⇐ ⌽⊸≡ ∊⟜letters⊸/

# Write a dfn that takes an integer vector representing the sides of
# a number of dice and returns a 2 column matrix of the number of ways
# each possible total of the dice can be rolled.
Prob6 ⇐ >·(⊑≍≠)¨·⊐⊸⊔·⥊⟨0⟩+⌜´1+↕¨

# Imagine there are two circles that are tangent to one another. One
# circle is stationary, the other can “roll” around the stationary
# circle.  Write a dfn which takes the diameters of the stationary and
# mobile circles and returns the number of revolutions the mobile must
# traverse until the tangent points meet again.
# solution is lcm(𝕨,𝕩)÷𝕩 = 𝕨÷gcd(𝕨,𝕩)
Prob7 ⇐ ⊣÷{𝕨(|𝕊⍟(>⟜0)⊣)𝕩}

# Write a dfn that returns the distance between two points in a space
# of any number of dimensions.
Prob8 ⇐ +´⌾(×˜)-○⥊

# The following formula gives the horizontal distance a projectile
# travels [...]:  Where: v is the initial velocity, θ is the trajectory in
# degrees, d is the horizontal distance and G is the gravitational
# constant.  Write a dfn which calculates the distance (in meters)
# a projectile travels given an initial velocity in meters per second
# and a trajectory in degrees. Use 9.8 meters per second squared as the
# gravitational constant.
Prob9 ⇐ {9.8÷˜ (𝕨⋆2) × •math.Sin π×𝕩÷90}

# Given a vector representing monthly sales figures, write a dfn that
# returns the greatest percent month to month increase.
Prob10 ⇐ 100×·⌈´·(-˜´÷⊑)˘2⊸↕
```