combinatorics – Count the anagrams from ARARAQUARA, in such a way that there are not 2 As adjacent?

How many anagrams can be made from the word ARARAQUARA, in such a way that there are not 2 As adjacent?

My proposed solution: There are 10 letters, 5 As, 3 Rs,1 Q and 1 U. The general approach will be positioning the 5 As with spaces separating them (or before or after them) and counting the ways to fill these spaces with one or two letters.

I divided the problem in 2 cases:

(a) there is only 1 letter different from A between A’s. There are two cases here, starting with non-A, or finishing with non-A. Total number of possibilities for the 2 cases, considering the 3 repeated Rs:
$$2times frac{5!}{3!}=40.$$

(b) there is one pair of non-A letters between 2 A’s (only one pair is possible). Cases for the pairs (considering order): RR, RQ, QR, RU,UR, QU, UQ.

So the anagram possibilities for each pair is given by:
RR – $4!=24$ possibilities;
RQ – $4!/2!=12$ possibilities;
QR – $4!/2!=12$ possibilities;
UR – $4!/2!=12$ possibilities;
RU – $4!/2!=12$ possibilities;
UQ – $4!/3!=4$ possibilities; and,
QU – $4!/3!=4$ possibilities.

So the total number of anagrams considering restrictions is: 40+24+412+24=120.

My problem: the answer given is 128. Am I missing cases? or the answer is wrong?

DCEL: How to find all vertices adjacent to a given vertex in doubly-connected edge list?

I am trying to find all of the vertices that are adjacent to a given vertex in a doubly-connected edge list. How can I find it? Could you pls give an pseudo code example?

algorithm – Qix diagonally adjacent movement

I’m implementing a Qix clone game and I do not have any problems with implementation but rather with possible scenario.

Is this a valid scenario for this game and if yes how exactly should gameplay go in this case?

Black – Filled, Red – Current Player’s Path, Blue – Player

Step 1

If this is a possible scenario, then after completing the path player will end up with two diagonally adjacent rectangles.

Step 2

After that player can start moving from the bottom of the top rectangle to the right.

Step 3

In this case it should be immediately considered as a complete path and fill 1×1 square or player can create a path adjacent to the top of the bottom rectangle?

Step 4

ruby – Group by adjacent similar elements

In Python we have a function groupby which can be used as follows

from itertools import groupby
a = '111221144444433555511'
print((list(g) for k, g in groupby(a)))

which will give me

(('1', '1', '1'), ('2', '2'), ('1', '1'), ('4', '4', '4', '4', '4', '4'), ('3', '3'), ('5', '5', '5', '5'), ('1', '1'))

But in Ruby if I do the following

a = '111221144444433555511'
a.chars.group_by {|x| x }.map {|k, v| v}

I get this:

(("1", "1", "1", "1", "1", "1", "1"), ("2", "2"), ("4", "4", "4", "4", "4", "4"), ("3", "3"), ("5", "5", "5", "5"))

But I need like the one Python gave me. How to do this?

eu – Train fare 4 Euros higher for travel to airport than to its two adjacent stations

Is it legal to have a higher train fare for travel to/from airport when adjacent stops are way cheaper?

I frequently travel to an airport that is connected to its serving city by rail service.
A one way train fare to/from the airport to/from the city is 5 Euros. It’s roughly a 15 minutes train ride.
However, travelling on the same identical train that stops at the airport and boarding/alighting from any of the adjacent stops costs 1.10-1.20 Euros.


  • 1 station before the airport’s station to the city: 1.20 Euros
  • Airport’s station to the city: 5 Euros
  • 1 station after the airport’s station to the city: 1.10 Euros

I find the 5 Euros fare quite good compared to some prices that can be found elsewhere. However, I don’t find this to be ethical and was wondering if there might be any justification for the 450% higher rate (e.g. arguing that the airport’s station infrastructure is what adds to train fare).
If this is indeed Price Discrimination, is it legal?

bug – A REST query for a specific item using list/items(itemID) returns a single result that has data from adjacent list items. How is this possible?

This is perhaps one of the most bizarre problems/bugs I’ve ever seen with SharePoint. And, to be clear, I am only seeing it with one user (so far!), specifically using Edge (v.85.0.564.44). If I have the same user use their Chrome or Firefox browser, everything works as expected. I also have the same version of Edge on my laptop, and when I try using Edge on the same page to execute the same code, everything works as expected. So it definitely seems to be a very isolated issue, and I realize that because of that this is getting very close to being off-topic here.

But at the same time, the issue is that what seems to be a very straighforward REST query is showing bizarre results returned from the server, so it leads me to believe that something is going on with the request somehow that is causing the server to respond the way it does, so in that respect this is a question about the correct way to interact with the SharePoint REST API, and therefore on-topic.

Anyway, what is happening is… well, let me set up a very contrived, simple scenario to make it easy to illustrate what I’m seeing.

Imagine a list set up like so, which includes a multi-select lookup field:

ID    Title              AMultiLookup
--    ----------------   ------------
 1    I am Number One!   (1, 2, 3)
 2    It should be me    (4, 5, 6)
 3    The third one      (7, 8, 9)

(I’ve used the lookup IDs set in the lookup field to make it easier to see what’s happening.)

Now imagine that I send a simple REST request for item with ID 2, using the endpoint

/_api/web/lists/getbytitle('My List')/items(2)

with no additional oData query parameters – no $select, no $filter, nothing – just straight up “give me item number 2”.

Given the list data above, I would expect a result of

d: {
    AMultiLookup: {
        results: (4, 5, 6),
    ID: 2,
    Id: 2,
    Title: "It should be me"

However, what actually gets returned is

d: {
    AMultiLookup: {
        results: (7, 8, 9),
    ID: 2,
    Id: 2,
    Title: "I am Number One!"

Notice that although the ID in the response is the ID of the item I asked for (2), the value of the Title field is from item ID: 1 and the value of the AMultiLookup field is from item ID: 3.

What the what??? How is that possible?

I first saw this issue in another query on another page where I was applying some $select values to limit the response (so ID was not included), and I thought perhaps it was an “off by one” issue where somehow the browser was incrementing (or decrementing) the ID of the item I was querying for before the request got sent out, so therefore the server was returning the correct result, it was just my query that was messed up. But in all cases, I construct the URL like

var uri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('List Name')/items(" + desiredItemID + ")";
    url: uri,
    // etc

and I set breakpoints after the uri string was constructed, but before the request went out, and saw that the string did include the correct item ID being requested. The fact that the ID of the requested item was not being changed was borne out by the results of the request that did not add any $select parameters and returned the ID of the item in the result, which matched what was being requested.

Also, I don’t think it’s an “off by one” browser mutation kind of error being applied to the results after they’re received, because

  • How could the browser change the string of the Title property to exactly what the Title is of a different list item?
  • The lookup IDs in the multi-lookup array were not “off by one”. It the expected result was (4,5,6) the actual result was not (5,6,7), it was (7,8,9). And in any case, in the actual data, the expected result was not in numerical order (i.e. the true expected result was (4,6,5)), while the actual result was in numerical order, which perfectly matched the value of the field in the other list item.

So I think there is compelling evidence here that a request for a single list item (by ID) is returning data from adjacent list items on both sides of the requested item.

So…. how does that happen?

I’m using jQuery 3.4.1 to make the requests, and I’m not doing anything fancy with the requests, they’re super basic, like

    url: uri,
    method: 'GET',
    headers: {
        accept: 'application/json;odata=verbose'

Could Edge be adding some extra header that confuses the server and causes that behavior? If so, it’s not inherent in Edge v.85.0.564.44, since I also have that version and it behaves fine for me.

Any ideas here would be appreciated.

co.combinatorics – Why is the number of permutations of n adjacent transposition where the outputs are different equals $2^{n-2}$?

Maybe im wrong, but i just noticed that the different permutations of (1,2)(2,3)(3,4),…,(n-1,n) seems to be $2^{n-2}$ and i dont know why this is true. Can someone help if im right about this and explain a little bit?

e.g.: $n=4$, $(1,2)(3,4)(2,3) = (3,4)(1,2)(2,3)$ and $(2,3)(1,2)(3,4) = (2,3)(3,4)(1,2)$ but $(1,2)(2,3)(3,4)$ and $(3,4)(2,3)(1,2)$ gives unique outputs. So the number of different permutations is $2^{4-2}=4$, I checked it for 5, 6, 7 and gives the same pattern.

dnd 5e – When playing on a grid, can I pour a flask of oil on any adjacent square or just on the one I am standing on?

You can pour the oil on adjacent squares.

This is not spelled out very clearly, but your reach is assumed to be 5 feet unless specified otherwise. In the section on melee attacks, it is stated:

Most creatures have a 5-foot reach and can thus attack targets within 5 feet of them when making a melee attack. Certain creatures (typically those larger than Medium) have melee attacks with a greater reach than 5 feet, as noted in their descriptions.

Again, this is in the section on melee attacks, which may not appear to be entirely relevant. But the next paragraph has further guidance, concerning unarmed strikes:

Instead of using a weapon to make a melee weapon attack, you can use an unarmed strike: a punch, kick, head-butt, or similar forceful blow (none of which count as weapons).

So while it nowhere says I can pour my oil on an adjacent square, I can headbutt or punch enemies in adjacent squares, so it is quite natural that I can also pour a flask of oil into an adjacent square.

microsoft excel – How can I use VLOOKUP/INDEX/MATCH to search for my target term and adjacent results in a sequenced list?

I have a sequenced list of numbers from A2:A165000. In D1 I have my target number as a column heading: 2588. In this column I would like to generate a list all of the numbers that occur directly before my target. And in E1 a list of the numbers that occur directly after my target.

I am able to find a single instance with the following formulae:



How do I expand this to find all of the other instances?

algorithms – Find original array from array with pairs of adjacent elements

Given an array composed of pairs, like this:


Each element in the array (call it pair) means that pair(0) and pair(1) are adjacent in the original array. Note, they can come in either order. For instance, for the sample array above, the original array would be:

4,1,5,3,2 (or the reversed version of this)

How can I do this quickly? I tried doing this as follows, which works, but it’s too slow:

Create a hashmap that maps adjacent elements. Map = {3: (5,2), 1: (5,4), 5: (1,3), 4: (1), 2:(3)}. My algorithm would then start with one of the keys that only has a corresponding value length of 1 (in this case either 4 or 2), and then add to an output array, and go through the hashmap. I.e. First I would add 4 to my output, and then go from key of 4 (with a corresponding value of 1), to the key of 1, with corresponding values of 5 and 4. I’d ignore 4 (since it’s already in output), and add 5, then go to the key of 5, and so on and so forth. This is too slow! Is there a better algorithm?