terminology – How can I efficiently search the bitcoin-dev mailing list for discussion of a specific term?

The simplest way to do this is use a search engine e.g. Google and enter:

"bip37 site:lists.linuxfoundation.org"

(This is also useful for searching GitHub issues, pull requests as a Google search is often more effective than the github.com search functionality.)

Alternatively you can go to https://lists.linuxfoundation.org/pipermail/bitcoin-dev/ and download all the gzip mboxes (the URL scheme is simple, so you write a shell one-liner with curl), ungzip them, cat them together, and then use mutt -f combined.mbox.

This question was answered by various individuals on IRC.

function construction – Is there a way to do this more efficiently?

I’m trying to write this Mathematica function to find the optimal price for a model, given some model parameters. This is a stylized example of what I’m trying to do, and I’m wondering what’s a better way to do it. The code below takes a while to run (at least on my computer).

U(x_?NumericQ, p_?NumericQ, a_?NumericQ) := 
 RegionMeasure(ImplicitRegion( 
   (a*v - p - x >= 0 && 0 <= v <= 1 ) , {v}))
q(p_?NumericQ, 
  a_?NumericQ) := (x /. 
   FindRoot(x - U(x, p, a) == 0, {x, 0.00001, 0, 1}))
Purchase(p_, a_) := RegionMeasure(ImplicitRegion( 
   {(a*v - p - x >= 0  && 0 <= v <= 1) /. {x -> q(p, a)}} // 
    Evaluate , {v}))
bestPrice(a_) := 
 p /. Last(NMaximize({p*Purchase(p, a), 0 <= p <= a}, p)) 

bestPrice(2)

Is there a faster optimization function for this problem then NMaximize? The Purchase() function measures the total demand for the model, and the bestPrice() function figures out the optimal price to maximize the profit, given the model parameter ‘a’. In the full model I have, there is more than one model parameter and several conditions within the Purchase() function and U() function, so I’m wondering how I can make this simple example go faster. If you have any ideas, please let me know. Thanks in advacnce!

c++ – In a chess simulator, how to efficiently determine checkmate?

I’m working on a small C++ chess simulator game for the first time, and I have a bit of a programming dilemma. I have searched for similar questions on this site and StackOverflow, but can’t find a consensus on what to do here, so hopefully this is an appropriate question for this site.

I’m currently working on implementing check, through a function that starts at the king’s position and checks all knight moves, verticals, horizontals, and diagonals for threatening pieces. If it finds a threatening piece that isn’t blocked by another piece, then the king is considered to be in check and the player must make their next move in a way that gets them out of check. That seems to be the most efficient solution for determining check from the chess-related posts I’ve seen.

However, I’m stuck on how to efficiently implement checkmate. The only logical way I can think of is that once the check flag has been raised, run the check function on every legal follow-up move to see if it results in non-check, and if none of them do, it is checkmate.

Or, to express this in C++ pseudocode:

bool checkForCheckmate() {
  for (allLegalMoves)
  {
    doMoveTemporarily();
    if (!inCheck) {
      return false; // The player can get out of check, so it's not checkmate.
    }
  }
  return true; // If we got here, none of the player's legal moves can get them out of check, so it's checkmate.
}

While it makes sense to me and is logical, that seems extremely inefficient, and this is supposed to be a fairly simple and lightweight application. However, this seems to be the approach suggested by most sources when I look up “how to implement checkmate in a chess game.”

Is there another, potentially more efficient chess algorithm to check if a given arbitrary board arrangement is a checkmate?

algorithms – Choosing which connection to travel down efficiently

Suppose i want to check if my position is enclosed in a closed loop by following the connection of waypoints that surround it:

enter image description here

Now if i travel from node 0 to node 1. I’m at node 1 and i need to find the next connection of which as you can see i have multiple choices this time.

I can rule out where i came from quite easily, but that still leaves me with other options. How can I optimally pick which connection to follow next based on knowing that the connection from node 1 to node 2 is the only allowed option here anyway since as it’s an enclosed loop you can consider them equivalent to being walls.
I just am not sure how to check which is the most viable choice next logically speaking.

If node 1 to node 2 connection didn’t exist, naturally the first logical choice would be to just go straight on ahead which is easy to tell visually just not so easy when thinking in code.

automation – How to resize several images in Pages efficiently?

I have a document with illustrations that are 350px square. It’s a kind of a catalogue with a picture, a title, and product description.

The images are all too large in my first layout. I would like to smallify all of them to 35px square using some action such as ‘find and replace’ rather than doing one at a time using the Format > Arrange found in the right-hand side bar.

Is there more production-oriented capability in Pages to do such things?

unity – Manually and efficiently placing thousands of particles – positions incorrect?

I have a particle system based on this answer to another question about manually placing particles (no movement). However, it’s very costly to run Emit() and Play() after placing each particle via emitparams. I’ve written an alternate method that assigns the various positions to the particles themselves (rather than singly via emitparams) and then calls Emit() and Play(). It does perform much faster, but all the particles end up at 0,0,0 instead of their respective positions. I’ve logged out their positions to make sure they are correct and they are, but I’m not sure why this method is not working.

How do I set the positions of individual particles correctly in this more efficient method?

I am rendering many of these pools and around 5-6k particles at a time, so I need a more performant method than one at a time via emitparams.

The old, inefficient but working method in the script below is CreateParticle() produces this expected result:

expected result from non-performant code

The new, more performant method that doesn’t yet render the positions correctly is CreateParticles() and gives this undesired result with positions all at 0,0,0 for each particle system:

undesired result from performant code

  using UnityEngine;

  (RequireComponent(typeof(ParticleSystem)))
  public class ParticlePool : MonoBehaviour
  {
     int _lastParticleIndex = 0;  // keeps track of our oldest particle (for deletion)
 
      ParticleSystem _particleSystem;             // our object's particle system
      ParticleSystem.Particle() _particles;    // our reusable array of particles
      ParticleSystem.EmitParams _emitParams;   // reusable emitparams
      int _maxParticles = 0;       // total number of particles in our scene before re-using
      private float _maxValue;
      private bool _primed;

      private void Awake()
      {
          if (_primed == false)
          {
              Initialize(); // initialize all of our member variables
              _primed = true;
          }
      }

      public void ResetParticles() // used to erase all previous particles written to the system
      {
          for (int i = 0; i < _particles.Length; i++)
          {
              _particles(i).remainingLifetime = -1;
              _particles(i).startLifetime = 1;
          }
          _lastParticleIndex = 0;    // keep track of oldest particle - now, of course, reset to the beginning
          // have to re-write
              _particleSystem.SetParticles(_particles, _particles.Length);  // write those pesky particles back into our ParticleSystem
      }

      public void CreateParticles(Vector3() particlePositions, float() particleTransparencies, Color32 color)
      {
          for (int i = 0; i < particlePositions.Length; i++)
          {
              if (i > _maxParticles)
                  break;
          
              color.a = (byte) (particleTransparencies(i) * 255);
          
              var particle = _particles(i);
              particle.position = particlePositions(i);
              particle.startLifetime = _maxValue;
              particle.startColor = color;
              _particles(i) = particle;
          }
          _particleSystem.SetParticles(_particles, _particles.Length);
          _particleSystem.Emit(_particles.Length);
          _particleSystem.Play();
      }
  
      public void CreateParticle(Vector3 position, Color32 color)
      {
          // if we're at our particle count limit, kill our oldest particle.
      
          if (_lastParticleIndex >= _maxParticles)
          {
              // set lifetime to -1 to kill the particle
              _particles(_lastParticleIndex).remainingLifetime = -1;
              // we need to reset start lifetime to a normal value, too or the particle will still have infinite lifetime
              _particles(_lastParticleIndex).startLifetime = 1;
 
              _lastParticleIndex++;    // keep track of oldest particle
              if (_lastParticleIndex >= _maxParticles) _lastParticleIndex = 0;
 
              // have to re-write
              _particleSystem.SetParticles(_particles, _particles.Length);  // write those pesky particles back into our ParticleSystem
          }
          // set up params for this particle, you can use whatever you want (see unity docs for EmitParams for what's available)
          _emitParams.position = position;
          _emitParams.startColor = color;
          _emitParams.startLifetime = _maxValue; // float.MaxValue makes the particle's lifetime infinite
          _particleSystem.Emit(_emitParams, 1);
          _particleSystem.Play();
      }

      void Initialize()
      {
          if (_particleSystem == null)
          {
              _particleSystem = GetComponent<ParticleSystem>();
              _particleSystem.transform.parent = gameObject.transform;
           }
      
          _maxParticles = _particleSystem.main.maxParticles;
          _maxValue = float.MaxValue;
 
          if (_particles == null || _particles.Length < _particleSystem.main.maxParticles)
              _particles = new ParticleSystem.Particle(_particleSystem.main.maxParticles);
      }
   }

How can I efficiently check if a given email address is included in a distribution list in Microsoft Outlook OWA?

From what I can see, clicking on the distribution list in Microsoft Outlook OWA doesn’t give any efficient way to check if a given email address is included in a distribution list, since would have to go through the list of email addresses included in a distribution list (which is inconvenient if the distribution list contains many email addresses):

enter image description here

enter image description here

How can I efficiently check if a given email address is included in a distribution list in Microsoft Outlook OWA?

design – How do you efficiently map CSV file columns to Object in Java?

I want read the CSV files… and map it into class/object..

The CSV or Text file contains like below

col_name, col_name_2, col_name_3
data_1
           ,data,     data
data, 

I want to map like this

col_name --> ObjectABC.property
col_name2 or col_name3 --> ObjectDEF.property 

I am thinking to use ANTLR4 library, to minimize the code changes.

How to efficiently animate 2D scene spanning sprites in Unity?

Our game is a 2D point-and-click adventure game. One of the levels is set in a factory with conveyor belts that span the scene. The game is hand animated in 2D and so animating these conveyor belts could potentially take up lots of memory since the sprites are as long as the screen (it’s an HD game – 1920 x 1080).

I’m not sure if tiled sprite shapes can be animated, so I was wondering if there’s a prescribed way to handle larger sprite animation like this – efficiently.