Skip to content

Commit 087160b

Browse files
Foo🍫
1 parent dbb4cbb commit 087160b

File tree

63 files changed

+3296
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3296
-0
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Braille Translation
2+
===================
3+
4+
Because Commander Lambda is an equal-opportunity despot, she has several visually-impaired minions. But she 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.
5+
6+
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:
7+
1 4
8+
2 5
9+
3 6
10+
11+
So given the plain text word "code", you get the Braille dots:
12+
13+
11 10 11 10
14+
00 01 01 01
15+
00 10 00 00
16+
17+
where 1 represents a bump and 0 represents no bump. Put together, "code" becomes the output string "100100101010100110100010".
18+
19+
Write a function answer(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.
20+
21+
Languages
22+
=========
23+
24+
To provide a Python solution, edit solution.py
25+
To provide a Java solution, edit solution.java
26+
27+
Test cases
28+
==========
29+
30+
Inputs:
31+
(string) plaintext = "code"
32+
Output:
33+
(string) "100100101010100110100010"
34+
35+
Inputs:
36+
(string) plaintext = "Braille"
37+
Output:
38+
(string) "000001110000111010100000010100111000111000100010"
39+
40+
Inputs:
41+
(string) plaintext = "The quick brown fox jumps over the lazy dog"
42+
Output:
43+
(string) "000001011110110010100010000000111110101001010100100100101000000000110000111010101010010111101110000000110100101010101101000000010110101001101100111100011100000000101010111001100010111010000000011110110010100010000000111000100000101011101111000000100110101010110110"
44+
45+
Use verify [file] to test your solution and see how it does. When you are finished editing your code, use submit [file] to submit your answer. If your solution passes the test cases, it will be removed from your home folder.
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
def answer(plaintext):
2+
# Find the braille letter equale english letter
3+
switcher = {
4+
"a": "100000",
5+
"b": "110000",
6+
"c": "100100",
7+
"d": "100110",
8+
"e": "100010",
9+
"f": "110100",
10+
"g": "110110",
11+
"h": "110010",
12+
"i": "010100",
13+
"j": "010110",
14+
"k": "101000",
15+
"l": "111000",
16+
"m": "101100",
17+
"n": "101110",
18+
"o": "101010",
19+
"p": "111100",
20+
"q": "111110",
21+
"r": "111010",
22+
"s": "011100",
23+
"t": "011110",
24+
"u": "101001",
25+
"v": "111001",
26+
"w": "010111",
27+
"x": "101101",
28+
"y": "101111",
29+
"z": "101011",
30+
"1": "100000",
31+
"2": "110000",
32+
"3": "100100",
33+
"4": "100110",
34+
"5": "100010",
35+
"6": "110100",
36+
"7": "110110",
37+
"8": "110010",
38+
"9": "010100",
39+
"0": "010110",
40+
".": "010011",
41+
"-": "010010",
42+
",": "010000",
43+
"!": "011010",
44+
"?": "011001",
45+
":": "010010",
46+
"(": "011011",
47+
")": "011011",
48+
"/": "001100",
49+
"#": "001111",
50+
";": "011000",
51+
"[": "000001011011",
52+
"]": "011011001000",
53+
"capital": "000001",
54+
"_": "001001001001001001",
55+
"'": "001000",
56+
"+": "011010",
57+
"*": "011001",
58+
">": "101010",
59+
"<": "010101",
60+
"@": "001110",
61+
"%": "010110001011",
62+
" ": "000000"
63+
}
64+
result = ""
65+
lastCharIsDigit = False
66+
for l in plaintext:
67+
if l.isdigit():
68+
if not lastCharIsDigit:
69+
lastCharIsDigit = True
70+
result += switcher.get("#", "")
71+
else:
72+
lastCharIsDigit = False
73+
if l.isupper():
74+
result += switcher.get("capital", "")
75+
76+
result += switcher.get(l.lower(), "")
77+
return result
78+
79+
80+
# sample
81+
print(answer("Braille"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.Objects;
2+
import java.util.stream.Collectors;
3+
4+
public class Solution {
5+
6+
public static String solution(String encryptedText) {
7+
return encryptedText.chars()
8+
// Decodes the current character.
9+
.map(c -> (c >= 'a' && c <= 'z') ? ('a' + 'z' - c) : c)
10+
// Converts the mapped character from an integer.
11+
.mapToObj(c -> (char) c)
12+
.map(Objects::toString)
13+
.collect(Collectors.joining());
14+
}
15+
16+
public static void main(String... args) {
17+
String inputOne = "wrw blf hvv ozhg mrtsg’h vkrhlwv?";
18+
String inputTwo = "Yvzs! I xzm’g yvorvev Lzmxv olhg srh qly zg gsv xlolmb!!";
19+
String outputOne = "did you see last night’s episode?";
20+
String outputTwo = "Yeah! I can’t believe Lance lost his job at the colony!!";
21+
22+
assert solution(inputOne).equals(outputOne);
23+
assert solution(inputTwo).equals(outputTwo);
24+
}
25+
26+
}
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## I Love Lance & Janice
2+
3+
Time to solve: 48 hours.
4+
5+
### Description
6+
7+
You’ve caught two of your fellow minions passing coded notes back and forth – while they’re on duty, no less! Worse, you’re pretty sure it’s not job-related – they’re both huge fans of the space soap opera “Lance & Janice”. You know how much Commander Lambda hates waste, so if you can prove that these minions are wasting her time passing non-job-related notes, it’ll put you that much closer to a promotion.
8+
9+
Fortunately for you, the minions aren’t exactly advanced cryptographers. In their code, every lowercase letter [a..z] is replaced with the corresponding one in [z..a], while every other character (including uppercase letters and punctuation) is left untouched. That is, ‘a’ becomes ‘z’, ‘b’ becomes ‘y’, ‘c’ becomes ‘x’, etc. For instance, the word “vmxibkgrlm”, when decoded, would become “encryption”.
10+
11+
Write a function called answer(s) which takes in a string and returns the deciphered string so you can show the commander proof that these minions are talking about “Lance & Janice” instead of doing their jobs.
12+
13+
### Languages
14+
15+
To provide a Python solution, edit solution.py
16+
17+
To provide a Java solution, edit Solution.java
18+
19+
### Test cases
20+
21+
#### Test Case 1
22+
23+
Inputs:
24+
```
25+
(string) s = “wrw blf hvv ozhg mrtsg’h vkrhlwv?”
26+
```
27+
Output:
28+
```
29+
(string) “did you see last night’s episode?”
30+
```
31+
32+
#### Test Case 2
33+
34+
Inputs:
35+
```
36+
(string) s = “Yvzs! I xzm’g yvorvev Lzmxv olhg srh qly zg gsv xlolmb!!”
37+
```
38+
Output:
39+
```
40+
(string) “Yeah! I can’t believe Lance lost his job at the colony!!”
41+
```
42+
43+
### Constraints
44+
45+
#### Java
46+
47+
Your code will be compiled using standard Java 7. It must implement the answer() method in the solution stub.
48+
49+
Execution time is limited. Some classes are restricted (e.g. java.lang.ClassLoader). You will see a notice if you use a restricted class when you verify your solution.
50+
51+
Third-party libraries, input/output operations, spawning threads or processes and changes to the execution environment are not allowed.
52+
53+
#### Python
54+
55+
Your code will run inside a Python 2.7.6 sandbox.
56+
57+
Standard libraries are supported except for bz2, crypt, fcntl, mmap, pwd, pyexpat, select, signal, termios, thread, time, unicodedata, zipimport, zlib.
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Minion Task Scheduling
2+
Time to solve: 24 hours.
3+
4+
Description
5+
Commander Lambda's minions are upset! They're given the worst jobs on the whole space station, and some of them are starting to complain that even those worst jobs are being allocated unfairly. If you can fix this problem, it'll prove your chops to Commander Lambda so you can get promoted!
6+
7+
Minion's tasks are assigned by putting their ID numbers into a list, one time for each day they'll work on that task. As shifts are planned well in advance, the lists for each task will contain up to 99 integers. When a minion is scheduled for the same task too many times, they'll complain about it until they're taken off the task completely. Some tasks are worse than others, so the number of scheduled assignments before a minion will refuse to do a task varies depending on the task. You figure you can speed things up by automating the removal of the minions who have been assigned a task too many times before they even get a chance to start complaining.
8+
9+
Write a function called answer(data, n) that takes in a list of less than 100 integers and a number n, and returns that same list but with all of the numbers that occur more than n times removed entirely. The returned list should retain the same ordering as the original list - you don't want to mix up those carefully planned shift rotations! For instance, if data was [5, 10, 15, 10, 7] and n was 1, answer(data, n ) would return the list [5, 15, 7] because 10 occurs twice, and was thus removed from the list entirely.
10+
11+
Languages
12+
To provide a Python solution, edit solution.py
13+
14+
To provide a Java solution, edit solution.java
15+
16+
Test Cases
17+
Test Case 1
18+
Inputs:
19+
20+
(int list) data = [1, 2, 3]
21+
(int) n = 0
22+
Output:
23+
24+
(int list) []
25+
Test Case 2
26+
Inputs:
27+
28+
(int list) data = [1, 2, 2, 3, 3, 3, 4, 5, 5]
29+
(int) n = 1
30+
Output:
31+
32+
(int list) [1, 4]
33+
Test Case 3
34+
Inputs:
35+
36+
(int list) data = [1, 2, 3]
37+
(int) n = 6
38+
Output:
39+
40+
(int list) [1, 2, 3]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.google.challenges;
2+
3+
/**
4+
* A brute force solution to the challenge, but considering there are only 100 integers
5+
* in the array, it works.
6+
*/
7+
public class Answer {
8+
9+
/**
10+
* Actual method for the challenge.
11+
*
12+
* Will take in the array of integers data, and remove all instances of an element
13+
* that appears more than n times.
14+
*
15+
* @param data: the array of integers to check
16+
* @param n: the maximum number of times that an element can appear in the array
17+
*/
18+
public static int[] answer(int[] data, int n) {
19+
int i = 0;
20+
21+
//go through entire array (it will change size)
22+
while (i < data.length) {
23+
//element appears in array than n times
24+
if (count(data, data[i]) > n ) {
25+
//remove all instances of value in array
26+
data = removeValue(data, data[i]);
27+
} else {
28+
//it appears less than n times, so move to check next element
29+
i++;
30+
}
31+
}
32+
33+
return data; //return the newly trimmed array
34+
}
35+
36+
/**
37+
* Will count the number of times an element (the number) appears in the array.
38+
*
39+
* @param data: the array of integers
40+
* @param number: the number to check how many times it appears in the array
41+
*/
42+
public static int count(int[] data, int number) {
43+
int count = 0; //track number of times it appears
44+
for (int i = 0; i < data.length; i++) {
45+
if (data[i] == number) {
46+
count++;
47+
}
48+
}
49+
50+
return count;
51+
}
52+
53+
/**
54+
* Will return a new array with all instances of the given number removed.
55+
*
56+
* @param data: the array of integers of which to remove the number
57+
* @param number: the number to be removed from the array.
58+
*/
59+
public static int[] removeValue(int[] data, int number) {
60+
//integer holding length of the old array - the number of times
61+
int newLength = data.length-count(data,number);
62+
int[] newValues = new int[newLength]; //new array with the length
63+
int track = 0; //index tracker for the new array
64+
65+
//iterate through the old array
66+
for (int i = 0; i < data.length; i++) {
67+
//if the current element is not the number
68+
if (data[i] != number) {
69+
newValues[track] = data[i]; //add it to the new array
70+
track++; //increase the index tracker for the new array
71+
}
72+
}
73+
74+
return newValues; //return the new array
75+
}
76+
}

Level 1/Minor Labor Shifts/readme.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Minion Labor Shifts
2+
===================
3+
4+
Commander Lambda's minions are upset! They're given the worst jobs on the whole space station, and some of them are starting to complain that even those worst jobs are being allocated unfairly. If you can fix this problem, it'll prove your chops to Commander Lambda so you can get promoted!
5+
6+
Minions' tasks are assigned by putting their ID numbers into a list, one time for each day they'll work that task. As shifts are planned well in advance, the lists for each task will contain up to 99 integers. When a minion is scheduled for the same task too many times, they'll complain about it until they're taken off the task completely. Some tasks are worse than others, so the number of scheduled assignments before a minion will refuse to do a task varies depending on the task. You figure you can speed things up by automating the removal of the minions who have been assigned a task too many times before they even get a chance to start complaining.
7+
8+
Write a function called solution(data, n) that takes in a list of less than 100 integers and a number n, and returns that same list but with all of the numbers that occur more than n times removed entirely. The returned list should retain the same ordering as the original list - you don't want to mix up those carefully-planned shift rotations! For instance, if data was [5, 10, 15, 10, 7] and n was 1, solution(data, n) would return the list [5, 15, 7] because 10 occurs twice, and thus was removed from the list entirely.
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import collections
2+
3+
def solution(data, n):
4+
if len(data) >= 100:
5+
return None, None
6+
occurrences = collections.Counter(data)
7+
return [k for k in data if occurrences[k] <= n]

Level 1/Prison Labor Dodgers/__init__.py

Whitespace-only changes.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def answer(x, y):
2+
# find symmetric difference between the two sets
3+
diff = list(set(x) ^ set(y))
4+
# return fist item in output list
5+
return diff[0]

Level 1/Prison Labor Dodgers/test.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unittest
2+
from . import solution
3+
4+
class TestCase(unittest.TestCase):
5+
def test_case_1(self):
6+
self.assertEqual(
7+
solution.answer(
8+
[13, 5, 6, 2, 5],
9+
[5, 2, 5, 13],
10+
), 6
11+
)
12+
13+
def test_case_2(self):
14+
self.assertEqual(
15+
solution.answer(
16+
[14, 27, 1, 4, 2, 50, 3, 1],
17+
[2, 4, -4, 3, 1, 1, 14, 27, 50],
18+
), -4
19+
)

Level 1/Re-ID/readme.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Re-ID
2+
=====
3+
There's some unrest in the minion ranks: minions with ID numbers like "1", "42", and other "good" numbers have been
4+
lording it over the poor minions who are stuck with more boring IDs. To quell the unrest, Commander Lambda has tasked
5+
you with reassigning everyone new, random IDs based on her Completely Foolproof Scheme.
6+
She's concatenated the prime numbers in a single long string: "2357111317192329...". Now every minion must draw a
7+
number from a hat. That number is the starting index in that string of primes, and the minion's new ID number will be
8+
the next five digits in the string. So if a minion draws "3", their ID number will be "71113".
9+
Help the Commander assign these IDs by writing a function answer(n) which takes in the starting index n of Lambda's
10+
string of all primes, and returns the next five digits in the string. Commander Lambda has a lot of minions, so the
11+
value of n will always be between 0 and 10000.
12+
13+
Test cases
14+
Inputs: (int) n = 0 Output: (string) "23571"
15+
16+
Inputs: (int) n = 3 Output: (string) "71113"

0 commit comments

Comments
 (0)