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
"""Simple TCP server for playing Tic-Tac-Toe game. | |
Use Player-to-Player game mode based on naming auth. | |
No thoughts about distribution or pub/sub mode | |
(for monitoring or something like this). Just | |
basic functionality. | |
""" | |
import time | |
import logging |
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
(def open-for-business? (atom true)) | |
(def haircut-count (agent 0)) | |
(def waiting-room (ref [])) | |
(def waiting-room-size 3) | |
(defn open-shop [duration] | |
(do (Thread/sleep duration) (swap! open-for-business? not))) | |
(defn add-customers [] | |
(future |
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
-module(barber). | |
-export([run/2, barber/1, clients/1, simulator/2]). | |
-define(CUT_DUTAION, 20). | |
run(RoomSize, Duration) -> | |
% create barber | |
BPid = spawn(?MODULE, barber, [?CUT_DUTAION]), | |
% run simulartor with barber PID | |
SPid = spawn(?MODULE, simulator, [BPid, RoomSize]), |
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
package main | |
import ( | |
"fmt" | |
"time" | |
"math/rand" | |
) | |
const ( | |
CUTTING_TIME = 20 |
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
import scala.actors.Actor | |
import scala.actors.Actor._ | |
case object Ping | |
case object Pong | |
case object Stop | |
class Ping(count: Int, pong: Actor) extends Actor { | |
def act() { | |
var pingsLeft = count - 1 |
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
%% | |
%% Solve sleeping barber problem in most general case | |
%% Task description on Wikipedia: | |
%% http://en.wikipedia.org/wiki/Sleeping_barber_problem | |
%% | |
%% Additions to classic variant: | |
%% * many barbers | |
%% * many clients generators with random timeouts between clients | |
%% * calculation for total served clients | |
%% * random time for each client to make barber's job |
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
%% | |
%% Solve sleeping barber problem in most general case | |
%% Task description on Wikipedia: | |
%% http://en.wikipedia.org/wiki/Sleeping_barber_problem | |
%% | |
%% Additions to classic variant: | |
%% * many barbers | |
%% * many clients generators with random timeouts between clients | |
%% * calculation for total served clients | |
%% * random time for each client to make barber's job |
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
%% | |
%% Solve sleeping barber problem in most general case | |
%% Task description on Wikipedia: | |
%% http://en.wikipedia.org/wiki/Sleeping_barber_problem | |
%% | |
%% Additions to classic variant: | |
%% * many barbers | |
%% * many clients generators with random timeouts between clients | |
%% * calculation for total served clients | |
%% * random time for each client to make barber's job |
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
import Data.List | |
uniqSubstr :: String -> Int | |
uniqSubstr = sum . (map pair) . pairwise . sort . tails | |
where | |
pairwise l@(_:ht) = zip l ht | |
prefix pre post = length $ takeWhile (uncurry (==)) $ zip pre post | |
pair (pre, post) = length $ drop (prefix pre post) post |
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
-module(channels). | |
-compile(export_all). | |
make() -> | |
Ref = make_ref(), | |
Pid = spawn(?MODULE, channel, [Ref]), | |
{channel, Pid, Ref}. | |
channel(Ref) -> | |
receive |
OlderNewer