SharePoint Foundation 2013: download

SharePoint Foundation 2013 Language Packs: download

SP1:

SharePoint Foundation 2013 SP1: download

SharePoint Foundation 2013 Language Pack SP1: download

with SP1:

SharePoint Foundation 2013 with SP1: download

SharePoint Foundation 2013 Language Pack with SP1: download

Problem 2 is indicated as follows:

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

The first we can try is an obvious solution – try to go over every number in the Fibonacci sequence, check if it’s even valued, and add it to the accumulator if it is.

$sum = 0 $x = $y = 1 $limit = 4000000 while ($y -lt $limit) { if ($($y % 2) -eq 0) { $sum += $y } $z = $x + $y $x = $y $y = $z }

The solution goes in a loop through all Fibonacci sequence terms until the terms value goes over 4,000,000. In this solution variable `$x`

holds the last sequence term (the `n-1`

^{th} one), variable `$y`

holds the current sequence term (the `n`

^{th} one), and the variable `$z`

is temporary, used to calculate the next term in the sequence (the `n+1`

^{th} one). The `if`

statement checks if the current term is even, and if it is, the value is added to the accumulator `$sum`

. After breaking from the loop, `$sum`

holds the required answer.

However, checking every term to be even is not necessary – if you would write a long enough sequence, you would notice that every third term is even:

1, 1,

2, 3, 5,8, 13, 21,34, 55, 89,144, …

So, it is possible to get to the required answer without checking if the value is even.

So, we can adjust the code to

$sum = 0 $x = $y = 1 $z = $x + $y $limit = 4000000 while ($z -lt $limit) { $sum += $z $x = $y + $z $y = $z + $x $z = $x + $y }

and after the code runs, accumulator `$sum`

holds the required answer.

So, what is going on in the code? Lets start from the beginning. Before the `while`

loop starts, we calculate the first three terms in the sequence: 1, 1, 2. Because we know that the third term in the sequence is even, we add it to the accumulator. Next, we need to calculate the next three terms to get to the even valued one. So, we use

$x = $y + $z

to calculate the fourth term (that is, we add the second term `$y`

to the third term `$z`

and get the fourth term, which we assign to variable `$x`

. Then, we calculate the fifth term using

$y = $z + $x

(as before, we add the third term `$z`

to the fourth term `$x`

and get the fifth term, which we assign to variable `$y`

). And now, when we have both the fourth and the fifth terms, we can calculate the sixth term

$z = $x + $y

and assign it to variable `$z`

.

Now we get the sequence 1, 1, **2**, 3, 5, **8**. The `while`

loop starts over and treats the variables `$x`

, `$y`

, `$z`

as if they were the first three terms in the sequence. We check for the value not going over the limit, and if it’s not we continue to execute the `while`

loop. Applying the same logic that we outlined above, we add `$z`

to the accumulator `$sum`

and calculate the next three terms in the Fibonacci sequence.

Hope this was as interesting to read as it was writing it. Good luck implementing your own solutions!

]]>Problem 1 is indicated as follows:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

The first thing we can try is a brute force solution.

$sum = 0 foreach ($number in 1..999) { if ($($number % 3 -eq 0) -or $($number % 5 -eq 0)) { $sum += $number } }

The solution goes in a loop through all the numbers from 1 to 999 (because the problem states we need to find multiples **below 1000**). With the if statement we check if the current number is a multiple of 3 or 5. If it is, we add the value to our accumulator `$sum`

. After the loop ends, `$sum`

holds the required answer.

The brute force solution is an acceptable choice as the numbers involved are not very large. However, this is not a very elegant solution.

For a more elegant solution we will employ arithmetic progressions. At first, we need to notice that the multiples of the 3 and 5 are two arithmetic progressions – 3, 6, 9, 12, … and 5, 10, 15, 20, … Next, lets remember the formula to find the sum of a certain number of terms of an arithmetic progression:

where is the sum of terms ( partial sum), is the first term, is the term.

To effectively use the formula, we need to find the last terms in the progressions which are less than 1000. For multiples of 3 it is 999. It is the 333^{rd} term in the progression (999/3 = 333). For multiples of 5 it is 995. It is the 199^{th} term in the progression (995/5 = 199).

Now, we could use the formula to calculate the sums… but we would get the wrong answer! This is because some of the terms in the progressions are both multiples of 3 and 5 (e.g., 15, 30, 45, etc). Because of this, these items were included twice (once in the sum of multiples of 3 and once in the sum of multiples of 5). To counter this, we need to subtract all these terms from the sum. To do this, we can use the same summation formula, because the unneeded terms also form an arithmetic progression. The last term would be 990, and it is the 66^{th} term in the progression (990/15 = 66).

So, now our formula would be

So, we could calculate it in PowerShell by running this command:

$sum = ((333 * (3 + 999)) / 2) + ((199 * (5 + 995)) / 2) - ((66 * (15 + 990)) / 2)

And that’s it! I hope that you enjoyed reading this post and that it helped you in some way.

]]>In the following post I will try to explain how I came to a certain answer (but I will not post the answers). The point of these post is to get you on the right track. It’s more rewarding to find the answers by yourself. However, if you are truly desperate, I will be posting working solutions that you can use to calculate the answer – but where is the challenge in that?

Also, please note that I’m using these problems to get a bit more familiar with the possibilities of PowerShell. As such, most of the solutions will be in PowerShell scripting language.

]]>If we take a look at the SharePoint Management Shells Start menu link, we notice that it’s just a simple PowerShell window with some additional commands on top. As such, we can turn any PowerShell window into a SharePoint Management Shell. Just run

Add-PsSnapin Microsoft.SharePoint.PowerShell

in a PowerShell window and all the SharePoint management commands are yours to use.

my name is Tadas and this is my blog

Mostly I will be writing about technology, programming, and similar stuff – the things that fascinate me. Or just note down some piece of useful or interesting information. I hope you will enjoy reading my posts.

Best regards,

Tadas

]]>