This is a demo solution for exercise 10.1-1 of the famous CLRS’s Introduction to Algorithms, 3rd Edition book.
Here’re two powerset function implemented in Python and Haskell.
import copy
def powerset(s):
if s == []:
return [[]]
elif len(s) == 1:
return [[], s]
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 unittest | |
def binary_search(array, t): | |
l = 0 | |
h = len(array) - 1 | |
while (l <= h): | |
m = (l + h) // 2 | |
if (array[m] == t): | |
return m |
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
%% socket examples from Joe Armstrong's "Programming Erlang, Second Edition". | |
-module(socket_examples). | |
-compile(export_all). | |
-import(lists, [reverse/1]). | |
string2value(Str) -> | |
{ok, Tokens, _} = erl_scan:string(Str ++ "."), | |
{ok, Exprs} = erl_parse:parse_exprs(Tokens), | |
Bindings = erl_eval:new_bindings(), | |
{value, Value, _} = erl_eval:exprs(Exprs, Bindings), |
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
%% udp test client and server, from joe armstrong's "programming erlang, second | |
%% edition" | |
-module(udp_test). | |
-export([start_server/0, client/1]). | |
start_server() -> | |
spawn(fun() -> server(4000) end). | |
%% the server | |
server(port) -> |
This gist and its comments contains some topics for technology section of data weekly
OlderNewer