Algebra formula needed! Calculate a charge price to compensate for a fee - equation-solving

So this is really stumping me, and I think it should just be a linear equation.
Suppose I am charging my client $1000 for a good or service. The client wants to charge this to their credit card. I use Square as my payment processor, and they take a 2.75% cut of the transaction.
This cut is $27.50 for a $1000 sale, so the settlement ends up being only $972.50. Suppose I want the customer to pay the $27.50 fee, but they also want that fee charged to their card.
Well, if I charge $1027.50, Square will take a 2.75% cut of that amount, so their cut will be $28.26, and my settlement would be $999.24.
It's closer to $1000, but not exactly $1000.
I determined on a spreadsheet through trial and error that I'd need to charge $1028.28 to offset the processing fee and get my desired exact settlement.
I've been wracking my brains to think of a simple algebraic equation. It seems like it should just be a single variable, but maybe not?

Welcome to Stack Overflow. Not sure if it belongs on SO (not a programming question), but this is what my arithmetic teacher would say:
You charge X dollars. You want to get $1000 after fees. Fees are 2.75%; so you get 97.25%. Therefore X * .9725 = 1000. X = $1,028.28

Related

multiple percentages at one time in solidity

hello i have found a code that can (in solidity) divide an amount 50 /50 and send it off my problem is that i need to be able to change the amounts in percentages of a whole amount and i am not sure how to go about this. to clarify i take 10 percent of a transaction and it gets sent to say a tax wallet and I need part of this say 3% to go towards a burn wallet and 2% to a mint wallet and 5% to go to lp I don't need the mint or burn function or auto lp just the method of automatically dividing it up when its deposited into the initial 10%s wallet. thank you ahead of time .
i tried searching for several hours last night and I could only find a script that did 5050 but with no percentages that i could modify on my own .

Algorithm sorting details, but without excluding

I have come across a problem.
I’m not asking for help how to construct what I’m searching for, but only to guide me to what I’m looking for! 😊
The thing I want to create is some sort of ‘Sorting Algorithm/Mechanism’.
Example:
Imagine I have a database with over 1000 pictures of different vehicles.
A person sees a vehicle, he now tries to get as much information and details about that vehicle, such as:
Shape
number of wheels
number and shape of windows
number and shape of light(s)
number and shape of exhaust(s)
Etc…
He then gives me all information about that vehicle he saw. BUT! Without telling me anything about:
Make and model.
…
I will now take that information and tell my database to sort out every vehicle so that it arranges all 1000 vehicle by best match, based by the description it have been given.
But it should NOT exclude any vehicle!
So…
If the person tells me that the vehicle only has 4 wheels, but in reality it has 5 (he might not have seen the fifth wheel) it should just get a bad score in the # of wheels.
But if every other aspect matches that vehicle perfect it will still get a high score.
That way we don’t exclude the vehicle that he has seen, and we still have a change to find the correct vehicle.
The whole aspect of this mechanism is to, as said, sort out the most, so instead of looking through 1000 vehicles we only need to sort through the best matches which is 10 to maybe 50 vehicles out of a 1000 (hopefully).
I tried to describe it the best I could in a language that isn’t ‘my father’s tongue’. So bear with me.
Again, I’m not looking for anybody telling me how to make this algorithm, I’m pretty sure nobody even wants of have the time to do that for me, without getting paid somehow...
But I just need to know where to look regarding learning and understanding how to create this mess of a mechanism.
Kind regards
Gent!
Assuming that all your pictures have been indexed with the relevant fields (number of wheels, window shapes...), and given that they are not too numerous (a thousand is peanuts for a computer), you can proceed as follows:
for every criterion, weight the possible discrepancies (e.g. one wheel too much costs 5, one wheel too few costs 10, bad window shape costs 8...). Make this in a coherent way so that the costs of the criteria are well balanced.
to perform a search, evaluate the total discrepancy cost of every car, and sort the values increasingly. Report the first ten.
Technically, what you are after is called a "nearest neighbor search" in a high dimensional space. This problem has been well studied. There are fast solutions but they are extremely complex, and in your case are absolutely not worth using.
The default way of doing this for example in artificial intelligence is to encode all properties as a vector and applying certain weights to each property. The distance can then be calculated using any metric you like. In your case manhatten-distance should be fine. So in pseudocode:
distance(first_car, second_car):
return abs(first_car.n_wheels - second_car.n_wheels) * wheels_weight+ ... +
abs(first_car.n_windows - second_car.n_windows) * windows_weight
This works fine for simple properties like the number of wheels. For more complex properties like the shape of a window you'll probably need to split it up into multiple attributes depending on your requirements on similarity.
Weights are usually picked in such a way as to normalize all values, if their range is known. Optionally an additional factor can be multiplied to increase the impact of a specific attribute on the overall distance.

How would I clip a continuous action in an actor-critic agent?

Let's say we have a bot that has some money and some shares. The input is a list of prices for the last 30 days. It doesn't use an RNN and the prices are entered all at the same time. The output is a continuous action where a positive number is to buy and a negative number is to sell the amount of the stock. How can I restrict the action space so that it is clipped between how many shares it has(the lower bound) and how much money it has(the upper bound)?
Should I have it clipped or just penalize an illegal action? Which option would create the best results?
You can penalise illegal actions, but in my experience it hasn't shown to have a good effect on the AI (one more thing to worry about). Just clip the output so that if it tries to use more money that it has available it spends all its money. If it tries to sell more of a stock than it has, it sells all of it's stock. The network will learn what happens when it tries to use more resources than it has quite quickly, so it wont cause any degrade in performance.
The AI cannot sell a share amount it doesn't have or buy a share which is worth more than the money it has, so you should not allow this kind of transaction at all. However, if your AI looks at the trends and prefers shares which are expected to be more valuable in the near future, then there is a good chance that the total amount of property will be higher the next day. Let's say share1 had a starting value of s1 and an ending value of e1 and share2 had a starting value of s2 and an ending value of e2, then in the case when
e1 / s1 > e2 / s2
it is better to give share1 a higher priority. If any si / ei is smaller than 1, then the AI should not invest into it.
Also, you should value stability, if a share's value has increased continously in the last few days, then it has an increasing trend. If a share's initial value is smaller than the ending value, but in the last few days its value decreased, then it might be a decreasing trend and the share should not be preferable. Such rules need to be implemented and when they are conflicting, the AI must be able to intelligently choose its priorities.

Knapsack variation?

So, I'm going shopping, and I have x money, my truck can take up to y weight, and each item has a bonus credit, a weight and a price. The output should give the maximum bonus credit that can be obtained such that the total weight of the chosen items does not exceed the capacity of the truck and the money I have to spend!
Do you know the name of the algorithm? How should I proceed? I have to do it in C!
What have you tried?
These types of problems usually fall into the category of optimization or constraint satisfaction.
Try writing a functional expression for your problem and see if you can solve it with simple calculus or simplex methods.
I know of two variations of the knapsack problem. The 0-1 version can't contain fractional weights (take it or leave it), for example, I can't take half of the second best choice. The other version is the opposite, fractional items are allowed. This small difference is extremely significant and works in favor of the fractional version.
The fractional version can be solved via a greedy algorithm. You can simply take as much as you can of the item with the most VALUABLE "unit price". Repeat until your truck is full.
The 0-1 version is a bit harder, as it can't be solved via a straightforward greedy algorithm. As an example, say your truck can carry 800lbs. We can pick from a
1 Table weighing 500lbs with a value of $1000 (unit price $2/lb)
1 Bench : weight - 701lb : value - $1577.25 : unit $2.25/lb
3 Bookcases : weight - 100lb : value - $200 : unit $2/lb
A greedy algorithm would take the bench for a total of $1577.25.
The optimal value is 3 bookcases and the table = $1600.
If the above were the fractional knapsack version would would simply take the bench and 99lbs of table/bookcase for a total of $1775.25.
In the 0-1 case we would need to use something like dynamic programming to examine all solutions.
The item weights and item prices are constraints. The bonus credits are the objectives. Thus, you have a multi-dimensional knapsack problem (one objective; two constraints). The well-known dynamic programming solution knapsack will generalize, but the complexity grows exponentially with the number of constraints.

Best way of splitting website into Cities/Countries?

i am running a dating website, or better say, try to. I want to be as generic
as possible in terms of, coverage for countries.
Since it's a local dating oriented website, i have to keep track of cities
and so on so i am running into a few problems:
I need to have information about cities, people could join from
(a country i don't know anything about, i really can't decide about a city
or anything)
When people join from different countries, they would like to see people
near by. How would you approach this sort or problem?
This may seem like 2 easy points but they really make me some trouble these
days.
** Try to approach them as Database related issues **
I circled around SE and find this to be the best point to ask, not any other
SE website.
Thank you very much
The full name of a city in the USA is {country_name, state_name, city_name}. I say that assuming that, on a global scale, what I call state_name is not unique. I can easily imagine some region of a Latin American country being named "Nevada" or "Colorado".
You also have the problem of spelling. An American living in Germany might say she lived in Cologne, North Rhine-Westphalia, Germany. A German living there would call it "Köln".
"Nearby" is an even tougher nut to crack. I used to live in a big city. It wasn't unusual to drive an hour on an Interstate highway to pick up my date. I thought of that as "nearby". Now I live in a small city. Now 30 minutes seems like a long drive, but it's probably only 15 or 20 miles instead of 65 or 70.
If you live in a border town, 15 miles might be in a different country. Maybe two different countries.
I think your best bet is to use a geolocation API or service to get the latitude and longitude of new cities when they're inserted. The calculation of distance given two points is straightforward, but it leads to badly performing queries unless you use a bounding box. (You don't want to calculate the distance to every city in Texas to find people "near" Waco.)
Get the latitude/longitude for all of the cities. Don't worry about exact distances.
Play with excel and find the maximum change for latitude and/or longitude (Δlat or Δlong) for given distances (10miles, 25 miles, 50 miles), and then when you search for others, just search the database for within (Firstuser'sLongitude +/- Δlong) and within (Firstuser'sLatitude +/-Δlong).
I don't think people will mind the difference between 10miles and 10*2^0.5 miles.

Resources