Skip to content

Commit 73d62bb

Browse files
committed
Revert "Slopes between 2 indices and is_costas (#179)"
This reverts commit 58a070d.
1 parent bf4db92 commit 73d62bb

File tree

4 files changed

+0
-119
lines changed

4 files changed

+0
-119
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
- Matrix object
1414
- Function: Create Perm from a Matrix
1515
- Function: Create Matrix from Perm
16-
- Function: Get the slope between 2 indices
17-
- Function: Tells if perm is a Costas array
1816
- Enumeration strategy to check whether a class has finitely many simple permutations
1917

2018
### Changed

README.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ There are numerous practical methods available:
159159
[(1, 2)]
160160
>>> p.major_index()
161161
2
162-
>>> Perm((0, 1, 3, 2)).is_costas()
163-
True
164-
>>> Perm((2,1,0,4,3)).slope_between(0, 1)
165-
-1.0
166162
>>> Perm((2,3,1,0)).matrix_repr()
167163
Matrix(4, {(0, 2): 1, (1, 3): 1, (2, 1): 1, (3, 0): 1})
168164
>>> Perm.from_matrix(Matrix(4, {(0, 2): 1, (1, 3): 1, (2, 1): 1, (3, 0): 1}))

permuta/patterns/perm.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,49 +2929,6 @@ def cycle_notation(self) -> str:
29292929

29302930
cycles = cycle_notation
29312931

2932-
def slope_between(self, first: int, second: int) -> float:
2933-
"""Calculates the slope between the two given indices.
2934-
2935-
Examples:
2936-
>>> Perm((2,1,0,4,3)).slope_between(0, 1)
2937-
-1.0
2938-
>>> Perm((2,1,0,4,3)).slope_between(0, 2)
2939-
-1.0
2940-
>>> Perm((2,1,0,4,3)).slope_between(2, 3)
2941-
4.0
2942-
"""
2943-
if not 0 <= first < second < len(self):
2944-
raise ValueError("Incorrect indices")
2945-
return (self[second] - self[first]) / (second - first)
2946-
2947-
def is_costas(self) -> bool:
2948-
"""
2949-
Checks if permutation is a Costas Array, that is, all the slopes are different.
2950-
2951-
Examples:
2952-
>>> Perm((0, 1, 2, 3)).is_costas()
2953-
False
2954-
>>> Perm((0, 2, 1, 3)).is_costas()
2955-
False
2956-
>>> Perm((0, 3, 2, 1)).is_costas()
2957-
False
2958-
>>> Perm((0, 1, 3, 2)).is_costas()
2959-
True
2960-
>>> Perm((0, 2, 3, 1)).is_costas()
2961-
True
2962-
>>> Perm((0, 3, 1, 2)).is_costas()
2963-
True
2964-
"""
2965-
width: int = len(self)
2966-
prev_slopes: Set[float] = set()
2967-
for first in range(width - 1):
2968-
for second in range(first + 1, width):
2969-
slope = self.slope_between(first, second)
2970-
if slope in prev_slopes:
2971-
return False
2972-
prev_slopes.add(slope)
2973-
return True
2974-
29752932
def to_svg(self, image_scale: float = 1.0) -> str:
29762933
"""Return the svg code to plot the permutation. The image size defaults to
29772934
100x100 pixels and the parameter scales that.

tests/patterns/test_perm.py

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,76 +3684,6 @@ def test_count_foreminima():
36843684
assert Perm((3, 2, 1, 0)).count_foreminima() == 0
36853685

36863686

3687-
def test_slope_between():
3688-
assert Perm((0, 1, 2)).slope_between(0, 2) == 1.0
3689-
assert Perm((0, 2, 1)).slope_between(1, 2) == -1.0
3690-
assert Perm((1, 0, 2)).slope_between(1, 2) == 2.0
3691-
assert Perm((1, 2, 0)).slope_between(0, 2) == -0.5
3692-
assert Perm((2, 0, 1)).slope_between(1, 2) == 1.0
3693-
assert Perm((2, 1, 0)).slope_between(1, 2) == -1.0
3694-
assert Perm((0, 1, 2, 3)).slope_between(0, 1) == 1.0
3695-
assert Perm((0, 1, 3, 2)).slope_between(1, 2) == 2.0
3696-
assert Perm((0, 2, 1, 3)).slope_between(1, 2) == -1.0
3697-
assert Perm((0, 2, 3, 1)).slope_between(2, 3) == -2.0
3698-
assert Perm((0, 3, 1, 2)).slope_between(2, 3) == 1.0
3699-
assert Perm((0, 3, 2, 1)).slope_between(2, 3) == -1.0
3700-
assert Perm((1, 0, 2, 3)).slope_between(2, 3) == 1.0
3701-
assert Perm((1, 0, 3, 2)).slope_between(0, 3) == 0.3333333333333333
3702-
assert Perm((1, 2, 0, 3)).slope_between(0, 3) == 0.6666666666666666
3703-
assert Perm((1, 2, 3, 0)).slope_between(0, 1) == 1.0
3704-
assert Perm((1, 3, 0, 2)).slope_between(2, 3) == 2.0
3705-
assert Perm((1, 3, 2, 0)).slope_between(1, 2) == -1.0
3706-
assert Perm((2, 0, 1, 3)).slope_between(1, 2) == 1.0
3707-
assert Perm((2, 0, 3, 1)).slope_between(1, 2) == 3.0
3708-
assert Perm((2, 1, 0, 3)).slope_between(0, 1) == -1.0
3709-
assert Perm((2, 1, 3, 0)).slope_between(2, 3) == -3.0
3710-
assert Perm((2, 3, 0, 1)).slope_between(1, 3) == -1.0
3711-
assert Perm((2, 3, 1, 0)).slope_between(0, 1) == 1.0
3712-
assert Perm((3, 0, 1, 2)).slope_between(1, 3) == 1.0
3713-
assert Perm((3, 0, 2, 1)).slope_between(1, 2) == 2.0
3714-
assert Perm((3, 1, 0, 2)).slope_between(0, 2) == -1.5
3715-
assert Perm((3, 1, 2, 0)).slope_between(2, 3) == -2.0
3716-
assert Perm((3, 2, 0, 1)).slope_between(1, 3) == -0.5
3717-
assert Perm((3, 2, 1, 0)).slope_between(2, 3) == -1.0
3718-
3719-
3720-
def test_is_costas():
3721-
assert Perm(()).is_costas() == 1
3722-
assert Perm((0,)).is_costas() == 1
3723-
assert Perm((0, 1)).is_costas() == 1
3724-
assert Perm((1, 0)).is_costas() == 1
3725-
assert Perm((0, 1, 2)).is_costas() == 0
3726-
assert Perm((0, 2, 1)).is_costas() == 1
3727-
assert Perm((1, 0, 2)).is_costas() == 1
3728-
assert Perm((1, 2, 0)).is_costas() == 1
3729-
assert Perm((2, 0, 1)).is_costas() == 1
3730-
assert Perm((2, 1, 0)).is_costas() == 0
3731-
assert Perm((0, 1, 2, 3)).is_costas() == 0
3732-
assert Perm((0, 1, 3, 2)).is_costas() == 1
3733-
assert Perm((0, 2, 1, 3)).is_costas() == 0
3734-
assert Perm((0, 2, 3, 1)).is_costas() == 1
3735-
assert Perm((0, 3, 1, 2)).is_costas() == 1
3736-
assert Perm((0, 3, 2, 1)).is_costas() == 0
3737-
assert Perm((1, 0, 2, 3)).is_costas() == 1
3738-
assert Perm((1, 0, 3, 2)).is_costas() == 0
3739-
assert Perm((1, 2, 0, 3)).is_costas() == 1
3740-
assert Perm((1, 2, 3, 0)).is_costas() == 0
3741-
assert Perm((1, 3, 0, 2)).is_costas() == 0
3742-
assert Perm((1, 3, 2, 0)).is_costas() == 1
3743-
assert Perm((2, 0, 1, 3)).is_costas() == 1
3744-
assert Perm((2, 0, 3, 1)).is_costas() == 0
3745-
assert Perm((2, 1, 0, 3)).is_costas() == 0
3746-
assert Perm((2, 1, 3, 0)).is_costas() == 1
3747-
assert Perm((2, 3, 0, 1)).is_costas() == 0
3748-
assert Perm((2, 3, 1, 0)).is_costas() == 1
3749-
assert Perm((3, 0, 1, 2)).is_costas() == 0
3750-
assert Perm((3, 0, 2, 1)).is_costas() == 1
3751-
assert Perm((3, 1, 0, 2)).is_costas() == 1
3752-
assert Perm((3, 1, 2, 0)).is_costas() == 0
3753-
assert Perm((3, 2, 0, 1)).is_costas() == 1
3754-
assert Perm((3, 2, 1, 0)).is_costas() == 0
3755-
3756-
37573687
def test_matrix_class():
37583688
assert Matrix(0) == Matrix(0)
37593689
matrix = Matrix(size=3, elements={(0, 0): 1, (1, 1): 1, (2, 2): 1})

0 commit comments

Comments
 (0)