วันพุธที่ 31 สิงหาคม พ.ศ. 2559

ความคืบหน้า : Tic tac toe

ทำเป็นคลาส ใช้ระบบ MVC ในการทำ โดยแบ่งเป็น Class model view and controller ซึ่งแต่ละส่วน ทำงานแตกต่างกันไป ซึ่ง ทีมผม มีแนวคิดดังนี้

Model - ใช้เป็นส่วนเก็บข้อมูล ของตาราง และค่าต่างๆ เท่านั้น รวมถึงการคิดหาผู้ชนะ ด้วย
View - ใช้เป็นส่วนในการแสดงผลผ่านเทอมินอลซึ่งถูกเรียกใช้ เมตอด โดยผ่าน controller เท่านั้น
controller - เป็นส่วนที่รับ input จากทาง user เป็นส่วนที่ประสานงานระหว่าง model view ซึ่ง เป็นตัวพิจรณา ว่าควรเรียกใช้เมตอดไหนใน view เพื่อแสดงผลโดยใช้ ค่าที่ได้จากการตอบกลับมาจาก Model

ซึ่ง ณ ตอนนี้ ได้ ทำไห้สามารถ ทำเป็นรับทั้ง 1 - 2 input ได้โดยการแยกคลาส controller ออกเป็น 2 คลาส โดยมี คลาสแม่ 1 คลาส แล้วใช้คุณสมบัติ inheritance 

สิ่งที่จะทำต่อไป  ; ศึกษา การใช้ Kivy เพื่อนำมาทำ GUI


วันพฤหัสบดีที่ 25 สิงหาคม พ.ศ. 2559

สร้าง ทีมใน Bitbuckket



- สร้างทีมและโปรเจค TIC TAC TOE ใน Bitbuckket และชวนเพื่อนร่วมโปรเจคเข้ากลุ่มเรียบร้อยแล้ว
- นำงานล่าสุด(โค๊ด)ใส่ลงไปแล้วพร้อมแก้ไข ได้จาก ทุกที่ที่มีความพร้อม

วันพฤหัสบดีที่ 18 สิงหาคม พ.ศ. 2559

Building Software : stack

Code :

class Stack:
  def __init__(self):
    self.item = []

  def isEmpty(self):
    return self.item == []

  def push(self,item):
    self.item.append(item)

  def pop(self):
    return self.item.pop()

  def size(self):
    return len(self.item)


def setup():
  a = Stack()
  print a.isEmpty()
  a.push(1)
  a.push(2)
  print a.pop()
  print 'size is',a.size()
  a.push(7)
  a.push(8)
  a.push(10)
  a.pop()
  while(a.isEmpty() != True):
    print a.pop()

setup()

..................................................................................................................

result :

xxxxxx:~/ดาวน์โหลด/Work$ python stack.py
True
2
size is 1
8
7
1





Building Software : raw_input รับค่า Arg ทาง command line

โค๊ต : use raw_input

def setup():
  multiplier = int(raw_input(' multiplier is : '))
  count = 1
  while(count <= 12):
    result = multiplier * count
    print multiplier ,' x ', count ,' = ', result
    count = count +1



setup()


ผลลัพธ์

multiplier is :

จากนั้นเติมเลขลงไป ได้

 multiplier is : 7
7  x  1  =  7
7  x  2  =  14
7  x  3  =  21
7  x  4  =  28
7  x  5  =  35
7  x  6  =  42
7  x  7  =  49
7  x  8  =  56
7  x  9  =  63
7  x  10  =  70
7  x  11  =  77
7  x  12  =  84






...............................................................................................................................
โค๊ตที่ 2 : use arg in command line

import sys

def setup():
  jump_distant = int(sys.argv[1])
  total_distant = int(sys.argv[2])
  round_jump = total_distant /jump_distant # calculation
  if((total_distant % jump_distant) != 0): # check
    round_jump = round_jump + 1
  print 'frog must jump' ,round_jump, 'round'



setup()

ผลลัพธ์ :
 xxxxxxxxxxxxxxxx:~/ดาวน์โหลด/Work$ python frogAr.py 3 57
frog must jump 19 round










..............................................................................................................................
โค๊ตที่ 3 :  use open file





def setup():
  file_input = open('file','r') # open file
  jump_distant = int(file_input.readline()) # read next line
  total_distant = int(file_input.readline())
  file_input.close # close file
  round_jump = total_distant /jump_distant # calculation
  if((total_distant % jump_distant) != 0): # check
    round_jump = round_jump + 1
  print 'frog must jump' ,round_jump, 'round'



setup()

ผลลัพธ์ :

 xxxxxxxxxxxxxxxxxxxxx:~/ดาวน์โหลด/Work$ python frog.py file
frog must jump 6 round




# file file have number 2 line first is 5 second is 27



Building Software : ทดสอบการพิมพ์














ค่า เฉลี่ยคือ 45.2 WPM

วันอังคารที่ 16 สิงหาคม พ.ศ. 2559

Building Software - 0029 - กบ (frog)

ที่มา http://ninjapy.programming.in.th/task/0029/show

โจทย์
มีเจ้ากบน้อยอยู่ตัวหนึ่ง สามารถกระโดดได้ในทุกทิศทางบนระนาบ และจะกระโดดเป็นระยะทางครั้งละ X หน่วยพอดี อยู่มาวันหนึ่ง เจ้ากบน้อยต้องการกระโดดจากจุด A ไปยังจุด B ซึ่งเป็นจุดบนระนาบ ที่ตั้งอยู่ห่างกัน Y หน่วย เจ้ากบน้อยอยากให้คุณช่วยหาว่า มันจะต้องกระโดดอย่างน้อยกี่ครั้ง จึงจะไปหยุดที่จุด B พอดี
งานของคุณ
จงเขียนโปรแกรมเพื่อรับจำนวนเต็ม X และ Y แล้วคำนวณหาจำนวนครั้งที่น้อยที่สุดที่เจ้ากบน้อยต้องใช้ในการกระโดดจากจุด A ไปยังจุด B
ข้อมูลนำเข้า
มี บรรทัดเดียว ระบุจำนวนเต็ม X และ Y (1 ≤ X,Y ≤ 1,000) แทนระยะทางในการกระโดดแต่ละครั้งของเจ้ากบน้อย และระยะห่างระหว่างจุด A และจุด B
ข้อมูลส่งออก
มีบรรทัดเดียว แสดงจำนวนครั้งที่น้อยที่สุดที่เจ้ากบน้อยต้องใช้ในการกระโดดจากจุด A ไปยังจุด B
ที่มา
การแข่งขัน IOI Thailand League เดือนสิงหาคม 2553
โจทย์โดย: สุธี เรืองวิเศษ

.............................................................................................................................

code :

def setup():
  file_input = open('file','r') # open file
  jump_distant = int(file_input.readline()) # read next line
  total_distant = int(file_input.readline())
  file_input.close # close file
  round_jump = total_distant /jump_distant # calculation
  if((total_distant % jump_distant) != 0): # check
    round_jump = round_jump + 1
  print 'frog must jump' ,round_jump, 'round'


setup()

...............................................................................................................................
file :

5
27
..............................................................................................................................
ผลลัพธ์ :

frog must jump 6 round


วันจันทร์ที่ 15 สิงหาคม พ.ศ. 2559

ฺBuilding software : ทดสอบการพิม


.................................................................................................................

จากการทดสอบทั้งหมด 10 ครั้ง ได้ค่าเฉลีย ประมาณ 43.5 WPM

วันเสาร์ที่ 13 สิงหาคม พ.ศ. 2559

Work 0 : Warm

ลองทำแบบฝึกหัดตามที่ต่างๆเพือทวนความจำเกี่ยวกับวิธีการเขียน Python
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 ข้อ 000
โจทย์
You are driving a little too fast, and a police officer stops you. Write code to compute the result, encoded as an int value: 0=no ticket, 1=small ticket, 2=big ticket. If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless it is your birthday -- on that day, your speed can be 5 higher in all cases.


caught_speeding(60, False) → 0

caught_speeding(65, False) → 1

caught_speeding(65, True) → 0


ที่ทำ

def caught_speeding(speed, is_birthday):
  if(is_birthday == True):
    speed = speed - 5
  if(speed <= 60):
    return 0
  elif (speed <= 80):
    return 1
  return 2

ลง Ubuntu และลอง python ใน Ubuntu

โหลดและลง Ubuntu แบบ dual boot  โดยแบ่งเนื้อที่มา 40 GB

ซึ่งก็ใช้เวลาศึกษาวิธีการลงแบบนี้พอสมควร เพราะไม่เคยลง แบบ Dual boot มาก่อน หลังจากลองใช้มาซักพักพบว่า เปิดปิด เครื่องเร็วกว่า Window 10 มาก และมีความเร็ว(ในตอนนี้)มากกว่า Window 10 ซึ่งอาจจะเป็นเพราะเพิ่งได้ลง จึงยังมีข้อมูลไม่มากนัก 

....................................................................................................................................

และได้ลอง ใช้งาน Python โดยการ ทดลองโค๊ตที่ได้เคยเขียนไว้เมื่อเทอมที่แล้วนำมาลองรันดู ผ่าน Terminal .... python filename,py


 .....................................................................................................................................

ได้เรียนรู้ วิธีการ รัน python ผ่าน Terminal เบื้องต้นแล้ว รู้วิธีการลง Ubuntu วิธีการแยกพาร์ทซิชั่น.