Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python
Python
  1. ตรวจสอบว่า String เป็น Valid Identifier ใน Python หรือไม่

    โจทย์: กำหนด String ตรวจสอบว่าเป็น Valid Python Identifier หรือไม่ เกณฑ์: เริ่มต้นด้วย Underscore _ หรือ ตัวอักษร (A-Z, a-z) ไม่มี Whitespace ตัวอักษรถัดไป: ตัวอักษร, ตัวเลข, Underscore เท่านั้น (ไม่มี Special Char: $, #, % ฯลฯ) ตัวอย่าง id = _hello_56 → True อัลกอริทึม ตรวจสอบตัวแรก: isalpha()

  2. ตรวจสอบความยาว Linked List ว่า Even หรือ Odd ด้วย Python

    โจทย์: กำหนด Linked List ตรวจสอบว่าความยาวเป็น Even หรือ Odd ตัวอย่าง head = [5,8,7,4,3,6,4,5,8] → Odd (9 nodes) อัลกอริทึม (Fast Pointer) ใช้ Pointer วิ่งทีละ 2 Node (head = head.next.next) จบลูป: ถ้า head == None → Even (วิ่งครบคู่) ถ้า head != None → Odd (เหลือ Node เดียว) โค้ดตัวอย่าง class

  3. ตรวจสอบว่าเลขบวก 1 แล้วเป็น Perfect Square ได้หรือไม่ด้วย Python

    โจทย์: กำหนดเลข n ตรวจสอบว่า n+1 เป็น Perfect Square หรือไม่ ตัวอย่าง n = 288 → 288+1=289=17² → True อัลกอริทึม res_num = n + 1 sqrt_val = int(sqrt(res_num)) ตรวจสอบ sqrt_val² == res_num โค้ดตัวอย่าง from math import sqrt def solve(n): res_num = n + 1 sqrt_val = int(sqrt(res_num))

  4. ตรวจสอบว่าเลขจากการ Concatenate สองตัวเป็น Perfect Square หรือไม่ด้วย Python

    โจทย์: กำหนดเลข x และ y Concatenate แล้วตรวจสอบว่าเป็น Perfect Square หรือไม่ ตัวอย่าง x = 2, y = 89 → 289 = 17² → True อัลกอริทึม แปลง x, y เป็น String Concatenate → Integer หาค่ารากที่สองแบบ Integer (int(sqrt)) ตรวจสอบ sqrt² == เลขที่ได้ โค้ดตัวอย่าง from math import sqrt def solve(x, y):

  5. ตรวจสอบว่าเลขมี Bit ตั้งค่า (Set) เฉพาะ First และ Last Bit ด้วย Python

    โจทย์: กำหนดเลข n ตรวจสอบว่า Binary Representation มี Bit 1 เฉพาะตำแหน่งแรก (LSB) และตำแหน่งสุดท้าย (MSB) เท่านั้น ตัวอย่าง n = 17 (10001) → True (Bit 0 และ Bit 4 เป็น 1, อื่นๆ เป็น 0) อัลกอริทึม ถ้า n == 1 → True (Binary: 1) n - 1 ต้องเป็น Power of 2 (เช่น 17-1=16=2^4) ตรวจสอบ Power of 2: (n & (

  6. ตรวจสอบว่าจุด (x, y) อยู่บนเส้นตรง y = mx + b หรือไม่ด้วย Python

    โจทย์: กำหนดเส้นตรง y = mx + b (m = slope, b = y-intercept) และจุด (x, y) ตรวจสอบว่าจุดอยู่บนเส้นหรือไม่ ตัวอย่าง m = 3, b = 5, point = (6, 23) → True (23 = 3*6 + 5) อัลกอริทึม คำนวณ y ที่คาดหวัง = m * x + b เปรียบเทียบกับ y จริงของจุด เท่ากัน → True, มิฉะนั้น False โค้ดตัวอย่าง def solve(m, b,

  7. ตรวจสอบว่าผลรวม Absolute Difference ของหลักติดกันเป็น Prime หรือไม่ด้วย Python

    โจทย์: กำหนดเลข n ตรวจสอบว่าผลรวม |ความต่าง| ของคู่หลักติดกัน (Adjacent Digits) เป็น Prime หรือไม่ ตัวอย่าง n = 574 → |5-7| + |7-4| = 2 + 3 = 5 (Prime) → True อัลกอริทึม แปลง n เป็น String วน i=1 ถึง len-1 รวม abs(int(s[i-1]) - int(s[i])) ตรวจสอบว่าผลรวมเป็น Prime โค้ดตัวอย่าง 1: for i

  8. ตรวจสอบว่าผลรวมของจำนวนเฉพาะใน Array เป็นจำนวนเฉพาะหรือไม่ด้วย Python

    โจทย์: กำหนด Array nums ตรวจสอบว่าผลรวมของสมาชิกที่เป็น Prime ใน Array นั้น เองก็เป็น Prime อีกด้วยหรือไม่ ตัวอย่าง nums = [1,2,4,5,3,3] → True (Primes: 2,5,3,3 → Sum=13 ซึ่งเป็น Prime) อัลกอริทึม (Sieve of Eratosthenes) สร้าง Sieve ขนาด MAX (10000) หา Prime ทั้งหมด วน Array รวมค่าที่เป็น Prime ต

  9. ตรวจสอบว่าเลขสองตัวต่างกันที่ Bit เดียวเท่านั้นด้วย Python

    โจทย์: กำหนดเลข x และ y ตรวจสอบว่าต่างกันที่ Bit เดียว (One-bit position) หรือไม่ ตัวอย่าง x = 25 (11001), y = 17 (10001) → True (ต่างที่ bit เดียว) อัลกอริทึม z = x XOR y (Bit ที่ต่างกันจะเป็น 1) นับ Set Bits ใน z (Brian Kernighans Algorithm หรือ Bit Count) ถ้าจำนวน Set Bits = 1 → True, มิฉะนั้น

  10. ตรวจสอบว่าสระใน String เรียงตามลำดับอักษรหรือไม่ด้วย Python

    โจทย์: กำหนด String s ตรวจสอบว่าสระ (Vowels) ใน s เรียงตามลำดับอักษร (Alphabetical Order) หรือไม่ ตัวอย่าง s = helloyou → True (สระ: e, o, o, u เรียงตามลำดับ) อัลกอริทึม ตัวแปร character = ตัวอักษร ASCII 64 (@ ก่อน A) วนลูปทุกตัวอักษรใน s: ถ้าเป็นสระ (A,E,I,O,U,a,e,i,o,u): ถ้า ตัวอักษรปัจจุบัน

  11. ตรวจสอบว่า Triangle ถูกต้องหรือไม่จาก 3 ด้านด้วย Python

    โจทย์: กำหนด 3 ด้าน ตรวจสอบว่าเป็นสามเหลี่ยมได้หรือไม่ (Triangle Inequality Theorem) ตัวอย่าง sides = [14, 20, 10] → True เพราะ 20 < (10+14) อัลกอริทึม Sort ด้านทั้ง 3 ถ้า ผลรวม 2 ด้านเล็ก ≤ ด้านใหญ่ → False มิฉะนั้น → True โค้ดตัวอย่าง def solve(sides): sides.sort() if sides[0] + sides

  12. ตรวจสอบว่า String สองตัวเป็น Anagram กันหรือไม่ด้วย Python

    โจทย์: กำหนด String s และ t ตรวจสอบว่าเป็น Anagram กันหรือไม่ (ตัวอักษรเหมือนกันหมด ต่างแค่ลำดับ) ตัวอย่าง s = bite, t = biet → True อัลกอริทึม ถ้าความยาวต่างกัน → False Sort ตัวอักษรทั้งสอง String เปรียบเทียบว่าเหมือนกันหรือไม่ โค้ดตัวอย่าง def solve(s, t): if len(s) != len(t): ret

  13. ตรวจสอบว่า String สองตัวเทียบเท่ากันตามเงื่อนไขหรือไม่ด้วย Python

    โจทย์: กำหนด String s และ t ขนาดเท่ากัน ตรวจสอบว่า Equivalent หรือไม่ เงื่อนไข: ทั้งสองเท่ากันเลย, หรือ แบ่ง s, t เป็นครึ่งซ้าย-ขวา (s1,s2 และ t1,t2) แล้ว: s1 ≡ t1 และ s2 ≡ t2 (Recursive), หรือ s1 ≡ t2 และ s2 ≡ t1 (Recursive) ตัวอย่าง s = ppqp, t = pqpp → True แบ่ง: s1=pp, s2=qp, t1=pq, t2=pp

  14. วิธีสร้างโมเดล Keras ที่ระบุ Input Shape ล่วงหน้าด้วย Python

    TensorFlow: ML Framework Google Open-source Research/Production Keras: Deep Learning API Python จาก ONEIROS ระดับสูง รันบน TensorFlow Scalable, Cross-platform (TPU, GPU, Web, Mobile) เข้าถึงด้วย from tensorflow import keras ตัวอย่าง: เลเยอร์สร้าง Weights เมื่อรู้ Input Shape print(Three dense laye

  15. Common Debugging Workflow เมื่อสร้างโมเดลด้วย Keras ใน Python

    TensorFlow: ML Framework Google Open-source Optimization คณิตศาสตร์ซับซ้อน ใช้ NumPy, Multi-dimensional arrays (Tensors) ติดตั้ง pip install tensorflow Keras (ภาษากรีก: Horn) จาก ONEIROS รันบน TensorFlow Scalable, Cross-platform (TPU, GPU, Web, Mobile) เข้าถึงด้วย from tensorflow import keras ตัวอ

  16. วิธีใช้ Keras ดึง Features จากเลเยอร์เดียวของโมเดลด้วย Python

    TensorFlow: ML Framework Google Open-source Optimization คณิตศาสตร์ซับซ้อน ใช้ NumPy, Multi-dimensional arrays (Tensors) รองรับ Deep Neural Networks ติดตั้ง pip install tensorflow Keras (ภาษากรีก: Horn) จาก ONEIROS Deep Learning API Python ระดับสูง รันบน TensorFlow Scalable, Cross-platform (TPU, GP

  17. วิธีทำ Transfer Learning ด้วย Keras และ Python

    TensorFlow: ML Framework Google Open-source Tensor = Multi-dimensional array ใน Data Flow Graph Keras (ภาษากรีก: Horn) จาก ONEIROS Deep Learning API Python ระดับสูง รันบน TensorFlow Scalable, Cross-platform (TPU, GPU, Web, Mobile) เข้าถึงด้วย from tensorflow import keras ตัวอย่าง: Transfer Learnin

  18. วิธีใช้ Keras กับ Pre-trained Model ด้วย Python

    TensorFlow: ML Framework Google Open-source Research/Production Keras (ภาษากรีก: Horn) จาก ONEIROS Deep Learning API Python ระดับสูง รันบน TensorFlow Scalable, Cross-platform (TPU, GPU, Web, Mobile) เข้าถึงด้วย from tensorflow import keras ตัวอย่าง: Transfer Learning กับ Xception print(A convoluti

  19. อภิพาย: Keras Functional API สร้างเลเยอร์อย่างไรด้วย Python

    TensorFlow: ML Framework Google Open-source Optimization คณิตศาสตร์ซับซ้อน ติดตั้ง pip install tensorflow Keras (ภาษากรีก: Horn) จาก ONEIROS Deep Learning API Python ระดับสูง รันบน TensorFlow Scalable, Cross-platform เข้าถึงด้วย from tensorflow import keras Functional API ยืดหยุ่นกว่า Sequential A

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:214/451  20-คอมพิวเตอร์/Page Goto:1 208 209 210 211 212 213 214 215 216 217 218 219 220