레이블이 java인 게시물을 표시합니다. 모든 게시물 표시
레이블이 java인 게시물을 표시합니다. 모든 게시물 표시

2013년 5월 8일 수요일

mac os 에서 톰캣으로 돌릴때 java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence 나면 해결 방법

http://stackoverflow.com/questions/1663571/how-to-set-utf8-lang-on-tomcat-java-running-on-mac-os-10-5-8

CATALINA_OPTS="-Dfile.encoding=UTF-8"

2013년 1월 31일 목요일

List max size

fastutil이 뭔가 궁금해서 찾아보다가. 
collection util 관련 내용도 찾아봤습니다.

1.
http://b010.blogspot.kr/2009/05/speed-comparison-of-1-javas-built-in.html

2.
http://stackoverflow.com/questions/629804/what-is-the-most-efficient-java-collections-library


Generally, a List implementation can hold any number of items (If you use an indexed List, it may be limited to Integer.MAX_VALUE or Long.MAX_VALUE). As long as you don't run out of memory, the List doesn't become "full" or anything. 
링크에 이런 말이 있네요. 
2^31-1 개 만큼 list 를 담을 수 가 있어서 이 이상의 데이터는 리스트에 못 담네요. 

그래서 위의 fastutil에서 int[][] 이렇게 해서 64bit에서 된다는 건가요? ^^;;

http://stackoverflow.com/questions/3767979/how-many-data-a-list-can-hold-at-the-maximum

http://stackoverflow.com/questions/7632126/maximum-size-of-hashset-vector-linkedlist

http://stackoverflow.com/questions/3038392/do-java-arrays-have-a-maximum-size

http://stackoverflow.com/questions/816142/strings-maximum-length-in-java-calling-length-method


http://fastutil.di.unimi.it/docs/it/unimi/dsi/fastutil/BigArrays.html

2012년 4월 2일 월요일

project euler12


%%%-------------------------------------------------------------------
%%% @author jaejin <>
%%% @copyright (C) 2012, jaejin
%%% @doc
%%% The sequence of triangle numbers is generated by adding the natural numbers.%%%  So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

%%% 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

%%% Let us list the factors of the first seven triangle numbers:

%%  1: 1
%%  3: 1,3
%%  6: 1,2,3,6
%% 10: 1,2,5,10
%% 15: 1,3,5,15
%% 21: 1,3,7,21
%% 28: 1,2,4,7,14,28
%% We can see that 28 is the first triangle number to have over five divisors.

%% What is the value of the first triangle number to have over five hundred divisors?
%%% @end
%%% Created : 31 Jan 2012 by jaejin <>
%%%-------------------------------------------------------------------
-module(euler12).
-author(jaejin).
-compile(export_all).

trianglenumbers(N)->
    trianglenumbers(N,0).

trianglenumbers(N,Result) when N > 1 ->
    trianglenumbers(N-1,Result + N);
trianglenumbers(1,Result) ->
    Result +1.

divisors(N)->
    dict:fold(fun(_Key,Value,Sum)-> (Value+1) * Sum end,1, divisor_dict(N)).

divisor_dict(N)->
    divisor_dict(N,2,dict:new()).

divisor_dict(N,M,Dict) when N =:= M ->
    dictStore(Dict,M);
divisor_dict(N,M,Dict) when N rem M =:= 0 ->
    divisor_dict(N div M,M,dictStore(Dict,M));
divisor_dict(N,M,Dict) when N rem M =/= 0 ->
   divisor_dict(N,M+1,Dict).

dictStore(Dict,Key)->
    Is_key = dict:is_key(Key,Dict),
    if Is_key ->
            dict:store(Key,dict:fetch(Key,Dict)+1,Dict);
       true ->
            dict:store(Key,1,Dict)
    end.

run() ->
    run(7,28).

run(N,Result)->
   C =  divisors(Result),
%% %    io:format("Result => ~p ~n",[{Result,N,C}]),
%%     if C >= 200 ->
%%             N;
%%        C < 200 ->
%%             run(N+1,Result+N)
   end.


이걸로 했더니. 답이 안나온다. ㅡㅡ;;


안되서 자바로 했다.


import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: jaejinyun
 * Date: 12. 4. 2.
 * Time: 오후 11:11
 * To change this template use File | Settings | File Templates.
 */
public class Euler11 {

    public static int divisor(int n) {
        HashMap<Integer,Integer> divisor = new HashMap<Integer, Integer>();
        int find = 2;
        int m = n;
        System.out.println("find = "+find + " n = " + n + " m ="+m);
        while(find <= m) {
            System.out.println(find);
            if( m % find == 0) {
                m = m / find;
                if( divisor.get(find) != null ) {
                    divisor.put(find,divisor.get(find)+1);
                } else {
                    divisor.put(find,1);
                }
            } else {
                find++;
            }
        }

        int result =1;
        for(int value : divisor.values()) {
              result *= (value+1);
        }
        return result;
    }

    public static void find() {
        int n = 7;
        int result = 28;
        int divisorResult = 0;

        while(divisorResult <= 500)  {
             n++;
             result += n;
             divisorResult = divisor(result);

            System.out.println("n ="+n+" triagle num="+result + " divisor ="+divisorResult);
        }

    }

    public static void main(String[] args) {
        System.out.println("test");
        find();
    }
}