Finding all the Combinations – N Rectangles inside the Square

I am a beginner in Computational Geometry (Combinatorics) using Wolfram Mathematica and I need help from experts in the field.

How can I compute all the possible combinations: 6 Rectangles inside the Square (10×10) using Wolfram Mathematica?

Considering that the RESTRICTIONS of the problem are:

1) No Rectangle Can Overlap  2) The 6 rectangles may be vertical or horizontal 

See the image examples of possible and accepted solutions: Image-Accepted-Solutions-Examples

OUTPUT – Vector 100 elements by line (TEXT FILE):

0,1,1,0,0, . . . , 0,0,6,6,6 (Note: Image Example 01)
1,1,1,0,0, . . . , 0,0,0,4,4 (Note: Image Example 02)
0,0,5,5,0, . . . , 0,0,1,1,1 (Note: Image Example 03)
0,0,0,2,2, . . . , 0,0,0,0,0 (Note: Image Example 04)
0,0,0,0,2, . . . , 0,0,0,0,0 (Note: Image Example 05)
6,6,6,0,0, . . . , 0,4,4,4,0 (Note: Image Example 06)
Continue Combination…

Note: Please, do not put mathematical formulas. I would like the source code in Wolfram Mathematica that processes the input data (execute combinatorics task respecting the restrictions) and writes the direct output for text file to each iteration due to combinatorial explosion problems (Memory Overflow). Being that the detailed text output it is the example above: "OUTPUT – Vector 100 elements by line"

PostgreSQL Function – Finding the difference between 2 times

I want to create a simple function in Postgres to find the difference between 2 TIME – not TIMESTAMP. As show below, it accepts 4 parameters: hour, minute, second and expire (hour). In this example I have commented out seconds, just working on minutes.

CREATE OR REPLACE FUNCTION time_diff(hr INT, min INT, sec INT, exp_hr INT) RETURNS INT LANGUAGE plpgsql AS $  $   DECLARE     cur_time    TIME;     expire_time TIME;      diff_interval INTERVAL;     diff INT = 0; BEGIN     cur_time    = CONCAT(hr,  ':',  min, ':', sec) AS TIME; -- cast hour, minutes and seconds to TIME     expire_time = CONCAT(exp_hr, ':00:00') AS TIME;         -- cast expire hour to TIME      -- MINUS operator for TIME returns interval 'HH:MI:SS;     diff_interval = expire_time - cur_time;      diff = DATE_PART('hour', diff_interval);      diff = diff * 60 + DATE_PART('minute', diff_interval);      --diff = diff * 60 + DATE_PART('second', diff_interval);      RETURN diff; END; $  $  ; 

Example: 01:15:00 – 02:00:00 should give me 45 minutes, so I do the following and I get the correct answer.

select * from time_diff(1, 15, 0, 2); 

However, if I do this: 23:15:00 – 01:00:00 – the should give me 105 minutes (60 + 45).

select * from time_diff(23, 15, 0, 1); 

But the result I am getting is -1335. I am trying to work out where I have gone wrong here.

Also I am invoking DATE_PART functions, this seems to be a quite an expensive process in terms of CPU usage. Is there a better way of optimising this function. With the first example I am getting results in 0.007s on 2018 i7 Mac mini. Although I do think this function is quick, but could it be better?


Adsense Reporting – Finding Earning not Attributed to an Ad Unit

I’ve been a publisher using Adsense since 2006.

Up until sometime in 2020, I was pretty good with having all ad placements allocated to (or "tied to") Ad Units.

Recently though, as much as half of my actual earnings don’t show up in the Ad Units report. e.g. If my overall earnings on a given day was $ 60, only $ 30 of that shows up in the Ad Units report.

Clearly I must have an ad (or multiple ads) running that don’t have an Ad Unit?

How would I go about troubleshooting that?

It’s all on the same site/domain so hopefully it won’t be too hard to track down.

finding FWHM of a dataset with unknown mathematical equation

I have a dataset. I have plotted using "Listloglinearplot". Now I need to find the FWHM (full width half maxima) of the same, However I dont know which mathematical eqution describes best to fit my dataset to find out FWHM. I have the following data and plot:

dataset={{0., 0.0518175}, {1., 0.0306299}, {1.9, 0.610295}, {2.,    1.32653}, {2.2, 4.01183}, {2.5, 6.37931}, {3., 6.50091}, {5.,    6.54052}, {6., 6.57276}, {8.2, 6.59119}, {15., 6.56125}, {20.,    6.5267}, {30., 6.4484}, {45., 6.2987}, {60., 6.11953}, {75.,    5.84962}, {90., 5.43738}, {100., 4.96757}, {105., 4.54382}, {120.,    3.42917}, {135., 2.23092}, {150., 1.55222}, {165., 0.679385}, {180.,    0.444479}} dataplot =   ListLogLinearPlot[dataset,    PlotStyle -> {Dashing[{.0071, 0.005, 0.005}], Blue},    PlotMarkers -> {\[FilledCircle], 15}, Frame -> True,    FrameStyle -> Directive[Black, Thickness[0.002]],    FrameLabel -> {Style["x", Black, FontFamily -> "Times New Roman",       FontSize -> 26],      Style["y", Black, FontFamily -> "Times", FontSize -> 26]},    PlotRange -> {{0, 190}, {1, 7.2}}, FrameTicks -> Automatic,    ImageSize -> 650,    BaseStyle -> {FontFamily -> "Times", FontSize -> 10}] 

Can anyone please help me with the mathematical equation?

Thank you.

Is Wisdom (survival) skill used for both tracking and finding tracks?

It is mentioned that to follow tracks you need to find them. It is also mentioned it can take up to an hour outdoor to find tracks you have lost (all under tracking, which is Wisdom (Survival).

The way I read it would be to use Survival no matter the situation (for both finding and following) but I read some people would use perception or investigation to find the tracks. When looking at the table for Sylvan random encounter in DMG p.87, in one entry it uses Wisdom (Survival) to both find and follow the tracks.

Also, I see a problem using other skills to find the tracks for a Ranger character because Ranger favored enemy feature states you have advantage on Wisdom (Survival) to track your favored enemy. Then it would be very strange for the Ranger not being able to find tracks he could easily follow due to his advantage on a check. And what if the Ranger for some reason is not proficient in perception would never be able to find tracks so not able to follow any?

So, the question is easy but I fear the answer is not as I was not able to find a straight answer to it.

I want to make sure that any character who want to become a good tracker (either through ranger or rogue sub-class) can do so. I feel that having to be good at 2 or 3 skills to accomplish one thing (i.e.tracking) is not the common usage of skills in 5e.

thanks for helping out.

Pathfinding algorithm isn’t finding correct route

I am attempting an online coding challenge wherein I am to implement a pathfinding algorithm that finds the shortest path between two points on a 2D grid. The code that is submitted is tested against a number of test cases that I, unfortunately, am unable to see, but it will however tell me if my answer for shortest distance is correct or not. My implementation of the A* algorithm returns a correct answer on 2/3 test cases and I cannot seem to figure out what scenario might create an incorrect answer on the third?

I have tried several of my own test cases and have gotten correct answers for all of those and at this point am feeling a little bit lost. There must be something small in my code that I am not seeing that is causing this third case to fail.

More details

  • The grid is w by h and contains only 1’s (passable) and 0’s (impassable) with every edge having a cost of 1 and the pathway cannot move diagonally It all starts with the FindPath function which is to return the length of the shortest path, or -1 if no path is available
  • pOutBuffer is used to contain the path taken from beginning to end (excluding the starting point). If multiple paths are available then any will be accepted. So it isnt looking for one path in particular
  • I know the issue is not the result of time or memory inefficiency. I has to be either the distance returned is incorrect, or the values in pOutBuffer are incorrect.

Any help would be greatly appreciated as I am just about out of ideas as to what could possibly be wrong here. Thank you.

#include <set> #include <vector> #include <tuple> #include <queue> #include <unordered_map>  inline int PositionToIndex(const int x, const int y, const int w, const int h) {     return x >= 0 && y >= 0 && x < w  && y < h? x + y * w : -1; }  inline std::pair<int, int> IndexToPosition(const int i, const int w) {     return std::make_pair<int, int>(i % w, i / w); }  inline int Heuristic(const int xa, const int ya, const int xb, const int yb) {     return std::abs(xa - xb) + std::abs(ya - yb); }  class Map { public:     const unsigned char* mapData;     int width, height;      const std::vector<std::pair<int, int>> directions = { {1,0}, {0,1}, {-1,0}, {0,-1} };      Map(const unsigned char* pMap, const int nMapWidth, const int nMapHeight)     {         mapData = pMap;         width = nMapWidth;         height = nMapHeight;     }      inline bool IsWithinBounds(const int x, const int y)      {         return x >= 0 && y >= 0 && x < width && y < height;     }      inline bool IsPassable(const int i)     {         return mapData[i] == char(1);     }       std::vector<int> GetNeighbours(const int i)     {         std::vector<int> ret;          int x, y, neighbourIndex;         std::tie(x, y) = IndexToPosition(i, width);          for (auto pair : directions)         {             neighbourIndex = PositionToIndex(x + pair.first, y + pair.second, width, height);             if (neighbourIndex >= 0 && IsWithinBounds(x + pair.first, y + pair.second) && IsPassable(neighbourIndex))                 ret.push_back(neighbourIndex);         }          return ret;     } };  int FindPath(const int nStartX, const int nStartY,     const int nTargetX, const int nTargetY,     const unsigned char* pMap, const int nMapWidth, const int nMapHeight,     int* pOutBuffer, const int nOutBufferSize) {     int ret = -1;      // create the map     Map map(pMap, nMapWidth, nMapHeight);      // get start and end indecies     int targetIndex = PositionToIndex(nTargetX, nTargetY, nMapWidth, nMapHeight);     int startIndex = PositionToIndex(nStartX, nStartY, nMapWidth, nMapHeight);          // if start and end are same exit     if (targetIndex == startIndex) return 0;          std::unordered_map<int, int> pathway = { {startIndex, startIndex} };     std::unordered_map<int, int> distances = { {startIndex, 0} };      // queue for indecies to process     typedef std::pair<int, int> WeightedLocation;     std::priority_queue<WeightedLocation, std::vector<WeightedLocation>, std::greater<WeightedLocation>> queue;      queue.emplace(0, startIndex);          while (!queue.empty())     {         int currentWeight, currentIndex;         std::tie(currentWeight, currentIndex) =;         queue.pop();          if (currentIndex == targetIndex)             break;          int newDistance = distances[currentIndex] + 1;         for (int n : map.GetNeighbours(currentIndex))         {             if (distances.find(n) == distances.end() || newDistance < distances[n])             {                 distances[n] = newDistance;                  int weight = newDistance + Heuristic(n % nMapWidth, n / nMapWidth, nTargetX, nTargetY);                 queue.emplace(weight, n);                 pathway[n] = currentIndex;             }         }     }      if (pathway.find(targetIndex) != pathway.end())     {         int current = targetIndex;          while (current != startIndex)         {             int outIndex = distances[current] - 1;             pOutBuffer[distances[current] - 1] = current;             current = pathway[current];         }         ret = distances[targetIndex];     }          return ret; }