Skip to content

Instantly share code, notes, and snippets.

@RunasSudo
Last active January 3, 2016 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RunasSudo/8429011 to your computer and use it in GitHub Desktop.
Save RunasSudo/8429011 to your computer and use it in GitHub Desktop.
DSA Calculator
package io.github.runassudo.dsacalculator;
import java.io.*;
import java.net.*;
import java.util.*;
public class DSACalculator {
public static void main (String[] args) throws Exception { // :P
String REGION = args[0];
URLConnection conn = new URL("http://www.nationstates.net/cgi-bin/api.cgi?region=" + REGION + "&q=nations").openConnection();
BufferedReader rdr = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String data = rdr.readLine();
rdr.close();
float total = 0;
String[] nationsArray = data.substring(data.indexOf("<NATIONS>") + "<NATIONS>".length(), data.indexOf("</NATIONS>")).split(":");
List<String> nations = Arrays.asList(nationsArray);
rdr = new BufferedReader(new FileReader("nations.xml"));
data = null;
while ((data = rdr.readLine()) != null) {
if (data.contains("<NAME>")) {
String name = data.substring(data.indexOf("<NAME>") + "<NAME>".length(), data.indexOf("</NAME>")).toLowerCase().replace(" ", "_");
if (nations.contains(name)) {
while (!(data = rdr.readLine()).contains("<CATEGORY>"));
String category = data.substring(data.indexOf("<CATEGORY>") + "<CATEGORY>".length(), data.indexOf("</CATEGORY>"));
int score = 0;
if (category.equals("Psychotic Dictatorship") || category.equals("Iron Fist Consumerists") || category.equals("Corporate Police State"))
score = 1;
if (category.equals("Authoritarian Democracy") || category.equals("Moralistic Democracy") || category.equals("Right-wing Utopia"))
score = 2;
if (category.equals("Corrupt Dictatorship") || category.equals("Father Knows Best State") || category.equals("Mother Knows Best State") || category.equals("Compulsory Consumerist State"))
score = 2;
if (category.equals("Tyranny by Majority") || category.equals("Conservative Democracy") || category.equals("Free-Market Paradise"))
score = 4;
if (category.equals("Iron Fist Socialists") || category.equals("Libertarian Police State") || category.equals("Benevolent Dictatorship"))
score = 4;
if (category.equals("Democratic Socialists") || category.equals("Inoffensive Centrist Democracy") || category.equals("Capitalist Paradise"))
score = 8;
if (category.equals("Liberal Democratic Socialists") || category.equals("New York Times Democracy") || category.equals("Corporate Bordello"))
score = 8;
if (category.equals("Scandinavian Liberal Paradise") || category.equals("Left-Leaning College State") || category.equals("Capitalizt"))
score = 8;
if (category.equals("Left-wing Utopia") || category.equals("Civil Rights Lovefest") || category.equals("Anarchy"))
score = 8;
if (score == 0)
System.out.println("UNKNOWN CATEGORY: " + category);
total += score;
}
}
}
rdr.close();
System.out.println(total / nations.size());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment