Simple combinatorics - combinatorics

Im having some trouble understanding combinatorics and specifically how "choose" works. I have a homework problem that I think I understand but just want to make sure im not completely off.
The question is...
"We wish to make 6 letter string such that every even letter in an even position is a vowel (no constraints on the odd letters) How many possible strings can we make?" We have access to all 26 letters and repeats are allowed and distinct orderings are different strings.
The answer I am coming up with is...
(26 choose 1) x (5 choose 1) x (26 choose 1) x (5 choose 1) x (26
choose 1) x (5 choose 1)
Am I even on the right track?

Yes, that should be the exact answer unless your teacher is counting 'y' as a vowel to be a jerk

Yes it is a correct approach as for every odd letter position you have 26 alphabets to choose from and for the even ones you have a choice of the 5 vowels.

Related

Turing machine that adds two decimal numbers

I'm having trouble conceptualizing how I would start solving this problem.
I was able to create a Turing machine that adds two unary, and two binary numbers.
I have a general idea of how to solve this problem:
While first number > 0:
Decrement first number.
Increment the second number.
How do you actually decrement a decimal number?
This way, we can add two numbers.

Check if digits in a number can be rearranged to form a fibonacci number

This question is asked in a programming contest. I couldn't find any way other than generating all permutations. But the number of digits is upto 15 and no of permutations (15!) is very large. Is there any other way?
I know that if (5*N^2 + 4) or (5*N^2 - 4) is a perfect square, n is fibonacci.
You don't need to generate all permutations. Generate the fibonacci numbers of desired length (which will be less than 74 numbers, because 73rd fib. number is the highest with 15 digits) and then just check for those few whether they can be "constructed" from digits in the given number.

Minimum cost to group same characters in a string

I got stuck in a problem. The overall problem statement is big. I have solved the other pieces of it.
Got stuck in one piece.
Given a string containing some dashes('-') and some character lets say ('A'). Also, we are given with cost C to shift a character to its adjacent place. We need to find minimum cost such that all 'A' characters are grouped.
Example1: A-A--A---A and cost = 10
Minimum cost to group all 'A's would be: 80
Example2: AAAA------A and cost = 10
Minimum cost to group all 'A's would be: 60
Hint: for the cost to be minimum possible, one of the median As (2nd or 3rd of 4 in your first example, 3rd of 5 in your second example) can be left in place. Using this, you can compute the cost in O(n), where n is either the length of the string or the number of As, whichever is your input format.
I don't think this problem needs dynamic-programming.
You only need to move all A's towards the median A because this is the least total distance between all A's.
Just make sure not to move the media A. If the A at the median is moved to the right, each of the A's to its left will have to move one more step and each of the A's to its right will have to move one step less. This should cancel out, but you already added one unneeded step.

How to calculate modulus without the operator and any round function?

I have to calculate the modulus of a number to check if it's even or not, but the only instruction to compare two numbers is checking if they're equal, and there isn't the modulus operator and a function\operator to round numbers.
A way to round numbers would be an alternative to modulus operator, but i can't find a solution to either modulus and round.
Just need a pseudo code to work with.
We're learning some assembly basics at school with a "pseudo" assembly (DuplOne).
Thanks in advance!
Assuming the number to test is not negative, and that subtract and jump instructions are available, check if the number is 1 (i.e. the original number was odd) or 0 (i.e. the original number was even), otherwise subtract 2 and go back to the checks.
:label
if number = 1 then
original number is odd
finish
if number = 0 then
original number is even
finish
subtract 2 from number
go to label

Finding the absolute difference with positive and negative values

I have two columns. One with positive values and one with negative values. I need to find the absolute difference between the two columns.
What I am currently doing is the following: First of all, I edit both the columns to make all the values positive. Then I subtract the first column with the second column. I change any negative value to the positive one. Is this the same as the absolute difference?
Why not just use the ABS function
=ABS(B1-A1)
It sounds like what you're doing is actually
=ABS(ABS(B1)-ABS(A1))
which is not the same as
=ABS(B1-A1)
for example if you have -3 and 1 the first would give you 2 and the second would give 4. I don't know which one you want.
This works no matter which value is positive or negative:
=MAX(A1,B1) - MIN(A1,B1)
OK, so here's a pretty clunky workaround, but it is something where I can understand what's going on and works every time.
Here is my scenario where I needed to solve this problem. I had a system stock list showing 1 of these 10 of those but also showing -10 of these and 5 of those, and once entering my physical data from doing a stock take, I had pluses and minuses all over the place, so the data looked like this:
Physical stocktake value system value
0 0
1 0
1 2
0 -1
1 -1
Effectively all the different connotations of pluses and minuses.
so column 'a' is actual, column b is system
I created columns c,d,e,f ..... I warned you it was a little clunky, but it is sound in the result.
formula in column c = '=IF(A1>B1,A1+B1,A1-B1'
formula in column D = '=IF(B1+C1<>A1,A1-B1,C1)'
formula in column E = '=IF(D1>C1,C1,D1)'
Column E is the data you want, it rationalises all of the pluses and Minuses in your data to show a true difference (independent of positive and negative location) for the values you require.
Someone much cleverer than I will condense this down into a singular equation, but i read up on it, tried the current solutions/advise, and didn't have a clue what the techs were going on about, so came up with this faultless solution.
It does work and it s simply a transpose the A1's and B1's for your data content.
Hope it helps (a little).
I for one will check back, just to pick up on what the clever guys and gals come back with, just a case of life is to short to drive into this level of detail for a simple solution. Sometimes simple is best.
Yeah ok, set myself up for that one ..... so I'm simple, but I know what I'm doing and understand it ........

Resources