Coding/Java 삽질기2009. 6. 20. 02:35

'Coding > Java 삽질기' 카테고리의 다른 글

Insertion sort  (0) 2009.07.10
Android 설치  (0) 2009.05.25
J2EE를 이용한 프로젝트 디플로이  (0) 2005.10.13
Posted by chobocho
Coding/Perl 삽질기2009. 6. 16. 23:46
# Hex2Ascii
###############################################

$start_expression = '[0-9]+\|[0-9]{2}';
$data_expression = '[0-9a-fA-F]{2}';

%AsciiTable = (

"00" => " ",
"01" => " ",
"02" => " ",
"03" => " ",
"04" => " ",
"05" => " ",
"06" => " ",
"07" => " ",
"08" => " ",
"09" => " ",
"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" => "0",
"49" => "1",
"50" => "2",
"51" => "3",
"52" => "4",
"53" => "5",
"54" => "6",
"55" => "7",
"56" => "8",
"57" => "9",
"58" => ":",
"59" => ";",
"60" => "<",
"61" => "=",
"62" => ">",
"63" => "?",
"64" => "@",
"65" => "A",
"66" => "B",
"67" => "C",
"68" => "D",
"69" => "E",
"70" => "F",
"71" => "G",
"72" => "H",
"73" => "I",
"74" => "J",
"75" => "K",
"76" => "L",
"77" => "M",
"78" => "N",
"79" => "O",
"80" => "P",
"81" => "Q",
"82" => "R",
"83" => "S",
"84" => "T",
"85" => "U",
"86" => "V",
"87" => "W",
"88" => "X",
"89" => "Y",
"90" => "Z",
"91" => "[",
"92" => "\\",
"93" => "]",
"94" => "^",
"95" => "_",
"96" => "`",
"97" => "a",
"98" => "b",
"99" => "c",
"100" => "d",
"101" => "e",
"102" => "f",
"103" => "g",
"104" => "h",
"105" => "i",
"106" => "j",
"107" => "k",
"108" => "l",
"109" => "m",
"110" => "n",
"111" => "o",
"112" => "p",
"113" => "q",
"114" => "r",
"115" => "s",
"116" => "t",
"117" => "u",
"118" => "v",
"119" => "w",
"120" => "x",
"121" => "y",
"122" => "z",
"123" => "{",
"124" => "|",
"125" => "}",
"126" => "~",
"127" => "",
"128" => "€",
"129" => " ",
"130" => " ",
"131" => " ",
"132" => " ",
"133" => " ",
"134" => " ",
"135" => " ",
"136" => " ",
"137" => " ",
"138" => " ",
"139" => " ",
"140" => " ",
"141" => " ",
"142" => " ",
"143" => " ",
"144" => " ",
"145" => " ",
"146" => " ",
"147" => " ",
"148" => " ",
"149" => " ",
"150" => " ",
"151" => " ",
"152" => " ",
"153" => " ",
"154" => " ",
"155" => " ",
"156" => " ",
"157" => " ",
"158" => " ",
"159" => " ",
"160" => " ",
"161" => " ",
"162" => " ",
"163" => " ",
"164" => " ",
"165" => " ",
"166" => " ",
"167" => " ",
"168" => " ",
"169" => " ",
"170" => " ",
"171" => " ",
"172" => " ",
"173" => " ",
"174" => " ",
"175" => " ",
"176" => " ",
"177" => " ",
"178" => " ",
"179" => " ",
"180" => " ",
"181" => " ",
"182" => " ",
"183" => " ",
"184" => " ",
"185" => " ",
"186" => " ",
"187" => " ",
"188" => " ",
"189" => " ",
"190" => " ",
"191" => " ",
"192" => " ",
"193" => " ",
"194" => " ",
"195" => " ",
"196" => " ",
"197" => " ",
"198" => " ",
"199" => " ",
"200" => " ",
"201" => " ",
"202" => " ",
"203" => " ",
"204" => " ",
"205" => " ",
"206" => " ",
"207" => " ",
"208" => " ",
"209" => " ",
"210" => " ",
"211" => " ",
"212" => " ",
"213" => " ",
"214" => " ",
"215" => " ",
"216" => " ",
"217" => " ",
"218" => " ",
"219" => " ",
"220" => " ",
"221" => " ",
"222" => " ",
"223" => " ",
"224" => " ",
"225" => " ",
"226" => " ",
"227" => " ",
"228" => " ",
"229" => " ",
"230" => " ",
"231" => " ",
"232" => " ",
"233" => " ",
"234" => " ",
"235" => " ",
"236" => " ",
"237" => " ",
"238" => " ",
"239" => " ",
"240" => " ",
"241" => " ",
"242" => " ",
"243" => " ",
"244" => " ",
"245" => " ",
"246" => " ",
"247" => " ",
"248" => " ",
"249" => " ",
"250" => " ",
"251" => " ",
"252" => " ",
"253" => " ",
"254" => " ",
"255" => " "
);

#$in_filename = "data.txt";

if (@ARGV == 0)
{
   print "Useage h2a.pl filename";
   exit;
}

$in_filename = $ARGV[0];

$out_filename = "result_".$in_filename;

if (-f $in_filename)
{
    print $filename."\n";
   
    open (IN_FILE, "<".$in_filename) || die $!;
    open (OUT_FILE,">".$out_filename) || die $!;
    while (my $line = <IN_FILE>)
    {
        if ( $line =~ /$start_expression/ )
        {
            print $line;
            print OUT_FILE $line;
        }
        elsif ( $line =~ /$data_expression/ )
        {
            # print $line;
            # print OUT_FILE $line;
           
            @hex_arr = $line =~ /$data_expression/g;
            foreach $data(@hex_arr)
            {
                print $AsciiTable{$data};
                print OUT_FILE $AsciiTable{$data};
            }
            print "\n";
            print OUT_FILE "\n";
        }
    }
    close (IN_FILE);
    close (OUT_FILE);
}



Posted by chobocho
Coding/Java 삽질기2009. 5. 25. 01:01
1. http://java.sun.com 에서 JavaSE SDK를 다운 받는다.

2. http://developer.android.com/index.html 에서 안드로이드 SDK를 다운 받아 압축을 푼다.

2. http://www.eclipse.org/downloads 에서 Eclipse Classic을 다운 받는다. ( 맨아래에 있음)

3. Eclipse를 실행 한다.


4. Help > Software Updates.. 메뉴 를 클릭한다.

5. Available Software 탭을 선택 후, 우측의 Add Site...를 클릭한다. 

6. 위와 같이 주소를 입력한다. ( http://dl-ssl.google.com/android/eclipse/ )

7. 인스톨 후 Preference 창에서 Android 탭을 선택 후 SDK Location에 안드로이드 SDK의 위치를 지정한다. (경로에 한글이 포함되면 안됨)


8. 에뮬레이터 실행화면

'Coding > Java 삽질기' 카테고리의 다른 글

Lifegame  (0) 2009.06.20
J2EE를 이용한 프로젝트 디플로이  (0) 2005.10.13
jar 파일 실행하기  (0) 2005.08.31
Posted by chobocho
Coding/CPP 삽질기2009. 3. 24. 22:49

#include <stdio.h>
#include <io.h>

int main(void) {
  _finddatai64_t file;
  intptr_t files;

  files = _findfirsti64("*.*", &file);
  do {
      printf("%s\n", file.name);
  } while(_findnexti64(files, &file) == 0);
  _findclose(files);

  return 0;
}

'Coding > CPP 삽질기' 카테고리의 다른 글

[CPP] Lotto 생성기  (0) 2010.01.22
함수 포인터  (0) 2009.01.08
[CPP] Linux Thread Example Code  (0) 2008.12.14
Posted by chobocho
Coding/CPP 삽질기2009. 1. 8. 22:29

[ 예제 코드 1 ]

     #include <stdio.h>

    void HelloWorld(int num)
    {
       int idx = 0;

       for (idx = 0; idx < num; idx++)
       {
           printf ("Hello World!\n");
       }
    }

    int main(void)
    {
        void (*Fptr)(int);

        Fptr = HelloWorld;
        Fptr(2);

        return 0;
    }

[ 예제 코드 1 실행결과 ]

fptr_screen.png


이 글은 스프링노트에서 작성되었습니다.

Posted by chobocho
Coding/Python 삽질기2008. 12. 22. 23:42
#!/usr/bin/python
# HelloWorld.py

import wx

app = wx.App()

frame = wx.Frame(None, wx.ID_ANY, "Hello World")
frame.Show()

app.MainLoop()


Posted by chobocho
Coding/Math2008. 12. 20. 01:38

'Coding > Math' 카테고리의 다른 글

홀수의 합으로 제곱근 구하기  (0) 2012.06.01
[Math] 사선 공식  (0) 2011.09.12
헤론의 공식  (2) 2011.08.30
Posted by chobocho
Coding/CPP 삽질기2008. 12. 14. 21:49
#include <stdio.h>
#include <pthread.h>

void *Count (void *);

int main(int argc, char **argv)
{
    pthread_t p_thread[2];
    int pthread_status;

    pthread_create(&p_thread[0], NULL, Count, (void *)NULL);
    pthread_create(&p_thread[1], NULL, Count, (void *)NULL);
 
    pthread_join(p_thread[0], (void **)&pthread_status);
    pthread_join(p_thread[1], (void **)&pthread_status);

    return 0;
}


void *Count (void *arg)
{
    pthread_t thread_id = pthread_self();
    int num = 0;
   
    while (num < 10)
    {
        printf ("%x : %d\n", thread_id, num);
        num++;
        sleep(1);
    }
}


'Coding > CPP 삽질기' 카테고리의 다른 글

함수 포인터  (0) 2009.01.08
[CPP] STL에서 List의 sorting 방법  (0) 2008.10.30
Copy & Paste 신공  (0) 2008.03.08
Posted by chobocho
Coding/CPP 삽질기2008. 10. 30. 23:57

#include <iostream>
#include <list>
using namespace std;

class CData {
public:
    CData (int x = 0) { data = x; }
    void set (int x) { data = x; }
    int  get (void)  { return data ; }
    // 방법 1: 비교를 위한 함수를 만든다.
    int operator()( CData &lhv, CData &rhv) const { return (lhv.get() > rhv.get()); }
    // 방법 2: < 연산자를 오버로딩 한다.
    int operator<( CData &rhv) const { return (this->data < rhv.get()); }
 
private:
    int data;       
};

void process(void);
void prinfList( list<CData> myList );


int main (int argc, char **argv)
{

    process();
   
    getchar();
    return 0;   
}


void process (void)
{
     list<CData> myData;

         
     myData.push_front(10);
     myData.push_front(17);
     myData.push_front(11);
     myData.push_front(1);
     myData.push_front(20);

     prinfList( myData );
 
     // STL의 list는 제너릭한 sort를 사용할 수 없다.
     // 멤버함수를 호출하면 < 연산자를 비교 함수로 쓴다.

     myData.sort();         // method 2
     prinfList( myData );
    // 직접 비교 함수를 넣을 수도 있다.
     myData.sort(CData()); // metod 1
     prinfList( myData );
}


void prinfList( list<CData> myList )
{
     list<CData> :: iterator iter;
    
     for (iter = myList.begin(); iter != myList.end(); iter++)
         cout << iter->get() << " ";
     cout << endl;
}

'Coding > CPP 삽질기' 카테고리의 다른 글

[CPP] Linux Thread Example Code  (0) 2008.12.14
Copy & Paste 신공  (0) 2008.03.08
연산자 우선 순위  (0) 2008.01.13
Posted by chobocho
Coding/Python 삽질기2008. 10. 9. 01:12

#!/usr/local/bin/python
#-*- coding: cp949 -*-
# date   : 2006.  10.  15
#
# 스도쿠를 풀어주는 스크립트

import random

class Sodoku:
 def __init__(self):
  self.timer = 0
  self.board = []
  self.tmpBoard=[]
  for y in range(0, 82):
   self.board.append(0)
   self.tmpBoard.append(511)

 def display(self):

  for y in range(0, 9):
   for x in range(0, 9):
    idx = y* 9 + x + 1;

    if self.board[idx] != 0:
     print "%d" %(self.board[idx]),
    else:
     print "_",
    print '|',
   print '\n'
 
 def checkSquare(self,  sx,  sy):
  sum = 0;
 
  for y in range(0, 3):
   for x in range(0, 3):
    if ( int(self.board[ (y+sy)*9+(x+sx)+1]) > 0):
     sum |= (1 << (int(self.board[ (y+sy)*9+(x+sx)+1]-1)))
  return sum

 def checkBoard(self):
  ret = 0;
  for y in range(0, 9):
   sum = 0;
   for x in range(0, 9):
    if ( int(self.board[y*9+x+1]) > 0):
     sum |= (1 << (int(self.board[y*9+x+1]-1)))
   if (sum != 511):
    ret = 1
   
  for x in range(0, 9):
   sum = 0;
   for y in range(0, 9):
    if ( int(self.board[y*9+x+1]) > 0):
     sum |= (1 << (int(self.board[y*9+x+1]-1)))
   if (sum != 511):
    ret = 2

  for y in range(0, 3):
   for x in range(0, 3):
    sum = self.checkSquare(x*3, y*3)
   if (sum != 511):
    ret = 3
  return ret

 def readData(self):
  fp = open("sudoku.dat", 'r')
  self.board = map(int, fp.read().split(','))
  fp.close()
 
  for y in range(0, 82):
   self.tmpBoard[y] =511
 
 def guessCount(self, num):
  count = 0
  for i in range(0, 9):
   if ( (1 << i) & num ) != 0:
    count += 1
  return count

 def findStartPos(self):
  sx = 0
  sy = 0
  mvalue = 511
  mcount = 10
  for y in range(0,9):
    for x in range(0,9):
     if (self.board[y * 9 + x + 1] == 0):
      temp = self.guessCount(self.tmpBoard[y*9 + x + 1] )
      if (mcount >  temp):
       mvalue = self.tmpBoard[y*9 + x + 1]
       mcount = temp
       sx = x
       sy = y
  return (sx, sy, mvalue)

 def isFull(self):
  count = 0
  for y in range(0,9):
    for x in range(0,9):
     if (self.board[y * 9 + x + 1] != 0):
      count += 1
  return count == 81

 def solve(self):
  if (self.checkBoard() != 0):
   if (self.isFull()):
    return 0
   #get position
   (x, y, num) = self.findStartPos()
   # set number
   for i in range(0, 9):
    if ( (1 << i) & num ) != 0:
     self.board[y*9 + x + 1] = i+1
     # checkTempBoard
     self.checkWidthTempBoard(x, y)
     self.checkHeightTempBoard(x, y)
     self.checkSquareTempBoard(x/3, y/3, x, y)
     if (self.solve() == 1):
       return 1
     else:
      self.unCheckWidthTempBoard(x, y)
      self.unCheckHeightTempBoard(x, y)
      self.unCheckSquareTempBoard(x/3, y/3, x, y)
      self.board[y*9 + x + 1] = 0
   return 0
  else:
   return 1

       
 def checkTempBoard(self):
  for y in range(0, 9):
   for x in range(0, 9):
    if (self.board[y * 9 + x + 1] != 0):
     self.checkWidthTempBoard(x, y)
     self.checkHeightTempBoard(x, y)
     self.checkSquareTempBoard(x/3, y/3, x, y)
 
 def checkWidthTempBoard(self, sx, sy):
   for x in range(0,9):
    if (self.board[sy * 9 + x + 1] == 0):
     self.tmpBoard[sy * 9 + x + 1] &= ~(1 << (self.board[sy * 9 + sx + 1] - 1))

 def checkHeightTempBoard(self, sx, sy):
   for y in range(0,9):
    if (self.board[y * 9 + sx + 1] == 0):
     self.tmpBoard[y * 9 + sx + 1] &= ~(1 << (self.board[sy * 9 + sx + 1] - 1))


 def checkSquareTempBoard(self, sx, sy, tx, ty):
   for y in range(0,3):
    for x in range(0,3):
     if (self.board[(y + sy) * 9 + sx + x + 1] == 0):
      self.tmpBoard[(y + sy * 3) * 9 + sx * 3 + x + 1] &= ~(1 << (self.board[ty * 9 + tx + 1] - 1))    

 def unCheckWidthTempBoard(self, sx, sy):
   for x in range(0,9):
    if (self.board[sy * 9 + x + 1] == 0):
     self.tmpBoard[sy * 9 + x + 1] |=  (1 << (self.board[sy * 9 + sx + 1] - 1))
     
 def unCheckHeightTempBoard(self, sx, sy):
   for y in range(0,9):
    if (self.board[y * 9 + sx + 1] == 0):
     self.tmpBoard[y * 9 + sx + 1] |= (1 << (self.board[sy * 9 + sx + 1] - 1))
     
 def unCheckSquareTempBoard(self, sx, sy, tx, ty):
   for y in range(0,3):
    for x in range(0,3):
     if (self.board[(y + sy) * 9 + sx + x + 1] == 0):
      self.tmpBoard[(y + sy * 3) * 9 + sx * 3 + x + 1] |= (1 << (self.board[ty * 9 + tx + 1] - 1))


 def generate(self):
  self.readData()
  self.checkTempBoard()


def main():
 sodoku = Sodoku()
 
 sodoku.generate()
 sodoku.display()
 sodoku.solve()
 print "-"*60
 sodoku.display()

#----------------------------------------------------------
# main
if __name__ == "__main__":    
   main()


 

[sudoku.dat]
0, 6, 0, 9, 0, 0, 0, 0, 4, 3, 0, 0, 0, 2, 9, 0, 7, 1, 0, 0, 0, 4, 0, 1, 0, 0, 5, 8, 5, 0, 0, 0, 0, 8, 0, 6, 0, 8, 0, 7, 1, 0, 9, 4, 0, 5, 0, 3, 0, 7, 0, 0, 0, 0, 2, 1, 5, 0, 0, 8, 0, 3, 0, 0, 0, 4, 8, 0, 6, 2, 0, 0, 0, 7, 2, 0, 0, 0, 0, 6, 0, 9




 

[실행결과]

6 | _ | 9 | _ | _ | _ | _ | 4 | 3 |

_ | _ | _ | 2 | 9 | _ | 7 | 1 | _ |

_ | _ | 4 | _ | 1 | _ | _ | 5 | 8 |

5 | _ | _ | _ | _ | 8 | _ | 6 | _ |

8 | _ | 7 | 1 | _ | 9 | 4 | _ | 5 |

_ | 3 | _ | 7 | _ | _ | _ | _ | 2 |

1 | 5 | _ | _ | 8 | _ | 3 | _ | _ |

_ | 4 | 8 | _ | 6 | 2 | _ | _ | _ |

7 | 2 | _ | _ | _ | _ | 6 | _ | 9 |
-----------------------------
6 | 1 | 9 | 8 | 7 | 5 | 2 | 4 | 3 |

3 | 8 | 5 | 2 | 9 | 4 | 7 | 1 | 6 |

2 | 7 | 4 | 6 | 1 | 3 | 9 | 5 | 8 |

5 | 9 | 2 | 4 | 3 | 8 | 1 | 6 | 7 |

8 | 6 | 7 | 1 | 2 | 9 | 4 | 3 | 5 |

4 | 3 | 1 | 7 | 5 | 6 | 8 | 9 | 2 |

1 | 5 | 6 | 9 | 8 | 7 | 3 | 2 | 4 |

9 | 4 | 8 | 3 | 6 | 2 | 5 | 7 | 1 |

7 | 2 | 3 | 5 | 4 | 1 | 6 | 8 | 9 |


'Coding > Python 삽질기' 카테고리의 다른 글

WxPython - HelloWorld  (0) 2008.12.22
[조각코드] 숫자 배열 읽어서 리스트에 저장하는 코드  (0) 2008.10.06
간단한 메모장2  (0) 2008.09.17
Posted by chobocho