Puzzle Master

So I just joined this group called Puzzle Master (while waiting for my friends to arrive to go watch Year One)

I finished the first puzzle Hoppity Hop!… took all of 10 mins.

Heres my code. I’ll upload it later instead of just copy/pasting it in my blog.

package com.rungeek.puzzles.hoppityhop;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Main {

    /**
     * Hoppity Hop!
     * 
     * This is a puzzle from Facebook.
     * Website: http://www.facebook.com/careers/puzzles.php#/careers/puzzles.php?puzzle_id=7
     * 
     * @param args input file
     */
    public static void main(String[] args) {
        int count = 0;

        if (args.length > 0) {
            try {
                File file = new File(args[0]);
                BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
                String line = bufferedReader.readLine();
                count = Integer.parseInt(line.trim());
            } catch (IOException e) {
                System.err.println("Could not find or bad file");
                System.err.println(args[0]);
                e.printStackTrace();
            }

            for (int i = 1; i <= count; i++) {
                if (((i % 3) == 0) && ((i % 5) == 0)) {
                    System.out.println("Hop");
                } else if ((i % 3) == 0) {
                    System.out.println("Hoppity");
                } else if ((i % 5) == 0) {
                    System.out.println("Hophop");
                }
            }
        } else {
            System.out.println("Please enter File Location as first arg");
        }

    }

}

Comments (View)

Comments powered by Disqus