## Number of nodes in a BST between two given numbers

Suppose there is a balanced binary search tree with $$n$$ nodes, where at each node, in addition to the key, we store the number of elements in the sub tree rooted at that node.

Now, given two elements $$a$$ and $$b$$, such that $$a < b$$, we want to find the number of elements $$x$$ in the tree that lie between $$a$$ and $$b$$, that is, $$a \leq x \leq b$$. This can be done with (choose the best solution).

$$O(\log n)$$  comparisons and $$O(\log n)$$ additions. $$O(\log n)$$ comparisons but no further additions. $$O \left (\sqrt{n} \right )$$ comparisons but $$O(\log n)$$ additions. $$O(\log n)$$ comparisons but a constant number of additions. $$O(n)$$ comparisons and $$O(n)$$ additions, using depth-first- search.

I got this ans Find Number of elements X in the Tree that lie between a and b but still not able to got , if only O(log n) comparison sufficient to find number of nodes??

Say if our answer is whole tree, then how only log n comparison can do that with log n addition?? We need n addition .

right??

## Google Analytics showing FAR fewer numbers than WebTrends. Why?

We are attempting to track event / file downloads for a particular .pdf file and in our investigation, we have set the time-frame to 07/15/2019 – 08/15/2019 and here are the numbers for total downloads for that period:

WebTrends = 9,987
Google Analytics = 4

And for pageviews on the page where the .pdf is located, here are the numbers for that period:

WebTrends = 780
Google Analytics = 272

Downloads are WAY OFF, like by 9,983 off of what GA shows and pageviews are off by 508

And since…

Google Analytics showing FAR fewer numbers than WebTrends. Why?

## Both R and Python provide wrong arithmetic with very large numbers

Background:

I was watching a video about the “Diophantine equation” on YouTube (click here). tl;dr – someone finally found the 3 numbers x, y, and z, where:

x^3 + y^3 + z^3 = 33  

The three numbers are:

x = 8866128975287528

y = -8778405442862239

z = -2736111468807040

However, both R and Python provide the wrong answers when I sum the cubes of these three numbers, while Unix’s bc calculator provides the right answer.

R output:

> x <- 8866128975287528 > y <- -8778405442862239 > z <- -2736111468807040 > (x^3 + y^3 + z^3) [1] -2535301200456458802993406410752 

Python output (in Jupyter notebook):

x = 8866128975287528 y = -8778405442862239 z = -2736111468807040  x^3 + y^3 + z^3 27885068152614 

bc (unix calculator) output:

x = 8866128975287528 y = -8778405442862239 z = -2736111468807040  x^3 + y^3 + z^3 33 

I was just doing this out of boredom at work, but this has me worried. Only the Unix calculator provides the right answer, and both of the wrong answers provided by R and Python are different from each other! Does this mean they are unreliable if/when I might need to use large numbers in a data science project?

Any help would be appreciated. Thank you!

## Both R and Python provide wrong arithmetic with very large numbers

Background:

I was watching a video about the “Diophantine equation” on YouTube (click here). tl;dr – someone finally found the 3 numbers x, y, and z, where:

x^3 + y^3 + z^3 = 33  

The three numbers are:

x = 8866128975287528

y = -8778405442862239

z = -2736111468807040

However, both R and Python provide the wrong answers when I sum the cubes of these three numbers, while Unix’s bc calculator provides the right answer.

R output:

> x <- 8866128975287528 > y <- -8778405442862239 > z <- -2736111468807040 > (x^3 + y^3 + z^3) [1] -2535301200456458802993406410752 

Python output (in Jupyter notebook):

x = 8866128975287528 y = -8778405442862239 z = -2736111468807040  x^3 + y^3 + z^3 27885068152614 

bc (unix calculator) output:

x = 8866128975287528 y = -8778405442862239 z = -2736111468807040  x^3 + y^3 + z^3 33 

I was just doing this out of boredom at work, but this has me worried. Only the Unix calculator provides the right answer, and both of the wrong answers provided by R and Python are different from each other! Does this mean they are unreliable if/when I might need to use large numbers in a data science project?

Any help would be appreciated. Thank you!

## How to compute within a Multi tape turing machine [a binary substraction between 2 numbers and result on 3rd tape]?

I’m trying to compute a Multi-tape turing machine (of 3 tapes) that follows this statement.

“A binary subtraction operation between the first and second tape printing the result on the third tape”

I’ve been trying to do it in JFlap but I reached a halt point being pretty confused in this topic overall.

Any help regarding this MTTM would be really appreciated.

## How would I find out how how to depict a certain set of numbers from a sum [on hold]

I’m looking for an algorithm of sorts for my problem. I have 10 buttons, Alpha = 1, Bravo = 2, Charlie = 4, Delta = 8, Echo = 16, Fox = 32, Golf = 64, Hotel = 128, India = 256, Juliet = 512, Each button can only be pressed once at the same time, so for example; If I pressed Alpha, Bravo, Charlie and Delta at the same time, I would get 15. No number will ever be a duplicate either and should only go up to about 1023 possible combinations. Any ideas?

## Is this an adequate outline for a basic filter to prevent testing of stolen credit card numbers on my credit card charge script?

I have a web store with Stripe integration that has been used by one or more individuals to test stolen credit card numbers. Their method of testing the cards is to direct a large number of charge attempts at my credit card charge script both in a short period of time and over many days.

I can do some PHP scripting but am not a full-time or formally-trained developer and so want to stop the fraudulent use of my Stripe account in a manner that keeps things as technically simple as possible for me.

My plan is to develop an IP-based filter for my credit card charge script. Below is my general concept for the filter.

1. Create a MYSQL database with fields for IP, date of this IP’s last charge attempt, number of charges by this IP today, all-time total number of charges by this IP and blocked user.

2. When someone makes a charge attempt, before sending it to Stripe, check whether their IP is already in our database of IPs that have made a charge attempt in the past.

A. If the IP is not in our database, add it to the database and allow the charge attempt to be sent to Stripe.

B. If the IP is in our database, check to see if the blocked user field is set to “yes”. If so, do not allow the charge attempt and present an error message to the user.

C. Check to see if the date of this IP’s last charge attempt is today.

i. If the IP’s date of last charge attempt is not today, store today’s date in the date of this IP’s last charge attempt database field, set the number of charges today to 1, and allow the charge attempt to be sent to Stripe.

ii. If the date of last charge attempt by this IP is today, increment the number of charges by this IP today database field. If the number of charges hits a predetermined limit, do not allow the charge attempt and present an error message to the user. If the number of charges by this IP today is below the predetermined limit, do not block the charge attempt.

iii. increment the all-time total number of charges by this IP field. If the number of charges hits a predetermined limit, do not allow the charge, present an error message to the user, and set the blocked user field to “yes” for this IP. If the all-time total number of charges by this IP is below the predetermined limit, allow the charge attempt.

The above filter concept assumes individuals testing stolen credit card numbers will not be able to frequently change their IP to circumvent this primitive rate limiter. Is this a safe assumption? Are there any other potential problems with the above approach or better ways to do this?

## What are some efficient and easy-to-remember schemes for randomly-generated sequential ID numbers?

I am considering a new scheme for order numbers for our ERP system. For reasons I’d like not to get into, the number must be fairly easy to remember and must say something about the time (or at least sequential order) the order was placed. This eliminates things like UUIDs as an option, since those are both very hard to remember and lack any time information.

Another constraint is that I’d like the scheme to be able to handle multiple users generating numbers without any collisions. This can be done with something like a ticket server (which is plan B if this fails). This is where UUIDs would be perfect, if they met the other criteria.

I’m looking for a balance between minimizing the likelihood of collisions and the ease of remembering the number. This sounds impossible, but our business is small and these collisions would be very unlikely to happen even if the ID were a simple timestamp.

One idea was to essentially generate a number that represented a timestamp down to the current second, and append another few random digits to significantly decrease the chances of a collision. The more digits I add, the lower the probability of a collision, but the angrier my coworkers would be at me.

Is this even in the ballpark of sane? This seems like a problem others have run into and I’m curious to know how they solved it.

## how to validate textbox not to enter numbers in textbox

How to validate textbox not to enter numbers in textbox

function checkNum() {     if ((event.keyCode> 64 && event.keyCode< 91) || (event.keyCode > 96 &&      event.keyCode < 123) || event.keyCode == 8)     return true;     else      {         alert("Please enter only char");         return false;       } } <asp:TextBox ID="txtcity" runat="server" onkeypress=" return checkNum();"></asp:TextBox> 

Can anyone explain me the flow of code?

## What untyped term inhabits induction on natural numbers in CoC?

Induction on Church-encoded natural numbers (which I will call indNat) can not be defined within the Calculus of Constructions.

If we assumed indNat as an axiom, is there an untyped term that would have the semantics of the induction function? What if we had Scott-encoded natural numbers and fix?

Can induction be inhabited in CoC + fix (such that the function would have the proper semantics, not an infinite loop)?