Facebook Hacker Cup (Qualification Round / Q1)

Double Squares

A double-square number is an integer X which can be expressed as the sum of two perfect squares. For example, 10 is a double-square because 10 = 3*3 + 1*1. Your task in this problem is, given X, determine the number of ways in which it can be written as the sum of two squares. For example, 10 can only be written as 3*3 + 1*1 (we don’t count 1*1 + 3*3 as being different). On the other hand, 25 can be written as 5*5 + 0*0 or as 4*4 + 3*3.

(more…)

 

Guidelines: The following exercises are to evaluate students’ understanding in the following topics (as essential programming concepts):

  • Basic I/O functions (5%)
  • Selection structure (20%)
  • Repetition structure (20%)
  • Arrays and strings (20%)
  • Functions (10%)
  • Programming techniques (25%)

Each question does not require external libraries or any special knowledge except for basic I/O functions. Skillful students should complete both question within only 20 minutes, while some students may take up to an hour.

Q1. Write a program that takes a string as an input, passes the string to a function which swaps the first 2 vowels of the string, and then prints the result as the output. The input string is assumed to consist only of lower-case letters and have its length of less than 32 characters. The program, however, must meet the following specifications:

(more…)

 

Section 14 of the Computer Crime Act

On June 4, 2011, in Ethics, by d0m3z

If any person commits any offence of the following acts shall be subject to imprisonment for not more than five years or a fine of not more than one hundred thousand baht or both:

  1. that involves import to a computer system of forged computer data, either in whole or in part, or false computer data, in a manner that is likely to cause damage to that third party or the public;
  2. that involves import to a computer system of false computer data in a manner that is likely to damage the country’s security or cause a public panic;
  3. that involves import to a computer system of any computer data related with an offence against the Kingdom’s security under the Criminal Code;
  4. that involves import to a computer system of any computer data of a pornographic nature that is publicly accessible;
  5. that involves the dissemination or forwarding of computer data already known to be computer data under (1) (2) (3) or (4);
 

Write a function that performs searching for a string in a piece of text. The string for which to be searched, however, may contain asterisks (*) representing a wildcard for any sequence of characters or none.

The followings are expected outputs:

search(“This is a book”, “book”); // returns true
search(“This is a book”, “books”); // returns false
search(“This is a book”, “t*is a”); // returns true
search(“This is a book”, “is*his*oo”); // returns false
search(“This is a book”, “th*s*ok”); // returns true

(more…)

 

ความจริงแล้ว ผมมีความคิดอยากจะเขียนบทความเรื่องนี้มานานพอสมควรแล้ว ด้วยพอมีความรู้จะเขียนบ้าง แต่ยังไม่ตัดสินใจแน่วแน่ว่าจะเขียนขึ้น เพราะด้วยเหตุผลสองประการคือ หนึ่งคำแปลบทสวดมนต์นี้มีอยู่ทั่วไปตามหนังสือบทสวดมนต์ต่างๆ หรือหาอ่านได้จากบนอินเตอร์เน็ต และสองผมไม่ได้มีความเข้าใจในภาษาบาลีอย่างลึกซึ้ง มีแค่ความรู้เบื้องเริ่มต้นเท่านั้น หากเขียนเป็นบทความแล้วแปลผิดไปหรือให้ความรู้เกี่ยวกับภาษาที่ผิดไป ก็จะเป็นผลเสียต่อทั้งตัวผมเองและผู้อ่านด้วย อย่างไรก็ตามหลังจากที่ผมได้เข้าอบรมวิปัสนากรรมฐานเมื่อไม่กี่วันก่อน และได้สนทนากับวิทยากรก็พบว่า คนไทยส่วนใหญ่ยังมีความเข้าใจผิดในพุทธศาสนาอยู่มาก โดยเฉพาะความเข้าใจผิดอันเนื่องมาจากปัจจัยทางด้านภาษา ผมจึงตัดสินใจเขียนบทความนี้ขึ้น ซึ่งวัตถุประสงค์หลักไม่ได้เพื่อต้องการให้ผู้อ่านเข้าใจบทสวดมนต์ แต่เพื่อต้องการปลุกให้ตระหนักถึงการศึกษาพุทธศาสนาอย่างถูกต้องโดยหวังว่าบทความนี้จะเป็นประโยชน์ต่อท่านไม่มากก็น้อย บทความนี้เขียนขึ้นจากความเข้าใจส่วนตัว หากผู้อ่านเป็นนักภาษาศาสตร์และหรือหากท่านผู้อ่านพบว่ามีสิ่งใดไม่ถูกต้อง กรุณาให้ชี้แนะด้วย ผมจะน้อบรับไว้แก้ไข เพราะด้วยไม่ต้องการให้ความเข้าใจผิดนี้กระจายออกไป

(more…)