# Monthly Archives: March 2013

# The Theory of the Quantum Computer

A few days ago, a friend informed me of the recent actions of Lockheed Martin and D-Wave Systems with regards to the “Quantum Computer”. This information piqued my curiosity pertaining to the topic, and I elected to do a bit of research. According to Kevin Bonsor and Jonathan Strickland at “HowStuffWorks”, the power of the “Quantum Computing” theory lies within the principle of the “superposition” of digits: all computers today rely on the numerical digits of “Base 2”, consisting of “0” and “1”. Through the utilization of Quantum Theory, Quantum Computers can utilize the superposition of “1” and “0”, including all numbers between the two aforesaid digits. This realization is incredibly powerful; instead of a simple “on” or “off” position within a transistor mandating that only one calculation be performed per cycle, millions can be performed at one time, utilizing this “Quantum Computing” principle and “superposition”. The metric for computer calculation speed is the “flop”, which is defined as “Floating Point Operations Per Second”, or the amount of calculations utilizing decimal numbers, per second. Currently, desktop computers rank in the area of “Gigaflops”, which allow for billions of calculations, per second. One of the most advanced Quantum Computers produced by D-Wave Systems can perform calculations in the realm of “Teraflops”, or trillions of floating point calculations, per second. With advancements such as those made by D-Wave Systems, the computational power of laboratories and technological corporations could grow immensely. However, as described in the “HowStuffWorks” article, the main drawback in the development of Quantum Computing is the comprehension of Quantum Mechanics, itself. While the speeds claimed by Quantum Computer production corporations are incredible, they are equally questionable. This notion aside, Quantum Computing appears to be one of the most promising computing technologies in recent news.

Photo Courtesy of D-Wave Systems

http://en.wikipedia.org/wiki/FLOPS

# NWSC Supercomputer at Yellowstone National Laboratory

Delving inside Yellowstone National Laboratory, this video illustrates the immense power possessed by each of NWSC’s supercomputers.

# Interesting Programs

Below, you will find one Python function, and one Python program. Once I had created them, I was amused by their combination of simplicity, efficiency, and effectiveness.

####################### # Name: CDT Brendan Babcock # File Name: hw6.py ####################### # Problem 1 # # Program Explanation: This function computes the sum of the neighboring numbers of a number in a given list, for all numbers within the list. # The function then returns a new list (of the same length), containing the summed numbers. # # Test Case 1: # listOfNums = [10, 20, 30, 40, 50] # newListOfNums = [30, 60, 90, 120, 90] # # Test Case 2: # listOfNums = [20, 30, 40, 50, 60, 70, 80] # newListOfNums = [50, 90, 120, 150, 180, 210, 150] def sumOfNeighbors(old_list): lengthOld = len(old_list) new_list = [] newNumber = 0 newNumber2 = 0 newNumber3 = 0 for i in range (0, lengthOld): if i==0: newNumber = old_list[i]+old_list[i+1] new_list.append(newNumber) if i >0 and i < lengthOld-1: newNumber2 = old_list[i-1]+old_list[i]+old_list[i+1] new_list.append(newNumber2) if i==lengthOld-1: newNumber3 = old_list[lengthOld-1]+old_list[lengthOld-2] new_list.append(newNumber3) return new_list if __name__=="__main__": listOfNums = [20, 30, 40, 50, 60, 70, 80] newListOfNums = sumOfNeighbors(listOfNums) print newListOfNums # Problem 2 # # Program Explanation: This program takes as input a file containing a phrase, and encrypts it. This is done through transcription to an intermediary list, encryption, and finally re-writing the # original file to contain the encrypted phrase. # # Test Case 1: # Old Phrase: THE EAGLE FLIES AT DAWN. # New Phrase: WKH HDJOH IOLHV DW GDZQ. # # Test Case 2: # Old Phrase = the eagle flies at dawn. # New Phrase = WKH HDJOH IOLHV DW GDZQ. def caesarCipher(): userFile = "" userFile = raw_input("Please enter the name of the file you will be utilizing.") inputFile = open(userFile,"r") encodedList = [] encodedList2 = [] overLength = 0 for lines in inputFile: for char in lines: encodedList.append(char.capitalize()) for chars in encodedList: if char == " ": encodedList2.append(chars) if ord(chars) >=65 and ord(chars) <=87: chars = chr(ord(chars)+3) encodedList2.append(chars) elif ord(chars) == 88: overLength = 65 encodedList2.append(chr(overLength)) elif ord(chars) == 89: overLength = 66 encodedList2.append(chr(overLength)) elif ord(char) ==90: overLength = 67 encodedList2.append(chr(overLength)) else: encodedList2.append(chars) lengthList = len(encodedList) out_file = open(userFile,"w") for i in range (0, lengthList): out_file.write(encodedList2[i]) out_file.close() caesarCipher()

# Excursion into D.C’s Chinatown

# Preliminary Python Game

Below is the code for a Python game I have almost finished, entitled “Heap Of Beans”; in which a user competes against the computer to draw the final “bean” in the pile of sixteen. This program is still under development, and will be complete shortly.

# Problem 1

#

# Program Explanation: This program is the "Easy" function for the "Heap of Beans" program, and makes the computer player predictable to the user by

# only allowing the computer to deduct one bean each turn.

#

# Test Case 1:

# Please enter the difficulty you would like to utilize. Easy

# There are 16 beans in the pile.

# The amount of beans subtracted by the computer player is: 1.

# There are 15 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 1.

# There are 11 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 2

# The amount of beans subtracted by the computer player is: 1.

# There are 8 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 1.

# There are 4 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 2

# The amount of beans subtracted by the computer player is: 1.

# There are 1 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 1

# You won!!

#

#

# Test Case 2:

# Please enter the difficulty you would like to utilize. Easy

# There are 16 beans in the pile.

# The amount of beans subtracted by the computer player is: 1.

# There are 15 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 2

# The amount of beans subtracted by the computer player is: 1.

# There are 12 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 1.

# There are 8 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 1.

# There are 4 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 1

# The amount of beans subtracted by the computer player is: 1.

# There are 2 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 1

# You lost!!

# The amount of beans subtracted by the computer player is: 1.

import random

def Easy(beans):

print "There are 16 beans in the pile. "

computerSubtract = 1

while beans >= 0:

beans -= computerSubtract

if beans >0:

print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."

if beans >0:

print "There are "+str(beans)+" beans remaining."

if beans >0:

playerSubtract = input("Please enter the number of beans you would like to remove from the heap. ")

beans-=playerSubtract

if beans == 0:

print "You won!!"

if beans ==1:

print "You lost!!"

print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."

return beans

# Problem 2

#

# Program Explanation: This function expands upon Problem 1, allowing the computer player to choose any random (integer) number of beans, between 1 and 3.

#

#

# Test Case 1:

# Please enter the difficulty you would like to utilize. Medium

# There are 16 beans in the pile.

# The amount of beans subtracted by the computer player is: 2.

# There are 14 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 3.

# There are 8 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 2

# The amount of beans subtracted by the computer player is: 1.

# There are 5 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 1.

# There are 1 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 1

# You won!!

#

#

# Test Case 2:

# Please enter the difficulty you would like to utilize. Medium

# There are 16 beans in the pile.

# The amount of beans subtracted by the computer player is: 1.

# There are 15 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 2

# The amount of beans subtracted by the computer player is: 2.

# There are 11 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 3.

# There are 5 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 2

# The amount of beans subtracted by the computer player is: 3.

# You lost!

def Medium(beans):

print "There are 16 beans in the pile. "

while beans > 0:

computerSubtract = random.randint(1,3)

while computerSubtract > beans:

computerSubtract = random.randint(1,3)

beans-=computerSubtract

if beans >0:

print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."

if beans ==0:

print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."

print "You lost!"

if beans > 0:

print "There are "+str(beans)+" beans remaining."

playerSubtract = input("Please enter the number of beans you would like to remove from the heap. ")

beans -= playerSubtract

if beans == 0:

print "You won!!"

if beans <0:

print "You lost!"

return beans

# Problem 3

#

# Program Explanation: This function further expands upon the "Medium" difficulty, through the use of cascading "if-statements" to attempt to "guess" the user's input on the next turn,

# and a means of winning the game for the Computer player.

#

# Test Case 1:

# Please enter the difficulty you would like to utilize. Hard

# There are 16 beans in the pile.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 3.

# There are 10 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 2

# The amount of beans subtracted by the computer player is: 3.

# There are 5 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 2.

# You lost!

#

#

# Test Case 2:

# Please enter the difficulty you would like to utilize. Hard

# There are 16 beans in the pile.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 3.

# There are 10 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 2

# The amount of beans subtracted by the computer player is: 3.

# There are 5 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 1

# The amount of beans subtracted by the computer player is: 3.

# There are 1 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 1

# You won!!

#

#

# Test Case 3:

# Please enter the difficulty you would like to utilize. Hard

# There are 16 beans in the pile.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 3.

# There are 10 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 2.

# There are 5 beans remaining.

# Please enter the number of beans you would like to remove from the heap. 3

# The amount of beans subtracted by the computer player is: 2.

# You lost!

def Hard(beans):

print "There are 16 beans in the pile. "

while beans > 0:

playerSubtract = input("Please enter the number of beans you would like to remove from the heap. ")

beans -= playerSubtract

if beans == 0:

print "You won!!"

if beans <0:

print "You lost!"

if beans==3:

computerSubtract=3

if beans == 2:

computerSubtract = 2

if beans == 1:

computerSubtract = 1

if beans >=8 and beans <=14:

computerSubtract = 3

elif beans >=7 and beans >=2:

computerSubtract = 2

beans-=computerSubtract

if beans >0:

print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."

if beans > 0:

print "There are "+str(beans)+" beans remaining."

if beans ==0:

print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."

print "You lost!"

return beans

if __name__ == "__main__":

beans = 16

difficultySelect = raw_input("Please enter the difficulty you would like to utilize. ")

if str(difficultySelect)=="Easy":

beans = Easy(beans)

elif str(difficultySelect)=="Medium":

beans = Medium(beans)

elif str(difficultySelect)=="Hard":

beans = Hard(beans)