How can I create a function that prints out the number of deletions it has to make to remove char that are the same in a string?

This is the assignment. How can I make this?

Problem 1.1 : String Cleanup
You have been provided with a string s. Your task is to remove any matching adjacent characters and return the minimum number of deletions required to achieve this.

For example, here below are the wanted output:
AABBBBCCDD return 6
AAAAAA return 5
ABABABABA return 0

So I don’t want to count all the deletions of letters that are repeated in a string, only the one’s that are next to each other

All topic

Expected value of number of trials to get k SUCCESSIVE successes

Independent trials, each of which is a success with probability p, are performed until there are k consecutive successes. What is the mean of the number of the necessary trials?

Let $N_k$ be the number of trials needed to get k successive successes.

While I am convinced that to answer this problem we should start by
doing $$M_k = E[N_k]= E[E[N_k|N_{k-1}]]$$
like explained in another post on StackExchange(See Expectation by conditioning)
I don’t understand how to complete the solution.
The suggested solution is $$begin{align} M_k &= E[N_k] (line1 ) \&= E[E[N_k|N_{k-1}]] (Line 2)
\&=E[p(N_{k-1}+1)+q[N_{k-1}+1+E[N_k]]] (line3)
\ &=E[N_{k-1}+1+qE[N_k]] (Line 4 )
\ &=E[N_{k-1}]+1+qE[N_k] (Line 5 )
\&= M_{k-1}+1+qM_{k} (Line 6 )
\&=frac{1}{p}+frac{M_{k-1}}{p} (Line 7 ), M_0=0 end{align}$$

What I don’t understand is $(line3)$ especially $ q* [N_{k-1}+1+E[N_k]]$

Please someone could provide me an explanation ?

Thank you

All topic

Magnitude and phase of complex number with increasing exponential

I’d like to form the magnitude and phase of the following complex number:

$$[1 + exp(itheta) + exp(i2theta) + exp(i3theta) + exp(i4theta)]$$

I was told to take the $exp(i2theta)$ outside and simplify using Euler’s formula, but I’ve reached a block.

$$Rightarrow exp(i2theta)[exp(-i2theta) + exp(-itheta) + 1 + exp(itheta) + exp(i2theta)]$$
$$Rightarrow exp(i2theta)[cos(2theta) – isin(2theta) + cos(theta) – isin(theta) + 1 + cos(theta) + isin(theta) + cos(2theta) + isin(2theta)]$$
$$Rightarrow exp(i2theta)[2cos(2theta) + 2cos(theta) + 1]$$
Now I’m not sure where to go, when I try expanding anything it seems to become more complicated. Any help would be appreciated.

All topic

Number of Threads and Kernels

When I don’t have any information about the machine.
How can I get the number of threads and kernels of an computer?
Exist some System Calls or Command?

All topic

What is causing model destroy error – wrong number of arguments (given 2, expected 0..1)

For some todos, an error is raised for the wrong number of arguments and I don’t even know where to look. Below I have added the backtrace but I dont see any of my code listed anywhere. Could it be something wrong with the acts as list gem?

todo.destroy!

Heres the class definition. Not sure if it’s in one of the dependent destroys?

class Todo < ApplicationRecord
  belongs_to :list
  acts_as_list scope: :list, add_new_at: :top
  has_many :todo_labels, dependent: :destroy
  has_many :todo_assignees, dependent: :destroy
  has_many :todo_histories, dependent: :destroy
  has_many :user_list_todos, dependent: :destroy
  has_many :users, through: :todo_assignees
  has_one :project, through: :list
  belongs_to :estimate, optional: true



 -------------------------------
    Backtrace:
 -------------------------------

  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/errors.rb:98:in `initialize'
  /app/vendor/bundle/ruby/2.4.0/gems/transaction_isolation-1.0.3/lib/transaction_isolation/active_record/connection_adapters/mysql2_adapter.rb:57:in `new'
  /app/vendor/bundle/ruby/2.4.0/gems/transaction_isolation-1.0.3/lib/transaction_isolation/active_record/connection_adapters/mysql2_adapter.rb:57:in `translate_exception_with_transaction_isolation_conflict'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:597:in `translate_exception_class'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:616:in `rescue in log'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:610:in `log'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:212:in `execute'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/mysql/database_statements.rb:26:in `execute'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:223:in `execute_and_free'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/mysql/database_statements.rb:43:in `exec_delete'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract/database_statements.rb:140:in `update'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract/query_cache.rb:17:in `update'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/relation.rb:380:in `update_all'
  /app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-5.3.0.346/lib/new_relic/agent/instrumentation/active_record_prepend.rb:43:in `block in update_all'
  /app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-5.3.0.346/lib/new_relic/agent/transaction.rb:922:in `with_database_metric_name'
  /app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-5.3.0.346/lib/new_relic/agent.rb:645:in `with_database_metric_name'
  /app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-5.3.0.346/lib/new_relic/agent/instrumentation/active_record_prepend.rb:42:in `update_all'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/querying.rb:8:in `update_all'
  /app/vendor/bundle/ruby/2.4.0/gems/acts_as_list-0.9.10/lib/acts_as_list/active_record/acts/position_column_method_definer.rb:32:in `block (2 levels) in define_class_methods'
  /app/vendor/bundle/ruby/2.4.0/gems/acts_as_list-0.9.10/lib/acts_as_list/active_record/acts/position_column_method_definer.rb:24:in `block (2 levels) in define_class_methods'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/relation/delegation.rb:66:in `block in decrement_all'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/relation.rb:336:in `scoping'
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/relation/delegation.rb:66:in `decrement_all'
  /app/vendor/bundle/ruby/2.4.0/gems/acts_as_list-0.9.10/lib/acts_as_list/active_record/acts/list.rb:328:in `decrement_positions_on_lower_items'
  /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:413:in `block in make_lambda'
  /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:235:in `block in halting_and_conditional'
  /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:511:in `block in invoke_after'
  /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:511:in `each'
  /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:511:in `invoke_after'
    ....

All topic

Number of IC and BC required for a differential equation

enter image description here

The equation is parabolic since the determinant of the characteristic matrix is 0 . How can I justify this ?

I don’t know any proper method to find the number of IC’s and BC’s required for a problem. For me it’s equal to the order of the highest derivative. Therefore, total 2 BC’s or IC’s together.

All topic

Valid number of Cat 6 + Coax cables for pipe conduit?

Here’s some old wiring done in my absence as my parents could only monitor so much.

Hate the use of Skinnier version on Flexi Pipe that won’t allow any movement or pull once initial install is done. Crappy.
(Hidden behind the black pipe)

flexi pipe 2 cat 6 + c1 coax

2 Cat 6 + 1 Coax

It comes out over here at one of these pipes. I forget which one (we traced it w physical push pull)

conduit pipe 3/4 or 1 inch

Conduit Pipe is 3/4 or 1 inch. Need to check in morning.

This old school electrician guy is helping me out so we trying to figure out & have some debates.

Now I saw a link on SE which showed 5 cables inside a 3/4 inch conduit.
How many CAT6 cables can fit in 3/4 conduit?

He is saying there’s no way we can add a 3rd Cat 6 given the thick Coax we have.

Now I’m wondering if this was due to the flexible piping being the cause of his thought.

If we were to avoid flexible Pipe and due the following;

  • Only straight Runs
  • only use pull/ junction boxes or none at hidden turn locations (concealed above ceiling)
  • Use straight or 135 degree angle at 1-2 places through a wall (if at all we have to do that) will try to avoid.

What kind of Cat 6 + Coax additions/ increases could we do to the existing bunch?

Assume new conduit and flexible piping drama / flaws be eliminated.

All topic

avg # of guesses it takes to pick a certain number between 1-100 (random choices)

essentially…

a square on a 10×10 board is randomly assigned the letter X

what is the avg # of times it would take to guess that position while randomly guessing one at a time and not choosing numbers already guessed

my intuition says it involves binomial / geometric series??

thanks for any hints

All topic

Why is two the only even number that is prime?

The other prime numbers are all odd numbers such as $5, 11, 127,$ and $37$. So, why is $2$ the only prime even number there is?

Is it because it only has 1 and itself that way, even though it’s even? Check it out on this excellent math page one-fourth from the bottom.

All topic

How to sort values number in gridview andoid

I want to sort value in gridview in order from left to right, see image. Can you help me?
enter image description here

All topic