function numberOfAnagrams(S) {
// S.length!/repeat!
var total = factorial(S.length),
repeat = 1,
array = S.split('').sort();
for (var i=1;i<array.length;i++) {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import namedtuple | |
| TableEntry = namedtuple('Element', 'hash key value') | |
| class HashTable(object): | |
| DEFAULT_SIZE = 8 | |
| EMPTY_VALUE = TableEntry(None, None, None) | |
| DELETED_VALUE = TableEntry(None, None, None) | |
| LOAD_FACTOR = 2 / 3 | |
| MIN_FACTOR = 1 / 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pprint | |
| # Returns a row in a given column | |
| def column(matrix, i): | |
| return [row[i] for row in matrix] | |
| # Checks if a given row or column has all of the same value | |
| def check(list): | |
| if len(set(list)) <= 1: | |
| if list[0] != 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Amazon | |
| Microsoft | |
| Apple | |
| Zenefits | |
| Uber | |
| Airbnb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def is_square(integer): | |
| root = math.sqrt(integer) | |
| if int(root + 0.5) ** 2 == integer: | |
| return True | |
| else: | |
| return False |
Write a program that prints numbers from 1 to 100, one number per line. For each printed number, use the following rules:
- if the number is divisible by 3 or contains 3, replace 3 by "Foo";
- if the number is divisible by 5 or contains 5, replace 5 by "Bar";
- if the number is devisible by 7 or contains 7, replace 7 by "Qix".
Example: 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| You will be given two text files, train.txt and test.txt. The former is a large corpus of data of open source | |
| literature from Project Gutenberg and the latter is a small snippet from the same source which has been encoded | |
| with a simple substitution cipher. | |
| The substitution cipher is 1-to-1, every character in the alphabet will map to one character, possibly itself. | |
| The same mapping will be used consistently throughout any encoding. Case does not matter here, so if A is encoded | |
| by Z then a is encoded by z. Any characters other than A-Z/a-z will be left as is. | |
| The goal of this assignment is to write a program which consumes train.txt and: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Roman Numeral Converter -- TDD Practice | |
| Using your language of choice, create a RomanNumeralConverter class with a decimal_to_roman method that takes one positive integer argument and returns that argument represented as a Roman numeral. | |
| However, there's one hitch. You can't write any code until you have a failing test case. We've started you off with the first test in multiple languages. Now you must think about what test you would add next, then write the code to make the test pass. Work with your team to think about the additional tests that it would take to make you confident that -- if these tests all passed -- you'd have code that would work in a sufficient number of edge cases. (Covering up to a max value of 3000 is sufficient for this exercise.) | |
| Sure, you could cheat and Google for one of the elegant solutions that are available. But the point of this exercise isn't to find that most elegant solution... It's to practice test-driven development and involve the non-coders in thinking up edge c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| myList = [6,3,4,5,2,1,1, 20, 36, 50, 2] | |
| def selection(theList): | |
| for i in range(len(theList)): | |
| min = i | |
| for k in range(i+1, len(theList)): | |
| if theList[k] < theList[min]: | |
| tmp = theList[i] | |
| theList[i] = theList[k] |