# What is the Sandbox?

This "Sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to the main page. This is useful because writing a clear and fully specified challenge on the first try can be difficult. There is a much better chance of your challenge being well received if you post it in the Sandbox first.

See the Sandbox FAQ for more information on how to use the Sandbox.

## Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

# One Code, All the Challenges

## tag: code-golf

Now, I always want to solve as many s as possible, so I thought "Why not solve them all at once?".

Create a block of code that solves another code-golf challenge on this Stack Exchange network. You must also make it so that when it is rotated (90°, 180° or 270°) it solves a different challenge on this website. Examples of rotated code-blocks:

0°       90°      180°     270°
AB       FCA      F G       EF
CDE       DB      EDC      BD
F G      GE        BA      ACG

The code golf that you are answering must have a shortest answer > 10 score (usually bytes). It may also not be a duplicate of another challenge.
Answers do not have to have a code-gold linked to every rotations, although this helps with score.

When rotating, take the shape that the code occupies, and rotate that. Some more examples:

0°       90°   | 0°      90°
print    p     | print   hsp
r     | say~~   iar
i     | hi by    yi
n     |         b~n
t     |         y~t

This means non-rectangular code is allowed, but whitespace (like-all other characters) except newlines must stay in-tact. This means the tildes (~) must be occupied with a character to allow for the rotate.

### Scoring

Number of bytes in code * ((number of rotations that solve a challenge) * -2 + 7)
Lowest score wins.

Rotations | X
0 | Must work for at least one rotation
1 | 5
2 | 3
3 | 1
Number of bytes * X

Note
Please provide a link to each code golf question you are answering with each rotation. Also note that the questions answered must have been posted before this question, and each rotation must be in the same language. Also note if there are restrictions of source in one challenge, only the rotation that tries to solve that challenge has to comply with them.

### Python 3, 21 bytes, 2 rotations, 63 points

0 degrees: https://codegolf.stackexchange.com/questions/4/print-hello-world
180 degrees: https://codegolf.stackexchange.com/questions/3/crash-the-program
(Don't put in links in   in actual answers)

print("Hello world!")

0 degrees: prints the string 'Hello world!'
180 degrees: Crashes with a SyntaxError because of unopened close parenthesis.

• @Bigtoes That was an error. Fixed it, Thank you! – user34736 Mar 10 '15 at 17:01
• I can't figure out what you're trying to say about non-rectangular code. Maybe if you had an example which actually contained non-rectangular code it would be clearer. And I think allowing people to solve any of the 3000 existing questions is too broad. It essentially makes the spec 3000 pages long. – Peter Taylor Mar 10 '15 at 21:35
• Something tells me this question will just boil down to whoever can find the right subset of questions which work together. For example, taking the 1 byte from here sets the initial bar at 5. – Sp3000 Mar 12 '15 at 12:42

# Help the President!

## Tags: code-golf

There is an anonymous president of a country who needs your help! He wants to retain absolute control, but needs to have elections to prevent uprisings. They ask you to create a program to help them gerrymander.

These are the specifications:

### Input

(You will receive input via stdin or as a function argument)

You will be given an array of arrays of strings to represent the locations of voters (a 2D matrix), i.e:

[["Democratic", "Republican", "Republican", "Democratic"],
["Republican", "Democratic", "Democratic", "Democratic"],
["Democratic", "Republican", "Democratic", "Republican"],
["Democratic", "Republican", "Republican", "Republican"]]

Which is

[["Democratic", "Republican", "Republican", "Democratic"], ["Republican", "Democratic", "Democratic", "Democratic"], ["Democratic", "Republican", "Democratic", "Republican"], ["Democratic", "Republican", "Republican", "Republican"]]

You will also receive a party that is meant to win, like "Democratic" or "Republican". These will be in the matrix.

Thirdly, you will receive district sizes. The amount of items in the matrix will be a multiple of this. All districts must be this size.

## Output

An array of arrays of coordinates. Either the top left or the bottom left may be [0, 0] or [1, 1]. Going right increases the second number and going down / up increases / decreases the first number.

This country uses a first-past-the-post voting (Most votes win) per district (except if there is a tie, none of them win). You must split the matrix of voters into districts in such a way that the party wins as many districts as possible. A district is given by one of the arrays in the output. Districts must be contiguous, and going diagonally is not contiguous. Some visualisations by this helpful CGP Grey video on Gerrymandering and one example outputs:

f([["D", "R", "D"], ["D", "D", "R"], ["D", "D", "R"]], "D", 3)
[[[0, 0], [0, 1], [1, 0]], [[0, 2], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]]]
# In this case, the D party wins all of the votes.
f([["D", "R", "D"], ["D", "D", "R"], ["D", "D", "R"]], "R", 3)
[[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]]]
# R wins a third of the seats

This demographic could be visualised as

D  R  D
D  D  R
D  D  R

(Note there may be many possible "best" district boundaries. In this case, return any of them. And in a case where there are two cases that give the party the same amount in both cases, but the second case gives a smaller majority to another party, return the latter)

f([["B", "R", "B", "R", "B"], ["G", "B", "G", "R", "Y"], ["G", "R", "Y", "B", "Y"], ["B", "G", "B", "G", "Y"]], 4, "Y")
[[[0, 0], [1, 0], [1, 1], [2, 0]], [[0, 1], [0, 2], [0, 3], [0, 4]], [[1, 2], [1, 3], [1, 4], [2, 3]], [[2, 1], [3, 0], [3, 1], [3, 2]], [[2, 3], [2, 4], [3, 3], [3, 4]]]
# In this election, Y wins 2, B wins 1 and 2 are undecided

## Sandbox notes

This seems way too wordy for a problem which seems so simple. Any areas where it could be clarified to be more concise? I think it's my organisation of stuff that makes it unclear.

• Your proposal seems very similar to this earlier one. Is that intentional? Also, you should state whether the districts must have the same size. – Zgarb Mar 26 '15 at 10:23
• @Zgarb I never actually saw that. This one can be easier / harder than that one, as my one asks for the best district maps, but does not restrict perimeter. – user34736 Mar 26 '15 at 10:54

# Cooperative Tamagotchi

This is a new twist to the Tamagotchi-style ideas floating around. I also plan on creating a "no rules" version, but the cooperative version is the more complete idea at the moment.

Tamagotchi, more popularly known as StackEgg, is a game in which you nurture the growth of an adorable pet, also more popularly known as PPCG. The pet has a set of statistics which reflect the health and well-being of the pet. You also have a series of buttons. When you press a button, the pet's stats are affected. One stat receives a boost, but the other stats that did not receive a boost slowly wither away.

In the game, your goal is to work together to win a game of Tamagotchi. Each contestant program casts votes to determine which move will be played in a given game cycle. This is a competition, however, because your personal contributions are being measured. If you vote for a move, and that move wins the election, then the effect of the move will affect your score. If the action was beneficial to your pet, you gain points. If the action was detrimental to your pet, you will lose points.

I don't have a "theme" for the Tamagotchi yet. Here are some ideas for how it would work. I could alternatively wait for the source for StackEgg to be released or reverse-engineered and use those more realistic rules.

There would probably be a single game phase, probably based on the "full site" phase of StackEgg in terms of functionality. This means that there are five stacks and five "constructive" buttons.

Each stat has two numbers: the number of hearts, which is visible, and a decay counter, which is hidden. When calculating a player's positive or negative contribution, only the number of hearts is used (?).

More details coming sometime not now.

• One of the key (fun) things that StackEgg had going for it was figuring out what exactly did what. With the controller source being open (I assume), that mystery is gone. Without some big tweaks, I fear there will only be one optimum vote pattern which everyone uses. – Geobits Apr 2 '15 at 1:00
• @Bigtoes Yeah, I'm thinking about that too. Do you think adding in randomness would help? – PhiNotPi Apr 2 '15 at 1:36
• @PhiNotPi only if the randomness is at the initialization of the system, not each turn, so the bots have to figure out the best strategy, maybe? – rorlork Apr 2 '15 at 8:16
• How about completely randomly initializing the effects of each button, such as which stats are helped and hurt, and by how much? There would have to be some way to determine which settings are playable, but bots would have fun time trying to figure out causes and effects. – PhiNotPi Apr 2 '15 at 12:05
• @PhiNotPi I like the idea of randomly initializing the buttons. Also, perhaps a better way to measure the fitness of the bots would be to run the game K*N times, where N is the number of bots and K is a large constant, with a different bot missing for each of the N batches of K games. The score of a bot would be the average score of the games in which it participates. – Zgarb Apr 2 '15 at 12:48

# Quine Creator

The program F is in language A. F takes a program in language B as input. Lets call this program G. F outputs a program in language B. Lets call this program O. O Takes some input and for some values it will be a quine and for others it will run G.

The exact values which O decides behaviour must be the same for each different input to F but you can decide what the conditions will be. They must be short (5 or less bytes), reasonable and not turned into code and executed for the sake of a shorter program F. Acceptable behaviours include (but are not limited to):

• Quines for even digit, G for odd
• Quines for truthy input, G for anything else
• Quines for the input "0", G for anything else

For example your program F could be written in Java and take a Python program (G) as input and output a program in Python (O) that runs G when given at least 1 arg and prints it's source when not given any args.

Sorry if this is a bit confusing

• This is very similar to this challenge. I'd definitely be tempted to close this as a duplicate. You're also missing a winning criterion. – Martin Ender Apr 3 '15 at 9:53
• The code challenge tag is for when you make up your own winning criterion, so it would contradict the code golf tag. You might want to include a short sentence like "This is code golf, so the shortest submission (in bytes) wins." anyway, although the tag is pretty clear. Just for completeness's sake. – Martin Ender Apr 3 '15 at 12:22
• @MartinBüttner That challenge is different to this one but I'm new to asking questions, so you be the judge of if mine should go ahead. – HEGX64 Apr 3 '15 at 12:32
• Yes, it is certainly different, but very similar I think. For the record, my CJam submission would be "{q{;"q'}"_~"`"?}_~" which may look quite different but is essentially the same idea. I guess I probably wouldn't vote to close as duplicate myself, because I've got a dupehammer on the code golf tag, but I'm just saying others might think it's a dupe and close it. (Just to be clear, this is not a bad challenge idea. I really quite like it... just saying something very similar has been done before.) – Martin Ender Apr 3 '15 at 12:43
• One thing that's not entirely clear about the challenge is how general G is allowed to be. E.g. if O reads all of STDIN to decide whether to use G or print O, then G cannot receive any input on STDIN. Is this fine? – Martin Ender Apr 3 '15 at 12:47
• Is your edit intended to address my comment? If so, let me try to rephrase my question. I was asking whether G must potentially be completely general. E.g. the program G could be a program which reads a string on STDIN and reverses it. But if I generate O such that it reads all of STDIN and is a quine if STDIN is empty and calls G otherwise... then O has already read all of STDIN and G will have nothing to read on STDIN to reverse. Would this be allowed or does G have to be completely general? – Martin Ender Apr 3 '15 at 16:04
• In other words can the input method of O be destructive? Another example would be clearing the ARGV array to determine which code to execute - if I did this, then G could never use ARGV itself. – Martin Ender Apr 3 '15 at 16:05
• @MartinBüttner you can try to rephrase the question if you like. O should not consume too much input and I also think that G should be able to receive any input possible. So O taking the first arg and giving the rest to G or taking the first 4 bytes of STDIN would be fine. And yes the edit was sort of made in response to you comment so feel free to make an edit. – HEGX64 Apr 4 '15 at 3:32

## Find sequences in RSA_1024

I found an interesting way to factor numbers, while its far from been any efficient in compare to other known methods, its lots of fun!

Lets assume we want to factor N. X will be its factor, if and only if

N/X = floor(N/X)

So theoretically, if you could find a different representation of floor(N/X), you could easily find X, so while find such representation is unlikely it is very easy to find it within a small range, for example take a look at floor(N/X) of N = 691 ∗ 983 = 679253

At left is X at right is floor(N/X) - floor(N/(X+1))

512 2
513 3
514 3
515 2
516 3
517 2
518 3
519 2
520 3
521 2
522 3
523 2
524 3
525 2
526 3
527 2
528 2
529 3
530 2
531 3
532 2
533 2
534 3
535 2
536 3
537 2
538 2
539 3
540 2
541 2
542 3
543 2
544 2
545 2
546 3
547 2
548 2
549 2
550 3
551 2
552 2
553 2
554 3
555 2
556 2
557 2
558 2
559 3
560 2
561 2
562 2
563 2
564 2
565 2
566 3
567 2
568 2
569 2
570 2
571 2
572 2
573 2
574 2
575 2
576 2
577 2
578 2
579 2
580 2
581 2
582 2
583 2
584 2
585 2
586 2
587 2
588 2
589 2
590 2
591 2
592 2
593 2
594 2
595 2
596 2
597 2
598 2
599 1
600 2
601 2
602 2
603 2
604 2
605 2
606 1
607 2
608 2
609 2
610 2
611 2
612 1
613 2
614 2
615 2
616 2
617 1
618 2
619 2
620 2
621 1
622 2
623 2
624 2
625 1
626 2
627 2
628 2
629 1
630 2
631 2
632 1
633 2
634 2
635 1
636 2
637 2
638 2
639 1
640 2
641 1
642 2
643 2
644 1
645 2
646 2
647 1
648 2
649 1
650 2
651 2
652 1
653 2
654 1
655 2
656 2
657 1
658 2
659 1
660 2
661 1
662 2
663 2
664 1
665 2
666 1
667 2
668 1
669 2
670 1
671 2
672 1
673 2
674 1
675 2
676 1
677 2
678 1
679 2
680 1
681 2
682 1
683 1
684 2
685 1
686 2
687 1
688 2
689 1
690 1
691 2
692 1
693 2
694 1
695 2
696 1
697 1
698 2
699 1
700 2
701 1
702 1
703 2
704 1
705 1
706 2
707 1
708 1
709 2
710 1
711 1
712 2
713 1
714 1
715 2
716 1
717 1
718 2
719 1
720 1
721 2
722 1
723 1
724 2
725 1
726 1
727 1
728 2
729 1
730 1
731 2
732 1
733 1
734 1
735 2
736 1
737 1
738 1
739 2
740 1
741 1
742 1
743 2
744 1
745 1
746 1
747 1
748 2
749 1
750 1
751 1
752 1
753 2
754 1
755 1
756 1
757 1
758 2
759 1
760 1
761 1
762 1
763 1
764 2
765 1
766 1
767 1
768 1
769 1
770 1
771 2
772 1
773 1
774 1
775 1
776 1
777 1
778 2
779 1
780 1
781 1
782 1
783 1
784 1
785 1
786 1
787 2
788 1
789 1
790 1
791 1
792 1
793 1
794 1
795 1
796 1
797 1
798 1
799 1
800 1
801 2
802 1
803 1
804 1
805 1
806 1
807 1
808 1
809 1
810 1
811 1
812 1
813 1
814 1
815 1
816 1
817 1
818 1
819 1
820 1
821 1
822 1
823 1

Its easy to tell that in the range of 566,599 floor(N/X) act like a strait line y = 2x + 566. Also it's easy to verify as we can calculate the difference between floor(N/566) and floor(N/599) and see if its equal to 2 * 599 - 566, and indeed it is.

So now lets play

## Input

Your input is the number RSA_1024, while we will only use this input, your app should be able to work with any other inputs as well.

## Output

10,000 sequences that you found starting from Sqr(RSA_1024) and going up. Each sequences will be outputted in a new line. For each sequences you should output the next

• starting range value
• end range value
• type

Type is just a string defined by you that tells us what kind of sequence is it, strait-line or some thing else.

After you output the sequences, output one line with the total range you been able to cover with all the sequences.

## Criteria

Who covers the biggest Range wins.

# Realistic Fractal Terrain Generation

Don't you find that typical algorithms to generate random fractal terrains are boring and not too much realistic?

Fractal terrain generation is usually implemented with some random noise function applied in a fractal way. This can be seen with the typical Diamond-Square algorithm or the Perlin Noise function:

Diamond-Squares example output:

Perlin noise example output:

The problem is that these are used by their simplicity in creating them, but they are actually pretty boring when they are used as height maps:

... To be continued ...

• Terrain generation is interesting. I'd like to see this idea developed. Here is a simple, but pretty good, terrain generator, if you are looking for examples: Realistic Terrain Generation in 130 Lines. – PhiNotPi Apr 5 '15 at 1:47

# Make a fighter, then have them battle

Well, I was browsing around KOTH one day. I found two little interesting challenges: Save the last bullet for yourself and Codémon, I choose you!. But what if we combined the two?

### How your bot will work

Each match, your bot is assigned an opponent. It is randomly decided who goes first. Your bot is given HP of 100. You must output:
ATKID DEFID MOVED ATKDIR DEFDIR
ATKID is the attack's ID, and DEFID is the defense (or support) ID, for skills. MOVED is your move direction, on a number-pad (5 being 'stay still'). ATKDIR and DEFDIR are attack and defense skill directions (for Bullet, Wall, etc.)
Your bot must accept the following as input:
MYHP YOURHP MYPOS YOURPOS (additional projectile positions)

Your bot is allowed 2 attack and 2 defense skills.
List of attack skills:

0: Attack: Deal 10 damage.
1: Psychic Blast: Deal 5 damage this turn and 5 damage the next.
2: Bullet: Fire off a bullet that damages for 15 points when it hits an enemy.
3: Hadouken: Fire of a large flaming ball that can fly for 3 squares, and deals 50 damage.

List of defense skills:

0: Block: Block up to 10 points of damage this turn.
1: Heal: Heal for 10 points.
2: Wall: Add a wall in target direction.

### How the arena works

The arena starts as follows:

==========
|        |
|        |
|a      b|
|        |
|        |
==========

where a and b are bots' starting positions.

## Meta Questions

• What should I add as skills? Healing? Defensive?
• Is the arena too small?
• Have I left out any restrictions?
• Can I have some help with the 2D grid?
• Is the input/output sufficient?
• Does anyone want to pick up this challenge? I already have another KOTH, this was just an idea everyone liked.

# Missing distance between points

There are N points on a straight line. Someone calculates all possible distances between each pair of points and sort them.

In the following example I used 5 points. The sorted list of distances is [2, 5, 6, 8, 9, 14, 15, 17, 20, 22].

---X--X------X---------X-----X---

|-2|---6--|----9----|--5--|
|-----8---|-------14------|
|--------15------|
|---------17--------|
|----------20----------|
|----------22-------------|

You will receive the list, but one of the numbers is unreadable. This will be indicated by a zero. So you might receive the list [2, 5, 6, 8, 9, 0, 15, 17, 20, 22]. Your job is to find the missing number.

## Input / Output:

Write a function/program that finds the missing number. The input (via STDIN, command-line argument, prompt or function argument) format is a list or an array of distances (integers). You can optionally take the number of points (one integer) as a second parameter if you want. The output (via return value or STDOUT) is one single integer, namely the missing number in the distances list.

This is code-golf. Therefore the shortest code wins.

## Test cases:

#points, distances -> output
5, [2, 5, 6, 8, 9, 0, 15, 17, 20, 22] -> 14
3, [1, 0, 2, 2, 3, 4] -> 2
...

## Sandbox notes:

• This challenge is based on one problem of this year's Mathematical Kangaroo. My dad is a math teacher and brought me a copy of the 7.-8. grades test.

• Example and test cases don't look pretty and will be improved and extended for the final question on PPCG.

• My main concern about the challenge is the speed of the programs. My first (and only) solution is quite slow, because of the bad time complexity (about (n^2)^(n-1), where n is the number of points on the line). The 5-point example takes already about 1 second to compute, a 6-point example took about 10 minutes. My guess is, that most code-golf solutions will use a similar approach and the programs may be quite difficult to test.

There's definitely a better way of computing the missing number.

Maybe I'll add a few big testcases (one with 6, 7, 8, 9 and 10 points) and promise a 50% bonus if the program can solve all test-cases in under one minute.

• Are you sure the solution is unique? – xnor Apr 7 '15 at 23:25

The goal of this code challenge will be to take a grayscale image with shading as input and produce a height-map image with the same dimensions as output.

The input image will be a grayscale 256x256 png image, shaded with only a diffuse term, no ambient or specular term. It will be lit by a directional light source hitting the surface at a 45 degree angle, from above.

The output must be a 256x256 png image containing the height-map.

This is a code-challenge, the answer with the most accurate results wins. (A perfect match between the reverse engineered height-map and the original height-map used to produce the shaded image is near impossible, it is not expected that they are identical).

(working on test cases)

tags:

image-processing, code-challenge, graphical-output, conversion

# SVG file optimization

Yep, I got my idea off of this question, and it's amazing answer. All credit for this question goes to Illmari Karonen's answer

Now, for the challenge: Write a program that removes unnecessary clutter from SVG files in order to reduce their byte counts.

1. Remove comments <!-- comment -->
3. Shorten necessary ids to 1 letter, and remove unused ids.
4. remove unnecessary attributes and XML namespace attributes

Any other methods used to shorten the SVG files are welcome. (You can refer to the linked answer to look at an extensive list of ways to shorten SVG files)

Your program's score is how many bytes it removes from these SVG files:

test cases in progress

• See also Warm Welcome Secret Hat. If you're going to allow changing the paths, you should specify permitted changes / accuracy. E.g. if a transform is given to 3d.p. and the path coordinates to 3d.p., inlining the transform and then rounding to 3d.p. could produce visually perceptible changes. – Peter Taylor Apr 14 '15 at 9:47

# Randomly generated "Bézier petals"

## Introduction

A "bézier petal" is a:

• simple closed curve (no loops or self-intersection)
• made by two cubic Bézier curves which
• share endpoints
• but not necessarily control points

## Challenge

The challenge is to generate these randomly, such that:

• the entire space of possible valid curves is covered,
• any specific valid curve is as likely as any other,
• no "degenerate" (non-simple) petals are output.

## Background

I've been thinking about this for a while (see https://www.youtube.com/watch?v=TJdApKcAVD0), but was only able to arrive at a partial solution, which only covers a "safe" subset of possibilities (it never generates crescent or s-shapes). But, having followed this site for a while, I know that many of you are way more clever than I am.

## Output

The result should be a function which returns a single random petal, defined by two endpoints and two sets of two control points (six values in all) on a Cartesian plane — let's say with values between -1 and 1.

## Notes

Ideally, the algorithm works in constant time, or at least has a bounded stop; generating and filtering out degenerate petals until a good one is found is acceptable but a step down.

Entries which do not cover the entire possible space but do so with low complexity and at least beat out my "sort radially around center" approach are partial credit.

## Sandbox notes

I'll add some illustrations for valid and invalid petals, once I draw them.

• Are you sure "any specific valid curve is as likely as any other" is well-defined? – feersum Apr 22 '15 at 22:20

# Minimal convex partition (code-golf)

The goal of this challenge is dividing up the 'white' shape of a given 'black and white' pixel image into smaller pieces, which together form the original image (let's call this a partition). The restriction is that those pieces have to be convex, in our case everything is made up from square pixels, therefore the convex pieces can only be rectangles. Now of course you can just divide the whole shape up into the pixels it consists of, but that way you will get too many pieces (usually). The goal here is finding one partition that has the lowest number of (convex) pieces.

## Specs

### Input

The 'black and white' pixel image of $n \times m$ pixels is given as a string, row by row, each row separated by a comma. The white pixels are represented by a full stop ., and the black pixels are represented by a hash mark #.

### Output

The output consists of the same string, but now the white pixels must be replaced by alphabetic characters, one character for each piece of the partition. The minimal number of partition never exceeds 26 (you do not have to consider input that does not meed this condition), therefore you only have to use the letters a-z. If the minimal number is $n$, you have to use the first $n$ letters of the alphabet. Of course, the output is not necessarily unique.

Examples (without the commas, for better visibility):

n=2:
Input:
#.
..
Ouptut:
#A
BB

n=4
Input:
....
..#.
....
Output:
AABB
AA#C
DDDD

n=6
Input:
.....
.#...
.....
...#.
.....

# META:

I'd be happy for any interesting input examples. I could not think of any really interesting ones right away now.

• Very similar: codegolf.stackexchange.com/q/44654/14215 The output might not be minimal in some cases, though. – Geobits Apr 20 '15 at 16:26
• Thanks for pointing this out, I did not remember this challenge but it is indeed similar, but I still think looking for the solution with the minimal numbers of rectangles is again a different challenge, don't you agree? But I just noticed that I could write the introduction way more intuitive by using covering a region with rectangles instead of *partitioning into convex pieces*=) – flawr Apr 20 '15 at 19:28

Internet Relay Chat (or IRC for short) is a simple yet popular chat communication method. The challenge is to create a program that can take an IRC server from program arguments and print out new messages sent on that server.

e.g.: <your_irc_client> irc.freenode.net

A very simple implementation in Python of this idea which does not print responses to the user can be found here

# Interpret a Turing-Complete Language

This challenge is inspired by this esolangs.org page, which lists some languages with very small interpreters. There have been some similar challenges before, like this one about a self-interpreter, or a few other interpreter challenges, like one for BF.

This goal of this challenge is to write the smallest interpreter possible for a Turing-complete language. You may choose any Turing complete language (even one you create?) to interpret.

Your interpreter should take input representing the program to be executed, and give output representing the end result of the program. "Interactive" I/O is not required.

## More Rules

Your interpreter program may not contain/execute any eval-like commands.

• Maybe this could be a popularity contest, and whoever has the most creative answer wins? – ASCIIThenANSI Apr 20 '15 at 21:18
• I like this, but I think it needs to be more specific. Why not pick a specific OISC? That would probably be the winning strategy for the more general problem anyway. Also, I/O format should either be locked down or explicitly left open. If I'm golfing an OISC in Python 2, for example, I'd like to have the I/O be the memory of the machine represented as a Python list, read via input(). Is that okay, or cheating? – DLosc May 4 '15 at 4:06
• @ASCIIThenANSI For the popularity-contest version, see this question. – DLosc May 4 '15 at 4:07

# Number of ways to sum [1..n] with [n+1..2n] such that each sum is prime

In as few bytes as possible, write a program or function which produces this sequence (A070897), either as an infinite list on STDOUT, or in your interpreter of choice.

## Example

a(5)=2 because there are two ways: 1+10,2+9,3+8,4+7,5+6 and 1+6,2+9,3+10,4+7,5+8

## Rules

No built-in primality tests. No lookup table ;). No standard loopholes.

• Are build-in prime functions allowed? – Jakube Apr 22 '15 at 21:13
• Fixed //char count – alexander-brett Apr 22 '15 at 21:16
• It would be good to actually define the sequence explicitly in the question body instead of just in the title and by linking to OEIS (the link is still good for further reference, but it shouldn't be necessary to understand the question). Likewise, if you could reproduce the first 20 or so elements as test cases, that would be good to make the challenge self-contained. It's also not clear if "produce this sequence" means to print consecutive number ad infinitum, or given n to return a(n) or to return all numbers from a(1) to a(n). – Martin Ender Apr 24 '15 at 12:42
• @MB - I'll amend to repeat the title & give more examples. However I think 'an infinite list on stdout' is pretty clear? – alexander-brett Apr 24 '15 at 12:44

# Rabbit in a Snow Storm

## Scenario

A group member is giving a presentation in PowerPoint. He reaches a point where he wants to start writing on the whiteboard, but his slides have text that get in the way. He motions to the guy with the keyboard to just blank the screen so he can write. The next 2 minutes consist of everyone in the room bickering about how to do it until we arrive on using a full-screen-ish terminal (which is black, so we have to turn up the lights). Awful.

## Objective

Have the primary monitor become completely white.

## Rules

• You start with no programs running (or at least none that are important towards the goal)
• You may only use programs that are installed by default on your OS/distro (i.e. needs to be repeatable by someone else without installing anything in particular)
• You can't pre-load your background, slide-show, etc. with a pure-white image (though you could create the image then show it)

## Scoring

• Number of keystrokes required (keys depressed and released, i.e. opening Spotlight takes two (Command + Space), likewise Run... (Win + R))
• Clicks are scored as 5 keystrokes.
• In your scenario, PowerPoint is running. Yet in the rules, it isn't. I can understand if this is because the one-stroke solution w isn't interesting, but it still makes for a confusing question. Why not ditch PowerPoint from the scenario and replace it with a demo of some in-house software? – Peter Taylor Apr 23 '15 at 8:49
• Oh, and you should probably add to the bit about "installed by default" that the OS hasn't learnt which programs you use, so you should assume that no auto-completion occurs. – Peter Taylor Apr 23 '15 at 8:50
• @PeterTaylor I didn't know about w...magical! In the scenario the guy was actually using PDF slides, so I'm not sure if Reader has the same functionality. Good comment though, probably just forbid autocompleting? – Nick T Apr 23 '15 at 16:11

## Generate random seeds for strings

Consider the following pseudocode:

function randomString(long input) {
accumulator = "";
random = random.seededWith(input);
while(true) {
x = random.nextInteger(27); # generate integer 0-26
if(x == 0) break;
accumulator += x + 'a'; # add lowercase letter from a-z for values 1-26
}
return accumulator;
}

In other words, this generates a random lowercase string based on a random number seed.

Your job is not to write this behavior.

For this golf, your job is to REVERSE this process. Receive a String as input, and return the random seed that would generate this string, using whatever pseudorandom algorithm is included by default in your language - so different languages will have different numbers returned for the same string.

However, the algorithm used to regenerate the strings should be the same for all languages.

## Fine print

You may write a program or function, which returns the output as an integer or long (whatever's appropriate for your language) or printing it to STDOUT (or closest alternative). You may optionally include a single trailing newline in the output.

If the String cannot be generated in this method, your program should throw an exception and/or print an error message of some sort.

Additionally, standard loopholes which are no longer funny are banned. You may not use external libraries unless your language doesn't support seeded random number generation by default. If that is the case, then you may use the library for random number generation that is most commonly used by that language's community.

### Citations

This question has been brought to you by: Why does this code using random strings print hello world?

• "However, the algorithm used to regenerate the strings should be the same for all languages." I don't see how this can be possible, unless you're assuming either that the only way to do it is brute force (wrong) or that every standard library in the world uses linear congruential PRNGs (unlikely: there's probably some language designed by a security nut which only uses crypto PRNGs). – Peter Taylor Apr 25 '15 at 8:25
• @PeterTaylor I meant the pseudocode should be same, not the PRNG algorithm. – durron597 Apr 25 '15 at 14:38

# Structural Damage Simulation

(either or , haven't decided yet)

### Introduction

In this challenge, you are given a two-dimensional map or a brick structure. Each brick is glued to its four neighbors, and is guaranteed to be connected to the ground, that is, the bottom edge of the input grid, via adjacent bricks. This structure is affected by gravity, which may cause some of the bricks to break, depending on their durability. Your task is to predict whether this happens, and where.

### Spec

The input is given as a grid of the ASCII characters . and # that represent empty space and square bricks OR a black-and-white image with the black pixels representing bricks. You are also given a nonnegative number that represents the durability of the bricks; you can choose the valid type (integer or float) and range of this parameter and how it affects the computation. Your output is a grid in the same format as the input, but with some of the bricks replaced by Xs (or gray/red pixels); they represent bricks that have broken under the strain caused by the weight of the structure.

### Example

Suppose we have the following input grid (replace with an image if that's chosen as the input format)

................
..######...####.
..######...####.
..########.####.
...###...#.####.
.....#...######.
.....#.....####.
.....#......#...
.....#.######...
.....#####......
.....#######....
.....#######....

The narrow parts of the structure are likely to break, especially the vertical ones, but the solid parts may very well hold themselves together. A possible output would be

................
..######...####.
..######...####.
..######XX.####.
...###...X.####.
.....#...X#####.
.....X.....####.
.....X......X...
.....X.#XXXXX...
.....####X......
.....#######....
.....#######....

### Scoring

This is a popularity contest, meaning that the answer with the highest vote tally wins. Voters are encouraged to take the following criteria into account:

• Simplicity. Simple and elegant algorithms are favored over complex and over-engineered ones. Elegance includes reasonable speed, so very slow algorithms are discouraged.
• Realism. The outputs should be close to the physical intuition of most people.
• Flexibility. Solutions should preferably handle complicated structures and extreme values of durability.

# Cops 'n' Robbers - Hide a keyword in each answer answer-chaining

This is an idea I'm still working on, but I want some feedback on whether or not it could pan out well.

### Cops

The robbers are here! They've found our files! We, need to encrypt them! We need a certain key, something special that clearly shows what the real program is. We need to keep writing our new files, but we must keep encoding them. When a robber cracks a key, we find the key they cracked and write a new file off of that key! For example, we will hide the encryption key for file #2 in file #1, then file #2 hides a key for file #3, and so on. The files are safe if they go uncracked for 5 days, in which we win! But if the robbers crack all 100 of our files, we lose!

### Robbers

We found the cops' files! Not only that, we cracked their encryption scheme! In file #1, they hide a key for file #2, which hides a key for file #3, and so on. Our goal is to hack all 100 files. The only catch? We'll lose our connection if we don't crack a file within 5 days.

Basically, the cops will upload an answer with a program when the robbers crack the previous answer. The clue to the next answer is hidden in this one, encoded with the clue from the last answer. If a robber guesses wrong, that robber can not guess again on the same answer. If a answer remains uncracked for 5 days, cops win. If robbers guess all 100 answers, the robbers win.

### Winners

The winner for the cops is whoever made the uncrackable file. For the robbers, it's whoever cracked the most files (in event of a tie, later answers are better than old ones.)

• Just to be clear, each cop has to upload 100 files somewhere? – Geobits Apr 29 '15 at 18:09
• @Geobits No. The 'files' are the answers. The cops create 100 files (at any time) and post them (in order) as answers. The key to decode file #10 is in file #9. (File #1 will have its key posted in the question.) Robbers crack the code in a seperate thread. – ASCIIThenANSI Apr 29 '15 at 18:15
• The description right now is rather "themed" and isn't precise enough to explain the details of how the challenge will actually work. Themed intros are fine, but you should write a description that, for example, uses "answers" instead of "files" and uses a team name instead of "we." – PhiNotPi Apr 29 '15 at 18:43

# Astrometric Tiling

A common problem in astronomy is the stitching together of astronomical images to create a mosaic of the entire imaging survey. This can't be done by naively putting the images next to each other in a grid - they might have slightly different dimensions, and certainly have different positions & orientations, which might overlap.

The solution is to calculate the positions of the objects (usually stars) in each image in celestial coordinates, a process known as Astrometry. (This is not the challenge, as it's far too difficult for a codegolf, but if you're interested in that process, take a look at astrometry.net.) Once an astrometric solution for a given image is found, every star's position on the sky can be calculated based on its position on the image.

# The Challenge

Write a program to accept lists of coordinates for some number N>=2 of astronomical images, and output a transformation matrix for each image to create the mosaic.

# Input

You may accept either a list of coordinate lists, or a list of filenames containing coordinate lists, whichever is more convenient. The coordinate list (length >= 10) for a given image is made up of 4 coordinates per star: x,y in whole number pixel coordinates on the image, and a,d in float (requiring precision to at least 10^-5) celestial coordinates. Assume that every star's coordinates are exact, and that the same celestial coordinates in two different lists refer to the same star.

# Output

Your program should output a 3x3 affine transformation matrix for x,y in each image (alternatively, you can output a matrix for each image after the first, if you would like to use the first as a reference), which can be used to tile the images in such a way as to align the celestial coordinates in adjacent & overlapping images.

# Scoring

This is a (admittedly quite challenging) code golf, so shortest in bytes wins.

I'll need to produce a test case, which I will do before posting.

Create a program or function that, given a postfix expression, converts it to the simplest equivalent expression. The expression may contain real numbers, floating variables denoted a to z, and the basic arithmetic operators +-*/^.

Two expressions are equivalent if they produce the same result for all possible integer values of the variables. "Simplest" means you should return the equivalent expression with the least number of operators. If there are multiple expressions with the same number of operators, pick the shortest.

## Example

Consider the expression (8+4*y)/2+x*2. In postfix notation, this would be

8,4,y,*,+,2,/,x,2,*,+

This should yield the output

2,2,y,+,x,+,*

which corresponds to (2+y+x)*2.

Question:

this challenge is irrelevant of code length , so i want to ask , any scoring methods i can use in this defiance

i propose : picked up nine variant expressions with different polynomial degrees , which im free to choose , tested as input for all concurrent codes , then validate the lowest sum = (number_of_operations)^2+length(output_string)

# Detect limit points in (possibly) oscilating sequence

### Popularity Contest, Algorithms

Given an (infinite) sequence of numbers, your task is to find an algorithm (and write a corresponding program) that takes the sequence as input and determines

• Whether the sequence converges to a cyclic behaviour. That means the sequence will oscillate throu one or more values, that means whether it has one or more limit points. In this case it should output the limit points.

• diverges (does not end up in one or more limit point). In this case it should output a message that says so.

• No defined behaviour for sequences that do not have acyclic limit points.

A limit point is a value such that for every neighbourhood of that value an infinite number of sequence elements are within that neighbourhood.

Of course you can only use a finite part of the sequence, so you the task is ambiguous, but the larger the given sample the better your algorithm should be able to dectect the cycles. As this is difficult to achieve for arbitrary sequences, you are allowed to use 'fine tuing parameters' that can be changed manually in order for your algorithm to work best for the given set of sequences. Please document what those parameters do.

In this case here, you can assume that the sequence will converge to a behaviour where it cycles throu all the n limit points without gaps (intermediate values that are not limit points) and always in the same order.

### Motivation

You perhaps have already see this diagram (the bifurcation diagram of the logistic map)

In order to generate this diagram, you have to compute a sequence for every r and compute the limit points x of each of those sequences (which in this case are cyclic). Then you plot those x against r. The sequence is generated by the recursive function (logistic map) with a starting value 0< x(0) < 1 (usually something like 0.5)

x(n+1) := r * x(n) * (1 - x(n))

The sequences generated this way are nice examples of the sequences that your algorithm should be able to detect.

should consist of

• a function/program that executes your algorithm on a given sequence (input in any way you like),
• a description of how your algorithm works,
• and a program that uses your function for generating the bifurcation diagram above.

### Examples

Following sequence is generated by 1+(-1)^n*(10+n)/n This sequence does not converge in the usual sence of sequences but it has limit points at 0 and 2. The sequence looks like this, so the

This is from the example above (logistic map with r=3.5), here we have 4 limit points:

The following sequence is bounded (and therefore has at least one limit point) but does not converge and does not seem to have a cyclic behaviour. (It is generated by x(n) = [pi*n^3 (mod e)]/e)

# META:

I'm happy to hear from you what you think. So far I did not find any sources that described algorithms that do exactly this task, but there may very well exist such algorithms. If you can improve the text please do so! Any suggestions are welcome.

• Can you put in some example input/output? I'm still a little confused about the challenge – Sp3000 May 13 '15 at 1:15
• I know my wording is not that great, please tell me what to change! I just added some examples. – flawr May 13 '15 at 8:51
• What I mean is, is the string "1+(-1)^n*(10+n)/n" the input, will it be the sequence of numbers generated by the expression or...? – Sp3000 May 13 '15 at 8:59
• No the input is a list of numbers (or a function that can be repeatedly called and returns the next list element or something similar), so you do not need to parse an input, the mail goal is finding an algorithm that is looking for cyclic limit points, the actuall details of the program are not that relevant. Is that clear now? – flawr May 13 '15 at 9:01
• I was a bit worried that might be the case. What if you have something like 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, ... (a googol numbers later), 1, 0, 1, 0, 42, 42, 42, 42, 42, 42, 42,... (42s forever after)? – Sp3000 May 13 '15 at 9:35
• This is obviously a difficulty, as a reasonable algorithm can only consider a first (finite) section of the sequence, and it should find the a answer as good as possible with the given data. So the sequence x(n) = (-1/2)^n looks as if it is gonna be alternating between two points if you only consider lets say x(1),...,x(5), but if you consider the first 100 elements it could become more clear that is only one. So the algorithm should basically provide a criterion to make a classification with only limited data. And the more real examples it recognises the better. – flawr May 13 '15 at 13:26
• In your case as long it sees only 0,1,0,1,0,... the algorithm should obviously return the limit points 0 and 1 (cycle length 2), but if it gets e.g. one 42 at the end of the data, it could output that the sequence does not converge. But as soon as there are enough 42 it should probably say that the sequence converges to 42. (cycle lenght 1) – flawr May 13 '15 at 13:29

## Quaternion calculator

Quaternions are extensions of the complex number system that are used in 3d graphics and some other applications. In addition to i, there is also j and k. j^2 and k^2 are both -1, however, ij=k, jk=i, ki=j, ji=-k, kj=-i, and ik=-j. Write a calculator that can calculate addition, subtraction, multiplication, division, and exponents. This is a code golf challenge, shortest answer wins.

EDIT: sample input: (2+4i+3j)*i^(j+2k)/(5j-i)+1

• This should specify how operands and operations are given as input. However, this is a borderline duplicate. Multiplication has already been done, exponentiation can be trivially reduced to that, addition and subtraction and fairly uninteresting, so that leaves only division. So just doing division might be a better idea. – Martin Ender May 13 '15 at 18:08
• I had considered a sequel with division or inversion, but thought it was too likely it would be implemented as multiplying by the conjugates and rescaling by the norm, which would mostly still be about multiplication. – xnor May 14 '15 at 23:46

# Kaos Pendulum and Einstein's Revenge

The Double Pendulum system is a relatively simple system with quite complex behavior that's highly sensitive to initial conditions (i.e., "chaotic").

Doctor Kaos has designed a particularly fiendish double pendulum, using his diabolical machine "Einstein's Revenge". Einstein's Revenge is a device which couples matter and energy, causing the mass of the first pendulum (connected to the anchor point) to be a function of the energy of the second: m1 = sqrt(PE2**2 + KE2**2), with the potential energy measured from the rest position of the pendulum.

For this challenge, you must write a program or function to simulate a basic Kaos Pendulum, where the second pendulum has unit mass and both pendulums are unit length. It must accept the starting position of the Pendulum - two real numbers, theta1 and theta2 - as input or command-line arguments, and one positive integer equal to the number of seconds the pendulum will be active.

Your program must output the value of theta1 and theta2 for each second, either printing to stdout or returning as a list, or something similar.

## Notes

I don't know if this should be a golf, a popularity contest, or if there should be some scoring method for some other type of challenge.

# Blind (deterministic) Jenga

The idea for this came up in the chat room, under the broader topic of how to make a human dexterity game into a software KotH challenge. Here's the basic idea, which I don't think works, but I'd love to get feedback to make it better.

The jenga tower has three blocks per layer. Layers alternate between N/S aligned blocks and E/W aligned blocks.

There may be just two players, or more than two.

Each turn a player selects a block location to probe. If there's no block there, the player gets to go again. If there's a block there, it is removed from the stack. If this causes the tower to fall, the player loses. Otherwise, the block is placed in the next safe position at the top of the tower, unless all available positions are unsafe in which case the player loses. If the player has not lost, it is now the next player's turn. Continue until some player loses.

I think this won't work well because it will boil down to a relatively random competition between bots that start with edge pieces and bots that start with center pieces. I don't want to run the contest just to find out that that's the case. Maybe putting four blocks per layer would make that a non-issue. I'm open to other suggestions on how to make this challenge work.

A idea. Maybe I'll do it a long time later...

You have these options each turn (they need better names and a plausible background):

• Meet k If the bot k also did meet you, and nobody injects, both of your scores are increased by 1. Otherwise nothing happens. But if k is yourself, this is invalid and will be just like doing nothing.
• Invite k The bot k gets a notification that you are doing this, and in the next round, your output is ignored and you must do Meet k.
• Inspect k You will get these informations at the beginning of next round:
• What the bot k was doing.
• The score change of bot k.
• Who was inviting bot k.
• Who was trying to meet bot k. (This is not known by bot k if not inspecting himself and his score is not changed.)
• Who was inspecting bot k. (This is not known by bot k if not inspecting himself.)
• Who was injecting bot k (and another bot). (This is not known by bot k if not inspecting himself and his score is not changed.)
• Inject j k If j is meeting k and k is meeting j, your score is increased by 10 and their scores are both decreased by 1 instead. If one of them is pretending doing that, and the other is pretending or really doing that, your score doesn't change. Otherwise, your score is decreased by 10. They'll not know who is injecting unless they are inspecting you or self-inspecting instead.
• DoNothing Nothing happens.

Possible other options:

• Pretend action: action is any action other than Pretend. It's the same as doing nothing, but inspectors will be told that you are doing that action. The score change that the inspectors will see is calculated as if you really did that.
• Multiply: For each turn until the next time you meet some bot each other, the points you, the other bot and all the bots injecting you get are doubled (or incremented, I'm not sure).

Everybody can see only their own score, bots inviting them and the result from Inspect.

• I think that Pretend is a great action, and should definitely be included. – Nathan Merrill May 22 '15 at 19:30

# Is this a red-black tree?

A red-black tree is a binary search tree where each node has an additional 'colour' property, which can be black or red. The root and leaf nodes must be black, each red node must have black children, and the path from any node to any child leaves must have the same number of black nodes. For instance:

2B
|  \
1R  3B
|   |
~   ~

Is invalid because of a black violation (the path from the root to each leaf has a different number of blacks).

Your task is to determine whether a given tree is a valid Red-Black tree.

## Input

The input will be a string matching [ a-zA-Z]. A space represents a leaf, a lowercase character a black node, and an uppercase character a red node. The value of a node is the position in the alphabet: a is 0, b is 1, C is 2, and so on. The children of the node in position n are in positions 2n+1 and 2n+2. If the string ends before the position you're looking for, that node is a leaf. For instance, baD cf E corresponds to:

1,B

/     \

0,B         3,R

/     \

2,B         5,B

/

4,R

## Output

Your program should output something other than whitespace on STDOUT if and only if the input represents a valid tree.

## Simple test cases

True      False
" "       ""        (Root black violation)
"a"       "A"       (Root black violation)
"dBeac"   "dBea"    (Black violation)
"dAE B"   (Red violation)

Question about extrapolating data from an incomplete tennis scoreboard

Introduction

It is a fine day at the Stack Exchange tennis club. The players have just finished playing a grand tennis tournament in a round robin style (every player plays every other player once). The final results were about to be announced when suddenly, the scoreboard explodes! It is a total disaster - now nobody knows what the final scores were! Luckily, a piece of the scoreboard is still intact. Can you write a program to figure out the rest of the scoreboard from only a small part of it?

If there are k players, our scoreboard would have had k*3 entries, indicating each player's wins, losses, and draws. It is presented in a list of space separated comma separated tuples. For instance, in a game with 4 players here is a possible final scoreboard:

0,2,1 3,0,0 1,1,1 1,2,0

In this example the first player did not win anything, lost twice, and drew once; the second player won all three of their matches; the third player won once, lost once, and drew once; and the fourth player won once and lost twice.

Input Description

As input, you are given a scoreboard similar to the one above, except some of the numbers have been replaced by ?. The ? indicate the numbers that were unrecoverable after the explosion. For instance:

?,?,1 0,?,0 ?,?,?

Output Description

Output the scoreboard, with the ?s replaced with the actual scores. The input scoreboard will always have enough information for you to deduce the final scoreboard.

For example, consider the above input. We know that the second player has 0 wins and 0 draws, therefore, they must have lost both of their games. The first player has a single draw, and since we know the first player beat the second player, that draw must be with the third player. Thus the output is:

1,0,1 0,2,0 1,0,1

Sample inputs and outputs

TODO: Sample inputs and outputs of higher k

Sandbox Questions

• I have an alternate formulation for this question where instead of an incomplete scoreboard, the complete scoreboard is given and the program has to generate a table of which player beat which player. Which challenge do you think would be more interesting?

Sudoku Swapping Shenanigans

Honestly, there's not many shenanigans in this challenge but I wanted that sweet tautogram title.

Introduction

Imagine you're on a train, and there is a Sudoku grid that's already been entirely filled in left on the seat. We'll represent this grid as a series of 81 comma separated integers from 1-9 on a single line. Each cell in the grid can be numbered as follows:

As with all Sudoku grids, there will be exactly 9 of each number present in the input.

The Sudoku grid will not be completed correctly. It will have the right number of each number, but they will be positioned wrong. Your program's task is to swap these numbers to solve the Sudoku puzzle correctly.

(Since your stop is next, you want to make this program solve the Sudoku puzzle as fast as possible.)

or:

(Since you're writing this program on a napkin, you want to make it use as little bytes as possible.)

Input Description

Input consists of 81 positive integers that are comma separated. Some of them will be prefixed with an X which means those are the ones that are already placed and you can't swap them.

Example input goes here.

Output Description

Output the swaps required to solve the grid in the fewest number of swaps. You should have a line for each swap, consisting of two numbers in the form:

a,b

where a and b are both different and in the range 0-80.

Here's an example output (and I haven't actually written the example input yet!)

80,0
8,9
14,15

So that would mean that to solve the grid we need to swap the number in position 80 with the number in position 0, the number in position 8 with the number in position 9, etc.

Sandbox Questions

• Are we trying to solve it in the fewest number of swaps, or just transform it into any solved sudoku grid (meaning I could swap every input into a single predetermined pattern)? – Geobits May 27 '15 at 16:11
• @Geobits Fewest number of steps. – absinthe May 27 '15 at 22:03
• Do you guarantee that the original clues give a unique solution? If so, there's a lot of overlap with existing Sudoku-solver questions, and fastest-code would need a very large and well-chosen set of test cases to be confident that it's not overly sensitive to the order in which heuristics are applied. The interesting (IMO) part of the question reduces to "Decompose a non-simple graph into cycles", and I think there may be better settings to present it. – Peter Taylor May 30 '15 at 13:40

Code golf challenge: Write a program or a function that solves the following problem. Normal code-golf rules apply.

Given a set of subnets, give the smallest possible network these can belong to. You should consider the network- and broadcast addresses in your calculations.

Example input:

128.208.0.0/18
128.208.128.0/17
128.208.96.0/19

Example output:

128.208.0.0/16

You might want to read up on IP prefixes before trying this.