Skip to content

Instantly share code, notes, and snippets.

$$\binom{n}{k} = \frac{n!}{k! (n-k)!}$$

$$\binom{50}{5} = 2 \space 118 \space 760 \space \space \space \& \space \space \space \binom{12}{6} = 66$$

$$\binom{50}{5} \times \binom{12}{6} = 139 \space 838 \space 160$$

CREATE OR REPLACE TEMP TABLE AVERAGE_RATINGS_BY_YEAR_GENRE AS
WITH T1 AS ( -- T1 -> Common Table Expression (CTE)
SELECT r.rating, r.year, unnest(f.genres) AS genre
FROM Films f JOIN Ratings r ON (r.film_id = f.film_id)
)
SELECT year, genre, avg(rating) AS average_rating
FROM T1
GROUP BY year, genre
ORDER BY year DESC, genre
from mistralai import Mistral
client = Mistral(api_key=MISTRAL_API_KEY)
model_instructions = "..."
# for chunk in ...
def with_synchronous_streaming(user_prompt: str):
messages = [
{

Irrationality of Square Roots of Prime Numbers

We all remember from our fundamental mathematics classes the emphasis on the irrationality of $\sqrt{2}$ using a simple proof by contradiction.

Well, it turns out that we can extend this theorem more broadly to the square roots of prime numbers with the same kind of demonstration, and that's what we're going to demonstrate here in this article. But first, let's have some reminders about what prime numbers are.

Let $p$ be a natural number, we say that $p$ is prime if and only if $p$ is different from 1 and it has only 1 and itself as divisors. Let's denote this set of prime numbers as $\mathbb{P}$.

$$\forall p \in \mathbb{N}, \ p \in \mathbb{P} \iff \begin{cases} p \neq 1 \newline \nexists(a, b) \in \mathbb{N}^2/ \ a \neq 1 \And b \neq p \ \Longrightarrow \ p = ab \end{cases}$$

// @lib/utils.ts
import { twMerge } from 'tailwind-merge'
import { clsx, ClassValue } from 'clsx'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
const sleep = async (ms) => {
await new Promise(resolve => {
setTimeout(() => resolve(0), ms)
})
}
await sleep(2000)
const findSmallestInterval = (numbers) => {
numbers.sort((a, b) => a - b)
let r = Number.MAX_SAFE_INTEGER
numbers.forEach((e, i) => {
if (i + 1 > numbers.length)
return
const d = Math.abs(e - numbers[i + 1])
const arrayCalculation = (specialArray, depth = 1) => {
const r = []
specialArray.forEach((e) => {
if (Number.isInteger(e))
r.push(e)
if (Array.isArray(e))
r.push(arrayCalculation(e, depth + 1))
})
return depth * r.reduce((acc, cv) => acc + cv, 0)
const flattenDepth = (arr, depth = 1) =>
arr.reduce(
(acc, cv) => [
...acc,
...(depth === 0 || !Array.isArray(cv)
? [cv]
: flattenDepth(cv, depth - 1))
],
[]
);
@ahafidi
ahafidi / zip.js
Last active September 27, 2021 12:41
some zip implementations
const zip = (...rows) =>
rows[0].map((_, i) => rows.map((row) => row[i]))
const zip2 = (arr, ...arrs) =>
arr.map((val, i) => arrs.reduce((acc, cv) => [...acc, cv[i]], [val]))
const zip3 = (...arrs) => {
let r = []
for (let i = 0; i < arrs.length; i++) {