Recursive Football Problem

May 19th, 2012 No comments

I got bored and wanted to make something challenging, so I decided to make this. I know that it’s not really of any use to anyone, so I thought I’d post it for learning purposes. The way that I did this probably isn’t the best, but it’s the only way I could come up with.

Download Executable
Source
 

Categories: Code Snippets, Programs Tags:

Conjuguemos Auto-Complete Script

May 16th, 2012 No comments

This script will automatically complete Conjuguemos with your specified results, such as amount correct, amount incorrect, and the time it took to do it all. Once you paste the script into your browser and run it, a few message boxes will show, asking you for these settings.

To run Javascript, for let’s say Google Chrome, you just enter “javascript:” and then your javascript code in the URL box.

The Javascript script is:

if (start == 0)
	{
		if (activityType == "vocabulary") {
			jQuery.ajax('/au.php?x=sa&t='+activityType);
			randomizeList("yes");
			setvariable();
		}
		else if (activityType == "verbs") {
			jQuery.ajax('/au.php?x=sa&t='+activityType);
			howToSelectVerbs('yes');
			setvariable();
		} else {
			jQuery.ajax('/au.php?x=sa&t='+activityType);
		}
	}

	var getCorrect = parseInt(prompt("How many would you like to get correct?", 1));
	var getIncorrect = parseInt(prompt("How many would you like to get incorrect?", 1));

	var qTime = parseInt(prompt("How much time would you like each question to take? (in seconds)", 33));
	var totalSecs = (getCorrect + getIncorrect) * qTime;
	tmin = Math.round(totalSecs / 60);
	tsec = Math.round(totalSecs % 60);

	if(tmin > 59)
	{
		tmin = 59;
		tsec = 58;
	}

	var yi = 0;
	for(yi = 0; yi < getIncorrect; yi++)
	{
		$('#response').val(solution + yi);
		verifyAnswer();
		$("#form").submit();
	}

	for(yi = 0; yi < getCorrect; yi++)
	{
		$('#response').val(solution);
		verifyAnswer();
		$("#form").submit();
	}
	stopClock();

	alert("Done! Click 'Print Results', check your results, and if all is good click 'Record/send results'.\n\nCreate by Stevie Hetelekides.");

So to do it in Google Chrome, you'd navigate to the Conjuguemos page where you begin practice, and then you'd put this into the URL box:

javascript: *AND THE CODE ABOVE*

Notice that when pasting into the Google Chrome URL box, the "javascript:" prefix gets removed/trimed.

Categories: Uncategorized Tags:

PowerPC Fibonacci Sequence Generator

February 13th, 2012 No comments

The following code will generate the first ‘n’ numbers in the Fibonacci sequence, and store those numbers in ‘dest’.

void fibOfN(int n, int *dest)
{
	_asm
	{
		//load r5 and r6 with the
		//first numbers in the sequence
		li r5, 0
		li r6, 1

		//if n is one, then just store the
		//first number in the sequence
		cmpwi r3, 1
		beq store1
		//as long as they asked for at least 2
		//we can store 2
		stw r5, 0(r4)
		stw r6, 4(r4)
		//if the caller only wants 2 values, then
		//we need to return
		cmpwi r3, 2
		beq returnYo

		//subtract 2 from n
		subi r3, r3, 2

		//move our param n to the ctr
		mtctr r3

		//add 8 to the array, so that it's
		//now pointing at the int after the
		//spot where the second num in the series is
		addi r4, r4, 8

		loopStart:
			//calc. next number in sequence
			add r7, r5, r6
			//make r5 hold the next num in the series
			mr r5, r6
			//make r6 hold the next num in the series
			mr r6, r7
			//store the next num in the seris
			//in the array
			stw r6, 0(r4)
			//add to the array so that points to the next
			//element in the array
			addi r4, r4, 4
			//loop back to the top
			bdnz loopStart
		//return when finished
		blr

		store1:
			stw r5, 0(r4)
			blr

		returnYo:
			blr
	}
}
Categories: Code Snippets Tags:

x64 String Remove Between

January 30th, 2012 No comments

This function will remove the characters in a string between 2 indices, and return the address of the result.

mod glitches

Categories: Code Snippets Tags:

PowerPC Radical Reducer

January 30th, 2012 No comments

Hey, here is a pretty cool function I created using PowerPC with some help from Experiment5X. I just got my XDK, so I have been messing around with PowerPC alot, and it’s pretty fun. I’m pretty sure this code is really bad, but whatever for now. What it will do is, reduce a radical. So say you go:

int *reduced = reduceRadical(12);

It will return an integer pointer, with a static size of 2. The first element in the array is the number outside of the radical(must sqrt this!), and the second one is the integer inside/under the radical. So with the above code:

reduced[0] will equal 4. <- I could not figure out how to sqrt in PowerPC, so just look at my main() function in my source. (below)

reduced[1] will equal 3.

Pretty simple really. The only problem is, I could not figure out how to sqaure root a number using PPC, so I had to keep it as the square root. Here is some code, with the output(on XDK):

Source: #3270758 - Pastie
Full Solution: XboxProject.zip
Output:

Categories: Code Snippets, Programs Tags:

C File Reading Thread Thing

January 28th, 2012 No comments

I got the idea for this from watching Stanford’s Progamming Paradigms series, and I just wanted to re-create it for practice. Yes, I know it uses windows only functions, but I couldn’t seem to get POSIX to work, oh well. It is what it is, anyways, here’s the code.

#include 
#include 
#include 

#define fileLen 0x2D

char buffer[8];
HANDLE semEmptySlots;
HANDLE semFullSlots;

void readBytes();
void writeBytes();

int main()
{
    semEmptySlots = CreateSemaphore(NULL, 8, 8, "Empty Slots");
    semFullSlots = CreateSemaphore(NULL, 0, 8, "Full Slots");

    HANDLE readThread = (HANDLE)_beginthread(&readBytes, 0, 0);
    HANDLE writeThread = (HANDLE)_beginthread(&writeBytes, 0, 0);

    WaitForSingleObject(readThread, INFINITE);
    WaitForSingleObject(writeThread, INFINITE);
    printf("\n");
    return 0;
}

void readBytes()
{
    FILE *f = fopen("C:\\Users\\Adam\\Desktop\\Adam.txt", "r");
    fseek(f, 0, SEEK_SET);
    char c = 1;
    int i = 0;
    while (c != EOF)
    {
        WaitForSingleObject(semEmptySlots, INFINITE);
        buffer[i % 8] = fgetc(f);
        c = buffer[i % 8];
        ReleaseSemaphore(semFullSlots, 1, NULL);
        i++;
    }
    fclose(f);
}

void writeBytes()
{
    for (int i = 0; i < fileLen; i++)
    {
        WaitForSingleObject(semFullSlots, INFINITE);
        printf("%c", buffer[i % 8]);
        ReleaseSemaphore(semEmptySlots, 1, NULL);
    }
}
Categories: Code Snippets Tags:

PowerPC String Concatenate

January 27th, 2012 No comments

Experiment and I have just put together a little snippet in PowerPC which concatenates two strings together and returns the result. There are two functions that we have created (one gets the length of a string, and the other actually does the concatenation stuff). Not much to say about it, but if anyone is wondering how to compile it, you really can’t unless you have some kind of machine that supports it (XDK).

 

int strLength(const char* str)
{
    _asm
    {
        li r4, 0

        loop:
            lbz r5, 0(r3)
            cmplwi r5, 0
            beq exitFunc
            addi r3, r3, 1
            addi r4, r4, 1
            b loop

        exitFunc:
            mr r3, r4
    }
}

char* concatStr(const char* str1, const char* str2)
{
    _asm
    {
        //store these registers so we can pop them off later
        stw r31, -10h(r1)
        stw r30, -18h(r1)

        mr r31, r3
        mr r30, r4

        bl strLength
        mr r9, r3 //len of str1 is in r9

        mr r3, r30
        bl strLength
        mr r10, r3 //len of str2 is in r10

        add r11, r9, r10
        addi r11, r11, 1 //len of concated string is in r11

        //push these registers on the stack so we can get them back after malloc screws them up
        stw r9, -20h(r1)
        stw r10, -28h(r1)
        stw r11, -30h(r1)

        mr r3, r9
        bl malloc

        //get dem values back
        lwz r9, -20h(r1)
        lwz r10, -28h(r1)
        lwz r11, -30h(r1)

        loop1Start:
            lbz r6, 0(r31)
            stb r6, 0(r3)
            addi r31, r31, 1
            addi r3, r3, 1
            subi r9, r9, 1
            cmplwi r9, 0
            bne loop1Start

        loop2Start:
            lbz r6, 0(r30)
            stb r6, 0(r3)
            addi r30, r30, 1
            addi r3, r3, 1
            subi r10, r10, 1
            cmplwi r10, 0
            bne loop2Start

        li r4, 0
        stb r4, 0(r3)
        subi r11, r11, 1
        sub r3, r3, r11

        lwz r30, -18h(r1)
        lwz r31, -10h(r1)
    }
}
Categories: Code Snippets Tags:

Java Maze Solver

January 19th, 2012 No comments

This code will simply solve a maze, just make a text file that has S as the start, G as the goal, _ as the path, and # as the walls. It’s done using the breadth-first traversal which is more efficient than the depth-first traversal because it will find the quickest path first. I did get a bunch of help from google, especially on the part where I needed to trace the path, but whatever. Anyways, here’s the code.

Show Source Code »

import java.util.*;
import java.awt.Point;
import java.io.*;

public class MazeSolver
{
	static int height, width;
	static char[][] maze;

	public static void main(String[] args) throws FileNotFoundException
	{
		Scanner fileReader = new Scanner(new FileReader("Maze.txt"));
		width = fileReader.nextInt();
		height = fileReader.nextInt();
		maze = new char[height][width];
		Point start = null;
		for (int y = 0; y < width; y++)
		{
			String s = fileReader.next();
			for (int x = 0; x < height; x++)
			{
				maze[y][x] = s.charAt(x);
				if (maze[y][x] == 'S')
					start = new Point(x, y);
			}
		}
		fileReader.close();
		if (start == null)
		{
			System.out.println("No starting point found!");
			return;
		}
		solveMaze(start);
	}

	static void solveMaze(Point loc)
	{
		Set visited = new HashSet();
		Queue toVisit = new LinkedList();
		Map pathBuilder = new HashMap();
		toVisit.offer(loc);

		while (toVisit.size() != 0)
		{
			Point current = (Point)toVisit.remove();
			visited.add(current);
			if (maze[current.y][current.x] == 'G')
			{
				System.out.println("Maze is possible");
				Stack path = new Stack();
				Point parent = pathBuilder.get(current);
				path.push(current);
				while (parent != null)
				{
					path.push(parent);
					parent = pathBuilder.get(parent);
				}
				Point temp = path.pop();
				Point temp2 = path.pop();
				while (!path.isEmpty())
				{
					System.out.println(getInstruction(temp, temp2));
					temp = temp2;
					temp2 = path.pop();
				}
				System.out.println(getInstruction(temp, temp2));
				return;
			}

			Point p1 = new Point(current.x - 1, current.y);
			if (checkBounds(p1) && !visited.contains(p1) && maze[p1.y][p1.x] != '#')
			{
				pathBuilder.put(p1, current);
				toVisit.offer(p1);
			}
			Point p2 = new Point(current.x + 1, current.y);
			if (checkBounds(p2) && !visited.contains(p2) && maze[p2.y][p2.x] != '#')
			{
				pathBuilder.put(p2, current);
				toVisit.offer(p2);
			}
			Point p3 = new Point(current.x, current.y -1);
			if (checkBounds(p3) && !visited.contains(p3) && maze[p3.y][p3.x] != '#')
			{
				pathBuilder.put(p3, current);
				toVisit.offer(p3);
			}
			Point p4 = new Point(current.x, current.y + 1);
			if (checkBounds(p4) && !visited.contains(p4) && maze[p4.y][p4.x] != '#')
			{
				pathBuilder.put(p4, current);
				toVisit.offer(p4);
			}
		}
		System.out.println("Maze isn't possible.");
	}

	static boolean checkBounds(Point loc)
	{
		return (loc.x > -1 && loc.x < width && loc.y > -1 && loc.y < height);
	}

	static String getInstruction(Point p1, Point p2)
	{
		if (p1.x - p2.x < 0)
			return "Move right.";
		else if (p1.x - p2.x > 0)
			return "Move left.";
		else if (p1.y - p2.y < 0)
			return "Move down.";
		else if (p1.y - p2.y > 0)
			return "Move up.";
		return "";
	}
}
Categories: Code Snippets Tags:

Java Radical Reducer

January 17th, 2012 No comments

This program will allow you to reduce a radical. Simply enter the radicand, and it will display the reduced form in a message box. Also, I included the source for anyone who wants it.

pic

Show Source Code »

package hello;

import java.util.*;
import java.util.List;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class datClass
{
	public static void main(String[] args)
	{
		GUI ui = new GUI();
		ui.setVisible(true);
		ui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

class GUI extends JFrame
{
	private static final long serialVersionUID = 1L;

	//Controls
	JButton radicalSubmitButton = new JButton("Simplify");
	JTextField radicalSubmitBox = new JTextField();
	JLabel radicalLabel = new JLabel("Radicand: ");

	public GUI()
	{
		super.setLayout(null);
		Dimension d = new Dimension();
		d.height = 60;
		d.width = 315;
		super.setMaximumSize(d);
		super.setMinimumSize(d);
		super.setSize(d);
		super.setTitle("Radical Reducer");
		super.setName("Radical Reducer");
		Rectangle r = new Rectangle();
		super.setResizable(false);

		radicalLabel.setVisible(true);
		radicalLabel.setLocation(5, 5);
		radicalLabel.setSize(110, 20);
		super.add(radicalLabel);

		radicalSubmitBox.setVisible(true);
		radicalSubmitBox.setLocation(70, 5);
		radicalSubmitBox.setSize(140, 20);
		super.add(radicalSubmitBox);

		radicalSubmitButton.setVisible(true);
		radicalSubmitButton.setLocation(220, 5);
		radicalSubmitButton.setSize(80, 20);
		super.add(radicalSubmitButton);
		radicalSubmitButton.addActionListener(
				new ActionListener()
                {
	                public void actionPerformed(ActionEvent event)
	                {
	                	int[] nums = AdamsMathClass.ReduceRadical(Integer.parseInt(radicalSubmitBox.getText()));
	                	JOptionPane.showMessageDialog(null, String.format("%d v %d", nums[1], nums[0]));
	                }
                }
		);
	}
}

class AdamsMathClass
{
	//inside = 0, outside = 1
	public static int[] ReduceRadical(int insideArg)
	{
		int[] perfectSquares = GetPerfectSquares(insideArg + 1);
		int[] toReturn = { insideArg, 1 };

		if (Math.sqrt(insideArg) == Math.round(Math.sqrt(insideArg)))
		{
			toReturn[0] = 1;
			toReturn[1] = (int)Math.sqrt(insideArg);
		}

		for (int i = 1; i  toReturn = new LinkedList();
		toReturn.add(4);
		for (int i = 1; ; i++)
		{
			toReturn.add(toReturn.get(i - 1) + ((i - 1) * 2) + 5);
			if (toReturn.get(i) >= max)
			{
				toReturn.remove(i);
				return intListToArray(toReturn);
			}
		}
	}

	static int[] intListToArray(List list)
	{
		int[] ints = new int[list.size()];
		for (int i = 0; i < ints.length; i++)
			ints[i] = list.get(i);
		return ints;
	}
}

Categories: Code Snippets, Programs Tags:

MW3 Offline Editor

January 17th, 2012 2 comments

Hey, Experiment5X and I have created a tool which allows you to edit your Modern Warfare 3 offline stats(MPdata). This can be used to level up in split screen/system link, and you can also change your classes straight from the application. It is not completely finished, but we may get back to working on it soon. We plan to add support for Killstreaks and Challenge Unlocking.

1.0.2.1(Latest):
Download Source
Download Executable

Change Log:
1.0.2.1
- Added support for strike packages
- Added support for redicle sight
- Minor UI changes
- Minor bugs fixed

1.0.1.4
- Fixed the 17 & 18 item ID bug

1.0.1.0
- Merged assembly
- Checks to now ensure you are openeing the correct file
- Framework has been downgraded to 3.5
- Added a hidden camo (Maybe founder?)
- Minor bugs fixed

1.0.0.0
- Initial release

Please report any bugs, and feel free to suggest for future updates. ;)

READ:
Make sure you extract the mpdata out of the mpdata CON file, and then open the extracted onto the application.

Categories: Programs Tags: