Skip to content

Instantly share code, notes, and snippets.

@francisco-perez-sorrosal
francisco-perez-sorrosal / SpiralMatrix.java
Created December 22, 2011 12:06
Code that traverses a matrix in spiral using recursion and a simple state machine.
public class SpiralMatrix {
enum Direction {
LEFT_RIGHT, TOP_DOWN, RIGHT_LEFT, BOTTOM_UP
};
public static void traverseMatrixInSpiral(char[][] matrix, int initialRow,
int finalRow, int initialColumn, int finalColumn, int totalElems,
int visited, Direction direction) {
System.out.println("Num Elems: " + totalElems + " visited: " + visited);
private static String translateToProteins(String dna) {
String result = "";
int idx = dna.indexOf(START_CODON, 0);
while (idx < dna.length() && idx != -1) {
String dnaChunk = dna.substring(idx, idx + 3);
if (dnaChunk.equals(END_CODON_1) || dnaChunk.equals(END_CODON_2)
|| dnaChunk.equals(END_CODON_3)) {
idx = dna.indexOf(START_CODON, idx);
@francisco-perez-sorrosal
francisco-perez-sorrosal / CurrencyParser.scala
Created November 5, 2011 03:58
Program that parses a remote XML file containing info about currencies and outputs a new user-defined format for the parsed data in a new file (passed as parameter)
package com.linkingenius.parser
import java.io.File
import java.io.FileWriter
// Handler to perform write operations in a file
case class FileHandler(file: File) {
def add(text: String): Unit = {
val fw = new FileWriter(file, true)
@francisco-perez-sorrosal
francisco-perez-sorrosal / moving_box.html
Created September 22, 2011 20:33
My html containing the moving box Javascript example implemented in class with Carlos Benítez (Madrid, 14/Sep/2011)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
body{background-color:#ccc}
#box{
width:100px;