algorithms – Create binary numbers with a described pattern

I am looking for an algorithm that can create numbers following certain patterns. Let’s say I have a binary number of size n and the patterns I would like to create is having 0s and 1s in equal numbers such that they are repeated with different spacings. The pattern of repetition and spacing will be clear from the example below:

If size is 4, set of numbers are: {0101, 0011}.
If size is 8, set of numbers are: {01010101, 00110011, 00001111}.
If size is 16, set of numbers are: {“01”(8), “0011”(4), “00001111”(2)}.
If size is n, set of numbers are: {“01”
(2^n-1), “0011”(2^n-2), “00001111”(2^n-3), …}
Note: Sorry for the bad notation!

For this problem, n will always be an integer power of 2 (e.g. 2, 4, 8, 16, 32 …). So the size of set will always be $log_2$(n). Is there an algorithm that can generate each of these numbers in the set with algorithm in the range of O(1) to O(n)?


python – use regex to separate a list of serial numbers into multiple lists with matched prefix

The question comes from How to separate a list of serial numbers into multiple lists with matched prefix? on Stack Overflow.


sn = ('bike-001', 'bike-002', 'car/001', 'bus/for/001', 'car/002', 'bus/for/002')

Intended output:

# string with same prefix will be in the same list, e.g.:

sn1 = ('bike-001', 'bike-002')
sn2 = ('car/001', 'car/002')
sn3 = ('bus/for/001', 'bus/for/002') 

The original thread already had a brilliant answer using .startswith(<sub_str>), however I still want to use regex to solve the question.

Here’s what I’ve tried: I use re.sub() to get the prefix and to get the 3-digits serial number. I’d like to know if there is a better way (like using one-time regex function) to get the solution.

import re

sn = ('bike-001', 'bike-002', 'car/001', 'bus/for/001', 'car/002', 'bus/for/002')
sn_dict = {}
for item in sn:
    category = re.sub(r'd{3}', "", item)
    number ='d{3}', item).group()
    if category not in sn_dict.keys():
        sn_dict(category) = ()
    sn_dict(category).append(category + number)

After running the script we will have the following sn_dict:

    'bike-': ('bike-001', 'bike-002'), 
    'car/': ('car/001', 'car/002'), 
    'bus/for/': ('bus/for/001', 'bus/for/002')

Trace Cell Phone Numbers Different Ways to Trace a Cell Phone Number

Almost each person people have attempted or even simply tried to trace cellular telephone numbers however just a few genuinely realize a way to. We all have our reasons why one might need to trace a sure wide Phone Number List variety but irrespective of what they’re, the maximum essential thing is that you can eventually remove the prank callers or the suspicious wide variety that is always at your month-to-month bills. There are numerous methods so that you Phone Number List can hint a particular number and it’s miles as much as you as a way to healthy your precise scenario.

The oldest method to hint cellular phone numbers might be with the usage of an internet smartphone book but you must realize that this will only give you confined searches. The on-line phrasebook may be powerful if you are only trying to find a residential wide variety because cellular numbers are taken into consideration to be private and hence they’re impossible to be indexed on an internet cellphone book. Cell numbers are supposed to be non-public because they’re provided for via telecommunications businesses for private use. So it is rare that there are public statistics which can list all such numbers. However, there are nevertheless methods so you can hint those numbers without invading one’s privacy. Of path, that is best Phone Number List possible if you know what assets to use and the way to use them. You can trace cellular telephone numbers through the usage of your regular seeps like Google and Yahoo. Since those search engines like google and yahoo have a totally big community and almost everybody are the use of them, you may handiest anticipate that in some unspecified time in the future the variety in question were used in some private or enterprise count number Phone Number List on line. Of route, you’re just taking your possibilities because these search engines like google and yahoo do now not simply have a database that is devoted in storing cell numbers.

There are also reverse cellular smartphone directory sites that capabilities like a network website. Actually, they do no longer have Phone Number List other ways of accumulating mobile numbers except by means of asking their numbers to voluntarily listing their numbers. This isn’t always very practical due to the fact no longer anybody go to these styles of websites and now not absolutely everyone are inclined to provide their non-public numbers. The simplest and most handy manner in tracing cellular phone numbers is thru an internet reverse cellular smartphone lookup service. There are plenty of those sorts of web sites within the net and most of them are very dependable. You most effective need to go into the Phone Number List range in query and you may get the records that you need within some seconds. Aside from the name of the owner, you may additionally see other statistics such as the deal with, civil status, and many others.


2 numbers are chosen at random from set ${1,2,3..5n}$ (without replacement). Find the probability that $n_1^4-n_2^4$ is divisible by 5

All the numbers can be written in the form of $5k,5k+1,5k+2,5k+3,5k+4$

Also the given expression can be written as
$$(n_1-n_2)(n_1+n_2)(n_1^2 + n_2^2)$$

Case 1

Let $n_1-n_2$ be a multiple of 5

Which implies that both numbers have to be of the from $5k$, ie. $n$ possible numbers

Case 2

Let $n_1+n_2$ be a multiple of 5

So $(n_1,n_2)$ can be $(5k,5k), (5k+1, 5k+4), (5k+4, 5k+1), (5k+2,5k+3), (5k+3, 5k+2)$

With $n$ cases for each ordered pair

Case 3

Let $n_1^2 + n_2^2$ be a multiple of 5

So here cases can be 5k and 5k only (IMO)

The cases with $(5k,5k)$ are repeated 3 times, so count that as one case only

$$P=frac {binom n2 + 2times binom n2 +2times binom n2}{binom {5n}{2}}$$

But that doesn’t match with the given answer $frac{17n-5}{5(5n-1)}$

Where am I going wrong?

How do I create a list of ranked numbers in Sheets––one that will adjust if I change a number?

I have a column of numbers 1-50 in a Google Sheet, which are a ranking list for a different column of fifty items (items are ranked relative to one another, so 1 is the best in the list and 50 is the worst; there are no repeats). I want to create a formula that will automatically adjust the list if I change the ranking of an item. For example, if I change one item’s ranking from 25 to 30, I want the rankings 26-30 to automatically shift and become 25-29 (while still assigned to the same item they originally were). Are there existing functions I can use to do this?

nt.number theory – Sum of inverse squares of numbers divisible only by primes in the kernel of a quadratic character

Let $chi$ be a primitive quadratic Dirichlet character of d modulus $m$, and consider the product
$$prod_{substack{p text{ prime} \ chi(p) = 1}} (1-p^{-2})^{-1}.$$

What can we say about the value of this product? Do we have good upper or lower bounds?

Some observations, ideas, and auxiliary questions

  • When $chi$ is trivial, it has value $zeta(2)$.
  • In general, since Chebotarev density theorem (CDT) tells us that $chi(p)$ is equidistributed in the limit, I would “want” the value to be something like

$$Big(zeta(2)prod_{p | m} (1-p^{-2})Big)^{frac{1}{2}}.$$

However, if I’m not mistaken, it seems that the error terms in effective forms of CDT may cause this to be very far from the truth. We can’t ignore what happens before we are close to equidistribution as the tail and the head are both $O(1)$. We can’t even control the error term well (without GRH) because of Siegel zeroes.

  • I don’t think we can appeal to Dirichlet density versions of CDT since those only tell us things in the limit as $s$ goes to $1$ and here $s = 2$.
  • Is there a way to “Dirichlet character”-ify a proof of $zeta(2) = pi^2/6$ to get a formula for this more general case? At least with Euler’s proof via Weierstrass factorization, it seems that we would need some holomorphic function which has zeroes whenever $chi(n) = 1$.

I had a few other ideas but they all seem to run into the same basic problem of “can’t ignore the stuff before the limit”… am I missing something?

C# / Unity: Large numbers for idle games using a list

For learning purposes, I am developing the first steps of an idle game with exponentially higher income numbers. Usual int, long, etc. can’t store big enough numbers for that.

I looked through many threads which I found on google and using a list (or an array) which is separated in e.g. bronze coins, silver coins, gold coins, etc. seems to be the cleanest version.

In my first approaches I created this list:

namespace Coins
    public class script_coinHandler : MonoBehaviour
        public List<Coin> coinList = new List<Coin>() // list based on the "Coin" class
            new Coin() { Name = "bronze"},
            new Coin() { Name = "silver"},
            new Coin() { Name = "gold"},
            new Coin() { Name = "diamond"},

    public class Coin
        public string Name { get; set; }
        public int Amount { get; set; }
        public int Multiplier { get; set; }

I want each coin type to go up to 999999. This means 1 silver = 1000000 bronze, 1 gold = 1000000 silver.

I can’t get my head around a way to do maths with this list.

Player has 3000 GOLD, 320000 SILVER, 524321 BRONZE

Player wants to buy something for 20 GOLD, 120000 SILVER, 300000 BRONZE

Just subtracting 20 from GOLD, 120000 from SILVER, and 300000 from BRONZE won’t always work. For example when a Player has no BRONZE but some SILVER – you can’t subtract 300000 BRONZE without converting SILVER to BRONZE first.

Q: What would be an efficient function to subtract the price from the total amount? What about multiplying and dividing?
Accuracy is not important. When spending a few GOLD, nobody will care about 10000 BRONZE.

java – how to efficiently draw line numbers in edittext ondraw without causing lag in scrolling

I have an implementation of an edit text to show line numbers and also highlight the current line.
I think it needs more optimization because when I scroll through the edit text with about 500 lines of code, it lags, yet when I comment out the code, the scrolling is smooth.

I need help optimizing this onDraw method in which I do everything above.
The line numbers appear on the right with a custom separator e.g

public class NumberedEditText extends AppCompatEditText {

  private Rect nRect;
  private Rect nRect_;
  private int nOffset;
  private Paint nPaint;
  private Paint nPaint_;
  private boolean nShow;
  private int nAlignment;
  private char nSeparator;
  private boolean nLineHlt;

  public NumberedEditText (Context context, AttributeSet attrs) {
    super (context, attrs);

    nRect = new Rect ();
    nRect_ = new Rect ();
    nPaint = new Paint ();
    nPaint_ = new Paint ();

    nSeparator = '|';
    nLineHlt = true;
    nShow = true;
    nOffset = 2;

    nPaint_.setColor (Color.parseColor ("#222222"));

    nPaint.setColor (Color.LTGRAY);
    nPaint.setStyle (Paint.Style.FILL);
    nPaint.setTypeface (Typeface.MONOSPACE);

  public void onDraw (Canvas canvas) {
  // I use short variable names because i think
  // they are executed much faster.
    if (nShow) {
      nPaint.setTextSize (getTextSize () - nOffset);
      int bl = getBaseline ();
      int lc = getLineCount ();
      int lh = getLineHeight ();
      // i use an array here for efficient
      // random access to store the
      // positions where the line numbers
      // will be according to the number
      // of lines
      String lcs = Integer.toString (lc);
      int nl = lcs.length ();
      char() ch = new char(nl + 1);
      int cl = ch.length;
      String s;
      // i fill the array with spaces
      // ready to be replaced with numbers
        for (int i = 0; i < nl; i++)
          ch (i) = 32;
       // set the last character to the separator
        ch (nl) = nSeparator;
        // now i loop thru all the numbers
        // replacing the characters in the array
        // (with spaces) with numbers
        // to form something like
        // '   1|'
        // '  10|'
        // ' 100|'
          for (int i = 1, j = cl - 2; i <= lc; i++, bl += lh) {
            if (i == 10 || i == 100 || 1 == 1000 || i == 10000 || i == 100000)
            s = Integer.toString (i);
            if (j > -1)
              s.getChars (0, s.length (), ch, j);

            canvas.drawText (ch, 0, cl, nRect.left, bl, nPaint);
          // now i set the padding and an
          // additional margin
      setPadding ((int) nPaint.measureText (lcs + "__"), getPaddingTop (), getPaddingRight (), getPaddingBottom ());

    // this is to highlight the current line
    Layout l = getLayout ();
    if (nLineHlt && l != null) {
      int ln = l.getLineForOffset (getSelectionStart ());
      getLineBounds (ln, nRect_);
      canvas.drawRect (nRect_, nPaint_);
    super.onDraw (canvas);