Coding/CPP 삽질기2010. 1. 22. 23:58

/*
 ============================================================================
 Name        : Lotto.c
 Author      : chobocho
 Version     :
 Copyleft
 Description : Lotto
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void lotto(int num, int max_number);

void lotto(int num, int max_number)
{
    int number[100] = {0, };
    int i = 0;
    int prev = 0;
    int next = 0;
    int temp = 0;

    if (num > max_number || max_number < 0 || max_number >= 100)
    {
        return;
     }

    for (i = 0; i < max_number; i++)
    {
        number[i] = i+1;
     }

    srand((time(NULL)));

    for (i = 0; i < 1000; i++)
    {
        prev = rand() % max_number;
        next = rand() % max_number;

        temp = number[prev];
        number[prev] = number[next];
        number[next] = temp;
    }

    for (i = 0; i < num; i++)
    {
         printf ("%d ", number[i]);
     }
     puts("\n");

}

int main(int argc, char **argv) {
    lotto(6, 46);
    return 0;
}

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

[CPP] 파일 분할 프로그램 v0.01  (0) 2010.01.28
[CPP] 폴더내 파일 목록을 보여 주는 코드 조각  (1) 2009.03.24
함수 포인터  (0) 2009.01.08
Posted by chobocho
Coding/Python 삽질기2010. 1. 22. 01:10
# 리스트에서 음수 제거 하기
def remove_neg(num_list):
    num_list[:] = filter(lambda x: x > 0, num_list)
#-----------------------------------------------------------------------------------

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

[Python] Simple template maker  (0) 2010.02.02
[Python] 초간단 Lotto 생성기 소스  (0) 2010.01.22
[Python] Simple file viewer  (0) 2010.01.02
Posted by chobocho
Coding/Python 삽질기2010. 1. 22. 00:41
import random

lotto_set = ()
while ( len(lotto_set) < 6 ):
    lotto_set = set([random.randrange(1, 47, 1) for k in range(6)])
    
lotto = list(lotto_set)
lotto.sort()

print lotto

[2, 26, 33, 36, 39, 46]

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

[Python] 짧은 코드 모음  (0) 2010.01.22
[Python] Simple file viewer  (0) 2010.01.02
[Python] 회전 이동  (0) 2009.08.25
Posted by chobocho
Coding/Python 삽질기2010. 1. 2. 00:47

#-*- coding: cp949 -*-
# Name        : py_fileview.py
# Author      : chobocho.com
# Version     :
# Copyright   :
# Description : Simple text file viewer
#

from Tkinter import *
import tkMessageBox
import os.path
import glob 
 
class App:
    def __init__ (self, master):
        frame = Frame(master)
        frame.pack()
       
        # Text Area
        f0 = Frame(frame, width = 100, height = 100)
        f0.grid(row = 0, column = 0)
        self.text_scrollbar = Scrollbar (f0, orient=VERTICAL)
        self.text = Text(f0, width=80, height = 20, yscrollcommand=self.text_scrollbar.set)
        self.text_scrollbar.config(command=self.text.yview)
        self.text_scrollbar.pack(side=RIGHT, fill=Y)
        self.text.pack() 
       
        # List Box area
        f1 = Frame(frame, width = 100, height = 100)
        f1.grid(row = 0, column = 1)
       
        self.list_button = Button(f1, text="File List", command=self.ShowInfo)
        self.list_button.pack()
       
        self.listbox_scrollbar = Scrollbar (f1, orient=VERTICAL)
        self.listbox = Listbox(f1, height=19, yscrollcommand=self.listbox_scrollbar.set)
        self.listbox_scrollbar.config(command=self.listbox.yview)
        self.listbox_scrollbar.pack(side=RIGHT, fill=Y)
        # 파일 내용을 읽어서 보여 줄 것
        self.ReadTemplate()
        self.listbox.bind("<Double-Button-1>", self.LoadFile)
        self.listbox.pack(side=RIGHT)

    def ClearText(self):
        self.text.delete(1.0, END) 
   
    def ShowInfo(self):
        tkMessageBox.showinfo("Information","http://chobocho.com\nVersion 0.2")
   
    def ReadTemplate(self):
        all_flist = glob.glob ("*.txt")
       
        for f in all_flist:
            if os.path.exists(f):
                self.listbox.insert(END, f.decode('cp949'))
               
    def LoadFile(self, event):
        self.items = self.listbox.curselection()
        self.el = self.listbox.get(self.items)
        self.ClearText()
        if os.path.exists(self.el):
            self.fp = open(self.el, 'r')
            self.tempFileData = self.fp.read()
            self.fp.close()
            self.text.insert(1.0, self.tempFileData.decode('cp949'))

#----------------------------------------------------------
# main
if __name__ == "__main__":     
    root = Tk()
    app = App(root)
    root.mainloop()



실행화면

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

[Python] 초간단 Lotto 생성기 소스  (0) 2010.01.22
[Python] 회전 이동  (0) 2009.08.25
WxPython - HelloWorld  (0) 2008.12.22
Posted by chobocho
Coding/Haskell2009. 11. 12. 00:35
quicksort []       =  []
quicksort (x:xs)  = quicksort[y | y <- xs, y < x] ++ [x] ++ quicksort[y | y <- xs, y >= x]

Posted by chobocho
Coding/리눅스 삽질기2009. 11. 4. 01:20

용량 50M의 저용량 리눅스 Damn Small Linux를 Virtual Box로 부팅.

가볍 다는 이유로 설치 했는데, 한글이 지원 안되는걸 깜박했다. ^^;

홈페이지 : http://damnsmalllinux.org/

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

Virtual Box를 이용한 Ubuntu 설치  (0) 2008.05.13
SIGBUS  (0) 2005.09.21
Mplayer Porting  (3) 2005.06.03
Posted by chobocho
Coding/Java 삽질기2009. 10. 22. 00:54


자바로 만든 숫자 세기 게임.

규칙 : 숫자를 순서대로 마우스로 클릭 하면 된다. (제한시간 25초)

시작방법 : 스마일 버튼을 클릭하면 된다.

게임하기 : http://chobocho.com/game/speed/Speed.html

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

Fruit Game  (4) 2010.03.06
[Android] Speed Game  (0) 2009.10.13
Insertion sort  (0) 2009.07.10
Posted by chobocho
Coding/Java 삽질기2009. 10. 13. 22:49

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

[Java] 숫자 세기 게임  (0) 2009.10.22
Insertion sort  (0) 2009.07.10
Lifegame  (0) 2009.06.20
Posted by chobocho
Coding/Bada2009. 9. 4. 02:04


Bada에서 현재 시간을 구하기 위한 코드

* WALL_TIME : 상단 인디케이터에 나오는 시간 (DST를 더한 시간 임)

using namespace Osp::System;

DateTime dt;
Osp::System::SystemTime::GetCurrentTime(WALL_TIME, m_dt);



Update : 2010. 9. 4

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

[Bada] Bada로 만든 숫자 빨리 터치 하기 게임  (0) 2010.08.21
[Bada] Resource explore  (0) 2010.08.18
[Bada] SDK 설치  (0) 2010.08.18
Posted by chobocho
Coding/Python 삽질기2009. 8. 25. 21:52

# 원점에서 100만큼 떨어진 점 (0, 100)을 원점을 중심으로 15도씩 회전 하였을 때의 좌표
# 리스트를 계산하는 코드

import math

point_xy = []
 
for idx in range (0, 24) :
      end_y = -100;     
      degree = 15.0 * idx
      rad = math.pi * degree / 180.0
      new_end_x = int(-end_y * math.sin(rad))
      new_end_y = int(end_y * math.cos(rad))
   
      point_xy.append((new_end_x, new_end_y))
     
print point_xy


[(0, -100), (25, -96), (49, -86), (70, -70), (86, -50), (96, -25), (100, 0), (96, 25), (86, 49), (70, 70), (49, 86), (25, 96), (0, 100), (-25, 96), (-50, 86), (-70, 70), (-86, 50), (-96, 25), (-100, 0), (-96, -25), (-86, -50), (-70, -70), (-50, -86), (-25, -96)]

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

[Python] Simple file viewer  (0) 2010.01.02
WxPython - HelloWorld  (0) 2008.12.22
Sudoku를 풀어주는 스크립트  (0) 2008.10.09
Posted by chobocho