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 / solucio.hs
Created December 5, 2017 21:48
Examen parcial Haskell 2017-12-04
-- ------------------------------------------------
-- Apartat 1
-- ------------------------------------------------
eval1 :: String -> Int
eval1 e = eval' [] $ words e
where
eval' :: [Int] -> [String] -> Int
eval' [x] [] = x
@jordi-petit
jordi-petit / p1.cc
Last active April 26, 2018 07:31
2017-12-05 Generació combinatòria
// Genera totes les combinacions de vectors de n booleans.
#include <iostream>
#include <vector>
using namespace std;
void escriu(const vector<bool>& v) {
for (bool b : v) cout << b;
cout << endl;
@jordi-petit
jordi-petit / p1.py
Last active April 26, 2018 07:31
2017-12-15 Vectors en Python
# Ordenació per fusió (merge sort)
from jutge import read
from random import random
# random genera un nombre real a l'atzar entre 0 i 1
def merge(v1, v2):
"""Retorna la fusió de dos vectors ordenats."""
@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
@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 . . . . .
#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]) {
#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;
@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>
#include <queue>
#include <utility>
#include <map>
using namespace std;
const int infinit = 999999999;
@jordi-petit
jordi-petit / download.py
Last active September 4, 2018 13:51
Download bicing info
#!/usr/bin/env python3