Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Challenge: fastest program wins

Name: Anonymous 2009-04-14 12:59

Write a program in your language that
1.opens a file as arbitrary precision integer.
2.divides the number by 3.
3.stores the binary result in another file.

Name: Anonymous 2009-04-15 0:20

It's fast, believe me.

import java.io.File;
import java.io.FileOutputStream;
import java.math.BigInteger;
import java.util.Scanner;

public class Lol {
  private static final String IN  = "file1.txt";
  private static final String OUT = "file2.bin";

  public static void main(String[] args) {
    try {
      Scanner scanner = new Scanner(new File(IN));
      BigInteger n = scanner.nextBigInteger();
      scanner.close();
 
      n.divide(BigInteger.valueOf(3));
      byte[] b = n.toByteArray();

      FileOutputStream out = new FileOutputStream(new File(OUT));
      out.write(b);
      out.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List