Archivo

Entradas Etiquetadas ‘puzzles’

Facebook puzzles: (II, Hoppity)

Martes, 3 de Marzo de 2009

Un nuevo rompecabezas, un poco más complicado:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.kodegeek.blog.jobsearch.facebook.hoppity;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
 
/**
 * To help test whether your puzzle submissions fit the guidelines, try this simple test puzzle.
 * Your solution must follow the guidelines like any other puzzle.
 * Write a program that takes as input a single argument on the command line.
 * This argument must be a file name, which contains a single positive integer.
 * The program should read this file and obtain the integer within, and then output a sequence of strings
 * based upon the number (details below).
 * @author josevnz@kodegeek.com
 *
 */
public final class Hoppity {
 
	/**
	 * The input file will contain a single positive integer (in base 10) expressed as a string using standard ASCII text
	 * (e.g. for example, the number "15" but without the double quotes).
	 * This number may or may not be padded on either side with white space.
	 * There will be no commas, periods, or any other non-numeric characters present within the number.
	 * The file may or may not terminate in a single new line character ("\n")
	 * @param file file with the number
	 * @return integer
	 * @throws IOException
	 */
	private static int readNumber(File file) throws IOException {
		int aNumber = -1;
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			// Trim any spaces and then try to parse the number
			aNumber = Integer.parseInt(reader.readLine().replaceAll("\\s*", ""));
		} catch (IOException ioExp) {
			throw ioExp;
		} finally {
			if (reader != null) {
				reader.close();
			}
		}
		return aNumber;
	}
 
	/**
	 * @param args args[0] = Full path to input file
	 */
	public static void main(String[] args) throws Exception {
		if (args != null && args.length == 1 && args[0] != null) {
			File numFile = new File(args[0]);
			if (numFile.exists() && numFile.canRead()) {
				int number = readNumber(numFile);
				for (int i = 1; i < = number; i++) {
					boolean mod3 = i % 3 == 0;
					boolean mod5 = i % 5 == 0;
					if (mod5 && mod3) {
						System.out.println("Hop");
					} else if (mod3) {
						System.out.println("Hoppity");
					} else if (mod5) {
						System.out.println("Hophop");
					} else {
						continue;
					}
				}
			}
		}
		return;
	}
}

Lo más complicado aquí es asegurarnos que el número pueda ser leido si tiene espacios. No hay otras restricciones aparentes.

No muestro el wrapper ni el archivo de compilación Ant ya que son muy parecidos al del problema anterior.

Veneblogs: , , ,
Blogalaxia: , , ,

To2blogs: , , ,

Technorati: , , ,

Del.icio.us: , , ,

java, programación , ,

Facebook Puzzles (I, MeepMeep)

Lunes, 2 de Marzo de 2009

La gente de Facebook tiene un enlace permanente con rompecabezas para quienes quieren aplicar a una posición allí; La conseguí por un aviso clasificado que ellos mostraban en su sitio web y después de leerlos les puedo decir que me quedé pegado tratando de resolverlos.

Ya les iré contando como me fué con cada uno de los problemas, el primero de ellos es sólo para probar que el código enviado compila, para lo cual prepare mi archivo Ant:

1
2
3
4
5
< ?xml version="1.0" encoding="ISO-8859-1"?>
 
Solution for puzzles from 'Puzzle Master Facebook Page',
Solution sent to address: perl -e 'printf "%d\@facebook.com\n", 0xFACEB00C>>2'
Author: josevnz@kodegeek.com. http://kodegeek.com/blog/

El código de ‘MeepMeep’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.kodegeek.blog.jobsearch.facebook.meepmeep;
 
/**
 * Write a program that takes as input a single argument on the command line.
 * This argument must be a file name, which contains text.
 * The program should completely ignore this argument and instead print
 * to standard out the string "Meep meep!" (without the double quotes) followed by a newline.
 * @author josevnz@kodegeek.com
 *
 */
public final class MeepMeep {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("Meep meep!");
 
	}
}

Y el wrapper:

1
exec java -classpath . com.kodegeek.blog.jobsearch.facebook.meepmeep.MeepMeep $*

Ellos piden que lo envies a la siguiente dirección: {0xFACEB00C>>2 in decimal}@facebook.com

Decodificarla es trivial en Perl y en cualquier otro lenguaje:

 lang="Perl">
perl -e 'printf "%d\@facebook.com\n", 0xFACEB00C>>2'

Si todo sale bien, el robot de Facebook les dirá lo siguiente:

Dear submitter,

Thank you for your test submission of a puzzle solution to Facebook! After running your solution to meepmeep, I have determined it to be correct. Since your test has been successful, you are all set to try one of the other puzzles. Best of luck!

Sincerely,
-The puzzle robot

Veneblogs: , , ,
Blogalaxia: , , ,

To2blogs: , , ,

Technorati: , , ,

Del.icio.us: , , ,

java, perl, programación , , ,