How to solve for y in formula (y*known_number)%145 = 81 without a loop
Is it possible to solve for y in this equation without a loop?
known_number = 7
(y * known_number) % 145 == 81
I'm using a loop, but i'm thinking since it's simple multiplication, there may be a formula that can be used to solve it without a loop, or is there?
Here is my code i use to solve for it:
known_number = 7
for y in range(145):
if (y * known_number) % 145 == 81:
print(y) # > 53
1 answer

There is an other way, though it has a different kind of loop if you look closely.. anyway, it can be solved like this:
y*known_number ≡ 81 (mod 145) y ≡ 81 * known_number ^ 1 (mod 145)
Which works iff
known_number
indeed has a modular multiplicative inverse modulo 145, which happens when the GCD between the known number and the modulus is 1 (gcd(7, 145) = 1
so in this case it would work). Here the inverse is 83, so we computey = 81 * 83 % 145 = 53
.In general you may find that inverse by using the Extended Euclidean Algorithm, but also through various other methods, for example
pow(known_number, 111, 145)
, where 111 istotient(145)  1
. Computing a totient is not easy unless you have the primefactorization of the number. Thepow
function hides a loop, but a much shorter loop than bruteforcing the equation.
See also questions close to this topic

Why doesn't pyngrok detect my config file?
I am trying to use my own configuration file with
pyngrok
but I don't understand why it does not detect it, my project needs to be run forcefully withsudo
, thereforengrok
does not detect the configuration file in theroot
home directory for some users, it is that's why I want to mount my own configuration file in my project directory, here is my code:from pyngrok import ngrok, conf import os from pathlib import Path import re def ngrok_start (): file = Path (".config/ngrok.yml") if file.exists(): os.system("kill 9 $(pgrep ngrok)") ngrok.DEFAULT_CONFIG_PATH = ".config/ngrok.yml" ngrok.connect(443, "tcp") while True: ngrok_tunnels = ngrok.get_tunnels() url = ngrok_tunnels[0].public_url if re.match ("tcp://[09]*.tcp.ngrok.io:[09]*", url) is not None: print ("Ngrok TCP:" + url) break
With my code I get the following error:
Traceback (most recent call last): File "ngrok.py", line 27, in <module> ngrok_start () File "ngrok.py", line 20, in ngrok_start ngrok.connect (443, "tcp") File "/usr/local/lib/python2.7/distpackages/pyngrok/ngrok.py", line 181, in connect timeout = pyngrok_config.request_timeout)) File "/usr/local/lib/python2.7/distpackages/pyngrok/ngrok.py", line 321, in api_request status_code, e.msg, e.hdrs, response_data) pyngrok.exception.PyngrokNgrokHTTPError: ngrok client exception, API returned 502: {"error_code": 103, "status_code": 502, "msg": "failed to start tunnel", "details": {"err": "TCP tunnels are only available after you sign up. \ nSign up at: https://ngrok.com/signup\n\nIf you have already signed up, make sure your authtoken is installed. \ nYour authtoken is available on your dashboard: https: //dashboard.ngrok.com/auth/yourauthtoken\r\n\r\nERR_NGROK_302\r\n "}} No handlers could be found for logger "pyngrok.process"
My script is in the lib folder and my configuration file in
.config/ngrok.yml
, in which I have my token but I can't detect it, I hope you can support me, thanks. 
Cythonize python3 code without using type hints/annotations
Is it possible to cythonize python3 code without using type hints/annotations?
I am trying to cythonize a small python3 code base and I am facing some issues as some of the type hints in the code are incorrect and this is causing issues when trying to run the cythonized code.
Here is a simplified example,
a.py
def test_func(arg1) > str: return {"hello": "world"}
The error when trying to run the code after running cythonize
TypeError: Expected unicode, got dict
Everything works fine if I remove the
> str
annotation. So, it there a way to tell cython to ignore all annotations?I am aware the correct way of resolving this is to fix the type hints, but I am trying to find an alternate solution while I fix the annotations.
This is my setup.py
#cython: language_level=3 #cython: annotation_typing=False from setuptools import setup from setuptools.extension import Extension from Cython.Build import cythonize from Cython.Distutils import build_ext setup( name="lib", ext_modules=cythonize( [ Extension("pkg1.*", ["pkg1/*.py"], include_dirs = ["."], extra_compile_args = ['O3']), ], build_dir="build", compiler_directives=dict( always_allow_keywords=True, language_level=3)), cmdclass=dict( build_ext=build_ext ), packages=["pkg1"] )
Thanks.

How to press 'Scroll Lock' button with keyboard library in python?
I want to press 'Scroll Lock' button
so I've imported keyboard:
import keyboard
and try to execute itif(A3()==1): keyboard.press("scrolllock")
The loop works! if I change
keyboard.press("scrolllock")
forprint("hello")
it works. If I use 'pyautogui' library to press it, it works too.But why it isn't working with 'keyboard'? Where can I found all names of the keys for this library?
ValueError: ("Key 'scrolllock' is not mapped to any known key.", ValueError("Key name 'scrolllock' is not mapped to any known key."))

Only getting "0" and "NAN" values in array?
I am trying to make a T2 map (array) from some dicom images, but my code is only producing a T2 map of "NAN" and "0" values. Here is the block of code I am currently working with:
# T2 Calculations T2_map = np.empty((number_of_segments, number_of_segments, number_of_segments)) for i in range(1, number_of_slices + 1): if 3 + (i  1) <= number_of_segments: I1 = (dcm_pixel_array["array" + str(3 + (i  1))]) * 2 else: I1 = (dcm_pixel_array["array" + str(number_of_segments)]) * 2 if 3 + ((7 * number_of_slices) + (i  1)) <= number_of_segments: I8 = (dcm_pixel_array["array" + str(3 + ((7*number_of_slices) + (i1)))]) * 2 else: I8 = (dcm_pixel_array["array" + str(number_of_segments)]) * 2 print("I1:", I1) print("I8:", I8) print("") for j in range(I1.ndim): for k in range(I1[0].ndim): if (I1[j][k]) == 0 or (I8[j][k]/I1[j][k]) <= 0 or (np.log((I8[j][k]) / (I1[j][k]))) == 0: T2_map[j, k, i] = "NAN" elif (3.03  (17.85 + 14.87)) / (np.log(I8[j][k] / I1[j][k])) < 0: T2_map[j,k,i] = 0 elif (3.03(17.85+14.87))/(np.log(I8[j][k] / I1[j][k])) > 100: T2_map[j,k,i] = 100 else: T2_map[j,k,i] = ((3.03(17.85+14.87))/(np.log(I8[j][k] / I1[j][k]))) print() print("T2 map:", T2_map) print()
The values in I1 and I8 range from 0 to 16, so this code should technically produce actual numeric values. Any recommendations as to how I should proceed with troubleshooting this problem?
Clarifications: number_of_segments = 288, number_of_slices = 36
Thank you! :)

Sample Variance / kmeans problem with price/number/element in array (remove tail from normal distribution with irrelevant values )
As a disclaimer:
Hello, I am not sure about correct topic of this question. Also, couple of people will find it irrelevant for StackOverflow, and appropriated for MathExchange, but as for me I am solving a practical problem, and I guess this question and relevant answer on it could be useful for StackOverflow community, and for all those, who are dealing with mongoDB's
$bucket
operator (or it's SQL analogies), and building cluster/heatmap chart data.I have an array of unique/distinct values of prices from my DB (it's always array of
numbers
, with .01 precision).As you may see, most of it values are between ~8 and 40 (in this certain case).
[ 7.9, 7.98, 7.99, 8.05, 8.15, 8.25, 8.3, 8.34, 8.35, 8.39, 8.4, 8.49, 8.5, 8.66, 8.9, 8.97, 8.98, 8.99, 9, 9.1, 9.15, 9.2, 9.28, 9.3, 9.31, 9.32, 9.4, 9.46, 9.49, 9.5, 9.51, 9.69, 9.7, 9.9, 9.98, 9.99, 10, 10.2, 10.21, 10.22, 10.23, 10.24, 10.25, 10.27, 10.29, 10.49, 10.51, 10.52, 10.53, 10.54, 10.55, 10.77, 10.78, 10.98, 10.99, 11, 11.26, 11.27, 11.47, 11.48, 11.49, 11.79, 11.85, 11.9, 11.99, 12, 12.49, 12.77, 12.8, 12.86, 12.87, 12.88, 12.89, 12.9, 12.98, 13, 13.01, 13.49, 13.77, 13.91, 13.98, 13.99, 14, 14.06, 14.16, 14.18, 14.19, 14.2, 14.5, 14.53, 14.54, 14.55, 14.81, 14.88, 14.9, 14.98, 14.99, 15, 15.28, 15.78, 15.79, 15.8, 15.81, 15.83, 15.84, 15.9, 15.92, 15.93, 15.96, 16, 16.5, 17, 17.57, 17.58, 17.59, 17.6, 17.88, 17.89, 17.9, 17.93, 17.94, 17.97, 17.99, 18, 18.76, 18.77, 18.78, 18.99, 19.29, 19.38, 19.78, 19.9, 19.98, 19.99, 20, 20.15, 20.31, 20.35, 20.38, 20.39, 20.44, 20.45, 20.49, 20.5, 20.69, 20.7, 20.77, 20.78, 20.79, 20.8, 20.9, 20.91, 20.92, 20.93, 20.94, 20.95, 20.96, 20.99, 21, 21.01, 21.75, 21.98, 21.99, 22, 22.45, 22.79, 22.96, 22.97, 22.98, 22.99, 23, 23.49, 23.78, 23.79, 23.8, 23.81, 23.9, 23.94, 23.95, 23.96, 23.97, 23.98, 23.99, 24, 24.49, 24.5, 24.63, 24.79, 24.8, 24.89, 24.9, 24.96, 24.97, 24.98, 24.99, 25, 25.51, 25.55, 25.88, 25.89, 25.9, 25.96, 25.97, 25.99, 26, 26.99, 27, 27.55, 28, 28.8, 28.89, 28.9, 28.99, 29, 29.09, 30, 31.91, 31.92, 31.93, 33.4, 33.5, 33.6, 34.6, 34.7, 34.79, 34.8, 35, 38.99, 39.57, 39.99, 40, 49, 50, 50.55, 60.89, 99.99, 20000, 63000, 483000 ]
The problem or remove Normal distribution tail of (nonnormal) elements
I need to find/determinate irrelevant values, somekind of «dirty tail», and remove/exclude it. Actually I don't even need to remove it from array, the real case is to find the
latest
relevant number, to define it as acap
value, for finding a range betweenfloor
(min relevant) andcap
(max relevant), like:floor value => 8 cap value => 40
What am I talking about?
For example, in this certain cases: it will be values after 40:
49, 50, 50.55, 60.89, 99.99, 20000, 63000, 483000
or everything else, after 60+, something outside the curve of normal distribution.What have I already tried?
To be honest, I was 80% sure that I solve this problem couple of months ago, via this part of code:
let priceRangeArray = [1,2,3...] let priceArray = [] /** Data is already sorted by price ascending */ const L = priceRangeArray.length; /** Sample Variance algorithm */ for (let i = 1; i < L; i++) { /** * We skip the real first value, because it could be too low * The secondfirst value is also ignored */ if (priceRangeArray[i1]) { /** sV becomes previous sV */ prev_sV = sV; /** This part seems checking ok/nok values */ if (prev_sV * 1.1 < sV) { break; } } /** * Yo, it's a sample variance, right? * 1 / 100 * (50 ^ 2)  ( 1 / 100 * 50) ^ 2 * @type {number} */ sV = ( 1 / L * (Math.pow(priceRangeArray[i],2)))  (Math.pow((1 / L * priceRangeArray[i]),2)); /** Push every price to array of prices */ priceArray.push(priceRangeArray[i]); } console.log(priceArray)
But it seems I was a bit drunk when was writing it, the only thing that I can remember, that I have found probobal solution at Wikipedia's Variance article. The logic is quite simple, as long as I can't remove beginning (first 2 values, even if they are too low), I starting from 3rd element of array and check every next one of them, with my
control
formula (something with sqrt (pow^2)) but as for now I am not sure, that this solution is the most effective one.So I will appreciate every comment / answer / direction in this question. If you already faced the same problem, share your experience here. If you know some relevant math article about this problem? Don't be shy, post a link. I believe in StackOverflow community and I promise, that every piece of useful information will be rewarded with
+rep
from me.I will also appreciate any code, no matter it's
javascript
,python
orgoland
or even something else. But, first hand, I am looking for a logical solution of the problem. Like «how should I check every next value in such array for socalled normality»P.S. Also, please don't provide a tooobvious solutions like:
 Let's take 0.95% or
 Let's check every next value for (x2 or *no more then 0.1)
I have tried everything of that before. Data could be distributed non normal way, like:
[ 1,2,3,4, 13,14,16,22, 100, 500000]
so, in that case,cap
value could be 4. but it's wrongAfter googling with
Finding outliers without assuming normal distribution
query, gives me an idea that I am not the only one interested in this problem. 
Aggregation or simulation of inordinate data for chart plotting
I have a problem with visualizing data.
I too have the problem naming my problem and therefor searching for it or giving it a fitting title.
Excuse me, as the description of my problem is therefor a bit lengthy.I need to visualize data in a simple line chart.
But there are requirements and technical limitations that require me to prepare the data before I can plot the chart.The first limitation is that the software component, responsible for the plotting, is very primitive and can't be changed.
Primitive in the way, that it only plots tuples of data. The first value in the tuple will be the abscissa value and all other values are separate ordinate values for that abscissa value. The software component then just connects every nth ordinate value from abscissa to abscissa in the order the tuples where added.
But herein doesn't lie my problem.My actual problems are:
 the amount of data points I can plot are limited and scrolling is not an option
 the provided abscissa data is not continuous
 the resolution of the plot has to be variable
I solved the problem of converting generic numeric abscissa data into a continuous stream of data points, so that i have a e.g. nice chronological flow.
I too have solved the problem of "zooming" into the diagram, at least in the case when the provided abscissa data points align with the converted ones. (I calculate the line equations between the data points and just put in the missing abscissa values.)
But in the case when the abscissa data point aren't aligned, for "zooming" out or when the limit of plotable data points is reached, I am divided on how to tackle the corresponding ordinate values.I have two main contenders but am not really sure if either one is "right" and represents the true data good enough.
 The first one is simple: I use line equations to connect the real ordinate values, then just plug in my converted continuous abscissa values to get the appropriate ordinate values and together hand them over to be plotted.
 The second one involves calculating the differential values of the real ordinate values (y_{n}  y_{n1}) and then for an individual abscissa value forming the sum of all differential values that are equal or below that abscissa value.
Take the following arbitrary example, where
x
are the real abscissa data points andy
are the real ordinate data points.
(Notice that the abscissa values have gaps.) x  y    0 0  1 1  3 7  6 0  8 1  9 8  10 0  12 5  13 3  14 1  15 1  17 3  18 9  20 6
If I where now exemplary wise only able to plot even abscissa values, this example would produce the following numbers.
x
andy
are again the same real data point values andd
are the calculated differential ordinate values.
x'
are the abscissa values I need to plot, together withLE
being the ordinate values simulated by the line equations andD
the ordinate values simulated by summing the differential values in columnd
. x  y  d   x' LE  D     0 0 0  0 0 0  1 1 1  2 4 1  3 7 6  4 4.67 7  6 0 7  6 0 0  8 1 1  8 1 1  9 8 7  10 0 0  10 0 8  12 5 5  12 5 5  14 1 1  13 3 2  16 2 1  14 1 2  18 9 9  15 1 0  20 6 6  17 3 2  18 9 6  20 6 3
Plotted with Excel it looks like this:
Chart with original data and both simulating alternativesAs you can see both alternatives swallow the peak between 8 and 10.
And as the line equations represent the original "better" between 14 and 18, the alternative with the differential values represents the original "better" between 0 and 6.I guess I am looking for the correct mathematical way to do this and/or for resources about this topic.
I have the hunch that this kind of thing probably depends on the data that is displayed but then again have no idea what to search for and am not sure if my method(s) are "flawless".
Generally speaking I would like the "best" and "correctest" approach or the plural of this, as I will need to be able to plot "all kinds" of data.
The data to be plotted comes out of an REP system and at the moment I can think of: financial data of any kind and nature, production and performance numbers from machines, stocks or workers or statistics about clients, machines, teams, individual humans, products, etc.I hope my description is clear enough. If not, please let me know, and I will do what I can to iron out troublesome parts or add additional information.

Fortran DMOD vs Python numpy.remainder, update
Why do I get different results using "DMOD" in Fortran and "numpy.remainder" in Python?
In Fortran:
DOUBLE PRECISION aaa,bbb aaa = 2.11561d0 bbb = 1.19841d0 out = DMOD(aaa, bbb) print*,out
and I get: 0.917200029
In python:
import numpy as np print(np.remainder(2.11561,1.19841))
and I get: 0.9172000000000002

How to get the player bed location via minecraft mod?
Im coding my first mod in fabric and want to print my bed location. How to code that?

Compiling a minecraft mod from github
Ye hi ive been trying to compile a mod from github but i keep running into problems if you can help compile this mod for me add me on discord at ffoxxeyy#8464