Skip to content

Commit

Permalink
fix Sphinx doc and housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudblois committed Jan 21, 2018
1 parent d52b65f commit f74d253
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 25 deletions.
13 changes: 4 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from pathlib import Path
import os
import sys
import sphinx_rtd_theme

doc_dir = Path(os.path.dirname(os.path.abspath(__file__)))
src_path = doc_dir.parent / 'src'
#sys.path.insert(0, '/home/ursi/workspace/Python-coding-tests/src')
sys.path.insert(0, src_path)

sys.path.insert(0, os.path.abspath('..'))

# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -93,9 +93,7 @@
# a list of builtin themes.
#
# default theme
#html_theme = 'alabaster'

import sphinx_rtd_theme
# html_theme = 'alabaster'

html_theme = "sphinx_rtd_theme"

Expand Down Expand Up @@ -170,7 +168,6 @@
]



# -- Options for Epub output ----------------------------------------------

# Bibliographic Dublin Core info.
Expand All @@ -190,5 +187,3 @@

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']


2 changes: 1 addition & 1 deletion docs/sort.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
====================

.. automodule:: src.classic_algo.sort
:members:
:members:
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ requests
setuptools
Sphinx
sphinxcontrib-disqus

sphinx_rtd_theme
2 changes: 1 addition & 1 deletion src/challenges/CtCI/arrays/P9_string_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def is_rotated_string(s1, s2):
"""
The pythonic solution is found by considering the clue: use "in" only once.
Assuming the string is rotated, it can be thought as being split in this way
s1 = part1 + part2 and s2 = part2 + part1. We can notice that s2 + s1 =
s1 = part1 + part2 and s2 = part2 + part1. We can notice that s2 + s2 =
part2 + part1 + part2 + part1 = part2 + s1 + part1
-> s1 in s2 + s2 is the answer we need, this comparison is done is O(n)
"""
Expand Down
14 changes: 8 additions & 6 deletions src/classic_algo/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def longest_common_subsequence(s1, s2):

def solve_knapsack(items, max_weight):
"""
solves the knapsack problem: considering a list of an infinite numbers of
n sort of items characterised by a weight and a value (weight_i, value_i),
solves the knapsack problem: considering a list of an infinite number of
n sorts of items characterised by a weight and a value (weight_i, value_i),
returns the list of objects that maximises the value one can put in the
knapsack without exceeding the max_weight
"""
Expand Down Expand Up @@ -143,8 +143,10 @@ def change_making_bottom_up(target, coin_set):
# If we found a minimum coin we update the best_combo and coin_count
# (this may not be the case for some sets not containing 1)
if minimum_coin:
best_combo[change] = (best_combo[change - minimum_coin] +
[minimum_coin])
best_combo[change] = (
best_combo[change - minimum_coin]
+ [minimum_coin]
)
coin_count[change] = coin_count[change - minimum_coin] + 1

return best_combo[target]
Expand All @@ -154,8 +156,8 @@ def change_making_bottom_up(target, coin_set):
def change_making_top_down(target, coin_set):
"""
returns the minimal numbers of coins required to equal the target, or []
if the target cannot be reached. Note that the coin_set has to be of type
set or frozenset since we use memoization: the arguments must be hashable
if the target cannot be reached. Note that the coin_set has to be a tuple
or frozenset since we use memoization: the arguments must be hashable
and a list is not.
"""
# We sort the coins and return the trivial results (target below the
Expand Down
2 changes: 1 addition & 1 deletion src/classic_algo/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def quicksort_helper(a, first, last):

def partition_helper(a, first, last):
"""
A left_mark index are initiated at the leftmost index available (ie
A left_mark index are initiated at the leftmost index available (ie
not the pivot) and a right_mark at the rightmost. The left_mark is shifted
right as long as a[left_mark] < pivot and the right_mark left as long as
a[right_mark] > pivot. If left_mark < right_mark, the values at which the
Expand Down
5 changes: 2 additions & 3 deletions src/classic_algo/tests/test_sort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from unittest import TestCase
import random
from ..sort import (
bubble_sort, short_bubble_sort,
Expand Down Expand Up @@ -29,8 +28,8 @@ def test_empty():

def test_single_element():
"""sorting a list of one element"""
l1 = [1,]
l2 = [1,]
l1 = [1]
l2 = [1]
assert bubble_sort(l1.copy()) == l2
assert short_bubble_sort(l1.copy()) == l2
assert selection_sort(l1.copy()) == l2
Expand Down
6 changes: 3 additions & 3 deletions src/structures/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class BinaryTree:
The particularity of trees is that each node can be considered the root of
a subtree. This leads to interesting recursive properties to walk the tree.
"""
def __init__(root_node):
def __init__(self, root_node):
self.node = root_node
self.left_child = None
self.right_child = None

def insert_left(new_node):
def insert_left(self, new_node):
"""
Insert a new node as the left child of the tree. If there is no left
child already, the left child is directly added as the root of a new
Expand All @@ -51,7 +51,7 @@ def insert_left(new_node):
subtree.left_child = self.left_child
self.left_child = subtree

def insert_right(new_node):
def insert_right(self, new_node):
""" same as above but with the right child """
if self.right_child is None:
self.right_child = BinaryTree(new_node)
Expand Down

0 comments on commit f74d253

Please sign in to comment.