<a class="skip-link" aria-label="Skip to main content" href="#main">Skip to main content</a>
.skip-link {
width: 1px;
height: 1px;
overflow: hidden;
display: block;
mod a { | |
// pub fn foo() { println!("a::foo()"); } // Uncomment this line to see interception. | |
pub fn bar() { println!("a::bar()"); } | |
} | |
fn foo() { println!("foo()"); } | |
fn greet() { use a::*; foo(); bar(); } | |
<a class="skip-link" aria-label="Skip to main content" href="#main">Skip to main content</a>
.skip-link {
width: 1px;
height: 1px;
overflow: hidden;
display: block;
def subset_sum(elements, target): | |
""" | |
Determine if a subset of ELEMENTS sum exactly to TARGET. | |
We assume that ELEMENTS contain only non-negative numbers. The program can | |
be modified to accomodate negative numbers in ELEMENTS using a table that | |
has rows for -W to TARGET where -W is the smallest possible sum from ELEMENTS. | |
""" | |
if not elements: | |
return target == 0 |
# We represent the original network using a dictionary that maps edges into | |
# capacities. A residual graph maps edges into its weight and whether or not | |
# it is a forward edge. | |
# | |
# We assume that the source is 0 and sink is n-1 where n = #vertices. | |
def empty_graph(nvertices): | |
return [nvertices, dict()] | |
def nvertices(network): |
maplist
that takes a function and a list and returns a list of values obtained by applying the given function to each element in the list.def square(x): return x*x
def cube(x): return x*x*x
assert maplist(square, [1, 2, 3, 4]) == [1, 4, 9, 16]
assert maplist(cube, [1, 2, 3, 4]) == [1, 8, 27, 64]
intersecting
that takes as input a list of sets and a set and returns True
iff the given set has at least one common element with each set in the list.assert intersecting([{1, 2}, {3, 4}], {2, 3})
assert not intersecting([{1, 2}, {3, 4}], {1, 2})
If your program needs to define a new kind of values, use a class. Follow the below steps to define a class.
__init__
function that initializes the components of the type appropriately from the arguments. This may involve complex logic.To write functions that operate on your new type, follow the same instructions as for tuples. Instead of unpacking, you may use .
to access the components.
Use the following guidelines to manipulate lists.
for x in xs:
to process each element of the input sequence xs
in turn.x
appropriately.x
into the output list.