Archived entries for Programming

M68000 Assembly Language Bounce Animation

This is a bouncing ball animation I made in Easy68K – a Motorola 68000 assembly language simulator.

This animation places the coordinates of the ball onto the stack frame as the ball falls, and uses a recursive function call to draw the ball on the way back up.  Below is an animated GIF screen capture of the Console I/O window showing the animation. Cool stuff.

 

Polynomial Graphing Software

This is another project that I created for school. It can be used to graph any polynomial in terms of a single variable with an integer degree. The plotter allows the user to input a polynomial, the variable the polynomial is in terms of and the range they wish to model the given polynomial over. The software also automatically graphs the first and second derivatives of the given polynomial.

Users can specify polynomials using integer operands and the operators: +, – , *, (multiple * operators for exponentiation)

For example:

(x*x)-6

x*x*x*x+4*x-4

(x-3)*(x+4)

0

4*x

-x

etc…

You can download the jar file here.

Feel free to try it out, suggest improvements and identify any bugs! Feedback can be left below.

Java BigInteger Calculator

This is a project I made for school. It is very similar to the windows calculator and supports the following operations on objects of the Java BigInteger class: addition, subtraction, multiplication, division, factorial, remainder, negation.

You can download the .jar file here.

You can leave a comment below!

A Java Class For Rational Numbers

I thought I would post a Java Class I made for part of a project that deals with rational numbers. Pretty simple, yet sturdy implementation of rational numbers if needed. The code is pretty self explanatory. This implementation can create a Rational object given a string “a/b” where a, b are integers. It can also create a rational object given integers for the numerator and denominator directly. This class also supports methods to print, rationalize and compare Rational objects, as well as preform addition (add), subtraction (sub), multiplication (mul) and division of Rational objects.

You can take a look/download it here.

Scripting Craps Odds In Java

Just thought I would show you guys a nifty little program I made in Java to simulate your odds on the dice game Craps. The main for loop of the program simulates one game, and you can adjust int i to simulate different numbers of games.  The final output shows your total wins, the total house wins and your winning percentage. As you can see, the house ALWAYS wins!


package myPackage;
import java.util.Random;

class Main{

public static void main(String args[])
{
float houseWins = 0;
float yourWins = 0;
int thisSum;

Random myRandom = new Random();

for(int i = 0; i <= 10000; i++)
{

/**
Roll two die, take their sums to establish the "come out roll"
**/

int roll1 = myRandom.nextInt(6) + 1;
int roll2 = myRandom.nextInt(6) + 1;

int comeOutRoll = roll1 + roll2;

//Automatic win
if(comeOutRoll == 7 || comeOutRoll == 11)
{
yourWins += 1;
}

//Automatic loss
else if (comeOutRoll == 2 || comeOutRoll == 3 || comeOutRoll == 12){
houseWins += 1;
}

//Play the game
else
{
boolean playing = true;

while(playing)
{
roll1 = myRandom.nextInt(6) + 1;
roll2 = myRandom.nextInt(6) + 1;

thisSum = roll1 + roll2;

if(thisSum == comeOutRoll)
{
yourWins += 1;
playing = false;
}

else if (thisSum == 7){
houseWins += 1;
playing = false;
}
}
}
}

float winPercentage = (yourWins)/(yourWins + houseWins);

//Print the results
System.out.println("Your wins: " + yourWins);
System.out.println("House wins: " + houseWins);
System.out.println("You win: " + winPercentage + "% of the time!");
}
}

C# Palindrome Analysis

What is a palindrome you ask? It is a word spelled the same way forwards and backwards. Racecar and civic are examples of palindromes. In my lengthy and interesting quest to learn c#, I created a nifty little program that recursively determines if a given string is a palindrome. Pretty damn cool!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a string  to preform palindrome check: ");
string mystring = Console.ReadLine();

bool result = palindrome(mystring);

Console.WriteLine("{0} is a palindrome: {1}", mystring, result);

}

static bool palindrome(string mystring)
{
bool is_palindrome = true;

if (mystring.Length == 1)
{
is_palindrome = true;
}

else if (mystring[0] == mystring[mystring.Length - 1])
{
is_palindrome = palindrome(mystring.Substring(1, mystring.Length - 2));
}

else
{
is_palindrome = false;
}

return is_palindrome;
}
}
}

A little bit of Python

I made a quick game of hangman while studying for my university finals, and I thought I would post it for download. Feel free to try it out, modify the code and make changes as you wish. Most of all, don’t be afraid the leave a comment below. After downloading, simply unzip the file and import the project into eclipse (or your choice of IDE)  and run the ‘main.py’ pydev module. Take a look in the ‘word_to_guess.txt” file, where you can add words to the game.

Python Hangman Game

As you can see,  its nothing special,  but demonstrates the incredible power of Python, and the standard library alone. More interesting projects to come.

Kinda cool :)

Eclipse and Infinite While Loops

It’s 2AM. I’ve been programming all day. My laptop was acting up, and I am blaming it all on Eclipse. Ahhhhh Eclipse, its one of those love hate relationships, ya know?  Turns out I did not properly set a condition on a while loop, and my CPU got caught up in infinite loop. This, combined with the simple fact my desk can barely be seen amongst the Mountain Dew cans and miscelanous math homework, should indicate I should be getting to bed. After all, I have to do it all again tomorrow!

Installing GCC On iPhone/iPod Touch

After hearing that GCC had been ported over to the iPod Touch/iPhone, I was intrigued. GCC has always been my favourite compiler, and I think its pretty neat to have it installed on your iPhone/iPod Touch. I just finished setting it up on my touch and I will admit, its pretty cool. There’s not a whole lot of information about this on the web, it looks like there only a handful of people interested in this. Its not the most practical thing, but it is still nice to have. I guess if you wanted to get serious, you would simply cross compile all of your code. I will also mention that it has MAJOR issues. Unfortunately it does not even include the standard iostream file, for c++ programming. Pretty useless, but that can be simply installed later. For those of you who want to install GCC, it can be installed through Cydia. Make sure you have your settings set to “developer”, or you will not be able to find it in Cydia, the package name is “GNU C Compiler”. Once you search it (it can be found under “Development”) you will find that it cannot be installed. It depends on “libgcc” which cannot be found in Cydia. My understanding is that since the package is not incomplete and buggy, libgcc has been removed to discourage you from installing it. In order to install all the prerequisites for GCC, libgcc must be installed. Fortunately, a libgcc deb package has been created for this very propose! It is called “fake libgcc”. I thought I would have difficulty finding a libgcc deb file that has been ported to the iPhone, but I did (Google is the best!). Just do a quick search. After you have the file, simply SSH into your device. Upload the deb file to the root directory and run dpkg. Still in the root directory, run dkpg -i fake-libgcc_1.0_iphoneos-arm.deb (or whatever your particular libgcc file name happens to be). That’s it. You can now install GCC right through Cydia. Like I said before, the package does not include the standard iostream library. I am trying to figure that out, as you can’t program in C++ without it, obviously. I have not tried compiling a C program yet, but I doubt stdio.h is included either. If it does I don’t imagine it works. Like I said before, it appears to be VERY buggy. It doubt installing the headers will be very difficult, I imagine you simply download the header and SSH it to the appropriate location. Although, I’m not quite sure where that location might be… Hopefully I can get the iostream headers to work, because I think this is pretty neat!



Copyright © 2013. All rights reserved.

RSS Feed. This blog is proudly powered by Wordpress and uses Modern Clix, a theme by Rodrigo Galindez.