java – Calculate aim angle dead zone range

In my top down 2D shooter game the player has a shoulder mounted gun which rotates and aims automatically at enemies – that part is all working fine. Since the player can rotate as well, the gun is constantly updating it’s angle to keep aim on the enemy.

But this causes a problem where the gun aims at the player’s own head…! It doesn’t have any practical consequences in the game, but obviously looks weird and unrealistic. So I need to create a ‘dead zone’ angle range where the gun cannot aim. It will have to aim as best it can at an enemy up to just before it aims at the player’s head.

It seems tough to calculate since there are two angles in play. The dead zone will have to update itself as the player turns.

enter image description here

Disable dates for a selected range in Reac Sharepoint SPFx

I am new to React Sharepoint online SPFx and want to know how to disable dates in selected range in react-datetime. For now I am using npm-reactdatetime and able to disable dates from current date.
Like if a person is ill in the calendar for like 30th Oct, 2020 he should not be able to select date from 30th Oct to Nov 14, 2020.

python – CSES standard solution for range query problem giving TLE

Problem statement is from CSES

This is a standard question where we are given a list of numbers and a number of queries. For each query, you have to give the sum of numbers in the given range.

My implementation in python:

def solve():
    n,q = (int(a) for a in input().split(' '))
    arr = (int(a) for a in input().split(' '))
 
    cumulativeArray = (0) # Initial entry added to make 1 based indexing
    sum = 0
    for i in range(len(arr)):
        sum += arr(i)
        cumulativeArray.append(sum)
 
    for i in range(q):
        x,y = (int(a) for a in input().split(' '))
        print(cumulativeArray(y) - cumulativeArray(x-1))
 
solve()

This gives the required answers correctly for all my custom test cases. But gives TLE for huge test cases.

I believe this is happening due to split() method in my code.
Any leads are welcome.

sql server – Calendar Event table – best practice setup for range queries and individual retrieval

This seems like a generic problem that should have been solved already, but I can’t find anything about this. In general this question is – given a table where data is read by a date range, what is the best, most efficient setup?

We have a calendar event table that will quickly grow to millions of records.

The schema is something like:

CREATE TABLE (dbo).(CalendarEvent)(
(Id) (uniqueidentifier) NOT NULL,
(DtStart) (datetime) NULL,
(DtEnd) (datetime) NULL,
(Created) (datetime) NULL,
(LastModified) (datetime) NULL,
(CalendarEventType) (nvarchar)(255) NULL,
(CalendarId) (uniqueidentifier) NULL
PRIMARY KEY CLUSTERED 
(
    (Id) ASC
    )WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON (PRIMARY)
) ON (PRIMARY)

Forget about recurring events, etc. as that doesn’t bear on our problem.

Most queries will be of the type:

select * from CalendarEvent where CalendarId = 'b5d6338f-805f-4717-9c0a-4600f95ac515' AND dtStart > '01/01/2020' AND dtStart < '10/22/2020'

Notice no joins, etc.

But we will also have some that select for individual events, and include joins:

select * from CalendarEvent ce join tags t on ce.Id = t.CalendarEventId where Id = '17606330-5486-496a-a91c-f5d0e123bfff'

Questions and ideas:

  1. Should we keep the Id as the PK, but make the start date the clustered index?
  2. Should we just make an index on dtStart?
  3. Should we partition by month?
  4. Should we denormalize a little and break duplicate the dtStart data by include year and month columns that we can index and use in our range queries?

In general, when you do your querying on a table by date range, what is the best setup for this type of table?

Note: If you think this question could be improved to help more people, make it more generic and widely applicable, such as removing references to a Calendar Event table specifically, and making this just about date range querying in any type of table, please help me do that.

comparison – How to properly implement a “compare” operation for Range data type?

Say you have an object that represents a range of numeric values, Range<T>, where T is a numeric type.

It has a T upperBound, a T lowerBound, a bool lowerBoundExclusive, and bool upperBoundExclusive, which represent the lower bound of the range, the upper bound of the range, whether the lower limit is inclusive or exclusive, and whether the upper limit is inclusive or exclusive.

Implementing an equality test on this kind of object is very simple; you just test every value against the other instance’s values.

However, how should one implement a relative ordering of Range<T>s? I thought of the following ways of doing this:

  • Compare the upper bounds of both instances. If they’re different, return the sign of that comparison. If they’re the same, compare the lower bounds and return the sign of that comparison:

    int cmp = upperBound.compareTo(other.upperBound);
    
    return (cmp != 0) ? lowerBound.compareTo(other.lowerBound) : cmp;
    
  • Compute the median of both ranges, and compare those:

    T median = lowerBound + ((upperBound - lowerBound) / 2.0);
    T otherMedian = other.lowerBound + ((other.upperBound - other.lowerBound) / 2.0);
    
    return median.compareTo(otherMedian);
    
  • Compare the magnitude of the ranges:

    return (upperBound - lowerBound).compareTo(other.upperBound - other.lowerBound);
    

Is there an ‘accepted’ way to order ranges?

python – List index out of range, but I tried to debug it and I can’t find any errors

I am making a N-queens algorithm (The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other; thus, a solution requires that no two queens share the same row, column, or diagonal) and this is the “Outside”, not the algorithm: But it gives me an error (listed after the huge code) and I printed each thing, and 5 is within 8.

a = (0, 0, 0, 0, 0, 0, 0, 0)
b = (0, 0, 0, 0, 0, 0, 0, 0)
c = (0, 0, 0, 0, 0, 0, 0, 0)
d = (0, 0, 0, 0, 0, 0, 0, 0)
e = (0, 0, 0, 0, 0, 0, 0, 0)
f = (0, 0, 0, 0, 0, 0, 0, 0)
g = (0, 0, 0, 0, 0, 0, 0, 0)
h = (0, 0, 0, 0, 0, 0, 0, 0)

board = (a,b,c,d,e,f,g,h)
for row in board:
    for elem in row:
        print(elem, end=' ')
    print()

#ask for first queen position

firstq_x = int(input('What is x of first queen: '))
print(firstq_x)
firstq_y = int(input('What is y of first queen: '))
print(firstq_y)
#board(firstq_y) and board(firstq_y(firstq_x))

y = board(int(firstq_y)-1) # y is the selection of a,b,c,d,e,f,g, or h.
y(int(firstq_x)-1) = 'Q' # y(int(firstq_x)-1) is the selection of 0's based on y.

for row in board:
    for elem in row:
        print(elem, end=' ')
    print()

#horizontal
for floor in range(8):
    if y(floor) == 0:
        y(floor) = "X"
        
#vertical
board = (a,b,c,d,e,f,g,h)

count = 0

for vert in range(len(board)):
    vertical = board(count)
    if vertical(firstq_x-1) == 0:
        vertical(firstq_x-1) = "X"
    count+=1
    
#NW
#find y first
ytofill = 2
yminus1 = board(firstq_y-ytofill)  #this will give us list before current list
#find x next
xtofill = 1
xminus1 = yminus1(firstq_x-xtofill)  #this will give us letter before letter
#execute

if firstq_y>firstq_x:

    for NW in range(firstq_x):
        if yminus1(firstq_x-xtofill) == 0:
            yminus1(firstq_x-xtofill) = 'X'
        yminus1 = board(firstq_y-ytofill)
        xtofill+=1
        ytofill+=1

else:
    
    for NW in range(firstq_y):
        if yminus1(firstq_x-xtofill) == 0:
            yminus1(firstq_x-xtofill) = 'X'
        yminus1 = board(firstq_y-ytofill)
        xtofill+=1
        ytofill+=1

#NE
#find y first
ytofill = 2
yminus1 = board(firstq_y-ytofill)  #this will give us list before current list
#find x next
xtofill = 1
xminus1 = yminus1(firstq_x-xtofill)  #this will give us letter before letter
#execute

if firstq_y>firstq_x:

    for NE in range(firstq_y):
        if yminus1(firstq_x-xtofill) == 0:
            yminus1(firstq_x-xtofill) = 'X'
        yminus1 = board(firstq_y-ytofill)
        xtofill-=1
        ytofill+=1

else:
    
    for NE in range(firstq_x):
        if yminus1(firstq_x-xtofill) == 0:
            yminus1(firstq_x-xtofill) = 'X'
        yminus1 = board(firstq_y-ytofill)
        xtofill-=1
        ytofill+=1

board = (a,b,c,d,e,f,g,h)
for row in board:
    for elem in row:
        print(elem, end=' ')
    print()

However, it gives me the error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-4-cb78dab39eae> in <module>()
     54 
     55     for NE in range(firstq_y):
---> 56         if yminus1(firstq_x-xtofill) == 0:
     57             yminus1(firstq_x-xtofill) = 'X'
     58         yminus1 = board(firstq_y-ytofill)

IndexError: list index out of range
```

Dashboard charts where in some higher is better, others lower is better, and in yet others the values should fall between a range

As the title says, how are people approaching having multiple charts in a dashboard, where in some higher is better vs lower is better vs fits in range? All of these charts would have multiple values.

Consider, for example, a case where you want to show 3 charts side by side: 1] revenue by store [higher is better], 2] bad debts/write-offs [lower is better], and 3] price volatility [should be between upper and lower bounds]

I’ve struggled with this for years, and still haven’t found an elegant solution.

excel – Auto calculate random number in between given range sums up to specific value

I’m an engineer trying to formulate to ease my work, basically in excel or macro. I really need help of someone expert could help me to formulate. The situation are as follows and I simplified it.

I have a range distance length of X meter box where total number woods can be placed inside of a box for e.g. The wood consist of a Type A = 2.6-2.8 meter length, Type B = 3.9-4.2m and Type C 5.2-5.6m in length.

Within a given number of box length (X value), the box can be filled up with any 2 or 3 combination of Type A B C as long it fits the given length. It could be could be 4xType A of 2.750m + 3xType C of 4.111 m = X value. Or combination multiple Type ABC in given range of length as long it sums up to X value.

It is like a multiplication of 1, 2 or 3 type value with a given range, sums up to X value.

Excel Formula: Return range of True and False Values

I have a named range, returning values of 0 and >0.

I need to substitute the values in this range as follows:
0 = FALSE, more than 0 = TRUE

Say my range is A1:A10, with values:

  • 0, 0, 0.25, 0.5, 0.5, 0, 0, 0.36, 0, 0

What I need returned:

  • FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE

I’ve tried wrapping the indirect function inside the AND() function to perform the logical test, but this did not work.

dnd 5e – Does the Spell Sniper feat double the range of booming blade when you are not wielding a reach weapon?

The range of the spell doubles, but trivially so.

The first bullet of Spell Sniper says:

When you cast a spell that requires you to make an attack roll, the spell’s range is doubled.

This answer goes into detail about the interaction between Spell Sniper and booming blade. The short verion is, as Rubiksmoose writes:

Spell sniper will work because booming blade has an attack roll involved in it as long as you have a weapon capable of making a melee attack.

So it technically doubles the range of the spell, but this adjustment is entirely trivial without a reach weapon: with a reach of 5 feet, you can still only make an attack on a creature within 5 feet. Booming blade doesn’t extend the reach of your non-reach weapon, but the range of the spell is technically 10 feet with spell sniper, though it still fails if you do not make a melee attack against a creature (or cannot).

Unless you are a bugbear!

The bugbear playable race has a feature called Long-Limbed:

When you make a melee attack on your turn, your reach for it is 5 feet greater than normal.

So even with a non-reach weapon, Spell Sniper would enable the bugbear to use booming blade on targets 10 feet away. In this case, it’s actually very important to understand that the range of the spell is actually doubled.