How to translate Shona to English.

Shona to English translation is not easy. So is any translation, because no language is one to one with another language no matter how unrelated or related they are.

Shona for one, does not share any roots with English, other than that people of English decent ‘visited’ Shona lands for 90 years and then left.

Coming back to Translating Shona to English, consider VaShona.com’s Shona to English Translator. The translator seems to be in the developmental stage, however for simple translations it is sufficient.

I have not found any other (mechanical) Shona to English  translators that exist.

Posted in Uncategorized | Leave a comment

Generating n prime numbers in JavaScript

/**

* Prime number
* parameter n is an integer
* Generate n prime numbers
*/
var primeList=[2]; //seed
function prime(n)
{
n += 1;
for (var k = 0; k < primeList.length; k++)
{
if((n%primeList[k])==0)
return prime(n);
}
primeList.push(n);
}

Posted in algorithms, javascript prime number function, prime number, prime number function | Leave a comment

Get fibonacci numbers using JavaScript function

//Returns a Fibonnaci number
//@param n is an integer
function fibonacci(n)
{
if(n < 0)
{
return 0;
}
else if(n <= 2)
{
return 1;
}
else
{
return fibonacci(n - 1) + fibonacci(n - 2)
}
}
Posted in Uncategorized | Leave a comment

Fibonacci numbers : Python

def fibonacci(n):
""" Returns a fibonacci number
Author: http://www.victorbyte.net """
if (n == 1) or (n==2):
return 1;
elif n >= 3:
return fibonacci(n - 1)+fibonacci(n-2);
Posted in introduction, programming | Leave a comment

Find the factorial : Python


def factorial(n):
    """ Returns the factorial of an integer
        Author: http://www.victorbyte.net """
    if n == 0:
        return 1;
    elif n > 0:
        return n * factorial(n - 1);
Posted in Code samples | Tagged | Leave a comment

Remove duplicate characters: python

Python is a great language for text formatting. The trivial functions below are not fully representative of the things one can do in Python, however for a beginner they are sufficient. For further reading I suggest one looks at Python's regular expressions. 

Function #1.
The function takes a lot of overhead, and uses up a lot of resources.
 


def hasDuplicate(str_var):
    """ Checks for and removes repeated characters
        Author: http://www.victorbyte.net
        returns string value """
    iterate = True;
    while iterate:
        iterate = False;
        for i in range (0, len(str_var)):
            for j in range( i + 1, len(str_var)):
                if str_var[i].lower() == str_var[j].lower():
                    str_var = str_var[:j]+str_var[j+1:];
                    iterate = True;
                    break;
    return str_var;

Function #2.
We employ Python's set object. Since sets must not contain duplicate elements, Python removes duplicate characters. This is more efficient than Function #1


def duplicateRmv(str=""):
 setFrmt = set(str);
 str="";
 for i in setFrmt:
  str+=i;
 return str;
Posted in duplicate | Tagged | Leave a comment

Check for duplicate characters : Python

def hasDuplicate(str_var):
    """ Checks for repeated characters
        Author: http://www.victorbyte.net
        returns Boolean value """
    for i in range (0, len(str_var)):
        for j in range( i + 1, len(str_var)):
            if str_var[i].lower() == str_var[j].lower():
                return True;

    return False;
Posted in algorithms, python | 3 Comments

Check for repeated characters: csharp


/// Checks for repeated characters
/// Author: http://www.victorbyte.net
/// returns Boolean value

static bool hasDuplicate(string str)
{
   for (int i = 0; i < str.Length; i++)
   { 
       for (int j = i + 1; j < str.Length; j++)
       {                   
           if (str.ElementAt(i) == str.ElementAt(j))
               return true;               
       }       
   }        
   return false;
} 
Posted in Code samples | Tagged , | Leave a comment

Greatest Common Divisor : Java


/** 
* Gets GCD between two positive integers.   
* source: http://www.victorbyte.net  
* Returns int value   
*/ 
public static int getGCD(int numA, int numB)
{
    if(numA < numB)
    {
        int temp = numA;
        numA = numB;
        numB = temp;
    }

    if( numB <= 0 ) return 0;

    if((numA % numB) == 0)
        return numB;

    return getGCD( numB , numA %= numB );
}
Posted in Code samples | Tagged | Leave a comment

Using Python to visualize the div, mod and remainder of a number.

def divTheory(a,b):
n = a;
d = b;
q = n // d;
r = n % d;
print(n," = number n",d," = divisor n",q," = quotient n",r, " = remaindern");
Posted in Uncategorized | Leave a comment