instruction
stringlengths
34
53.1k
Possible Duplicate: Holiday Gift Exchange Background: Secret Santa is a Western Christmas tradition in which members of a group or community are randomly assigned a person to whom they anonymously give a gift. http://en.wikipedia.org/wiki/Secret_Santa Ok, me and my work colleges did this today during our lunch ho...
Given a series of numbers for events X and Y, calculate Pearson's correlation coefficient. The probability of each event is equal, so expected values can be calculated by simply summing each series and dividing by the number of trials. Input 1 6.86 2 5.92 3 6.08 4 8.34 5 8.7 6 8.16 7 8.22 8 7.68 9 12....
The objective is to write java code that detects the JVM version relying in compatibility changes, side effects, bugs and/or undefined behavior that works in a way in one version and another way in another version. Further, the code should be at least a bit readable, without sacrificing whitespaces and legible variable...
Challenge Write a program that generates the song "There Was A Stream", detailed below. Description The song "There Was a Stream" is a camping song. It takes N parameters and generates a song of length O(N2) lines. A sample song (first 3 verses) is given here. Rules Your entry must take a list of strings and out...
Write a program that takes a list of n space-separated integers, and outputs a permutation of that list using a maximum of 2*n comparisons. It should loop this until an empty line is input. Alternatively, it can accept inputs until an empty line is given, then output all the permutations. Though your program only has ...
A fragmented file is a file which is seperated into several parts on a harddrive, because it can't fit into a certain space. On all harddrives, there are files called unmovable files, which are unmovable. To simulate real data on a harddrive, the input will also have unmovable files. You are given several sequences of ...
Just-in-time edit: I decided to reveal part of the answer and highlight a single aspect of the challenge. Show how 4 weights, of 1, 3, 9, and 27 lbs. can be used to produce "weight differences" from 0 to 40 lbs. You have a two - pan balance scale. We define the difference in pan weights as the total weight placed on ...
Just had a 'spirited' conversation with a co-worker about the succinctness of the following BASIC statement: 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 It's the title of this book, and will simply print a sequence of / and \ characters, alternating between the two randomly, resulting in a pattern similar to this: (Image ...
John is writing a program that finds the best route from A to B using public transport. For a given pair of origin and destination the program calculates a set of routes with departure time and arrival time, such as this: 10:12 11:45 10:15 11:50 10:22 12:05 10:25 12:00 As you see, the output may include a few routes t...
Your task is to create one brainfuck program for each of the following binary operators. Each program should take one or two 8-bit numbers (A and B) from input and calculate the specified operation: A XOR B A AND B A OR B A Shifted Left by 1 (circular shift) NOT A You do not have to implement all 5. Score is calculat...
Write a program that count from 1 to 100 in Roman Numerals and print these numbers by standard output. Each one of the numbers must be separated by spaces. You cannot use any built in function to transform to roman numerals nor external application or library to do so. The desired result is I II III IV V VI VII VIII IX...
The Champernowne constant is a transcendental decimal number whose digits are the concatination of all positive integers. C10 = 0.12345678910111213141516...10 The binary version of this is C2 = 0.1101110010111011110001...2 Write a program that prints C2 in decimal. The program should never halt. It should continue p...
Roll 3 dice, count the two highest two values and add them to the result. Every 1 must be rolled once again. Now show the average throw after 1000000 tries and the probabilities for each result occurring: Desired Result: avg(9.095855) 2: 0.0023 3: 0.0448 4: 1.1075 5: 2.8983 6: 6.116 7: 10.1234 8: 15.4687...
An ionic compound is named like so: (metal name) (non-metal suffixed with -ide). Here is a list of all the suffixes that need to be replaced with -ide: -on -ogen -ygen -ine -orus -ur -ic -ium The number of atoms of each element in the compound is not used in naming ionic compounds. Ignore the multivalent metal naming ...
8-bit XOR encryption takes a single byte and XORs every byte in the file by that byte. Here is a reference program in C++: /*xorcipher.cpp *Encrypts a file using 8-bit xor encrytpion */ #include <iostream> #include <fstream> #include <stdlib.h> using namespace std; int main(int argc, char** argv){ ifstream* in =...
I'm sure most, if not all, of you have come across this at some point or another: Aoccdrnig to a rscheeachr at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a toatl mses and you can sitl...
Task The task is to display any of the 128 possible states of a 7-segment display. Your program should accept a string of 7 characters ("bits") that are either 0 or 1. First bit of input corresponds to segment A of the following illustration, the second to B, etc (ignore dp): How you represent the display is up to you...
In FIPS-197 (the Advanced Encryption Standard, known as AES), it is made heavy use of SubBytes, which could be implemented as unsigned char SubBytes(unsigned char x) { static const unsigned char t[256] = { 0x63,0x7C,0x77,0x7B,0xF2,0x6B,0x6F,0xC5,0x30,0x01,0x67,0x2B,0xFE,0xD7,0xAB,0x76, 0xCA,0x82,0xC9,0x7D,0xFA,0x59...
Wireworld is a cellular automaton that was designed to be resemble electrons flowing through wires. Its simple mechanics allow the construction of digital circuits. It has even permitted the construction of an entire computer. Your mission is to create the shortest Wireworld implementation in your language of choice. ...
Title says it all. Given some input, turn it into a boolean value (0 or 1), without using conditional statements (e.x. == > < <= >= != ~=), or any function which uses conditional statements within its implementation, such as if, while and for. Your program must work with floating points, although you get more if it wor...
Smallfuck is a brainfuck-like language with 1-bit cells. It has the following instructions: > Increment the pointer < Decrement the pointer * Flip the current bit [ If the current bit is not set, jump to the instruction after the matching ] ] If the current bit is set, jump to the instruction after the matching [ ...
can we print 1 to 100 without using any if conditions and loops in c&c++? Conditon: main point is you must not use recursion...and doesnt hardcode code in it for e.g print(1 2 3..etc);
Since Fibonacci numbers and sequences seems like a popular subject for code golf I thought that it might be a fun challenge to code golf with Keith numbers. So I propose a challenge that is to create a function that takes an integer and gives back a true or false depending on the number is a Keith number or not. More a...
Execute a Lindenmayer System A Lindenmayer System (or L-system) is related to Thue and Post systems, and is used in botanical modeling and fractal generation. An L-system is described by string-rewriting where a symbol from the symbol-alphabet is mapped to a replacement sequence of symbols. A collection of these mappin...
Befunge is a 2-dimensional esoteric programming language. The basic idea is that (one-character) commands are placed on a 2-dimensional grid. Control flow walks across the grid, executing commands it passes over, and changing direction when it hits an arrow (>^<v). Commands are stack-based; see this list. See also http...
Write a program that throws a StackOverflow Error or the equivalent in the language used. For example, in java, the program should throw java.lang.StackOverflowError. You are not allowed to define a function that calls itself or a new class(except the one containing main in java). It should use the classes of the selec...
You have two images (64x64 pixels each): Your program must take the file names of each of them as command line arguments and determine which has more average saturation among their pixels. The images are in ImageMagick .txt format. You can download and convert these images using convert pic.png pic.txt or download t...
Given a positive integer N, determine the starting pattern on a N x N-grid that yield the longest non-repeating sequence under Game of Life-rules, and ends with a fixed pattern (cycle of length 1), played on a torus. The goal is not the shortest program, but the quickest. Since the world is finite, you will eventually...
The world's changing to a new time system! We need to update our computer programs. Given an input of epoch time (number of seconds since January 1st, 1970 00:00), print out a time in the new Noxu date-time format. 864 seconds make one Fluffster. 100 Fluffsters make a Skizzle. There are 4 Skizzles in one Zestpond. ...
Those of you who like Numberphile would be familiar with Dr. James Grime, who described a non-transitive dice game on his channel. The game consists of three 6-faced dice: Die 1: 3,3,3,3,3,6 Die 2: 2,2,2,5,5,5 Die 3: 1,4,4,4,4,4 Two players each select a die to use. They roll them and the higher die wins, best-of-wha...
As the title said, the challenge is to write the longest sentence by only using the keywords of 1 programming language. For instance, using the keywords of C++, it is possible to write this sentence: do not try this float What can you come up with?
The challenge You are given a function compile(s: String): Integer which returns 0 if s could be compiled and anything other than 0 if it failed (the resulting code is not important). The thing is that you don't know for what language the function is made for, so it is up to you to figure that out by giving the functio...
Given the following test, implement an addOne function in C# so it passes, without any modification to the test. TIP: Yes, it is possible. [TestMethod] public void TheChallenge() { int a = 1; addOne(a); Assert.IsTrue(a == 2); } EDIT: clarified the Assert to avoid confusion. The value of a should be 2; th...
You have an array of working time period pairs (from, till) received from user input and written according 24-hour clock format convention. You have to merge these periods if the intersect each other. For example, if you have (10, 12), (11, 13), (12, 14) you should merge them into (10,14). Also (23, 0) and (0, ...
This falls under the Code puzzles the best. Fastest way to render the numbers 1-million in a web browser. Preferably using PHP, but use what you must. Numbers must be more than one on a line in the web browser and must line wrap (the horizontal scroll bar must not be triggered). rules: use any loop construct that...
It's me. Cave Johnson. It's May 21st. You are working at Aperture Science, finest company on Earth, and tomorrow we're releasing Version 3.0 of our flagship windowing system (or WindowS): CavOS. Unfortunately, tomorrow morning, our chief competitor is releasing Version 3.0 of their WindowS too! It's been leaked to me,...
Cyclic Words Problem Statement We can think of a cyclic word as a word written in a circle. To represent a cyclic word, we choose an arbitrary starting position and read the characters in clockwise order. So, "picture" and "turepic" are representations for the same cyclic word. You are given a String[] words, ea...
Your program gets a text as an input, at least 8 characters long, and always consisting of even number of characters. (no need to evaluate correctness of input). Your goal is to display that text as a rectangle. For example, given HelloWorld as an input, display Hell d o lroW Rules: Text goes around clockwise (star...
Imgur is a free image hosting service. Many people use it. Here is an example of an imgur link: https://i.stack.imgur.com/II8CA.png. Write a program that continually outputs random (valid) imgur links. For example, here is some sample output of my progam (not shown because it contains some tricks you will have to figu...
I have a combination padlock which has letters instead of numbers. It looks like this: http://pictures.picpedia.com/2012/09/Word_Combination_Padlock.jpg There are 5 reels, each of which has 10 different letters on it. Most people like to use a word for their combination rather than an arbitrary string of letters. (Less...
Possible Duplicate: Emulate an Intel 8086 CPU I know that there already is a code golf for this, but that one didn't require much. This one, however, is for masochists only! >:) OK, you need to emulate an entire 8086, every single opcode. Not every flag needs to be computed, but every single documented opcode needs ...
Print, on STDOUT, a pattern which shows in what direction a bouncing ball will take. The following assumptions are made: The ball starts at the top left corner: 0, 0 with zero initial velocity. Gravity is 9.8ms^-2 exactly, towards the floor (y positive.) The ball weighs 500g exactly. The ball bounces at 45 or 135 deg...
Obviously this challenge would be trivial with separate functions and libraries, so they aren't allowed. Your code must conform to an ECMAscript specification (any spec will do), so no browser-specific answers. The array must be accessible after it is instantiated. I have an answer that I'll withhold for now. Note: ...
The challenge is to write the most elaborate code, embedded in ASCII art that reads and prints "DFTBA". For example, the following reads DFTBA: oooooooooo. oooooooooooo ooooooooooooo oooooooooo. .o. `888' `Y8b `888' `8 8' 888 `8 `888' `Y8b .888. 888 888 888 8...
The Flesch-Kincaid readability algorithm depends on the measures of word count and syllable count, neither of which is entirely objective, or easily automatable using a computer. For example, does "code-golf", with the hyphen, count as one word or two? Is the word "million" two or three syllables? In this task, you wil...
You thought regular sudoku was hard, now try Killer Sudoku! In the game of Killer Sudoku, you aren't given any numbers at all. Instead, you're given regions that are said to add up to a certain number. Consider the following example, from Wikipedia: And its solution: The program you write will take a format consistin...
Write two programs: - One which reads a string and a key and encodes the string into a rail-fence cipher using that key. - Similarly, write a program for the reverse function: deciphering a rail fence using a key. For those who don't know what rail fence cipher is, it is basically a method of writing plain text in a wa...
While there are many code golf questions on here involving randomness, I haven't seen one yet that actually asks for building an algorithmic pseudorandom number generator. There's this one that asks you to generate a bit stream, but the randomness tests provided on that one were not very rigorous, and it's not code-gol...
You're writing a program for a new automated roulette croupier to be installed in a major casino. Unfortunately, the last guy bailed out on the company and published buggy software. You're stuck with a thousand burned flash chips with only a few kilobytes of space to store a working program. Can you do it? The task is ...
Problem You are given a sequence of coloured balls (red R and green G). One such possible sequence is: RGGGRRGGRGRRRGGGRGRRRG In as few moves as possible, you must make it so that each ball is a different colour to its neighbours (i.e. the sequence alternates.) RGRGRGRGRGRGRGRGRGRGRG You should write a program that c...
Redstone is a material in the game Minecraft, and it is used for many complex contraptions. For this program, you will only need to simulate three items: the redstone wire (noted with R), redstone torch (noted with T), and block (noted with B). Here are a list of basic rules about how redstone works: A redstone torch s...
A string is squarefree if it contains no substring twice in a row. It is possible to have an arbitrarily long squarefree word using a 3-letter alphabet. Write a program which accepts a positive integer n from stdin and prints any squarefree word of length n, using characters A, B and C. Shortest code wins.
Inspired by this. There is a number, given as either integer, string or array of digits (your choice). Find the base in which the representation of the number will have most "4"s and return that base. Number Result 624 5 444 10 68 16 restrictions: The base returned should not be greater than th...
This Perl code is supposed to calculate the Leibniz formula. The original problem is here. The input format is: T <T test cases, each on their own line> Each test case is a number < 10^7. The output format should be the same, minus the first line. For example, an input: 2 10 20 And for output: 0.760459904732351 0.7...
Using you language of choice, write the shortest function/script/program you can that will identify the word with the highest number of unique letters in a text. Unique letters should include any distinct character using UTF-8 encoding. Upper and lower case versions of the same character are different and distinct...
Similar to generating minesweeper grids, although the challenge is to make a working minesweeper grid. This will be longer code than normal (I think). more information on minesweeper. Minesweeper is a logic game found on most OS's. The goal of the game is to determine where the mines are on a grid, given numbers indi...
Based on this closed question on stack overflow, what is the shortest way to stimulate scope for variables in an input. For simplicity, print is replaced with >. copying critical information from the linked source: [ and ] start and end a new scope. Within scopes any changes to a variable outside of that scope is no...
I am constantly frustrated by how complicated it is to write graphical programs that would have been only a few lines of code 20+ years ago. Since the invention of the mouse this has become even worse it seems. I was hoping someone could put me out of my misery and show the shortest code to do the following really ba...
When I was a young teen I had a very boastful friend who claimed he could code up breakout in half an hour. Half an hour later he had done a great job but it didn't quite work. This challenge is to see in 2013 how short it is possible to code this classic game. For the purposes of the competition there need only be one...
I have a weakness for 3d nets which when cut out and folded allow you to make 3d shapes out of paper or card. The task is simple, written the shortest program you can that draws nets for the 13 Archimedean solids. The output should be an image file in any sensible format (png, jpg). All thirteen shapes are described...
This is a basic version of the rather more difficult Drawing 3d nets - Archimedean solids . I have a weakness for 3d nets which when cut out and folded allow you to make 3d shapes out of paper or card. The task is simple, write the shortest program you can that draws nets for the 5 Platonic solids. The output should b...
Implement String.prototype.toLowerCase() Description The toLowerCase method returns the value of the string converted to lowercase. toLowerCase does not affect the value of the string itself. Conditions Let count chars inside function and ignore all bootstrap code: String.prototype.toLowerCase = function(){ // code t...
Your task is to build a function in any language that takes a message m, an encryption e, and a modulus k (all positive integers), and takes m to the power of e modulo k. Your solution must not be a theoretical one, but one that would work on a reasonable computer such as your own, for RSA keys of currently used sizes ...
Produce a text file that prints "Hello World!" in as many programming languages as possible when compiled/interpreted, while also being as short as possible. The score for your submission is calculated as C / 2 ^ ((L - 1) / 4), where "C" is the length of the text file in characters and "L" is the number of languages th...
This is a common puzzle many of you have solved manually. Now this is the time to write an algorithm to solve the same. There are equal number match sticks lined up in two different side facing each other's direction. There is a single empty space between them. Say something like the following figure (if total number o...
The problem is as follows. Input: An integer n Output: The smallest prime bigger than n. The challenge is to give the fastest code possible to do this. I will test the code on values starting at size roughly 10^8 10^200 and doubling in size until it takes more than one minute 10 seconds on my computer. The winni...
In Chess, it's possible for the game to end after 4 moves (2 each) with a Fool's Mate. Your goal is to find the Fool's Mate of Halma: the 2-player game of Halma that minimises the number of turns played. There are over 1056 board states, and I've seen the branching factor surpass 1000, so chances are no one will find t...
Unsolved puzzle: Solved Puzzle: Rules Each circle with number must have as many lines from it as the number in the circle. It is not allowed to have more than two lines between two circles. The lines can not cross each other. All the lines must either be horizontal or vertical. It is not allowed to draw lines diagon...
Polygons are named after the number of sides that they have. A pentagon has 5 sides, an octagon has 8 sides. But how are they named? What's the name for a 248-sided polygon? All polygons are suffixed with -gon. There are specific prefixes for each polygon depending on the number of sides. Here are the prefixes for the ...
The worst part about long lines or code or math equations are the parentheses. Nobody wants to read through 2x(3y+4*abs(x^[2*e^x])-5{3(x+y)-5})! So, the goal of this challenge is to make it at least slightly easier to read these parentheses-filled beasts! For the above math equation, the output should be: 2x ( 3y+4*a...
The challenge is simple. Give the shortest code possible to reproduce the classic 2-player game of pong http://en.wikipedia.org/wiki/Pong . The level of graphics and functionality should be as close as possible to this javascript demonstration http://codeincomplete.com/posts/2011/5/14/javascript_pong/demo.html (but wi...
Check out this challenge: https://www.hackerrank.com/codesprint4/challenges/leibniz (The competition has already ended, so I'm just curious about the Python solution, which the organizers refused to reveal, so this is not cheating in any way.) Modified from that page: In Calculus, the Leibniz formula for \$\pi\$ is gi...
The challenge is to give as short code as possible to print an ASCII histogram of a set of data. Input. The number of bins followed by a number of integers representing the data. The data are space separated. Output. An ASCII histogram of the data using the specified number of bins. Score. Number of characters in the ...
Over at https://math.stackexchange.com/questions/33094/deleting-any-digit-yields-a-prime-is-there-a-name-for-this the following question is asked. How many primes are there that remain prime after you delete any one of its digits? For example 719 is such a prime as you get 71, 19 and 79. While this question is unresolv...
Write a function or program to validate an e-mail address against RFC 5321 (some grammar rules found in 5322) with the relaxation that you can ignore comments and folding whitespace (CFWS) and generalised address literals. This gives the grammar Mailbox = Local-part "@" ( Domain / address-literal ) Local-...
Write a program which generates keyboard events which type Hello, World!. It doesn't have to be platform-independent. It can't leave any keys pressed. For example, in Java, Robot.KeyPress('H'); will leave H pressed, so you must release it with Robot.KeyRelease('H'); You may assume that the caps lock is off when your p...
Currently I have the code (expanded for your benefit): <number> != <number> ? printf("|\\"); : <number>; The idea here, is to do this condition in the least number of characters. This is currently, roughly the same number of characters it would take to be doing the exact same thing using an if statement, due to the fa...
In my essay "Use the 24-hour clock", I claim that trying to represent the 12-hour clock directly in data is a terrible exercise in patchy, inelegant programming: "No problem, we'll just use computers to do these calculations for us." Yes, but computers need to be programmed. And trying to account for AM and PM directl...
Write a program which displays the current system time as an analog clock, using ASCII graphics. The clock must show at least the hour and minute pointers, and must have enough resolution of at least 5 minutes. The display can be as small and as ugly as you wish, but the shown time should be easily recognizable. The p...
Your task is to build the largest program you can that uses exactly one GOTO, without which the entire program (or at least a huge chunk of it) must be completely restructured. The score is counted as the number of statements in your code that change places or are newly introduced (removing statements doesn't add to y...
Write the shortest program that solves Rubik's cube (3*3*3) within a reasonable amount of time and moves (say, max. 5 seconds on your machine and less than 1000 moves). The input is in the format: UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR (this particular input represents the solved cube). Fi...
I asked this question on programmers 10 days back but wasn't able to get the answer that I wanted. Write program in java to print the squares of first 25 integers(1-25) without using any variables. I am not looking for any theory explaining concepts about java or functional programming. I just want to know if its pos...
Output the same length of Lorem ipsum your code is! Rules: Code can't be identical to output No compression libraries Shortest program in two weeks wins No network usage, file reading and other tricks which with one could easily solve any code golf problem (with eval, exec, etc) Example Your code with length 25. Out...
You are given a list of numbers L = [17, 5, 9, 17, 59, 14], a bag of operators O = {+:7, -:3, *:5, /:1} and a number N = 569. Task Output an equation that uses all numbers in L on the left-hand side and only the number N on the right-hand side. If this is not possible, output False. Example solution: 59*(17-5)-9*17+14...
The task is to group adjacent values from collection and output it as a new aggregated collection. Consider we have following input: Sequence Number Value ======== ===== 1 9 2 9 3 15 4 15 5 15 6 30 7 9 The aim is to enumerate over Sequence ...
(I've tagged the question "C" for the time being, but if you're aware of another language that supports unions, you can also use that.) Your task is to build the four standard mathematical operators + - * / for the following struct: union intfloat{ double f; uint8_t h[8]; uint16_t i[4]; uint32_t j[2]; ...
the question is "complete this subtraction by replacing the asterisks with digits so the numbers 1-9 only appear once each" 9** -*4* ____ **1 my code tries random numbers until it works, and displays the answer. here is the entire html app. I want one to fit in a tweet at 140 characters (not counting tags) <scri...
The task is simple: write a program that branches differently in x86 (32-bit) and x86-64 (64-bit) using only printable visible ASCII characters 0x21...0x7e (space and del are not allowed) in the machine code. Conditional assembly is not allowed. Using API calls in not allowed. Using kernel-mode (ring 0) code is not al...
Write the shortest code that calculates all possible (legal) moves of current player from a given FEN string. What is FEN string? (Wikipedia) Shortest code wins, language doesn't matter. Output moves must obey chess rules of movement except en passant, castling, and pawn promotion. Ignore check, checkmate, and stale...
This is "programming" at its most fundamental. Build a diagram of (two-wire) NAND logic gates that will take the input wires A1, A2, A4, A8, B1, B2, B4, B8, representing two binary numbers A to B from 0 to 15, and return values on the output wires C1, C2, C4, and C8 representing C, which is the sum of A and B modulo 16...
Generate math problems (addition, subtraction, or multiplication) using numbers 0-10. Provide feedback on whether the user was right or wrong and show a score. Specifics: Must generate addition, subtraction, or multiplication problems Numbers used must be 0-10 Each problem must be equally likely If user is correct, mu...
Ok, I found myself with a nice little problem: you will get from stdin a string. In this string you will find some hex colors (like #ff00dd). You must return the string with the colors inverted (#ff00dd inverted is #00ff11). A sample input/output could be: ascscasad #ff00ff csdcas dcs c#001122 #qq5500 ascscasad #00ff00...
Good Afternoon Golfers, Our challenge for today is inspired by XKCD comics 356 and 370. We're going to write a program to calculate the resistance of a group of resistors. A forewarning that this is nearly tough enough to warrant being a code challenge, however I think that there is a certain art to writing slightly mo...
Taken straight from the ACM Winter Programming Contest 2013. You are a person who likes to take things literally. Therefore, for you, the end of The World is ed; the last letters of "The" and "World" concatenated. Make a program which takes a sentence, and output the last letter of each word in that sentence in as litt...
Have a look at my (javascript) version of a O(log(n)) xn algorithm: function pow(x,n) { return n==0?1:n==1?x:n==2?x*x:pow(pow(x,(n-n%2)/2),2)*(n%2==0?1:x); } Can you get it shorter?
I'm trying to come up with ways to write Sieve of Eratosthenes in Octave that vectorize as much as possible (ie minimizing the number of times iterating over the for-loop/while-loop/recursive call) I found one that requires only O(log(log(n))) iterations inside the for-loop, but the big-O running time (and also space) ...
Convert JSON (key/value pairs) to two native arrays, one array of keys and another of values, in your language. var X = '{"a":"a","b":"b","c":"c","d":"d","e":"e","f":"f9","g":"g2","h":"h1"}'; The value array could be an array of strings or integers. So we need two functions keys & vals, returning native arrays on inp...
Puzzle: Find a deck of c cards, each containing p pictures, such that no two pictures match on a given card, and exactly 1 picture on each card matches exactly 1 picture on each of the other cards, where the number of unique pictures in the deck is minimized. Criteria: Fastest code for c = 31 and p = 6. Inspiration: Th...
Introduction You use Twitter (let's pretend, if not), where you are limited to 140 characters per individual tweet you care to share with the world. If you wanted to tweet to your followers Abraham Lincoln's Gettysburg Address, then you would need to break up the text into multiple 140-character chunks in order to get ...
Implement the following JavaScript method as short as possible: function same_subnet(ip_a,ip_b,sn_mask) { } It should get 2 IP addresses and a subnet mask. It should return true if ip_a and ip_b are in the same subnet. Example calls: same_subnet("192.168.0.1","192.168.0.15","255.255.255.0") → true same_subnet("192....