Skip to content

Instantly share code, notes, and snippets.

View jordi-petit's full-sized avatar

Jordi Petit jordi-petit

View GitHub Profile
@jordi-petit
jordi-petit / tipus.md
Created March 9, 2022 10:20
Guió tipus en Python per AP2

Guió tipus en Python per AP2

Intro

  • Python té un sistema de tipus dinàmic.
  • El tipus d'una variable depèn del seu valor en aquell moment.
  • En programes grans, això incrementa els bugs i complica el seu manteniment.
  • Des de fa un temps, els programes en Python es poden anotar amb tipus, de forma semblant al C++.
  • Aquestes anotacions no tenen cap efecte en temps d'execució.
  • Però hi ha eines que poden comprovar que no hi hagi errors de tipus (igual que fa el compilador de C++).
@jordi-petit
jordi-petit / p1.hs
Created November 4, 2019 11:16
Solució parcial LP de Haskell 2019-11-04
-- string to int conversion
s2i :: String -> Int
s2i = read
add :: String -> String
add = show . sum . (map s2i) . words
main = do
contents <- getContents
putStrLn $ add contents
#!/usr/bin/env python3
@jordi-petit
jordi-petit / download.py
Last active September 4, 2018 13:51
Download bicing info
#!/usr/bin/env python3
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <map>
using namespace std;
const int infinit = 999999999;
@jordi-petit
jordi-petit / P56483.py
Created May 10, 2018 18:17
AP2 2018-05-10
from jutge import read
def dfs(G, u, y, vis):
if not vis[u]:
vis[u] = True
for v in G[u]:
if vis[y]:
return
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
void dfs (const Graph& G, int u, int y, vector<bool>& vis) {
vis[u] = true;
#include <iostream>
#include <vector>
using namespace std;
using Graf = vector<vector<int>>; // llistes d'adjacència
void dfs(const Graf& G, int u, int y, vector<bool>& vis) {
if (not vis[u]) {
@jordi-petit
jordi-petit / 1.txt
Created January 15, 2018 08:31
Sudoku
. . . . . 2 3 . 7
. . . . . 6 4 5 .
1 . . 9 3 . . . .
. . . . 6 1 8 . .
. 4 8 . . . 5 6 .
. . 6 4 2 . . . .
. . . . 7 5 . . 8
. 2 9 1 . . . . .
4 . 5 6 . . . . .
@jordi-petit
jordi-petit / p1.py
Last active April 26, 2018 07:32
2017-12-19 Exponenciació ràpida
# retorna x^n, amb n natural
def exp(x, n):
if n == 0:
return 1
else:
return x * exp(x, n - 1)
# retorna x^n, amb n natural