from jutge import read
def zeros_o_uns(n):
z = 0 # nombre de zeros
u = 0 # nombre de uns
while n != 0:
if n % 2 == 1:
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
// 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
-- ------------------------------------------------ | |
-- 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
// Programa per trobar tots els primers entre 0 i n. | |
// Implementació amb n+1 crides a es_primer() | |
#include <iostream> | |
#include <vector> | |
#include <ctime> | |
using namespace std; | |
double now() { | |
return clock() / double(CLOCKS_PER_SEC); |
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
// Gestor d'àlbums de cançons en un reproductor MP3. | |
// Com el de la classe anterior, però ordenant les cançons | |
// usant diferents criteris. | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; |
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 <string> | |
#include <vector> | |
using namespace std; | |
struct CancoMP3 { | |
string artista; | |
string titol; | |
int estrelletes; // de 0 a 5 |
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
-- 1.1 | |
shuffleOnce :: [a] -> [a] | |
shuffleOnce xs = ys' | |
where | |
n = length xs | |
(l1, l2) = splitAt (n `div` 2) xs | |
ys = concat $ zipWith pair l2 l1 | |
pair a b = [a, b] | |
ys' |
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 Fila = vector<double>; | |
using Matriu = vector<Fila>; | |
void escriu(const Matriu& a) { | |
int m = a.size(); // nb files |
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 <algorithm> | |
#include <cstdlib> | |
#include <ctime> | |
#include <cassert> | |
using namespace std; | |
double now() { |