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
-- Joc de pedra paper o tisora | |
data Jugada = Pedra | Paper | Tisora | |
guanya :: Jugada -> Jugada -> Bool | |
Pedra `guanya` Tisora = True | |
Tisora `guanya` Paper = True | |
Paper `guanya` Pedra = True | |
_ `guanya` _ = False |
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() { |
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 <algorithm> | |
using namespace std; | |
void ordernacio_per_insercio(vector<double>& v) { | |
int n = v.size(); | |
for (int i = 1; i < n; ++i) { | |
for (int j = i; j > 0 and v[j - 1] > v[j]; --j) { | |
swap(v[j - 1], v[j]); |
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() { |
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
-- 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 <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
// 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
// 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); |