Tag Archives: Java

Projects that kept (and keep) me busy in these months

Hi everybody! I don’t know why i keep update this wordpress release but not post something new.. maybe i lack of inspiration or i just think that people don’t care (and me too). So, this is the first 2009 update, let’s start.

  1. NeXtRL.it FanZine
    I was six years old when i bought and read my first magazine, console magazine, and now i’m a sort of publisher of a community-made magazine, the NeXtRL.it Fanzine (started on December 2008). Here are the published issues.
    I made a lot of experience with both amateur (publisher 2007) and professional (quarkxpress) press software and i studied some way to share works (the written articles) and simplify human interactions with a “nothing-can-go-wrong” module (see point (2)). Now i’m working on the third issue of the fanzine and i’d like to do it with adobe indesign (another pro app) because i didn’t enjoy my experience with quarkxpress – complicated also on easy tasks like pick the right tool from the panel and no color picker!
  2. NeXtRL.it – Form to submit articles for the FanZine
    It’s a simple form with some javascriptย  that uses a validation engine (in javascript too) found on this tutorial. People can enter various type of articles, filling in the different fields that the chosen type of article requires. Then they can modify, delete or send (to themselves or to publisher – me) their ready-to-print articles. Then the articles arrive on my google docs account so i can share them with my collaborators that check for grammar errors and i finally i can paginate the final articles.
    I made it with php, mysql and IPB API because nextrl.it uses IPB Forum. So here it is the link, but you can’t access if you’re not logged in – and it’s all written in italian, too.
    Source code not available because i made it just for nextrl.it
  3. NeXtRL.it – Tournament script
    Here, i enanched an old script that i made adhoc for nextrl.it a year ago. It was messy and hardcoded, now it’s more flexible and still a bit messy ๐Ÿ˜› I think i need to switch my php’s habits to OOP and start comment while (and not after) coding.
    Now the script can handle more than one tournament and of various type: ladders, points, victories. I rewritten quite the 95% of the code and it took me a week. This is the link and, also there, you can’t access if you’re not logged in and it’s in italian too.
    Source code not available because i made it just for nextrl.it
  4. Automata & Languages: Cocke-Younger-Kasami Parser
    I made this parser in a month for university purpose. I will post and explain the code when i will pass the related exam, so here there are some info form wikipedia. Basically, i did a program that manipulate a context-free grammar to eliminate epsilon production, unit production, put it in chomsky normal form and last parse a word with CYK algorithm and say if it belong, or not, to the given grammar.
    Made with Java (instead of C++) for it’s wide library of string manipulation functions.
  5. ns2/nsmiracle
    I started to study about my thesis: understand how ns2 and nsmiracle modules are written to implement specific ones. Next monday (the 18th of May 2009) i will know more about those modules.
  6. WWTBAFM: new release?
    I though two times about release a new version of wwtbafm: two separated homebrew, one to play and the other to update questions. when i’ll have time and i will get my nds back i would give it a try, now that palibs are fixed to work with latest ndslib

That’s all, let’s hope more updates soon ๐Ÿ™‚

UPDATE: oh, well, i forgot to mention that i have also build a simple rs232-ttl interface to mod my x360. I will post schema and how-to on next post ๐Ÿ™‚

PowerSet Construction

well.. almost a year is passed from my last post.. :\ ugh. it must seems that i did nothing! while it’s quite true on the programming side.. it’s not so much true on life side. i just miss four exam, two apprenticeship and a thesis to get gratueted as IT engineer. So apart from my wasted social life, here it is one of my last work: an algoritm to compute a generic powerset construction. I did it while i was studying something about grammars and languages. So here it is, the program in java ๐Ÿ™‚

Basically, a powerset construction it’s the set of all combinations of the items given, and the number of combinations is very simple to calculate: 2^x is the answer where x is the number of element to combine. well, after this we need to think how to pick the elements to write down all the combinations. we will have 2^x combinations starting from the empty set to the full elements set. but how to compute that on an easy way?
that is the basic idea: 2^x is our number of combinations (ugh i said it about twenty-eight times..) that can pratically be represented by a binary number where every digit represent an element.. then now we have now to include (or exclude) an element if its representative digit is one or zero.

So we will have just four elements a,b,c,d and we start from the binary number “0000” (if we have 4 element to combine) and we will exclude all the elements (empty set, represented with “{}”). Then we just need to “add 1” (logically, in binary!) to get the next set: “0001” -> {a}, sum 1, “0010” -> {b}, sum 1 again, “0011” -> {a,b}, sum 1, “0100” -> {c}, “0101” -> {a,c}, “0110” -> {b,c}, “0111” -> {a,b,c}, and go on till have “1111” -> {a,b,c,d}.. now let’s put all togheter to make our powerset construction!

{};{a,};{b,};{a,b,};{c,};{a,c,};{b,c,};{a,b,c,};{d,};{a,d,};{b,d,};{a,b,d,};{c,d,};{a,c,d,};{b,c,d,};{a,b,c,d,}

So that is the result.. but it’s very simple and a bit odd.. because it isn’t not in the standard order.. maybe one day i will improve the algoritm including ordering. not that hard to do.

well, here it is the code ๐Ÿ™‚ thank you for reading.

import java.util.Scanner;
import java.util.StringTokenizer;

public class Powerset {

private int num;
private boolean save_parts;
private String string;
private String elements[];
private boolean binary[];
private String parts[];

public Powerset()
{
num=0;
string=””;
save_parts=false;
}

public void save_parts_on()
{
save_parts=true;
}

public void save_parts_off()
{
save_parts=false;
}

public void insert_elements()
{
System.out.print(“Please type in the elements separated by \”|\” symbol: “);
Scanner scanner = new Scanner(System.in);
string=scanner.next(); //carico la stringa digitata
StringTokenizer token = new StringTokenizer(string, “|”);
int count = token.countTokens();
elements = new String[count]; //dimensiono l’array degli elementi
num=(int)Math.pow(2, count);
if (save_parts) parts = new String[num];
binary = new boolean[count]; //e quello dei valori binari

count = 0;
while (token.hasMoreTokens()) //prendo gli elementi uno ad uno e li assegno nel vettore
elements[count++] = new String(token.nextToken());

if (save_parts)
for (count=0; count