Sei sulla pagina 1di 3

File: Untitled Document 1 Page 1 of 3

aPlease note: Questions 7-9 are optional and only meant to give an overview of
your current skills in various technical areas.
Just skip the questions you are not familiar with, we do not expect you to excel
in all areas ;-)
Feel free to add comments in your answers.
#Test 1 - 6 is written in python

[rco] Evaluation: 6 / 8 = 75%

Test 1: Any language (required)


Write a program that outputs sequentially the integers from 1 to 99 but on some
conditions prints a string instead:
when the integer is a multiple of 3 print “Open” instead of the number,
when it is a multiple of 7 print “Source” instead of the number,
when it is a multiple of both 3 and 7 print “OpenSource” instead of the number.
def Integers():
for i in range(1,100):
if i % 7 == 0 and i % 3 == 0:
print "OpenSource"
elif i % 3 == 0:
print "Open"
elif i % 7 == 0:
print "Source"
else:
print i
Integers()

[rco] 1

Test 2: Any language (required)


Expand a random range from 0-5 to 0-7. Given a function rand5() that returns a
random float in the range [0,5] with a uniform distribution, write a function that
returns a random float in the range [0,7] using only rand5() and keeping a uniform
distribution.
def rand7():
return 1.4*rand5()

[rco] 1

Test 3: Any language (required)


Write a function that takes a list of strings and returns the sum of the list
items that represents an integer (skipping the other items)
def lists(list_of_strings):
sum = 0
for i in list_of_strings:
try:
sum += int(i)
except:
pass
return sum

[rco] 1

Test 4: Any language (required)


Write a recursive version of the previous function (or an iterative version if you
already did a recursive version).
global s
s = 0
def lists_recursive(list_of_strings):
global s
if len(list_of_strings)==0:
return ""
else:
try:
sum += int(list_of_strings[0])
list_recursive(list_of_strings[1:])
File: Untitled Document 1 Page 2 of 3

except:
pass

[rco] 0 - I see the idea, but s is never returned, nor initialized upon every
"first" call

Test 5: Any language (required)


Write a program to download the contents of http://www.sap.com/belgique/index.html
(the SAP homepage for Belgium), and then save the contents of the page to a new
local file, with all occurrences of "SAP" replaced by "Odoo".
# This solution will only save the source code of the web page to a local file -
website.html
# You need to download the module requests in order to run the program : pip
install requests
def Scrape():
import requests
url = "http://www.sap.com/belgique/index.html"
source_code = requests.get(url)
plain_text = source_code.text.replace("SAP","Odoo")
f = open("website.html","w+")
f.write(plain_text.encode('utf-8'))
f.close()
## In order to downlaod all the content (images, scripts, css, etc) code would be
something like this (pseudo code):
for a in regex(that matches images, scripts, and other downloadable content):
get_the_path
download the file with urllib.request
update_the_page_soruce_code_with_new_path_to_locally_downloaded_file
replace SAP with ODOO in source_code
save_page_source_code locally to website.com

[rco] 1

Test 6: Any language (required)


You have a huge file named "data.bin" that does not fit in memory, code a program
that deletes every 7th byte of it, without opening other files. truncate can be
used to change its size.
def Resize():
f = open("data.bin",'r+')
counter = 1
new_text = ''
for line in f:
for a in line:
if counter % 7 == 0:
pass
else:
new_text += a
counter += 1
f.write(new_text)
f.close()
truncate("data.bin')

[rco] 0 - the file does not fit in memory, hence appending to new_text will
crash...

Test 7: Regular Expression (if you know regexes)


Write a regular expression to match strings containing both "Odoo" and "#rules" in
any order.
.*Odoo+.*#rules+.*|.*#rules+.*Odoo+.*

[rco] 1

Test 8: Javascript (if you know javascript)


Given the following code, write two lines of Javascript to call the print()
function in a way that prints the Window global object in the Javascript console ?
Your code must not use the variable `window`. Feel free to comment.
File: Untitled Document 1 Page 3 of 3

Printer = function(){
this.print = function() {
console.log(this);
}
}
var printer = new Printer();

Test 9: Unix (if you know C and Unix)


Write a C program that roughly measures the overhead of a context switch between
the kernel and userspace on a UNIX/Linux system (without using the pthread API).
Please indicate the assumptions your rough estimation is based on.

Test 10: SQL (if you know SQL)


Write pseudo-SQL statements to create database tables to store the products of a
basic webshop. Each product has a name, a price, a creation date and may belong to
several categories. Categories have a name and a flag to indicate whether the
category is private or public.
Imagine that these tables are populated with 10000 products and 300 categories,
with products being assigned a random set of public and private categories. Write
a SQL query to find the list of products that belong to more than 5 public
categories.
How would you populate the tables with test data (thousands of products with
random values and categories)
1.
# CREATING TABLE CATEGORY
CREATE TABLE CATEGORY COLUMNS ID TYPE INT,NAME TYPE VARCHAR,PUBLIC BOOLEAN
PRIMARY KEY ID
ID AUTOINCREMENT

#CREATING TABLE PRODUCT


CREATE TABLE PRODUCT COLUMNS ID TYPE INT,NAME TYPE VARCHAR,PRICE TYPE
FLOAT,CREATION DATE TYPE TIMESTAMP
PRIMARY KEY ID
ID AUTOINCREMENT

#CREATE TABLE BELONGS - TABLE WILL CONNECT PRODUCTS WITH CATEGORIESS


CREATE TABLE BELONGS COLUMNS ID_PRODUCT TYPE INT, ID_CATEGORY TYPE INT
PRIMAREY KEY = ID_PRODUCT,ID_CATEGORY
CONSTRAINT1 (FOREIGN KEY1) = PRODUCT_ID = TABLE PRODUCT.ID
CONSTRAINT2 (FOREIGN KEY2) = ID_CATEGORY = TABLE CATEGORY.ID

2.
SELECT * FROM PRODUCT WHERE ID IN (SELECT ID_PRODUCT FROM (SELECT ID_PRODUCT,COUNT
(ID_CATEGORY) AS NCATS FROM BELONGS WHERE ID_CATEGORY IN (SELECT ID FROM CATEGORY
WHERE PUBLIC = TRUE ) GROUP BY ID_PRODUCT) AS B WHERE NCATS > 5)

3.
FIRST I WILL INSERT CATEGORIES -- INSERT INTO CATEGORIES NAME,PUBLIC VALUES
( NAME, TRUE/FALSE)
THEN I WILL INSERT ALL THE PRODUCTS AND FOR EACH PRODUCT I WILL CHECK THE IDS OF
CATEGORIES THAT IT BELONGS. WITH THE ID OF THE PRODUCT AND ITS' CATEGORIES I WILL
POPULATE THE TABLE BELONGS
AND COONECT THE PRODUCTS WITH CATEGORIES

[rco] 1

Potrebbero piacerti anche