Categories

## How to get the value of each integral independently in c++?

I am using simpson’s 1/3 rule in c++ to try to find the integral of k*(x*x), where k=2*m and ‘m’ goes from 1 to 10, hence I have to do 10 integrals. When I wrote the code below I got the answers but its adding the value of integral from the previous one! e.g. for […]

Categories

## Replace values in an array dynamically

I have a scenario like this. Say: let a = [2,5,6] and let b = [1,2,3,4,5,6,7,8]. Array b is displayed in boxes and revealed when one clicks any of the boxes. What I am trying to do is, when one clicks on any box and the value is the same as any value in array […]

Categories

## How to count the occurrence of each character in a given name(string) in python and display it in normal format without dict?

Suppose my input is: marcel bentok tanaka Output should be m-1,a-4,r-1,c-1,l-1,e-2,l-1,b-1,n-2,t-2,o-1,k-2 I don’t want to count spaces and don’t want to use dict or import functions.How can I achieve this in the easiest way possible? Please do help. I tried searching online,but all of them display output in dict format i.e., {m-1,a-4,r-1,c-1,l-1,e-2,l-1,b-1,n-2,t-2,o-1,k-2} I am just […]

Categories

## R: How to mutate new ID by modifying previous ID?

I asked the question(How to mutate a new column by modifying another column?) Now I have another problem. I have to use more ‘untidy’IDs like, df1 <- data.frame(id=c(“A-1″,”A-10″,”A-100″,”b-1″,”b-10″,”b-100”),n=c(1,2,3,4,5,6)) from this IDs, I want to assign new ‘tidy’ IDs like, df2 <- data.frame(id=c(“A0001″,”A0010″,”A0100″,”B0001″,”B0010″,”B0100”),n=c(1,2,3,4,5,6)) (now I need capital ‘B’ instead of ‘b’) I tried to use str_pad […]

Categories

## Finding integer points of parallel lines

Given two numbers $a, b \in \mathbb{Z}$ with $gcd(a, b) = 1$, the set $P = \{(k \cdot a, k \cdot b) \; | \; k \in \mathbb{Z}\}$ is the intersection of points on the line $g: ax = by$ and the integer points $I = \{(x, y) \; | \; x,y \in \mathbb{Z}\}$ in […]

Categories

## Finding integer points of parallel lines

Given two numbers $a, b \in \mathbb{Z}$ with $gcd(a, b) = 1$, the set $P = \{(k \cdot a, k \cdot b) \; | \; k \in \mathbb{Z}\}$ is the intersection of points on the line $g: ax = by$ and the integer points $I = \{(x, y) \; | \; x,y \in \mathbb{Z}\}$ in […]

Categories

## Game Theory – Nash Equilibrium (Example)

Consider the following game (two players, two actions): (1) Find values of $A$, $B$, $C$, and $D$ such that this game has no pure strategy Nash equilibrium. If we set A=1, C=-1, B=-1, D=1, than this game has no pure strategy (matching pennies example). (2) Find values of A, B, C, and D such that […]

Categories

## Find all integer pairs $(a, b)$ such that $(ab + a + b) \mid (a^2 + b^2 + 1)$.

Find all positive integer pairs $(a, b)$ such that $$(ab + a + b) \mid (a^2 + b^2 + 1)$$ Let $a^2 + b^2 + 1 = k(ab + a + b), k \in \mathbb N, k \ge 1$. For $k = 1$, we have that a^2 + b^2 – ab – a – b […]

Categories

## Custom algorithm to deal with negative values within a DataFrame

To start, I have a DataFrame that looks like the following: df = pd.DataFrame({‘a’: [25, 22, -2, 16, 10], ‘b’: [-5, 18, -2, 25, 48], ‘c’: [34, -12, 7, 8, 22], ‘d’: [10, 8, -2, -4, 12]}) Goal: Eliminate all zeroes using a specific script or function that preserves the effect of the negative value […]

Categories

## Count every instance of an item in a list of lists and sum them

In Python 3.x, I have a list of lists: [[‘a’,’b’,’c’], [‘a’, ‘c’], [‘c’, ‘d’] ] I saw this answer, but it only applies to a single list. How would I do this for a list of lists? My desired output would be a sorted list (or a sortable list) of the frequency of a particular […]