Find Standard Deviation with C++

2 January, 2010

I wrote a small C++ program to calculate the mean and standard deviation of a given data set. Here it is:

#include <iostream>
#include <cmath>
using namespace std;

int main (int argc, char* argv[])
{
	int number_of_items;
	cout << "How many pieces of data are in the list? ";
        cin >> number_of_items;
	float list[number_of_items];

	// get all the data items
	cout << "Please enter the data:" << endl;
	int i;
	for (i = 1; i <= number_of_items; i++)
	{
		cout << i << ". "; 		cin >> list[i];
	}

	// find the mean (average) of the data
	float xbar = 0;
	for (i = 0; i <= number_of_items; i++)
		xbar = xbar + list[i];

	xbar = xbar / number_of_items;
	cout << "The mean (average) is " << xbar << "." << endl;

	// find the standard deviation
	float numerator = 0;
	float denominator = number_of_items;

	for (i = 1; i <= number_of_items; i++)
		numerator = numerator + pow((list[i] - xbar), 2);

	float standard_deviation = sqrt (numerator/denominator);
	cout << "The standard deviation for the given data is "
		 << standard_deviation << "." << endl;

	return 0;
}

The Web Invaded the Desktop

30 September, 2009

I can officially say that the web has infiltrated itself into my desktop operating system. On my dock, eight out of the fourteen applications are directly web-related: Safari, my web browser; Mail, my mail client; Adium, my messaging client; Colloquy, my IRC client; Hulu Desktop, a desktop version of the online TV website; iTunes, especially in regards to the iTunes store; Songbird, for finding music online; and Times, for viewing news online.


Slowing Down

27 August, 2009

Due to other things that have come up, I haven’t been able to write too many blog posts recently. To any followers, I apologize. I will try to set some time apart to write something else soon.


Keynote Thumbnails in Quick Look

31 July, 2009

As can be seen from Apple’s Leopard presentations before release, as well as on page 22 of the Leopard manual, opening a Keynote presentation using Quick Look should allow you to see slide thumbnails on the side, as in 0:28 in this video. However, this is not set as the default behavior. Achieving this is very simple, though. In Keynote’s preferences, under General, simply check off “Include preview in document by default.” There you have it!

via Apple’s Support page


Snow Leopard is Darker

26 July, 2009

It seems that my predictions, which were one of the first on the internet regarding the subject, that Snow Leopard would be darker have come true! Here’s a quick timeline of how I came about the idea and all the steps that Apple took to make it glaringly obvious that Snow Leopard’s UI would be even the slightest bit darker than Leopard’s:

  1. Someone on IRC (nick JHKKHJK or similar, I can’t quite recall it)  in a WWDC discussion channel told me that Snow Leopard’s UI would be darker. That started originally what seemed like a wild goose chase, but ended up being a lot more meaningful than that.
  2. First up was MobileMe, which sported a dark toolbar. Knowing how Apple feels about design and a look of integration across all its products, I found it obvious that it was only a matter of time before other applications started going dark as well.
  3. Next, interfaces began to merge with iTunes 8, which  in Grid View has a dark “sub-toolbar” and even darker scrollbars.
  4. When QuickTime X’s new interface was announced I was sure that my ideas were no longer simply speculation and that Apple was giving way too many clus that they were going to give us a darker interfaces.
  5. Now, Dock context menus are dark. Having five interface items be dark is interesting enough; I wonder what else will be darker in future Snow Leopard releases. Besides, all the iLife apps have dark scrollbars.

Oh, and there are new wallpapers available for Snow Leopard; I’m already using some of them.


What Happened to Project Looking Glass?

9 July, 2009

Project Looking Glass is a cross-platform (compatible with many Unix-based operating systems) three-dimensional desktop environment based on Java technology made by Sun Microsystems. The technology started with the vision of recreating the way the desktop environment works, taking it from the plain 2D and 2.5D we are used to to something rather different.

The project originally went beyond a simple conception into a full-fledged stable desktop environment. Its last stable release (1.0.1), however, was in 2007. Its development seems to have virtually stopped, though. It’s plainly obvious, especially since its website hasn’t been updated in two years or so and we hardly hear anything about it. So what ever happened to Project Looking Glass? Why did the project stagnate?

After giving it some thought and research, here are a few reasons I came up with:

  • There is a lack of user base. Sure, it’s interesting, but not many people felt the compulsion to switch from their two-dimensional desktop environment, one to which they had gotten completely accustomed, to something completely new. Besides, how many common users besides “techies” have heard of Looking Glass at all?
  • There is a lack of interest. This builds up on the previous point. It seems Sun simply got tired of the project and promoting it. Besides, Sun has already accepted GNOME as the de facto standard desktop environment for its OS releases, such as OpenSolaris.
  • It’s another platform. Modern developers, despite being relatively welcoming to new technologies, seem to have already found their niche and divided themselves into what they find suitable. Further more, Looking Glass and its APIs, as far as it seems, has a lot unique features that are not easily or readily deployable to other platforms, so it’s not a WORA (write-once-run-anywhere) situation.

Given these, and other reasons, such as the easier availability of other 3D desktop environments, such as Compiz, it’s relatively easy to see why Looking Glass died out. The project’s latency is still a loss for the world of development.


Project Euler 5 by Exhaustion in Python

30 June, 2009

Here is my solution to the 5th problem of Project Euler, solved via exhaustion in Python. Please note that I am aware that this problem is more preferably solved by factoring, but programatic exhaustion can be “fun.” With a few added print statements, a file around 3 GB large could be outputted from this 4 kilobyte program.

This program is Python 3-compatible. To make it compatible with earlier versions, remove the parentheses from the final print statement. It is released under the CC BY-SA (Creative Commons Attribution-ShareAlike license).

5. What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?

divisors = range(1, 21)
i = 1

while i:
\t for x in divisors:
\t\t if i % x != 0:
\t\t\t break

\t if i % x == 0 and x == 20:
\t\t answer = i
\t\t i = -1

\t i = i + 1

print(answer)


Follow

Get every new post delivered to your Inbox.