Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Last active March 24, 2016 13:24
Show Gist options
  • Select an option

  • Save lovasoa/9e14b9b2bd985af25f7d to your computer and use it in GitHub Desktop.

Select an option

Save lovasoa/9e14b9b2bd985af25f7d to your computer and use it in GitHub Desktop.
Énigme pour Alexis. Que fait ce script ?
#!/usr/bin/env python3
import sqlite3
conn = sqlite3.connect(":memory:");
cur = conn.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS nums(n INTEGER PRIMARY KEY)");
cur.executemany("INSERT INTO nums VALUES (?)", ((i,) for i in range(1,1000)));
cur.execute("DELETE FROM nums WHERE (SELECT COUNT(n2.n)>2 FROM nums AS n2 WHERE nums.n%n2.n=0)");
for (n,) in cur.execute("SELECT * FROM nums"): print(n, end=' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment