Based on http://stackoverflow.com/questions/9591561/java-cartesian-product-of-a-list-of-lists
550859
private DataContainer crossJoin(DataContainer left, DataContainer right, Optional<BooleanExpression> joinCondition, JoinType joinType) {
        final List<DataRow> leftRows = left.getRows();
        final List<DataRow> rightRows = right.getRows();
        final Set<Integer> matchedIndexes = new HashSet<>();

        boolean isLeftJoin = joinType == JoinType.LEFT;
        boolean isRightJoin = joinType == JoinType.RIGHT;
        int leftColumnsCount = left.getColumnNames().size();
        int rightColumnsCount = right.getColumnNames().size();

        DataContainer dataContainer = mergeContainerColumns(left, right);
        crossProduct(leftRows, rightRows, DataRow::getValues, (indexesPair, newRowValues) -> {
            DataRow dataRow = new DataRow(dataContainer, newRowValues);
            if (!joinCondition.isPresent() || expressionEvaluator.evaluateAs(joinCondition.get(), dataRow, Boolean.class)) {
                dataContainer.addRow(dataRow);
                if (isLeftJoin) {
                    matchedIndexes.add(indexesPair.getFirst());
                }
                if (isRightJoin) {
                    matchedIndexes.add(indexesPair.getSecond());
                }
            }
        });

        if (isLeftJoin || isRightJoin) {
            int rowsCount = isLeftJoin ? leftRows.size() : rightRows.size();
            for (int i = 0; i <= rowsCount - 1; i++) {
                if (!matchedIndexes.contains(i)) {
                    DataRow rowWithNulls = new DataRow(
                            dataContainer,
                            rowWithNullsValues(leftRows, leftColumnsCount, rightRows, rightColumnsCount, i, isLeftJoin)
                    );
                    dataContainer.addRow(rowWithNulls);
                }
            }
        }
        return dataContainer;
    }
398373
static Turn[] turns(Point2d[] points) {

        final Turn[] turns = new Turn[points.length];

        // cycle of size 6 is [1,2,3,4,5,6] not closed
        for (int i = 1; i <= points.length; i++) {
            Point2d prevXy = points[i - 1];
            Point2d currXy = points[i % points.length];
            Point2d nextXy = points[(i + 1) % points.length];
            int parity = (int) Math.signum(det(prevXy.x, prevXy.y,
                                               currXy.x, currXy.y,
                                               nextXy.x, nextXy.y));
            if (parity == 0) return null;
            turns[i % points.length] = parity < 0 ? Right : Turn.Left;
        }

        return turns;
    }
335657
def post_order(parent):
    
    n = len(parent)
    k = 0

    p = matrix(0,(n,1))
    head = matrix(-1,(n,1))
    next = matrix(0,(n,1))
    stack = matrix(0,(n,1))

    for j in range(n-1,-1,-1):
        if (parent[j] == j): continue
        next[j] = head[parent[j]]
        head[parent[j]] = j

    for j in range(n):
        if (parent[j] != j): continue
        k = __tdfs(j, k, head, next, p, stack)

    return p
1264903
private static <T extends Comparable<T>> List<T> lcs(List<T> arg0, List<T> arg1, int i, int j) {
        if (arg0.size() == i || arg1.size() == j) {
            return new ArrayList<>(Math.min(arg0.size(), arg1.size()));
        }

        if (arg0.get(i) != null && arg1.get(j) != null && arg0.get(i).compareTo(arg1.get(j)) == 0) {
            T t = arg0.get(i);
            List<T> list = lcs(arg0, arg1, i + 1, j + 1);
            list.add(t);
            return list;
        } else {
            List<T> l1 = lcs(arg0, arg1, i + 1, j);
            List<T> l2 = lcs(arg0, arg1, i, j + 1);
            return l1.size() > l2.size() ? l1 : l2;
        }
    }
524930
def cross_products(c)
      c.to_a.group_by{ |_, v| v.sort }.map{ |k,v| [ v.map{ |a| a[0] }.sort, k ] }
    end
1100287
def union_elements(elements):
    

    if len(elements) < 2: return elements
    assert set( [e[3] for e in elements] ) == set( [elements[0][3]] ), "more than one id"
    el_id = elements[0][3]

    unioned_elements = []
    for ch, chgrp in groupby(elements, key=itemgetter(0)):
        for (s, e) in elem_u( np.array([itemgetter(1, 2)(_) for _ in chgrp], dtype=np.uint) ):
            if (s < e):
                unioned_elements.append( (ch, s, e, el_id) )
    assert len(unioned_elements) <= len(elements)
    return unioned_elements
1235082
public static <T> List<T> subList(List<T> list, int pageSize, int pageNo) {
        pageSize = (pageSize <= 0 ? 10 : pageSize);
        pageNo = (pageNo <= 0 ? 1 : pageNo);
        int begin = (pageSize * (pageNo - 1) > list.size() ? list.size() : pageSize * (pageNo - 1));
        int end = (pageSize * pageNo > list.size() ? list.size() : pageSize * pageNo);
        return new ArrayList<T>(list.subList(begin, end));
    }
357050
def p_concatlist(self, p):
        ''
        p[0] = p[1] + (p[3],)
        p.set_lineno(0, p.lineno(1))
818620
function M(list, assimilateSublists) {
    var self = this, idx = 0;
    if (list)
      for (var i = 0, len = list.length; i < len; i++) {
        var item = list[i];
        if (assimilateSublists && isList(item))
          for (var j = 0, len2 = item.length; j < len2; j++)
            self[idx++] = item[j];
        else
          self[idx++] = item;
      }
    else
      self[idx++] = assimilateSublists;

    self['length'] = idx;
    self['_'] = true;
  }
264317
def _sumLists(a, b):
    
    val = 0
    for i in map(lambda a, b: a * b, a, b):
        val += i
    return val
1037486
function(startRow, endRow, startCol, endCol) {
            	var x = [];
            	
            	if(endRow == 0)
            	    endRow = this.rows();
            	
            	if(endCol == 0)
            	    endCol = this.cols();

            	for(i = startRow; i <= endRow; i++) {
            	    var row = [];

            	    for(j = startCol; j <= endCol; j++) {
            		row.push(this.e(i, j));
            	    }

            	    x.push(row);
            	}

            	return $M(x);
                }
675550
def binom(n, k):
    
    prod = 1
    for i in range(k):
        prod = (prod * (n - i)) // (i + 1)
    return prod
397634
int createList(int listData) {
		int list = newList_();
		// m_lists.set_field(list, 0, null_node());//head
		// m_lists.set_field(list, 1, null_node());//tail
		// m_lists.set_field(list, 2, null_node());//prev list
		m_lists.setField(list, 3, m_list_of_lists); // next list
		m_lists.setField(list, 4, 0);// node count in the list
		m_lists.setField(list, 5, listData);
		if (m_list_of_lists != nullNode())
			setPrevList_(m_list_of_lists, list);

		m_list_of_lists = list;
		return list;
	}
679759
def cartesian(n, states):
    
    length = 1. / n  # arm_length
    pos_x = hstack((states[0], zeros(n)))
    pos_y = zeros(n + 1)
    for j in arange(1, n + 1):
        pos_x[j] = pos_x[j - 1] + length * cos(states[j])
        pos_y[j] = pos_y[j - 1] + length * sin(states[j])
    pos = hstack((pos_x, pos_y))
    return pos
1277011
def geometricmean(inlist):
    
    mult = 1.0
    one_over_n = 1.0 / len(inlist)
    for item in inlist:
        mult = mult * pow(item, one_over_n)
    return mult
411630
def is_list_of_list(item):
    
    if (
        type(item) in (list, tuple)
        and len(item)
        and isinstance(item[0], (list, tuple))
    ):
        return True
    return False
827463
def flatten(list_of_lists):
  
  ret = []
  for lst in list_of_lists:
    if not isinstance(lst, list):
      raise ValueError('%r is not a list' % lst)
    ret.extend(lst)
  return ret