Tutorials/Functions/Solutions

From Kx Wiki
Jump to: navigation, search

1. You can pass in your inputs with or without square brackets:

q)f[10] % f[6] * f[4]
210f
q)(f 10) % (f 6) * f 4
210f

Defining a function to calculate the binomial coefficient:

q)binom:{[n;k] f[n] % f[k] * f[n-k]}

2. What function did you write? Here's one that tells the time.

q)time:{"the time is ", 5# string .z.T}
q)time[]
"the time is 10:46"

3. There are many possible solutions to this. Some examples:

q)evens:{2 * 1 + til x div 2}
q)evens:{b:1+til x; b where 0=b mod 2}

Back to Tutorials

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export
Toolbox