#!/usr/bin/python
#-*- coding: iso-8859-1 -*-

## Programador: Rodrigo Andrés Contreras Martínez
## Última actualización: 11 de Julio del 2015

from math import sqrt

#def type(algo):
#	try:
#		return algo.type
#		return type(algo)
#	except:
#		return type(algo)
#		return algo.type

class Vector():
	def __init__(self,*otros):
		self.type="vector"	# se tiene type(Vector())="vector"
		self.lista=[]
		for i in otros:
			self.lista.append(i)
		self.modulo=0
		for i in self.lista:
			self.modulo+=i*i
		self.modulo=sqrt(self.modulo)

	def __str__(self):
		retorno="["
		n=len(self.lista)
		for i in range(n):
			if i!=n-1:
				retorno+=str(self.lista[i])+", "
			else:
				retorno+=str(self.lista[i])
		retorno+="]"
		return retorno
	def __repr__(self):
		return str(self.lista)

	def append(self,x):
		self.lista.append(x)
		self.modulo=self.modulo*self.modulo
		self.modulo+=x*x
		self.modulo=sqrt(self.modulo)
	def __getitem__(self,n):
		return self.lista[n]
	def __setitem__(self,n,x):
		self.lista[n]=x
	def __add__(self,otro):
		retorno=Vector()
		for i in range(len(self.lista)):
			retorno.append(self[i]+otro[i])
		return retorno
	def __sub__(self,otro):
		retorno=Vector()
		for i in range(len(self.lista)):
			retorno.append(self[i]-otro[i])
		return retorno
	def __rmul__(self,otro):
		if type(otro)==type(2.3) or type(otro)==type(2) or type(otro)==type(3L) or type(otro)==type(3+1j):
		#### ponderación por escalar ####
			retorno=Vector()
			for i in range(len(self.lista)):
				retorno.append(otro*self[i])
			return retorno
		else:
		#### producto punto de vectores ####
			retorno=0
			for i in range(len(self.lista)):
				retorno+=self[i]*otro[i]
			return retorno
	def __len__(self):
		return len(self.lista)
