2012년 4월 29일 일요일
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();
}
}
2012년 3월 29일 목요일
mosaic
- 스택오버플로어 http://stackoverflow.com/questions/5478519/photo-mosaic-algorithm-how-to-create-a-mosaic-photo-given-the-basic-image-and-a
- 모자이크 아티클 http://drdobbs.com/184404848?pgno=1
- 모자이크 마소 기사 http://www.imaso.co.kr/?doc=bbs%2Fgnuboard.php&bo_table=article&sselect=wr_subject%7Cwr_content&stext=%B8%F0%C0%DA%C0%CC%C5%A9&soperator=0&x=0&y=0
스캔 책 이미지 사이즈 줄이기에 대한 노력들.
- gimp filter로 해보기 : 간단히 되질 않는다. 포기
- opencv + python 해보기 : filter을 다시 찾아봐야 함.
- python + pil 로 이미지를 palette로 바꾸기 : 검색, 흰색만
- 할일: pil palette 공부하기
2012년 3월 26일 월요일
2012년 3월 19일 월요일
[opencv] ROI
crop으로 검색해서 나옴
http://nashruddin.com/OpenCV_Region_of_Interest_(ROI)
todo
http://nashruddin.com/OpenCV_Region_of_Interest_(ROI)
todo
- python 으로 일단은 해보기
- 매칭관련해서 공부해보기
2012년 3월 17일 토요일
opencv python
opencv, numpy 설치시
cv2 : c++ 바인드, 가장 최신
cv : c 바인드, 예전 버젼
이미지 로우딩 :
import cv2,cv
im = cv2.imread("file.jpg")
im : numpy.ndarray 로 return
src: numpy.ndarray
grey_src = cv2.cvtColor(src : numpy.ndarray, cv.CV_RGB2GRAY)
grey_src : numpy.ndarray
이미지 저장 :
import cv2
cv2.imwrite("파일명", numpy.ndarry=> 위의 im 같은값)
cv2 : c++ 바인드, 가장 최신
cv : c 바인드, 예전 버젼
이미지 로우딩 :
import cv2,cv
im = cv2.imread("file.jpg")
im : numpy.ndarray 로 return
src: numpy.ndarray
grey_src = cv2.cvtColor(src : numpy.ndarray, cv.CV_RGB2GRAY)
grey_src : numpy.ndarray
이미지 저장 :
import cv2
cv2.imwrite("파일명", numpy.ndarry=> 위의 im 같은값)
피드 구독하기:
글 (Atom)