This file contains 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
sem task_chosen[0..49] = ([50] 0) | |
sem able_to_work[0..49] = ([50] 0) | |
sem notify_completion[0..9] = ([10] 1) // Mutex array for notifying each shared task was finished by a single student. | |
sem grade_mutex = 1 | |
sem some_task_was_finished = 0 | |
task tasks[0..9] = ([10] generate_task()) | |
int students_that_finished[0..9] = ([10] 0) // Amount of students that finished working on each task. | |
int grade[0..9] // Puntaje. Es el orden en el que cada equipo 0..9 terminó de trabajar en su tarea. | |
int finished_task // Sólo la declaro. No la inicializo porque su valor inicial no importa. |
This file contains 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
assignment assignments[40] = ([40] nil) // Inicializa las tareas en nulo. | |
error_report corrections[40] = ([40] nil) // Inicializa las correcciones en nulo. | |
boolean has_left[40] = ([40] false) // Indica si el alumno se ha ido. | |
boolean doing_assignment[40] = ([40] false) // Indica si el alumno i esta ocupado haciendo tarea. | |
sem can_do_assignment[40] = ([40] 0) | |
sem can_see_correction[40] = ([40] 0) | |
sem can_check_assignment = 0 // Alumnos esperando corrección | |
This file contains 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
queue resource_queue[5] = [r1, r2, r3, r4, r5] | |
sem resources = 5 | |
sem queue_mutex = 1 | |
process Consumer { | |
p(resources) | |
p(queue_mutex) | |
resource my_resource = pop(resource_queue) | |
v(queue_mutex) | |
This file contains 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
sem free_detectors = 3 // Cantidad de detectores libres a cada instante | |
sem allocation = 1 // Limita la cantidad de personas que buscan ascensor al mismo tiempo | |
// Declara un arreglo de 0 a n-1 de booleans inicializados como false en todas sus posiciones. | |
// Representa los detectores valiendo para cada uno true si está ocupado o false si está libre. | |
boolean detector_taken[0:n-1] = ([n] false) | |
process Person[w = 1 to 100] { | |
p(free_detectors) | |
This file contains 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
// Declara 2 arreglos de 0 a n-1 de booleans inicializados como false en todas sus posiciones. | |
boolean permissions[0:n-1] = ([n] false) | |
boolean requesters[0:n-1] = ([n] false) | |
process Coordinator { | |
while true { | |
int i = 0 | |
while !requesters[i] { // Barre repetidamente el arreglo buscando un proceso que esté pidiendo entrar a su sección crítica. | |
i = (i + 1) MOD n | |
} |
This file contains 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
class Pie | |
def make | |
add_main_ingredient | |
add_secondary_ingredients | |
cook | |
add_toppings | |
let_cool | |
end | |
def add_ingredient(ingredient) |
This file contains 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
require 'benchmark' | |
executions = 100_000_000 | |
Benchmark.bm do |conditional_assignment| | |
conditional_assignment.report { executions.times do a ||= 1; end } | |
conditional_assignment.report { executions.times do a = a || 1; end } | |
end | |
=begin |
This file contains 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
# TODO: Cómo hago que funcione con métodos que reciben parámetros? | |
# Referencia: http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/ | |
module Countable | |
module ClassMethods | |
def count_invocations_of(sym) | |
alias_method "original_#{sym}".to_sym, sym | |
define_method(sym) do | |
start_counter |
This file contains 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
VALUE = 'global' | |
module A | |
VALUE = 'A' | |
class B | |
VALUE = 'B' | |
def self.value | |
VALUE |
This file contains 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
class Parcial { | |
public ListaGenerica<Vertice<T>> maxBottleneckPath(Grafo<T> g) { | |
ListaGenerica<ListaGenerica<Vertice<T>>> caminos = new ListaGenerica<ListaGenerica<Vertice<T>>>(); | |
boolean[] visitados; | |
agregarCaminos(g, indice_s, indice_t, visitados, caminos); | |
return selectMaxBottleneckPath(caminos) | |
} | |
public selectMaxBottleneckPath(paths) { //comparar los pesos de las aristas con menor peso de cada camino |