Comments

Foobar

 1- Braille Translation

===================

Because Commander Lambda is an equal-opportunity despot, they have several visually-impaired minions. But Lambda never bothered to follow intergalactic standards for workplace accommodations, so those minions have a hard time navigating her space station. You figure printing out Braille signs will help them, and -- since you'll be promoting efficiency at the same time -- increase your chances of a promotion.

Braille is a writing system used to read by touch instead of by sight. Each character is composed of 6 dots in a 2x3 grid, where each dot can either be a bump or be flat (no bump). You plan to translate the signs around the space station to Braille so that the minions under Commander Lambda's command can feel the bumps on the signs and "read" the text with their touch. The special printer which can print the bumps onto the signs expects the dots in the following order:
1 4
2 5
3 6

So given the plain text word "code", you get the Braille dots:

11 10 11 10
00 01 01 01
00 10 00 00

where 1 represents a bump and 0 represents no bump. Put together, "code" becomes the output string "100100101010100110100010".

Write a function solution(plaintext) that takes a string parameter and returns a string of 1's and 0's representing the bumps and absence of bumps in the input string. Your function should be able to encode the 26 lowercase letters, handle capital letters by adding a Braille capitalization mark before that character, and use a blank character (000000) for spaces. All signs on the space station are less than fifty characters long and use only letters and spaces.
-- Python cases --
Input:
solution.solution("code")
Output:
    100100101010100110100010

Input:
solution.solution("Braille")
Output:
    000001110000111010100000010100111000111000100010

Input:
solution.solution("The quick brown fox jumps over the lazy dog")
Output:
    000001011110110010100010000000111110101001010100100100101000000000110000111010101010010111101110000000110100101010101101000000010110101001101100111100011100000000101010111001100010111010000000011110110010100010000000111000100000101011101111000000100110101010110110

sol: alpha = {'a':"100000",
        'b':"110000",
'c':"100100",
'd':"100110",
'e':"100010",
'f':"110100",
'g':"110110",
'h':"110010",
'i':"010100",
'j':"010110",
'k':"101000",
'l':"111000",
'm':"101100",
'n':"101110",
'o':"101010",
'p':"111100",
'q':"111110",
'r':"111010",
's':"011100",
't':"011110",
'u':"101001",
'v':"111001",
'w':"010111",
'x':"101101",
'y':"101111",
'z':"101011"}

def answer(plaintext):
count = 0
string = ""
while count < len(plaintext):
letter = str(plaintext[count])
count += 1
if letter.isupper() == False:
if letter in dict.keys(alpha):
string += alpha.get(letter)
else:
string += "000000"
else:
letter = letter.lower()
if letter in dict.keys(alpha):
string += "000001"
string += alpha.get(letter)
else:
string += "000000"
else:
print(string)
print(answer("code"))
print(answer("Braille"))
#
2-Please Pass the Coded Messages
==============================

You need to pass a message to the bunny workers, but to avoid detection, the code you agreed to use is... obscure, to say the least. The bunnies are given food on standard-issue plates that are stamped with the numbers 0-9 for easier sorting, and you need to combine sets of plates to create the numbers in the code. The signal that a number is part of the code is that it is divisible by 3. You can do smaller numbers like 15 and 45 easily, but bigger numbers like 144 and 414 are a little trickier. Write a program to help yourself quickly create large numbers for use in the code, given a limited number of plates to work with.

You have L, a list containing some digits (0 to 9). Write a function solution(L) which finds the largest number that can be made from some or all of these digits and is divisible by 3. If it is not possible to make such a number, return 0 as the solution. L will contain anywhere from 1 to 9 digits. The same digit may appear multiple times in the list, but each element in the list may only be used once.
-- Python cases --
Input:
solution.solution([3, 1, 4, 1])
Output:
    4311

Input:
solution.solution([3, 1, 4, 1, 5, 9])
Output:
    94311
sol::
def solution(l):
highest_num = 0
for i in range(1, len(l) + 1):
for subset in permutations(l, i):
if len(subset) >= 1:
num = ''.join(str(x) for x in subset)
num = int(num)
mod_check = num % 3
if mod_check == 0:
if num > highest_num:
highest_num = num
return highest_num


print(solution([3, 1, 4,5, 1]))

sol

Share on Google Plus

About Inas AL-Kamachy

    Blogger Comment
    Facebook Comment

0 Comments:

Post a Comment