How To Run JYTHON Scripts (Windows XP)

30 10 2007
I wrote (Windows XP), because in Linux is too easy.. just add the #! path.. at the beginning
So, let’s get back to the main topic here. I’ll describe what you will obtain.. You will get an option in the right click pop-up menu to run with Jython the clicked file.
Here are the steps you have to follow:

  1. Open a window (you can do that by pressing WinKey+E)
  2. From the menu bar click Tools, and then Folder Options (Alternatively you could this from control panel -> Folder Options
  3. Click the File Types tab, and scroll till you reach the PY extension (You can type P to find it faster..) and select it
  4. Click the Advanced button from the bottom
  5. In the new little window :) click the New.. button
  6. In the new new little window :)), and more precisely in the Action text box type the name you wish to appear in the right click pop-up menu, something like “Run with Jython”
  7. In the next text box type the path to your Jython.bat executable followed by "%1" %*… something like C:\jython2.2.1\jython.bat “%1″ %*
  8. Check the USE DDE option and type Jython in the Application text box and System in the Topic text box.
  9. Now press OK on all those windows.. and that’s it, you’re set!


Python is Great !!!

27 10 2007
I’ve coded my first python program, while… not really, i’ve translated it from c++. It’s a small program made by me in c++ two years ago as homework.
Here it is in C++, and then in Python
/****************************************************************
 * Sa se genereze o matrice patratica de dimensiune n cu elementele 	*
 * 1,2, ... ,n² asezate in spirala ca in exemplul alaturat:				*
 * Ex: pt n=4 avem     10 11 12  1							*
 *                      9 16 13  2									*
 *                      8 15 14  3									*
 *                      7  6  5  4									*
 ****************************************************************/

# include
# include
# include 

int **a, n;

void afisare (int *a[], int n)
{
	for (int i=0; i=k+1; i--) a[n-1-k][i] = v++;
		// coloana din stanga de jos in sus (primele (n-1)-2*k elemente)
		for (i=n-1-k; i>=k+1; i--) a[i][k] = v++;
		// linia de sus de la st la dr (primele (n-1)-2*k elemente)
		for (i=k; i>n;
	}
	while (n
#-------------------------------------------#
# Sa se genereze o matrice    | 10 11 12  1 #
# patratica de dimensiune n   |  9 16 13  2 #
# cu elementele 1,2,...,n²    |  8 15 14  3 #
# asezate in spirala          |  7  6  5  4 #
#-------------------------------------------#

def afisare (matrix, dim):
    for i in range(dim):
        print; #mergea si cu taburi #print matrix[i][j], "\t",
        for j in range(dim): print '%3d' % (matrix[i][j]),

def genmat (dim):
    value = 1; matrix = [[0]*dim for m in range(dim)]
    for k in range(dim/2):
        j = dim-k-1
        for i in range(k,j):
            matrix[i][j] = value
            value += 1
        for i in range(j,k,-1):
            matrix[j][i] = value
            value += 1
        for i in range(j,k,-1):
            matrix[i][k] = value
            value += 1
        for i in range(k,j):
            matrix[k][i] = value
            value += 1
    if (dim%2==1): matrix[dim/2][dim/2] = value
    return matrix

print "Dati dimensiunea matricei patratice A"; dim = -1
while dim 0 obligatoriu!\ndim = ")
matrix = genmat(dim); afisare(matrix,dim)


Windows DropDown Console & Prototype Docs

8 09 2007
A nice post here on instructables.com on how to build your own windows quake-like console.
You will need to install two utilities first, and their combination will lead to the final product.

I noticed that prototype (the javascript framework) changed their site look (although i haven’t had visited it for a long time, so i don’t know when this actually happened) and now they have a well made documentation available also for download as a pdf file or as chm file. They even have a firefox extension, a prototype library reference sidebar, that is dependent on another firefox extension devboi, which i personally don’t use.



java j8 problem

7 09 2007
/*
* J8. Pentru 3


java j2 problem

7 09 2007
/*
 * J2. Sa se determine toate descompunerile unui numar natural
 * n > 0 in suma de termeni distincti ai sirului lui Fibonacci
 */

import java.io.*;
import java.util.Scanner;
import java.util.Vector;
import java.util.List; // pt a folosi doar metodele noi de adaugare/accesare elem vector
import static java.lang.System.*;

class j2 {

	//private static Scanner intrareTastatura = null; // stream de citire de la tastatura
	private static Scanner intrareFisier = null; // stream de citire din fisier
	private static PrintWriter iesireFisier = null; // stream de scriere in fisire

	private static int n = -1; // nr citit din fisier
	private static int nrSol = 0; // nr de solutii LONG dc le las pe toate... si nu le ordonez...

	private static int[] fib;

	private static int[] convLaIntPrimitiv (Integer[] t)
	{
		int[] a = new int[t.length];
		for (int i = 0; i  n) return false;
		return true;
	}

	private static boolean sol (int[] x, int k)
	{
		int sumaTotala = 0;
		for (int i = 0; i  -1) // cat timp n-am iesit din vector
		{
			++x[k]; // trec la urm valoare din domeniu
			if (x[k] > nrMaxim) --k; // trec inapoi pe poz precedenta din vector dc am ajuns la sf domeniului pt acest k
			else if (valid(x, k))
			{
				if (sol(x, k)) afisare(x, k);
				else x[++k] = -1; // trec la urm pozitie si initializez cu prima val din afara dom
			}
		}

		iesireFisier.println(nrSol + " solutii gasite");
		out.println(nrSol + " solutii gasite");
	}

	private static void operatii () throws FileNotFoundException, IOException, Exception
	{
		if (intrareFisier.hasNextInt()) n = intrareFisier.nextInt(); // pt intrare tastaturea se fol intrareTastatura
		if (!(n > 0)) // dc n exista si dc n >= 1
		{
			err.println("Fisierul de intrare trebuie sa contina un numar intreg n >= 1");
			exit(-1); // sau System.
		}

		fib = convLaIntPrimitiv(genereazaTermFib());
		backtracking();
	}

	public static void main(String[] args)
	{
		if (args.length != 2)
		{
			err.println("Argumente: fisierIntrare si fisierIesire !");
			exit(-1);
		}
		try
		{
			intrareFisier = new Scanner(new BufferedReader(new FileReader(args[0])));
			iesireFisier = new PrintWriter(new BufferedWriter(new FileWriter(args[1])));
			//intrareTastatura = new Scanner(new BufferedReader(new InputStreamReader(in)));

			operatii();
		}
		catch (FileNotFoundException e)
		{
			err.println("EROARE CATASTROFALA: imposibli de gasit fisierul");
			e.printStackTrace();
		}
		catch (IOException e)
		{
			err.println("EROARE APOCALIPTICA: operatie intrareFisier/iesireFisier esuata lamentabil");
			e.printStackTrace();
		}
		catch (Exception e)
		{
			err.println("EROARE 821098313: adica necunoscuta");
			e.printStackTrace();
		}
		finally
		{
			if (intrareFisier != null) intrareFisier.close();
			if (iesireFisier != null) iesireFisier.close();
		}
	}
}


Pagina: [1] 2 »