combinatorics – Counting the number of ways in which an integer can be written as a sum of other two integers belonging to two different finite sets.

I am trying to count the number of ways in which I can write a given $l = 1,.., a+b$ as $l = j+m$ where $j = 1, .., a$ and $m = 1, .. ,b$. I suppose partitions could be used to solve the problem, but I am not an expert of those and do not really know how to use them properly. Any help would be appreciated.

c++ – LeetCode 639: Decode Ways II

I’m posting my code for a LeetCode problem copied here. If you would like to review, please do so. Thank you for your time!


A message containing letters from A-Z is being encoded to numbers
using the following mapping way:

'A' -> 1 
'B' -> 2 
'Z' -> 26

Beyond that, now the encoded string can also contain the character
‘*’, which can be treated as one of the numbers from 1 to 9.

Given the encoded message containing digits and the character ‘*’,
return the total number of ways to decode it.

Also, since the answer may be very large, you should return the output
mod $10^9 + 7$.

Example 1:

  • Input: “*”
  • Output: 9
  • Explanation: The encoded message can be decoded to the string: “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”.

Example 2:

  • Input: “1*”
  • Output: 9 + 9 = 18

Example 3:

Example 4:

Example 5:


  • The length of the input string will fit in range (1, 105).
  • The input string will only contain the character ‘*’ and digits ‘0’ – ‘9’.


#include <string>
#include <vector>

class Solution {
    static constexpr size_t MOD = 1e9 + 7;
    static size_t numDecodings(const std::string message);
    static size_t decode(const char a_num_ast);
    static size_t decode(const char a_num_ast, const char b_num_ast);

inline size_t Solution::decode(const char a_num_ast) {
    if (a_num_ast == '*') {
        return 9;

    } else if (a_num_ast == '0') {
        return 0;

    } else {
        return 1;

inline size_t Solution::decode(const char a_num_ast, const char b_num_ast) {
    if (a_num_ast == '1') {
        if (b_num_ast == '*') {
            return 9;

        } else if (b_num_ast >= '0' && b_num_ast <= '9') {
            return 1;

    } else if (a_num_ast == '2') {
        if (b_num_ast == '*') {
            return 6;

        } else if (b_num_ast >= '0' && b_num_ast <= '6') {
            return 1;

    } else if (a_num_ast == '0') {
        return 0;

    } else if (a_num_ast == '*') {
        return decode('1', b_num_ast) + decode('2',  b_num_ast);

    return 0;

inline size_t Solution::numDecodings(const std::string message) {
    const size_t length = message.size();
    std::vector<size_t> decodes_dp(3, 0);
    decodes_dp(0) = 1;
    decodes_dp(1) = decode(message(0));

    for (size_t index = 2; index <= length; index++) {
        decodes_dp(index % 3) = (decodes_dp((index - 1) % 3) * decode(message(index - 1)) % MOD +
                                 decodes_dp((index - 2) % 3) * decode(message(index - 2), message(index - 1)) % MOD) % MOD;

    return decodes_dp(length % 3);


dnd 5e – Ways to prevent Counterspell from being cast?

As usual in questions that lead to considerably large lists (e.g. What are the official, WotC-published classes and subclasses in 5e?), I will post this as a community wiki answer and we can, as a community, update it with all possibilities.

Make the enemy unable to use reactions

  • Arms of Hadar

  • Confusion

  • Shocking Grasp

  • Slow

  • Staggering Smite

Force the enemy to use its reaction

  • Dissonant Whispers

  • Dominate Beast

  • Dominate Monster

  • Dominate Person

Allow the enemy to use its reaction

Make the enemy unable to cast spells

  • Animal Shapes

  • Antimagic Field

  • Feebelmind

  • Mass Polymorph

  • Polymorph

  • True Polymorph

Stopping their counterspell

  • Counterspell

  • Temporal Shunt

Become invisible

  • Greater invisibility

  • Invisibility

  • Surprise them and move before them (can’t take reactions)

  • Cause any condition that stops them from using a reaction (incapacitated, stunned, paralyzed, unconscious, petrified).

  • Be a monk and use Open Hand Technique to Stop them from taking reactions.

  • Cast the spell outside the range of counterspell (more than 60 ft.)

  • Have them already use their reaction such as for an opportunity attack

dnd 5e – Are there ways Changelings can overcome their shape-shifting limitations?

While the changeling’s shapeshifting ability does provide the player with quite a variety of creatures (both pc and npc) to choose from, the rules do limit it to medium human-like (as humanoid is a type) creatures lacking tails, horns (and arguably horns).

As an action, you can change your appearance and your voice. You
determine the specifics of the changes, including your coloration,
hair length, and sex. You can also adjust your height and weight, but
not so much that your size changes. You can make yourself appear as a
member of another race, though none of your game statistics change.
You can’t duplicate the appearance of a creature you’ve never seen,
and you must adopt a form that has the same basic arrangement of limbs
that you have. Your clothing and equipment aren’t changed by this

However, I am left to wonder if this means that the changeling is barred from accessing the image of nearly half the PC list, or if the wording of “a form that” suggests there are ways for a changeling to overcome their limits, relying on RAW?

For instance:

  • Could a changeling personalize the visage they use beyond the race’s traits, such as a Drow with black hair, a shifter’s shifting features, or a tiefling that lost its tail?
  • Could a potion of giant size, or the Enlarge-Reduce spell allow a changeling to temporarily dip in the visages of other races?
  • Would consuming “Blood of Lycanthrope” give them access to the tail due to the hybrid form?
  • Are there any feats yet in 5e that can allow the changeling to upgrade his shifting from alter-self like to disguise self like?

As a side question, I noticed that changelings don’t appear to have darkvision like their doppelganger cousins(?) do. Did I miss this point or would this also apply a disadvantage to the kinds of masks a changeling can effectively use?

dnd 5e – What are all the ways that stacking resistance becomes immunity by RAW?

This particular search on DND Beyond reveals 1 racial trait, 2 spells, and 21 magic items having both “resistance” and “immunity” in their descriptions. The only items appearing having the sought after property are the ones already observed: the dragon masks.

Is this a thorough enough search? I would think so. An ability, spell description, or magic item certainly must contain both word, resistance and immunity (or one of its forms, I tried all those as well), so if it exists, it at least is not on DND Beyond.

Maybe this seems like an unsatisfactory answer, but sometimes the answer is no. I hope I’m wrong.

Now for the details of my reasoning.

First, we have the rules for damage resistance:

Multiple instances of resistance or vulnerability that affect the same damage type count as only one instance.

And of course, specific beats general:

If a specific rule contradicts a general rule, the specific rule wins.

The general rule is that multiple instances of resistance count as one. For a particular rule to trump this, it must be a specific rule that mentions resistance and immunity. The idea is that for it to be specific for the purposes of overriding specific-beats-general, it must cite resistance to override normal resistance rules, and it must cite immunity to grant immunity.

What are virtual ways to travel?

I’ve been missing the experience of traveling due to the pandemic and I’m curious if there are other apps or websites etc such as this one (which allows people to take a virtual drive around a variety of cities around the world) that allow people to travel virtually.

30 Ways to make money from cryptocurrency – Other Money Making Opportunities

Discover How To Make Money With Cryptocurrency – Even If You Have NO Experience!

With loads of advice, guides & tutorials, this gig will teach you EVERYTHING you need to know about how to make money with cryptocurrency

Here’s why this income-boosting gig is a MUST have: 

 30 Ways To Make Money With Cryptocurrency

 The Top 5 Best Crypto Investments For 2020
 Avoid The FATAL Mistakes Most Traders Make

 ZERO Experience Needed

 Insanely Cheap Price

 Fast Delivery

 Your Investment Now Will Pay Off For The Rest Of Your Life!


Get Yours Here

Are there any ways to simplify this if statement?

Are there any ways to make memmove not redundant?

if (Index < NewIndex) {
    memmove(LayersPtr+Index, LayersPtr+Index+1, NewIndex-Index);
} else {
    memmove(LayersPtr+NewIndex+1, LayersPtr+NewIndex, Index-NewIndex);

ways to rearrange a closed graph witch cycles

Let’s say we have the following graph defined by its initial node, final node, and edges in a transition table:

enter image description here

what are the possible ways to rearrange this data structure in order to have something easily representable as the following (using dot or graphivz for example):

enter image description here

What are the many ways to prevent business failures

I don’t think anyone will get into a business to fail. But sometimes it always beyond our control and before you know a business we started with some huge capital collapses. What are there ways and things we can do to prevent business failure. I know taking feasible study is very important. What are the others things we should do to arrest failure.