istr-python 1.1.39.post0__tar.gz → 1.1.41__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/PKG-INFO +48 -1
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/README.md +47 -0
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/istr/istr.py +75 -6
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/istr_python.egg-info/PKG-INFO +48 -1
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/pyproject.toml +1 -1
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/tests/test_istr.py +88 -18
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/istr/LICENSE.txt +0 -0
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/istr/__init__.py +0 -0
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/istr/istr - Copy.py +0 -0
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/istr_python.egg-info/SOURCES.txt +0 -0
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/istr_python.egg-info/dependency_links.txt +0 -0
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/istr_python.egg-info/top_level.txt +0 -0
- {istr_python-1.1.39.post0 → istr_python-1.1.41}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.41
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -880,6 +880,53 @@ E.g. `print(istr.long_sqrt(123 ** 2, as_str=True))` will print
|
|
|
880
880
|
0
|
|
881
881
|
```
|
|
882
882
|
|
|
883
|
+
#### long multiplication
|
|
884
|
+
|
|
885
|
+
The method `long_multiplication` gives a list of all lines to do a long multiplition.
|
|
886
|
+
|
|
887
|
+
E.g. `print(istr.long_multiplication(1234,567)` will print
|
|
888
|
+
|
|
889
|
+
`[istr('1234'), istr('567'), istr('8638'), istr('7404'), istr('6170'), istr('699678')]`
|
|
890
|
+
|
|
891
|
+
The method has an optional parameter `as_str`, that can be used t0 get a nice representation of the long multiplication lines.
|
|
892
|
+
|
|
893
|
+
E.g. `print(istr.long_multiplication(1234,567, as_str=True)` will print
|
|
894
|
+
|
|
895
|
+
```
|
|
896
|
+
1234
|
|
897
|
+
567
|
|
898
|
+
------ x
|
|
899
|
+
8638
|
|
900
|
+
7404
|
|
901
|
+
6170
|
|
902
|
+
------
|
|
903
|
+
699678
|
|
904
|
+
```
|
|
905
|
+
|
|
906
|
+
#### long division
|
|
907
|
+
|
|
908
|
+
The method `long_division` gives a list of all lines to do a long division (note that the divisor and dividend count as separate lines).
|
|
909
|
+
|
|
910
|
+
E.g. `print(istr.long_division(1395, 45)` will print
|
|
911
|
+
|
|
912
|
+
[istr('31'), istr('45'), istr('1395'), istr('135'), istr('45'), istr('45'), istr('0')]
|
|
913
|
+
|
|
914
|
+
The method has an optional parameter `as_str`, that can be used to get a nice representation of the long multiplication lines.
|
|
915
|
+
|
|
916
|
+
E.g. `print(istr.long_division(1395, 45, as_str=True)` will print
|
|
917
|
+
|
|
918
|
+
```
|
|
919
|
+
31
|
|
920
|
+
----
|
|
921
|
+
45 ) 1395
|
|
922
|
+
135
|
|
923
|
+
---
|
|
924
|
+
45
|
|
925
|
+
45
|
|
926
|
+
--
|
|
927
|
+
0
|
|
928
|
+
```
|
|
929
|
+
|
|
883
930
|
#### generate istr with digits
|
|
884
931
|
|
|
885
932
|
The class method `digits` can be used to return an istr of digits according to a given specification.
|
|
@@ -867,6 +867,53 @@ E.g. `print(istr.long_sqrt(123 ** 2, as_str=True))` will print
|
|
|
867
867
|
0
|
|
868
868
|
```
|
|
869
869
|
|
|
870
|
+
#### long multiplication
|
|
871
|
+
|
|
872
|
+
The method `long_multiplication` gives a list of all lines to do a long multiplition.
|
|
873
|
+
|
|
874
|
+
E.g. `print(istr.long_multiplication(1234,567)` will print
|
|
875
|
+
|
|
876
|
+
`[istr('1234'), istr('567'), istr('8638'), istr('7404'), istr('6170'), istr('699678')]`
|
|
877
|
+
|
|
878
|
+
The method has an optional parameter `as_str`, that can be used t0 get a nice representation of the long multiplication lines.
|
|
879
|
+
|
|
880
|
+
E.g. `print(istr.long_multiplication(1234,567, as_str=True)` will print
|
|
881
|
+
|
|
882
|
+
```
|
|
883
|
+
1234
|
|
884
|
+
567
|
|
885
|
+
------ x
|
|
886
|
+
8638
|
|
887
|
+
7404
|
|
888
|
+
6170
|
|
889
|
+
------
|
|
890
|
+
699678
|
|
891
|
+
```
|
|
892
|
+
|
|
893
|
+
#### long division
|
|
894
|
+
|
|
895
|
+
The method `long_division` gives a list of all lines to do a long division (note that the divisor and dividend count as separate lines).
|
|
896
|
+
|
|
897
|
+
E.g. `print(istr.long_division(1395, 45)` will print
|
|
898
|
+
|
|
899
|
+
[istr('31'), istr('45'), istr('1395'), istr('135'), istr('45'), istr('45'), istr('0')]
|
|
900
|
+
|
|
901
|
+
The method has an optional parameter `as_str`, that can be used to get a nice representation of the long multiplication lines.
|
|
902
|
+
|
|
903
|
+
E.g. `print(istr.long_division(1395, 45, as_str=True)` will print
|
|
904
|
+
|
|
905
|
+
```
|
|
906
|
+
31
|
|
907
|
+
----
|
|
908
|
+
45 ) 1395
|
|
909
|
+
135
|
|
910
|
+
---
|
|
911
|
+
45
|
|
912
|
+
45
|
|
913
|
+
--
|
|
914
|
+
0
|
|
915
|
+
```
|
|
916
|
+
|
|
870
917
|
#### generate istr with digits
|
|
871
918
|
|
|
872
919
|
The class method `digits` can be used to return an istr of digits according to a given specification.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# |_||___/ \__||_|
|
|
6
6
|
# strings you can count on
|
|
7
7
|
|
|
8
|
-
__version__ = "1.1.
|
|
8
|
+
__version__ = "1.1.41"
|
|
9
9
|
import functools
|
|
10
10
|
import itertools
|
|
11
11
|
import types
|
|
@@ -767,6 +767,13 @@ class istr(str):
|
|
|
767
767
|
|
|
768
768
|
return str(self)
|
|
769
769
|
|
|
770
|
+
def interpret_as_istr(self):
|
|
771
|
+
# ignore leading zeroes
|
|
772
|
+
if isinstance(self, collections.abc.Iterable) and not isinstance(self, str):
|
|
773
|
+
return istr.join(self)*1
|
|
774
|
+
|
|
775
|
+
return istr(self)*1
|
|
776
|
+
|
|
770
777
|
def _str_method(self, name, *args, **kwargs):
|
|
771
778
|
return self.__class__(getattr(super(), name)(*args, **kwargs))
|
|
772
779
|
|
|
@@ -864,7 +871,7 @@ class istr(str):
|
|
|
864
871
|
if as_str is True, a formatted output will be returned
|
|
865
872
|
"""
|
|
866
873
|
|
|
867
|
-
number = istr
|
|
874
|
+
number = istr.interpret_as_istr(self)
|
|
868
875
|
|
|
869
876
|
lines = []
|
|
870
877
|
if len(number)%2==1:
|
|
@@ -921,8 +928,8 @@ class istr(str):
|
|
|
921
928
|
return lines
|
|
922
929
|
|
|
923
930
|
def long_multiplication(self, number,as_str=False):
|
|
924
|
-
number0 = istr
|
|
925
|
-
number1=istr(number)
|
|
931
|
+
number0 = istr.interpret_as_istr(self)
|
|
932
|
+
number1=istr.interpret_as_istr(number)
|
|
926
933
|
lines=[number0,number1]
|
|
927
934
|
for i in number1.reversed():
|
|
928
935
|
lines.append(number0*i)
|
|
@@ -941,9 +948,71 @@ class istr(str):
|
|
|
941
948
|
else:
|
|
942
949
|
return lines
|
|
943
950
|
|
|
951
|
+
def long_division(self, divisor, as_str=False):
|
|
952
|
+
dividend = istr.interpret_as_istr(self)
|
|
953
|
+
divisor = istr.interpret_as_istr(divisor)
|
|
954
|
+
|
|
955
|
+
if dividend < 0:
|
|
956
|
+
raise ValueError("dividend must be non-negative.")
|
|
957
|
+
|
|
958
|
+
if divisor <= 0:
|
|
959
|
+
raise ValueError("divisor must be positive.")
|
|
960
|
+
|
|
961
|
+
dividend_start = len(divisor) + 3
|
|
962
|
+
total_width = dividend_start + len(dividend)
|
|
963
|
+
|
|
964
|
+
quotient_characters = [" "] * len(dividend)
|
|
965
|
+
|
|
966
|
+
remainder = 0
|
|
967
|
+
division_started = False
|
|
968
|
+
lines=[]
|
|
969
|
+
|
|
970
|
+
for digit_index, digit_character in enumerate(dividend):
|
|
971
|
+
current = remainder * 10 + digit_character
|
|
972
|
+
quotient_digit = current // divisor
|
|
973
|
+
|
|
974
|
+
if quotient_digit != 0 or division_started:
|
|
975
|
+
division_started = True
|
|
976
|
+
|
|
977
|
+
if digit_index == len(dividend) - 1:
|
|
978
|
+
division_started = True
|
|
979
|
+
|
|
980
|
+
if not division_started:
|
|
981
|
+
remainder = current
|
|
982
|
+
continue
|
|
983
|
+
|
|
984
|
+
quotient_characters[digit_index] = quotient_digit
|
|
985
|
+
|
|
986
|
+
product = quotient_digit * divisor
|
|
987
|
+
remainder = current - product
|
|
988
|
+
|
|
989
|
+
if as_str:
|
|
990
|
+
end_column = dividend_start + digit_index
|
|
991
|
+
current_start = end_column - len(current) + 1
|
|
992
|
+
product_start = end_column - len(product) + 1
|
|
993
|
+
bar_start = min(current_start, product_start)
|
|
994
|
+
bar_length = end_column - bar_start + 1
|
|
995
|
+
lines.append(" " * current_start | current)
|
|
996
|
+
lines.append(" " * product_start | product)
|
|
997
|
+
lines.append(" " * bar_start + "-" * bar_length)
|
|
944
998
|
|
|
945
|
-
|
|
946
|
-
|
|
999
|
+
else:
|
|
1000
|
+
lines.append(current)
|
|
1001
|
+
lines.append(product)
|
|
1002
|
+
|
|
1003
|
+
quotient = istr.join(quotient_characters).rstrip()
|
|
1004
|
+
if as_str:
|
|
1005
|
+
remainder_start = total_width - len(remainder)
|
|
1006
|
+
lines.append(" " * remainder_start | remainder)
|
|
1007
|
+
lines=[" " * dividend_start | quotient," " * dividend_start + "-" * len(dividend),f"{divisor} ) {dividend}",*lines[1:]]
|
|
1008
|
+
return "\n".join(lines)
|
|
1009
|
+
|
|
1010
|
+
else:
|
|
1011
|
+
lines.append(remainder)
|
|
1012
|
+
lines=[istr(quotient),divisor,dividend,*lines[1:]]
|
|
1013
|
+
return lines
|
|
1014
|
+
|
|
1015
|
+
|
|
947
1016
|
def this_base(self):
|
|
948
1017
|
return self._this_base
|
|
949
1018
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.41
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -880,6 +880,53 @@ E.g. `print(istr.long_sqrt(123 ** 2, as_str=True))` will print
|
|
|
880
880
|
0
|
|
881
881
|
```
|
|
882
882
|
|
|
883
|
+
#### long multiplication
|
|
884
|
+
|
|
885
|
+
The method `long_multiplication` gives a list of all lines to do a long multiplition.
|
|
886
|
+
|
|
887
|
+
E.g. `print(istr.long_multiplication(1234,567)` will print
|
|
888
|
+
|
|
889
|
+
`[istr('1234'), istr('567'), istr('8638'), istr('7404'), istr('6170'), istr('699678')]`
|
|
890
|
+
|
|
891
|
+
The method has an optional parameter `as_str`, that can be used t0 get a nice representation of the long multiplication lines.
|
|
892
|
+
|
|
893
|
+
E.g. `print(istr.long_multiplication(1234,567, as_str=True)` will print
|
|
894
|
+
|
|
895
|
+
```
|
|
896
|
+
1234
|
|
897
|
+
567
|
|
898
|
+
------ x
|
|
899
|
+
8638
|
|
900
|
+
7404
|
|
901
|
+
6170
|
|
902
|
+
------
|
|
903
|
+
699678
|
|
904
|
+
```
|
|
905
|
+
|
|
906
|
+
#### long division
|
|
907
|
+
|
|
908
|
+
The method `long_division` gives a list of all lines to do a long division (note that the divisor and dividend count as separate lines).
|
|
909
|
+
|
|
910
|
+
E.g. `print(istr.long_division(1395, 45)` will print
|
|
911
|
+
|
|
912
|
+
[istr('31'), istr('45'), istr('1395'), istr('135'), istr('45'), istr('45'), istr('0')]
|
|
913
|
+
|
|
914
|
+
The method has an optional parameter `as_str`, that can be used to get a nice representation of the long multiplication lines.
|
|
915
|
+
|
|
916
|
+
E.g. `print(istr.long_division(1395, 45, as_str=True)` will print
|
|
917
|
+
|
|
918
|
+
```
|
|
919
|
+
31
|
|
920
|
+
----
|
|
921
|
+
45 ) 1395
|
|
922
|
+
135
|
|
923
|
+
---
|
|
924
|
+
45
|
|
925
|
+
45
|
|
926
|
+
--
|
|
927
|
+
0
|
|
928
|
+
```
|
|
929
|
+
|
|
883
930
|
#### generate istr with digits
|
|
884
931
|
|
|
885
932
|
The class method `digits` can be used to return an istr of digits according to a given specification.
|
|
@@ -10,7 +10,7 @@ authors = [
|
|
|
10
10
|
{ name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com" },
|
|
11
11
|
]
|
|
12
12
|
description = "istr - strings you can count on"
|
|
13
|
-
version = "1.1.
|
|
13
|
+
version = "1.1.41"
|
|
14
14
|
readme = "README.md"
|
|
15
15
|
requires-python = ">=3.10"
|
|
16
16
|
dependencies = []
|
|
@@ -218,6 +218,7 @@ def test_divmod():
|
|
|
218
218
|
def test_iter():
|
|
219
219
|
assert [x for x in istr.range(3)] == [istr(0), istr(1), istr(2)]
|
|
220
220
|
|
|
221
|
+
|
|
221
222
|
def test_none():
|
|
222
223
|
assert istr(None) is None
|
|
223
224
|
|
|
@@ -1066,12 +1067,13 @@ def test_is_triangular():
|
|
|
1066
1067
|
assert istr(424581).is_triangular()
|
|
1067
1068
|
assert not istr(424582).is_triangular()
|
|
1068
1069
|
assert istr.is_triangular(424581)
|
|
1069
|
-
|
|
1070
|
+
|
|
1071
|
+
|
|
1070
1072
|
def test_sum():
|
|
1071
|
-
assert istr(1234).sum() == istr(
|
|
1072
|
-
assert istr.sum(
|
|
1073
|
-
assert istr.sum(1234) == istr(
|
|
1074
|
-
assert istr.sum(1234, 5) == istr(
|
|
1073
|
+
assert istr(1234).sum() == istr("10")
|
|
1074
|
+
assert istr.sum("1234") == istr("10")
|
|
1075
|
+
assert istr.sum(1234) == istr("10")
|
|
1076
|
+
assert istr.sum(1234, 5) == istr("15")
|
|
1075
1077
|
|
|
1076
1078
|
|
|
1077
1079
|
def test_prod():
|
|
@@ -1217,18 +1219,49 @@ def test_compose():
|
|
|
1217
1219
|
assert istr(":=") == ":="
|
|
1218
1220
|
assert istr("=") == "="
|
|
1219
1221
|
|
|
1222
|
+
|
|
1220
1223
|
def test_long_sqrt():
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1224
|
+
assert istr.long_sqrt(1234**2) == [
|
|
1225
|
+
istr("1234"),
|
|
1226
|
+
istr("1522756"),
|
|
1227
|
+
istr("1"),
|
|
1228
|
+
istr("52"),
|
|
1229
|
+
istr("44"),
|
|
1230
|
+
istr("827"),
|
|
1231
|
+
istr("729"),
|
|
1232
|
+
istr("9856"),
|
|
1233
|
+
istr("9856"),
|
|
1234
|
+
istr("0"),
|
|
1235
|
+
]
|
|
1236
|
+
assert istr.long_sqrt(1234**2 + 1) == [
|
|
1237
|
+
istr("1234"),
|
|
1238
|
+
istr("1522757"),
|
|
1239
|
+
istr("1"),
|
|
1240
|
+
istr("52"),
|
|
1241
|
+
istr("44"),
|
|
1242
|
+
istr("827"),
|
|
1243
|
+
istr("729"),
|
|
1244
|
+
istr("9857"),
|
|
1245
|
+
istr("9856"),
|
|
1246
|
+
istr("1"),
|
|
1247
|
+
]
|
|
1248
|
+
lines = istr.long_sqrt(1234**2 + 1)
|
|
1249
|
+
assert istr(1234**2).long_sqrt() == [
|
|
1250
|
+
istr("1234"),
|
|
1251
|
+
istr("1522756"),
|
|
1252
|
+
istr("1"),
|
|
1253
|
+
istr("52"),
|
|
1254
|
+
istr("44"),
|
|
1255
|
+
istr("827"),
|
|
1256
|
+
istr("729"),
|
|
1257
|
+
istr("9856"),
|
|
1258
|
+
istr("9856"),
|
|
1259
|
+
istr("0"),
|
|
1260
|
+
]
|
|
1261
|
+
assert istr.long_sqrt(34**2) == [istr("34"), istr("1156"), istr("9"), istr("256"), istr("256"), istr("0")]
|
|
1262
|
+
assert (
|
|
1263
|
+
istr.long_sqrt(34**2, as_str=True)
|
|
1264
|
+
== """\
|
|
1232
1265
|
3 4
|
|
1233
1266
|
----
|
|
1234
1267
|
\\/1156
|
|
@@ -1237,8 +1270,45 @@ def test_long_sqrt():
|
|
|
1237
1270
|
256
|
|
1238
1271
|
256
|
|
1239
1272
|
---
|
|
1240
|
-
0
|
|
1241
|
-
|
|
1273
|
+
0"""
|
|
1274
|
+
)
|
|
1275
|
+
|
|
1276
|
+
|
|
1277
|
+
def test_long_multiplication():
|
|
1278
|
+
assert istr.long_multiplication(1234, 567) == [istr("1234"), istr("567"), istr("8638"), istr("7404"), istr("6170"), istr("699678")]
|
|
1279
|
+
assert istr(1234).long_multiplication(567) == [istr("1234"), istr("567"), istr("8638"), istr("7404"), istr("6170"), istr("699678")]
|
|
1280
|
+
assert (
|
|
1281
|
+
istr.long_multiplication(1234, 567, as_str=True)
|
|
1282
|
+
== """\
|
|
1283
|
+
1234
|
|
1284
|
+
567
|
|
1285
|
+
------ x
|
|
1286
|
+
8638
|
|
1287
|
+
7404
|
|
1288
|
+
6170
|
|
1289
|
+
------
|
|
1290
|
+
699678"""
|
|
1291
|
+
)
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
def test_long_division():
|
|
1295
|
+
assert istr.long_division(1395, 45) == [istr("31"), istr("45"), istr("1395"), istr("135"), istr("45"), istr("45"), istr("0")]
|
|
1296
|
+
assert istr(1395).long_division(45) == [istr("31"), istr("45"), istr("1395"), istr("135"), istr("45"), istr("45"), istr("0")]
|
|
1297
|
+
assert (
|
|
1298
|
+
istr.long_division(1395, 45, as_str=True)
|
|
1299
|
+
== """\
|
|
1300
|
+
31
|
|
1301
|
+
----
|
|
1302
|
+
45 ) 1395
|
|
1303
|
+
135
|
|
1304
|
+
---
|
|
1305
|
+
45
|
|
1306
|
+
45
|
|
1307
|
+
--
|
|
1308
|
+
0"""
|
|
1309
|
+
)
|
|
1310
|
+
|
|
1311
|
+
|
|
1242
1312
|
if __name__ == "__main__":
|
|
1243
1313
|
pytest.main(["-vv", "-s", "-x", __file__])
|
|
1244
1314
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|