istr-python 1.1.37__tar.gz → 1.1.38__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.37
3
+ Version: 1.1.38
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
@@ -854,6 +854,12 @@ istr.getitem('1234',5, None) ==> None
854
854
  ```
855
855
  Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
856
856
 
857
+ #### long square root
858
+ 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.
859
+ E.g. `istr.long_sqrt(123 ** 2)` results in
860
+
861
+ `[istr('123'), istr('015129'), istr('1'), istr('51'), istr('44'), istr('729'), istr('729'), istr('0')]`
862
+
857
863
  #### generate istr with digits
858
864
 
859
865
  The class method `digits` can be used to return an istr of digits according to a given specification.
@@ -841,6 +841,12 @@ istr.getitem('1234',5, None) ==> None
841
841
  ```
842
842
  Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
843
843
 
844
+ #### long square root
845
+ 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.
846
+ E.g. `istr.long_sqrt(123 ** 2)` results in
847
+
848
+ `[istr('123'), istr('015129'), istr('1'), istr('51'), istr('44'), istr('729'), istr('729'), istr('0')]`
849
+
844
850
  #### generate istr with digits
845
851
 
846
852
  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.37"
8
+ __version__ = "1.1.38"
9
9
  import functools
10
10
  import itertools
11
11
  import types
@@ -855,6 +855,42 @@ class istr(str):
855
855
  def enumerate(cls, iterable, start=0):
856
856
  for i, value in enumerate(iterable, int(start)):
857
857
  yield cls(i), value
858
+
859
+ def long_sqrt(self):
860
+ """
861
+ this function does long squre root and returns all the lines to be written.
862
+ (modified from a ChatGPT code suggestion)
863
+ returns root, number (possibly with an extra 0) and the lines below the number, all istr-ed
864
+ """
865
+ number=istr(istr.interpret_as_str(self))
866
+ lines = []
867
+
868
+ if len(number)%2==1:
869
+ number = "0" | number
870
+
871
+ pairs=list(istr.batched(number,2,join=True))
872
+ root = istr(0)
873
+ remainder = 0
874
+
875
+ for pair in pairs:
876
+ dividend = remainder * 100 + pair
877
+
878
+ x = 0
879
+ for d in range(10):
880
+ if (20 * root + d) * d <= dividend:
881
+ x = d
882
+ else:
883
+ break
884
+
885
+ trial = (20 * root + x) * x
886
+ remainder = dividend - trial
887
+
888
+ root = root * 10 + x
889
+ lines.append(dividend)
890
+ lines.append(trial)
891
+ lines.append(remainder)
892
+ return [root]+[number]+ lines[1:] # ignore the first dividend
893
+
858
894
 
859
895
  def this_base(self):
860
896
  return self._this_base
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.37
3
+ Version: 1.1.38
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
@@ -854,6 +854,12 @@ istr.getitem('1234',5, None) ==> None
854
854
  ```
855
855
  Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
856
856
 
857
+ #### long square root
858
+ 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.
859
+ E.g. `istr.long_sqrt(123 ** 2)` results in
860
+
861
+ `[istr('123'), istr('015129'), istr('1'), istr('51'), istr('44'), istr('729'), istr('729'), istr('0')]`
862
+
857
863
  #### generate istr with digits
858
864
 
859
865
  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.37"
13
+ version = "1.1.38"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.10"
16
16
  dependencies = []
@@ -1217,7 +1217,14 @@ def test_compose():
1217
1217
  assert istr(":=") == ":="
1218
1218
  assert istr("=") == "="
1219
1219
 
1220
-
1220
+ def test_long_sqrt():
1221
+ lines=istr.long_sqrt(1234**2)
1222
+ assert lines==[istr('1234'), istr('01522756'), istr('1'), istr('52'), istr('44'), istr('827'), istr('729'), istr('9856'), istr('9856'), istr('0')]
1223
+ lines=istr.long_sqrt(1234**2+1)
1224
+ assert lines==[istr('1234'), istr('01522757'), istr('1'), istr('52'), istr('44'), istr('827'), istr('729'), istr('9857'), istr('9856'), istr('1')]
1225
+ lines=istr(1234**2).long_sqrt()
1226
+ assert lines==[istr('1234'), istr('01522756'), istr('1'), istr('52'), istr('44'), istr('827'), istr('729'), istr('9856'), istr('9856'), istr('0')]
1227
+
1221
1228
  if __name__ == "__main__":
1222
1229
  pytest.main(["-vv", "-s", "-x", __file__])
1223
1230
 
File without changes