istr-python 1.1.42__tar.gz → 1.1.43__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.42
3
+ Version: 1.1.43
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
@@ -852,16 +852,24 @@ istr.getitem('1234',5, None) ==> None
852
852
  Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
853
853
 
854
854
  #### long square root
855
- The method `long_sqrt` gives a list of the lines of a long square root. Both the result (root) and the original number, possibly with a trailing 0 are returned, along with the calculated values.
856
- E.g. `istr.long_sqrt(123 ** 2)` results in
855
+ The method `long_sqrt` returns an instance of a class with attributes `lines`, `line_lengths` and `output`.
856
+
857
+ `lines` is list of the lines of a long square root. Both the result (root) and the original number, possibly with a trailing 0 are returned, along with the calculated values.
858
+ E.g. `istr.long_sqrt(123 ** 2).lines` results in
857
859
 
858
860
  `[istr('123'), istr('15129'), istr('1'), istr('51'), istr('44'), istr('729'), istr('729'), istr('0')]`
859
861
 
860
862
  Note the final `istr('0')` is included to support also long square roots that are not perfect.
861
863
 
862
- The method `long_sqrt`has an optional parameter `as_str`, that can be used to get a nice string representation of the long square root lines.
864
+ `line_lengths` returns a list of the length of the lines (not istr-ed). E.g.:
865
+
866
+ E.g. `istr.long_sqrt(123 ** 2).line_lengths` results in
867
+
868
+ `[3, 5, 1, 2, 2, 3, 3, 1]`
863
869
 
864
- E.g. `print(istr.long_sqrt(123 ** 2, as_str=True))` will print
870
+ `output` can be used to get a nice string representation of the long square root lines.
871
+
872
+ E.g. `print(istr.long_sqrt(123 ** 2).output)` will print
865
873
  ```
866
874
  1 2 3
867
875
  -----
@@ -879,18 +887,26 @@ E.g. `print(istr.long_sqrt(123 ** 2, as_str=True))` will print
879
887
 
880
888
  #### long multiplication
881
889
 
882
- The method `long_multiplication` gives a list of all lines to do a long multiplition.
890
+ The method `long_multiplication` returns an instance of a class with attributes `lines`, `line_lengths` and `output`.
891
+
892
+ `lines` is list of the lines of a long multiplication.
893
+
894
+ E.g. `print(istr.long_multiplication(1234,567).lines` will print
883
895
 
884
- E.g. `print(istr.long_multiplication(1234,567)` will print
885
-
886
896
  `[istr('1234'), istr('567'), istr('8638'), istr('7404'), istr('6170'), istr('699678')]`
887
-
888
- The method has an optional parameter `as_str`, that can be used t0 get a nice representation of the long multiplication lines.
889
-
890
- E.g. `print(istr.long_multiplication(1234,567, as_str=True)` will print
897
+
898
+ `line_lengths` returns a list of the length of the lines (not istr-ed). E.g.:
899
+
900
+ E. g. `print(istr.long_multiplication(1234,567).line_lengths` results in
901
+
902
+ `[4, 3, 4, 4, 4, 6]`
903
+
904
+ `output` can be used to get a nice string representation of the long multiplication lines.
905
+
906
+ E.g. `print(istr.long_multiplication(1234, 567).output)` will print
891
907
 
892
908
  ```
893
- 1234
909
+ 1234
894
910
  567
895
911
  ------ x
896
912
  8638
@@ -902,15 +918,23 @@ E.g. `print(istr.long_multiplication(1234,567, as_str=True)` will print
902
918
 
903
919
  #### long division
904
920
 
905
- 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).
921
+ The method `long_division` returns an instance of a class with attributes `lines`, `line_lengths` and `output`.
906
922
 
907
- E.g. `print(istr.long_division(1395, 45)` will print
923
+ `lines` is a list of the lines of a long division.
908
924
 
909
- [istr('31'), istr('45'), istr('1395'), istr('135'), istr('45'), istr('45'), istr('0')]
910
-
911
- The method has an optional parameter `as_str`, that can be used to get a nice representation of the long multiplication lines.
912
-
913
- E.g. `print(istr.long_division(1395, 45, as_str=True)` will print
925
+ E.g. `print(istr.long_division(1395, 45).lines` will print
926
+
927
+ `[istr('31'), istr('45'), istr('1395'), istr('135'), istr('45'), istr('45'), istr('0')]`
928
+
929
+ Note the final `istr('0')` is included to support also long divisions roots that are not perfect.
930
+
931
+ E.g. `print(istr.long_division(1395, 45).line_lengths` will print
932
+
933
+ `[2, 2, 4, 3, 2, 2, 1]`
934
+
935
+ `output` can be used to get a nice string representation of the long divsion lines.
936
+
937
+ E.g. `print(istr.long_division(1395, 45).output` will print
914
938
 
915
939
  ```
916
940
  31
@@ -922,8 +946,8 @@ E.g. `print(istr.long_division(1395, 45, as_str=True)` will print
922
946
  45
923
947
  --
924
948
  0
925
- ```
926
-
949
+ ```
950
+
927
951
  #### generate istr with digits
928
952
 
929
953
  The class method `digits` can be used to return an istr of digits according to a given specification.
@@ -839,16 +839,24 @@ istr.getitem('1234',5, None) ==> None
839
839
  Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
840
840
 
841
841
  #### long square root
842
- The method `long_sqrt` gives a list of the lines of a long square root. Both the result (root) and the original number, possibly with a trailing 0 are returned, along with the calculated values.
843
- E.g. `istr.long_sqrt(123 ** 2)` results in
842
+ The method `long_sqrt` returns an instance of a class with attributes `lines`, `line_lengths` and `output`.
843
+
844
+ `lines` is list of the lines of a long square root. Both the result (root) and the original number, possibly with a trailing 0 are returned, along with the calculated values.
845
+ E.g. `istr.long_sqrt(123 ** 2).lines` results in
844
846
 
845
847
  `[istr('123'), istr('15129'), istr('1'), istr('51'), istr('44'), istr('729'), istr('729'), istr('0')]`
846
848
 
847
849
  Note the final `istr('0')` is included to support also long square roots that are not perfect.
848
850
 
849
- The method `long_sqrt`has an optional parameter `as_str`, that can be used to get a nice string representation of the long square root lines.
851
+ `line_lengths` returns a list of the length of the lines (not istr-ed). E.g.:
852
+
853
+ E.g. `istr.long_sqrt(123 ** 2).line_lengths` results in
854
+
855
+ `[3, 5, 1, 2, 2, 3, 3, 1]`
850
856
 
851
- E.g. `print(istr.long_sqrt(123 ** 2, as_str=True))` will print
857
+ `output` can be used to get a nice string representation of the long square root lines.
858
+
859
+ E.g. `print(istr.long_sqrt(123 ** 2).output)` will print
852
860
  ```
853
861
  1 2 3
854
862
  -----
@@ -866,18 +874,26 @@ E.g. `print(istr.long_sqrt(123 ** 2, as_str=True))` will print
866
874
 
867
875
  #### long multiplication
868
876
 
869
- The method `long_multiplication` gives a list of all lines to do a long multiplition.
877
+ The method `long_multiplication` returns an instance of a class with attributes `lines`, `line_lengths` and `output`.
878
+
879
+ `lines` is list of the lines of a long multiplication.
880
+
881
+ E.g. `print(istr.long_multiplication(1234,567).lines` will print
870
882
 
871
- E.g. `print(istr.long_multiplication(1234,567)` will print
872
-
873
883
  `[istr('1234'), istr('567'), istr('8638'), istr('7404'), istr('6170'), istr('699678')]`
874
-
875
- The method has an optional parameter `as_str`, that can be used t0 get a nice representation of the long multiplication lines.
876
-
877
- E.g. `print(istr.long_multiplication(1234,567, as_str=True)` will print
884
+
885
+ `line_lengths` returns a list of the length of the lines (not istr-ed). E.g.:
886
+
887
+ E. g. `print(istr.long_multiplication(1234,567).line_lengths` results in
888
+
889
+ `[4, 3, 4, 4, 4, 6]`
890
+
891
+ `output` can be used to get a nice string representation of the long multiplication lines.
892
+
893
+ E.g. `print(istr.long_multiplication(1234, 567).output)` will print
878
894
 
879
895
  ```
880
- 1234
896
+ 1234
881
897
  567
882
898
  ------ x
883
899
  8638
@@ -889,15 +905,23 @@ E.g. `print(istr.long_multiplication(1234,567, as_str=True)` will print
889
905
 
890
906
  #### long division
891
907
 
892
- 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).
908
+ The method `long_division` returns an instance of a class with attributes `lines`, `line_lengths` and `output`.
893
909
 
894
- E.g. `print(istr.long_division(1395, 45)` will print
910
+ `lines` is a list of the lines of a long division.
895
911
 
896
- [istr('31'), istr('45'), istr('1395'), istr('135'), istr('45'), istr('45'), istr('0')]
897
-
898
- The method has an optional parameter `as_str`, that can be used to get a nice representation of the long multiplication lines.
899
-
900
- E.g. `print(istr.long_division(1395, 45, as_str=True)` will print
912
+ E.g. `print(istr.long_division(1395, 45).lines` will print
913
+
914
+ `[istr('31'), istr('45'), istr('1395'), istr('135'), istr('45'), istr('45'), istr('0')]`
915
+
916
+ Note the final `istr('0')` is included to support also long divisions roots that are not perfect.
917
+
918
+ E.g. `print(istr.long_division(1395, 45).line_lengths` will print
919
+
920
+ `[2, 2, 4, 3, 2, 2, 1]`
921
+
922
+ `output` can be used to get a nice string representation of the long divsion lines.
923
+
924
+ E.g. `print(istr.long_division(1395, 45).output` will print
901
925
 
902
926
  ```
903
927
  31
@@ -909,8 +933,8 @@ E.g. `print(istr.long_division(1395, 45, as_str=True)` will print
909
933
  45
910
934
  --
911
935
  0
912
- ```
913
-
936
+ ```
937
+
914
938
  #### generate istr with digits
915
939
 
916
940
  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.42"
8
+ __version__ = "1.1.43"
9
9
  import functools
10
10
  import itertools
11
11
  import types
@@ -727,14 +727,14 @@ class istr(str):
727
727
  return self[::-1]
728
728
 
729
729
  def ceil(self, divisible_by=1):
730
- if divisible_by != int(divisible_by) or divisible_by<1:
730
+ if divisible_by != int(divisible_by) or divisible_by < 1:
731
731
  raise ValueError(f"divisible_by has to be an integer value >=1 , not {divisible_by}")
732
732
  n = istr.interpret_as_float(self)
733
733
  return istr((math.ceil(n / divisible_by)) * divisible_by)
734
734
 
735
735
  def floor(self, divisible_by=1):
736
- if divisible_by != int(divisible_by) or divisible_by<1:
737
- raise ValueError(f"divisible_by has to be an integer value >=1 , not {divisible_by}")
736
+ if divisible_by != int(divisible_by) or divisible_by < 1:
737
+ raise ValueError(f"divisible_by has to be an integer value >=1 , not {divisible_by}")
738
738
  n = istr.interpret_as_float(self)
739
739
  return istr((math.floor(n / divisible_by)) * divisible_by)
740
740
 
@@ -764,13 +764,13 @@ class istr(str):
764
764
 
765
765
  return str(self)
766
766
 
767
- def interpret_as_istr(self):
767
+ def interpret_as_istr(self):
768
768
  # ignore leading zeroes
769
769
  if isinstance(self, collections.abc.Iterable) and not isinstance(self, str):
770
- return istr.join(self)*1
770
+ return istr.join(self) * 1
771
+
772
+ return istr(self) * 1
771
773
 
772
- return istr(self)*1
773
-
774
774
  def _str_method(self, name, *args, **kwargs):
775
775
  return self.__class__(getattr(super(), name)(*args, **kwargs))
776
776
 
@@ -860,22 +860,15 @@ class istr(str):
860
860
  for i, value in enumerate(iterable, int(start)):
861
861
  yield cls(i), value
862
862
 
863
- def long_sqrt(self, as_str=False):
864
- """
865
- this function does long squre root and returns all the lines to be written.
866
- (modified from a ChatGPT code suggestion)
867
- returns root, number and the lines below the number, all istr-ed
868
- if as_str is True, a formatted output will be returned
869
- """
870
-
871
- number = istr.interpret_as_istr(self)
872
-
863
+ @staticmethod
864
+ @functools.lru_cache(maxsize=1)
865
+ def _long_sqrt(number):
873
866
  lines = []
874
- if len(number)%2==1:
875
- pairs=istr.chain(number[0],istr.batched(number[1:],2,join=True))
876
- else:
877
- pairs=istr.batched(number,2,join=True)
878
-
867
+ if len(number) % 2 == 1:
868
+ pairs = istr.chain(number[0], istr.batched(number[1:], 2, join=True))
869
+ else:
870
+ pairs = istr.batched(number, 2, join=True)
871
+
879
872
  root = istr(0)
880
873
  remainder = 0
881
874
 
@@ -899,118 +892,180 @@ class istr(str):
899
892
 
900
893
  lines.append(remainder)
901
894
  lines = [root] + [number] + lines[1:]
902
- if as_str:
903
- result = []
904
- extra = len(number)%2==0
905
- result.append(f" {extra*' '}{' '.join(lines[0])}")
906
- result.append(f" {len(lines[1])*'-'}")
907
- result.append(f"\/{lines[1]}")
908
-
909
- last_len=len(lines[2])
910
- for i, line in enumerate(lines):
911
-
912
- if i >= 2:
913
- if i == len(lines) - 1:
914
- n = i - 2 + extra
915
- else:
916
- n = i + extra
895
+ return lines
917
896
 
918
- if i % 2 == 0:
919
- result.append(f" {line:>{n}}")
920
- result.append(f" {last_len*'-':>{n}}")
921
- else:
922
- result.append(f" {line:>{n+1}}")
923
- last_len=len(line)
924
- return "\n".join(result)
925
- else:
926
- return lines
927
-
928
- def long_multiplication(self, number,as_str=False):
929
- number0 = istr.interpret_as_istr(self)
930
- number1=istr.interpret_as_istr(number)
931
- lines=[number0,number1]
897
+ def long_sqrt(self):
898
+ """
899
+ this function does long squre root and returns all the lines to be written.
900
+ (modified from a ChatGPT code suggestion)
901
+ returns root, number and the lines below the number, all istr-ed
902
+ if as_str is True, a formatted output will be returned
903
+ """
904
+
905
+ class NumberHolder:
906
+ def __init__(self, number):
907
+ self.number = number
908
+
909
+ def __getattr__(self, attr):
910
+ match attr:
911
+ case "lines":
912
+ return istr._long_sqrt(self.number)
913
+ case "line_lengths":
914
+ return [*map(len, istr._long_sqrt(self.number))]
915
+ case "output":
916
+ lines = istr._long_sqrt(self.number)
917
+ result = []
918
+ extra = len(number) % 2 == 0
919
+ result.append(f" {extra*' '}{' '.join(lines[0])}")
920
+ result.append(f" {len(lines[1])*'-'}")
921
+ result.append(f"\/{lines[1]}")
922
+
923
+ last_len = len(lines[2])
924
+ for i, line in enumerate(lines):
925
+ if i >= 2:
926
+ if i == len(lines) - 1:
927
+ n = i - 2 + extra
928
+ else:
929
+ n = i + extra
930
+
931
+ if i % 2 == 0:
932
+ result.append(f" {line:>{n}}")
933
+ result.append(f" {last_len*'-':>{n}}")
934
+ else:
935
+ result.append(f" {line:>{n+1}}")
936
+ last_len = len(line)
937
+ return "\n".join(result)
938
+ case _:
939
+ raise AttributeError()
940
+
941
+ number = istr.interpret_as_istr(self)
942
+
943
+ return NumberHolder(number)
944
+
945
+ @staticmethod
946
+ @functools.lru_cache(maxsize=1)
947
+ def _long_multiplication(number0, number1):
948
+ lines = [number0, number1]
932
949
  for i in number1.reversed():
933
- lines.append(number0*i)
934
- lines.append(number0*number1)
935
- if as_str:
936
- result=[]
937
- n=len(lines[-1])
938
- result.append(f'{lines[0]:>{n}}')
939
- result.append(f'{lines[1]:>{n}}')
940
- result.append(f"{n*'-'} x")
941
- for i,line in enumerate(lines[2:-1]):
942
- result.append(f"{line:>{n-i}}")
943
- result.append(f"{n*'-'}")
944
- result.append(lines[-1])
945
- return '\n'.join(result)
946
- else:
947
- return lines
948
-
949
- def long_division(self, divisor, as_str=False):
950
- dividend = istr.interpret_as_istr(self)
951
- divisor = istr.interpret_as_istr(divisor)
952
-
950
+ lines.append(number0 * i)
951
+ lines.append(number0 * number1)
952
+
953
+ return lines
954
+
955
+ def long_multiplication(self, number, as_str=False):
956
+ class NumbersHolder:
957
+ def __init__(self, number0, number1):
958
+ self.number0 = number0
959
+ self.number1 = number1
960
+
961
+ def __getattr__(self, attr):
962
+ match attr:
963
+ case "lines":
964
+ return istr._long_multiplication(self.number0, self.number1)
965
+ case "line_lengths":
966
+ return [*map(len, istr._long_multiplication(self.number0, self.number1))]
967
+ case "output":
968
+ lines = istr._long_multiplication(self.number0, self.number1)
969
+ result = []
970
+
971
+ n = len(lines[-1])
972
+ result.append(f"{lines[0]:>{n}}")
973
+ result.append(f"{lines[1]:>{n}}")
974
+ result.append(f"{n*'-'} x")
975
+ for i, line in enumerate(lines[2:-1]):
976
+ result.append(f"{line:>{n-i}}")
977
+ result.append(f"{n*'-'}")
978
+ result.append(lines[-1])
979
+ return "\n".join(result)
980
+ case _:
981
+ raise AttributeError()
982
+
983
+ number0 = istr.interpret_as_istr(self)
984
+ number1 = istr.interpret_as_istr(number)
985
+ return NumbersHolder(number0, number1)
986
+
987
+ @staticmethod
988
+ @functools.lru_cache(maxsize=1)
989
+ def _long_division(dividend, divisor, as_str=False):
953
990
  if dividend < 0:
954
991
  raise ValueError("dividend must be non-negative.")
955
-
992
+
956
993
  if divisor <= 0:
957
994
  raise ValueError("divisor must be positive.")
958
-
995
+
959
996
  dividend_start = len(divisor) + 3
960
997
  total_width = dividend_start + len(dividend)
961
-
998
+
962
999
  quotient_characters = [" "] * len(dividend)
963
-
1000
+
964
1001
  remainder = 0
965
1002
  division_started = False
966
- lines=[]
967
-
1003
+ lines = []
1004
+
968
1005
  for digit_index, digit_character in enumerate(dividend):
969
1006
  current = remainder * 10 + digit_character
970
1007
  quotient_digit = current // divisor
971
-
1008
+
972
1009
  if quotient_digit != 0 or division_started:
973
1010
  division_started = True
974
-
1011
+
975
1012
  if digit_index == len(dividend) - 1:
976
1013
  division_started = True
977
-
1014
+
978
1015
  if not division_started:
979
1016
  remainder = current
980
1017
  continue
981
-
1018
+
982
1019
  quotient_characters[digit_index] = quotient_digit
983
-
1020
+
984
1021
  product = quotient_digit * divisor
985
1022
  remainder = current - product
986
-
1023
+
987
1024
  if as_str:
988
1025
  end_column = dividend_start + digit_index
989
1026
  current_start = end_column - len(current) + 1
990
- product_start = end_column - len(product) + 1
1027
+ product_start = end_column - len(product) + 1
991
1028
  bar_start = min(current_start, product_start)
992
1029
  bar_length = end_column - bar_start + 1
993
1030
  lines.append(" " * current_start | current)
994
1031
  lines.append(" " * product_start | product)
995
1032
  lines.append(" " * bar_start + "-" * bar_length)
996
-
1033
+
997
1034
  else:
998
1035
  lines.append(current)
999
1036
  lines.append(product)
1000
-
1037
+
1001
1038
  quotient = istr.join(quotient_characters).rstrip()
1002
1039
  if as_str:
1003
1040
  remainder_start = total_width - len(remainder)
1004
1041
  lines.append(" " * remainder_start | remainder)
1005
- lines=[" " * dividend_start | quotient," " * dividend_start + "-" * len(dividend),f"{divisor} ) {dividend}",*lines[1:]]
1042
+ lines = [" " * dividend_start | quotient, " " * dividend_start + "-" * len(dividend), f"{divisor} ) {dividend}", *lines[1:]]
1006
1043
  return "\n".join(lines)
1007
-
1044
+
1008
1045
  else:
1009
1046
  lines.append(remainder)
1010
- lines=[istr(quotient),divisor,dividend,*lines[1:]]
1011
- return lines
1012
-
1013
-
1047
+ lines = [istr(quotient), divisor, dividend, *lines[1:]]
1048
+ return lines
1049
+
1050
+ def long_division(self, divisor):
1051
+ class NumbersHolder:
1052
+ def __init__(self, dividend, divisor):
1053
+ self.dividend = dividend
1054
+ self.divisor = divisor
1055
+
1056
+ def __getattr__(self, attr):
1057
+ match attr:
1058
+ case "lines":
1059
+ return istr._long_division(self.dividend, self.divisor)
1060
+ case "line_lengths":
1061
+ return [*map(len, istr._long_division(self.dividend, self.divisor))]
1062
+ case "output":
1063
+ return istr._long_division(self.dividend, self.divisor, as_str=True)
1064
+
1065
+ dividend = istr.interpret_as_istr(self)
1066
+ divisor = istr.interpret_as_istr(divisor)
1067
+ return NumbersHolder(dividend, divisor)
1068
+
1014
1069
  def this_base(self):
1015
1070
  return self._this_base
1016
1071
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.42
3
+ Version: 1.1.43
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
@@ -852,16 +852,24 @@ istr.getitem('1234',5, None) ==> None
852
852
  Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
853
853
 
854
854
  #### long square root
855
- The method `long_sqrt` gives a list of the lines of a long square root. Both the result (root) and the original number, possibly with a trailing 0 are returned, along with the calculated values.
856
- E.g. `istr.long_sqrt(123 ** 2)` results in
855
+ The method `long_sqrt` returns an instance of a class with attributes `lines`, `line_lengths` and `output`.
856
+
857
+ `lines` is list of the lines of a long square root. Both the result (root) and the original number, possibly with a trailing 0 are returned, along with the calculated values.
858
+ E.g. `istr.long_sqrt(123 ** 2).lines` results in
857
859
 
858
860
  `[istr('123'), istr('15129'), istr('1'), istr('51'), istr('44'), istr('729'), istr('729'), istr('0')]`
859
861
 
860
862
  Note the final `istr('0')` is included to support also long square roots that are not perfect.
861
863
 
862
- The method `long_sqrt`has an optional parameter `as_str`, that can be used to get a nice string representation of the long square root lines.
864
+ `line_lengths` returns a list of the length of the lines (not istr-ed). E.g.:
865
+
866
+ E.g. `istr.long_sqrt(123 ** 2).line_lengths` results in
867
+
868
+ `[3, 5, 1, 2, 2, 3, 3, 1]`
863
869
 
864
- E.g. `print(istr.long_sqrt(123 ** 2, as_str=True))` will print
870
+ `output` can be used to get a nice string representation of the long square root lines.
871
+
872
+ E.g. `print(istr.long_sqrt(123 ** 2).output)` will print
865
873
  ```
866
874
  1 2 3
867
875
  -----
@@ -879,18 +887,26 @@ E.g. `print(istr.long_sqrt(123 ** 2, as_str=True))` will print
879
887
 
880
888
  #### long multiplication
881
889
 
882
- The method `long_multiplication` gives a list of all lines to do a long multiplition.
890
+ The method `long_multiplication` returns an instance of a class with attributes `lines`, `line_lengths` and `output`.
891
+
892
+ `lines` is list of the lines of a long multiplication.
893
+
894
+ E.g. `print(istr.long_multiplication(1234,567).lines` will print
883
895
 
884
- E.g. `print(istr.long_multiplication(1234,567)` will print
885
-
886
896
  `[istr('1234'), istr('567'), istr('8638'), istr('7404'), istr('6170'), istr('699678')]`
887
-
888
- The method has an optional parameter `as_str`, that can be used t0 get a nice representation of the long multiplication lines.
889
-
890
- E.g. `print(istr.long_multiplication(1234,567, as_str=True)` will print
897
+
898
+ `line_lengths` returns a list of the length of the lines (not istr-ed). E.g.:
899
+
900
+ E. g. `print(istr.long_multiplication(1234,567).line_lengths` results in
901
+
902
+ `[4, 3, 4, 4, 4, 6]`
903
+
904
+ `output` can be used to get a nice string representation of the long multiplication lines.
905
+
906
+ E.g. `print(istr.long_multiplication(1234, 567).output)` will print
891
907
 
892
908
  ```
893
- 1234
909
+ 1234
894
910
  567
895
911
  ------ x
896
912
  8638
@@ -902,15 +918,23 @@ E.g. `print(istr.long_multiplication(1234,567, as_str=True)` will print
902
918
 
903
919
  #### long division
904
920
 
905
- 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).
921
+ The method `long_division` returns an instance of a class with attributes `lines`, `line_lengths` and `output`.
906
922
 
907
- E.g. `print(istr.long_division(1395, 45)` will print
923
+ `lines` is a list of the lines of a long division.
908
924
 
909
- [istr('31'), istr('45'), istr('1395'), istr('135'), istr('45'), istr('45'), istr('0')]
910
-
911
- The method has an optional parameter `as_str`, that can be used to get a nice representation of the long multiplication lines.
912
-
913
- E.g. `print(istr.long_division(1395, 45, as_str=True)` will print
925
+ E.g. `print(istr.long_division(1395, 45).lines` will print
926
+
927
+ `[istr('31'), istr('45'), istr('1395'), istr('135'), istr('45'), istr('45'), istr('0')]`
928
+
929
+ Note the final `istr('0')` is included to support also long divisions roots that are not perfect.
930
+
931
+ E.g. `print(istr.long_division(1395, 45).line_lengths` will print
932
+
933
+ `[2, 2, 4, 3, 2, 2, 1]`
934
+
935
+ `output` can be used to get a nice string representation of the long divsion lines.
936
+
937
+ E.g. `print(istr.long_division(1395, 45).output` will print
914
938
 
915
939
  ```
916
940
  31
@@ -922,8 +946,8 @@ E.g. `print(istr.long_division(1395, 45, as_str=True)` will print
922
946
  45
923
947
  --
924
948
  0
925
- ```
926
-
949
+ ```
950
+
927
951
  #### generate istr with digits
928
952
 
929
953
  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.42"
13
+ version = "1.1.43"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.10"
16
16
  dependencies = []
@@ -1227,7 +1227,7 @@ def test_compose():
1227
1227
 
1228
1228
 
1229
1229
  def test_long_sqrt():
1230
- assert istr.long_sqrt(1234**2) == [
1230
+ assert istr.long_sqrt(1234**2).lines == [
1231
1231
  istr("1234"),
1232
1232
  istr("1522756"),
1233
1233
  istr("1"),
@@ -1239,7 +1239,7 @@ def test_long_sqrt():
1239
1239
  istr("9856"),
1240
1240
  istr("0"),
1241
1241
  ]
1242
- assert istr.long_sqrt(1234**2 + 1) == [
1242
+ assert istr.long_sqrt(1234**2 + 1).lines == [
1243
1243
  istr("1234"),
1244
1244
  istr("1522757"),
1245
1245
  istr("1"),
@@ -1251,8 +1251,8 @@ def test_long_sqrt():
1251
1251
  istr("9856"),
1252
1252
  istr("1"),
1253
1253
  ]
1254
- lines = istr.long_sqrt(1234**2 + 1)
1255
- assert istr(1234**2).long_sqrt() == [
1254
+
1255
+ assert istr(1234**2).long_sqrt().lines == [
1256
1256
  istr("1234"),
1257
1257
  istr("1522756"),
1258
1258
  istr("1"),
@@ -1264,11 +1264,12 @@ def test_long_sqrt():
1264
1264
  istr("9856"),
1265
1265
  istr("0"),
1266
1266
  ]
1267
- assert istr.long_sqrt(34**2) == [istr("34"), istr("1156"), istr("9"), istr("256"), istr("256"), istr("0")]
1268
- assert istr.long_sqrt("001156") == [istr("34"), istr("1156"), istr("9"), istr("256"), istr("256"), istr("0")]
1269
-
1267
+ assert istr.long_sqrt(34**2).lines == [istr("34"), istr("1156"), istr("9"), istr("256"), istr("256"), istr("0")]
1268
+ assert istr.long_sqrt("001156").lines == [istr("34"), istr("1156"), istr("9"), istr("256"), istr("256"), istr("0")]
1269
+ assert istr.long_sqrt(34**2).line_lengths == [2, 4, 1, 3, 3, 1]
1270
+ assert istr.long_sqrt("001156").line_lengths == [2, 4, 1, 3, 3, 1]
1270
1271
  assert (
1271
- istr.long_sqrt(34**2, as_str=True)
1272
+ istr.long_sqrt(34**2).output
1272
1273
  == """\
1273
1274
  3 4
1274
1275
  ----
@@ -1283,12 +1284,12 @@ def test_long_sqrt():
1283
1284
 
1284
1285
 
1285
1286
  def test_long_multiplication():
1286
- assert istr.long_multiplication(1234, 567) == [istr("1234"), istr("567"), istr("8638"), istr("7404"), istr("6170"), istr("699678")]
1287
- assert istr(1234).long_multiplication(567) == [istr("1234"), istr("567"), istr("8638"), istr("7404"), istr("6170"), istr("699678")]
1288
- assert istr("01234").long_multiplication("0567") == [istr("1234"), istr("567"), istr("8638"), istr("7404"), istr("6170"), istr("699678")]
1287
+ assert istr.long_multiplication(1234, 567).lines == [istr("1234"), istr("567"), istr("8638"), istr("7404"), istr("6170"), istr("699678")]
1288
+ assert istr(1234).long_multiplication(567).lines == [istr("1234"), istr("567"), istr("8638"), istr("7404"), istr("6170"), istr("699678")]
1289
+ assert istr("01234").long_multiplication("0567").lines == [istr("1234"), istr("567"), istr("8638"), istr("7404"), istr("6170"), istr("699678")]
1289
1290
 
1290
1291
  assert (
1291
- istr.long_multiplication(1234, 567, as_str=True)
1292
+ istr.long_multiplication(1234, 567).output
1292
1293
  == """\
1293
1294
  1234
1294
1295
  567
@@ -1302,12 +1303,12 @@ def test_long_multiplication():
1302
1303
 
1303
1304
 
1304
1305
  def test_long_division():
1305
- assert istr.long_division(1395, 45) == [istr("31"), istr("45"), istr("1395"), istr("135"), istr("45"), istr("45"), istr("0")]
1306
- assert istr(1395).long_division(45) == [istr("31"), istr("45"), istr("1395"), istr("135"), istr("45"), istr("45"), istr("0")]
1307
- assert istr.long_division(istr("01395"), istr("045")) == [istr("31"), istr("45"), istr("1395"), istr("135"), istr("45"), istr("45"), istr("0")]
1308
-
1306
+ assert istr.long_division(1395, 45).lines == [istr("31"), istr("45"), istr("1395"), istr("135"), istr("45"), istr("45"), istr("0")]
1307
+ assert istr(1395).long_division(45).lines == [istr("31"), istr("45"), istr("1395"), istr("135"), istr("45"), istr("45"), istr("0")]
1308
+ assert istr.long_division(istr("01395"), istr("045")).lines == [istr("31"), istr("45"), istr("1395"), istr("135"), istr("45"), istr("45"), istr("0")]
1309
+ assert istr.long_division(1395, 45).line_lengths == [2, 2, 4, 3, 2, 2, 1]
1309
1310
  assert (
1310
- istr.long_division(1395, 45, as_str=True)
1311
+ istr.long_division(1395, 45).output
1311
1312
  == """\
1312
1313
  31
1313
1314
  ----
File without changes