- Aggregated Pivot Table
- Bit Shifting
- Bitwise XOR
- Calculate Tick Size
- Collapsing Dictionaries
- Graphs - Breadth First Search
- Graphs - Depth First Search
- Graphs - Detecting Cycles
- Greatest Common Divisor
- Identity Matrix
- Least Common Multiple
- Log Parser
- Nanosleep
- One Hot Encoding
- Parent Child ID Mapping
- Slippage
- Split Training and Testing Sets
- Stratified Sampling
- Symbol Column Update
- Table Indexing
- Word Count
Least Common Multiple
Question: Define a function 'lcm' that returns the least common multiple of two integers, as an integer.
More Information:
https://en.wikipedia.org/wiki/Least_common_multipleExample
q)lcm[12;80]
240
q)lcm[12;13]
156
q)lcm[12;12]
12
Solution
######## solution.q ########
gcd:{$[y=0;x;.z.s[y;x mod y]]}
lcm:{div[x*y] gcd[x;y]}
Explanation: The least common multiple of two numbers is their product divided by their greatest common divisor. Use 'div' instead of '%' to return an integer.