This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ------------------------------------------------ | |
-- Apartat 1 | |
-- ------------------------------------------------ | |
eval1 :: String -> Int | |
eval1 e = eval' [] $ words e | |
where | |
eval' :: [Int] -> [String] -> Int | |
eval' [x] [] = x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. . . . . 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 . . . . . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <queue> | |
#include <utility> | |
#include <map> | |
using namespace std; | |
const int infinit = 999999999; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |