555
\$\begingroup\$

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

Sandbox FAQ

Posting

To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal, use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3935 Answers 3935

1
121 122
123
124 125
132
-1
\$\begingroup\$

Breaking BogoBogoSort (In Badness)

The title says it all - make a sorting algorithm with a time complexity of \$O(n!^{n!})\$ or higher in the fewest bytes possible - as far as I can tell, that will require you to make a double exponentiatial formula or worse: that is, \$O(a^{b^n})\$, where \$a, b > 1\$.

Rules (since there must be some)

The list must be returned sorted in a finite time. This can be as high or as low as you want.

The algorithm must work for any real numbers (-30% if you can sort any single type given it's non-mixed).

The algorithm must work of any list length, and must eventually outpace ALL \$O(n!^{n!})\$ formulas, not just BogoBogoSort, and you must state the exact \$O\$ growth rate (for example, \$O(2^{3^n})\$). It may start off slow, but must eventually outpace all other expo-factorial functions (as I now name this growth rate).

Shortest code wins.

\$\endgroup\$
2
  • \$\begingroup\$ What prevents someone from doing a loop just to make it slower (or calculating \$ n!!!! \$, etc.), and then just sorting the array with quicksort? \$\endgroup\$ Jun 5, 2021 at 8:00
  • \$\begingroup\$ Logic. Logic prevents them from doing something that the question didn't mean you to do. Standart loopholes are forbidden by default \$\endgroup\$ Jun 7, 2021 at 8:25
-1
\$\begingroup\$

Get the Collatz Sequence

The Challenge

Write a full program or function that, when given an integer \$n \ge 0\$, outputs all steps of the Collatz Sequence (A006577) of \$n\$.

The Collatz Sequence

The Collatz Sequence is defined as: $$ a(n) = \begin{cases} n/2, & \text{if $n$ is even} \\ 3n+1, & \text{if $n$ is odd} \end{cases} \text{while n > 1} $$

Input

Input is some integer \$n \ge 0\$.

Output

Output is the sequence of numbers visited while calculating the Collatz Sequence, while the output is greater than 1.

Additional Rules

Test Cases

n -> sequence
0 -> [0]
1 -> [1]
2 -> [2, 1]
3 -> [3, 10, 5, 16, 8, 4, 2, 1]
4 -> [4, 2, 1]
5 -> [5, 16, 8, 4, 2, 1]
6 -> [6, 3, 10, 5, 16, 8, 4, 2, 1]
7 -> [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
8 -> [8, 4, 2, 1]
9 -> [9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
10 -> [10, 5, 16, 8, 4, 2, 1]
15 -> [15, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
20 -> [20, 10, 5, 16, 8, 4, 2, 1]
25 -> [25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
30 -> [30, 15, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
35 -> [35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
40 -> [40, 20, 10, 5, 16, 8, 4, 2, 1]
45 -> [45, 136, 68, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
100 -> [100, 50, 25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
9329 -> [9329, 27988, 13994, 6997, 20992, 10496, 5248, 2624, 1312, 656, 328, 164, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, 182, 91, 274, 137, 412, 206, 103, 310, 155, 466, 233, 700, 350, 175, 526, 263, 790, 395, 1186, 593, 1780, 890, 445, 1336, 668, 334, 167, 502, 251, 754, 377, 1132, 566, 283, 850, 425, 1276, 638, 319, 958, 479, 1438, 719, 2158, 1079, 3238, 1619, 4858, 2429, 7288, 3644, 1822, 911, 2734, 1367, 4102, 2051, 6154, 3077, 9232, 4616, 2308, 1154, 577, 1732, 866, 433, 1300, 650, 325, 976, 488, 244, 122, 61, 184, 92, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
4637823 -> [4637823, 13913470, 6956735, 20870206, 10435103, 31305310, 15652655, 46957966, 23478983, 70436950, 35218475, 105655426, 52827713, 158483140, 79241570, 39620785, 118862356, 59431178, 29715589, 89146768, 44573384, 22286692, 11143346, 5571673, 16715020, 8357510, 4178755, 12536266, 6268133, 18804400, 9402200, 4701100, 2350550, 1175275, 3525826, 1762913, 5288740, 2644370, 1322185, 3966556, 1983278, 991639, 2974918, 1487459, 4462378, 2231189, 6693568, 3346784, 1673392, 836696, 418348, 209174, 104587, 313762, 156881, 470644, 235322, 117661, 352984, 176492, 88246, 44123, 132370, 66185, 198556, 99278, 49639, 148918, 74459, 223378, 111689, 335068, 167534, 83767, 251302, 125651, 376954, 188477, 565432, 282716, 141358, 70679, 212038, 106019, 318058, 159029, 477088, 238544, 119272, 59636, 29818, 14909, 44728, 22364, 11182, 5591, 16774, 8387, 25162, 12581, 37744, 18872, 9436, 4718, 2359, 7078, 3539, 10618, 5309, 15928, 7964, 3982, 1991, 5974, 2987, 8962, 4481, 13444, 6722, 3361, 10084, 5042, 2521, 7564, 3782, 1891, 5674, 2837, 8512, 4256, 2128, 1064, 532, 266, 133, 400, 200, 100, 50, 25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]

Tags:

For Meta

  • Is it clear?
  • Any corrections?
\$\endgroup\$
3
  • \$\begingroup\$ I'd consider this a duplicate of the current Collatz challenge, as the only way to find the length is to generate the sequence, so the answers will all be doing the same thing, just without a length call tacked on the end \$\endgroup\$ Jul 31, 2021 at 16:38
  • \$\begingroup\$ That is what I've always wondered, though, is how we have a length of Collatz challenge but not a Collatz sequence generation challenge \$\endgroup\$
    – bigyihsuan
    Jul 31, 2021 at 19:58
  • \$\begingroup\$ Because there is no way to determine the length of a Collatz sequence without generating it, so the core of the challenges would be the same - generating the Collatz sequence. \$\endgroup\$ Jul 31, 2021 at 20:00
-1
\$\begingroup\$

Shortest common superstring

Your challenge is to find the shortest common superstring (SCS) for a sequence of English words. The SCS for a sequence is the smallest string that contains all the words in the sequence. The words should be passed as a function parameter.

Answers should be posted in the following format:

<Language name>, <Byte count>

<code>

This is code-golf, so the answer with the least bytes wins.


Any suggestions?
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I wouldn't suggest using a popularity contest for a task that looks like it can be code-golf. However, this is likely a duplicate. caird will be around in a while with a more length message and a link to a dupe :P \$\endgroup\$
    – user
    Aug 18, 2021 at 18:53
  • 1
    \$\begingroup\$ Welcome to Code Golf, and thank you for using the Sandbox first! Unfortunately, this is a duplicate. \$\endgroup\$ Aug 18, 2021 at 19:03
  • \$\begingroup\$ Ok, well that's fine. \$\endgroup\$
    – Bgil Midol
    Aug 18, 2021 at 19:04
-1
\$\begingroup\$

Tac-Tok-Toe

Tac-Tok-Toe is just like tic-tac-toe, but instead of three in a row, the winning condition is three in a row but each letter is exactly one space apart horizontally, vertically, or diagonally. The win can also go in any direction.

The games

Each team (X and O) will make their own tac-tok-toe AI's. 10000 games will be played.

The moves

AI.PUT_TILE(board: List[List[str]], place: List[int])
    Places a tile at the specified location

AI.DECIDE_MOVE(board: List[List[str]])
    Decides and returns the index the AI wants to move depending on the current board situation.

AI.GET_WINNER(board: List[List[str]])
    Returns the winner of the board.

The board

The starting board looks like this:

 | | 
 | | 
 | | 

(Yes, I know, that indeed is a horrible tac-tok-toe board.) For example, place [0, 0] is in the upper left square, and place [1, 1] is in the middle. If the X AI places an X at [2, 2], the board would now look like this:

 | | 
 | | 
 | |X

An example of a completed grid could look like this:

X|X|O
O|X|X
O|O|X

We see that X has won, so the game should print: "X wins!"

Game files

[Your side]AI.py:

class [Your side]AI:  # Maybe change to something more meaningful?
    def PUT_TILE(board, place):
        pass
    def DECIDE_MOVE(board):
        pass
    def GET_WINNER(board):
        pass

startboard.txt:

 | | 
 | | 
 | | 

Meta

Any suggestions?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Given that tic-tac-toe is a solved game, you're going to get a lot of near-identical submissions that play perfectly and always end in a draw. Unless you can put some kind of extra spin on tic-tac-toe that makes it more challenging, I'd pick a different game for a KotH. (Maybe one of these variants could work.) \$\endgroup\$
    – DLosc
    Sep 23, 2021 at 19:16
  • \$\begingroup\$ If you want some tips on writing KotHs with interesting gameplay, check out the king-of-the-hill tag wiki! \$\endgroup\$ Sep 23, 2021 at 19:20
  • 1
    \$\begingroup\$ Can you explain the win condition a bit better? How can you have 3 in a row with 1 space between them unless the board is 5x5 or larger? \$\endgroup\$
    – hyper-neutrino Mod
    Sep 23, 2021 at 19:26
  • \$\begingroup\$ It can go in different directions. \$\endgroup\$
    – Bgil Midol
    Sep 23, 2021 at 19:26
-1
\$\begingroup\$

Randombility of number

The aim of golf is to calculate score of how random 10 inputs given by users were. The Criteria is given below.

  • Points Rule
  • 5+(1.1)^n If inputted numbers are not in Arithmetic OR Geometric progression for n cnsecutive terms
  • 5+(1.1)^n if inputted numbers are not strictly increasing or decreasing for n>2
  • 5*n if number is prime number > 100 here n is number of such terms
  • -5-(1.1)^n if number is substring of $\pi$$ (3.1415926535897932384626433) for n>2
  • 5 if difference between largest and smallest input is greater than 1000
  • -5*n for n repeated inputs
  • -5 + ln(log(p)) if number is square or cube of any number beetween -100 and 100 here p is number
  • -5 if any three input ressemble any valid date (dd/mm/yyyy or mm/dd/yyyy) time(hh/mm or mm/hh) format
    • -Additional
  • (1.5)^n if time interval between two inputs is less than 1.5 seconds

Improvements required Score system.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Can you please clarify your challenge? I don't get even the point of the challenge or how to win. \$\endgroup\$
    – Seggan
    Oct 26, 2021 at 15:05
-1
\$\begingroup\$

Secretary Problem - Cops and Robbers

Both threads

(Link to other thread)

The Secretary Problem is a famous problem. In this challenge, it’s a little different:

  1. You need a new secretary that asks for the least salary
  2. You have a lot of applicants that you can interview one at a time, but don’t know how many applicants there are
  3. Each applicant will tell you how much salary they want (they’ll want at least $1 salary, but may all want $5)
  4. Applicants do not ever request the same salary for some weird reason (not sure if they’re robots or eavesdroppers)
  5. After you interview an applicant, you must give an immediate "yes, I accept you" (truthy) or "no, go away" (falsey)
  6. You want the applicant that asks for the lowest salary, so you can stay rich
  7. No applicant ever requests more than 1 million dollars (for obvious reasons)

In the maths world, it’s actually that you want the highest leveled applicant, but I put it this way because who doesn’t want to stay rich

Cops Thread

Your challenge is to write a program that takes two inputs: the previous applicants’ salaries, the current applicant’s salary, and outputs whether to accept the applicant (truthy) or deny him/her (falsey).

The robbers will attempt to find a list of applicants (and the salaries they demand) that forces your program to accept a person with a high salary demand. You need to attempt to make your program only accept the applicant which asks for the LEAST salary (that way you can stay rich)

The answer that (when answered against by a robbers thread - [link]) accepts the person with the least salary wins/gets accepted (i.e. the answer that accepts a $1, if that doesn’t exist, then the answer that accepts a $2, if THAT doesn’t exist ... and so on)

If your answer does not accept any, (up to the last applicant) you automatically get

Robbers thread

Each answer in the cop’s thread is a program that takes two inputs: the previous applicants’ salaries, the current applicant’s salary, and outputs whether to accept the applicant (truthy) or deny him/her (falsey).

Your challenge is to find a program in the cop’ thread (insert link here) and attempt to give it an input such that it accepts a person with a HIGH salary request. Answer that forces an algorithm to accept the highest amount of money gets accepted (i.e. the answer that forces a cop answer to accept a $1000000 salary applicant, if that doesn’t exist, the answer that forces a cop answer to accept a $999999 salary applicant, if THAT doesn’t exist ... and so on)

Put a link cop answer you are attempting to make go broke in your answer.

You must have at least 100 applicants (with at least one applicant that requests <$100)

Both threads (again)

To stop people getting free points, you cannot make a robbers answer for your own cop answer. 1 answer per thread (you can have both a robber answer and a cop answer as long as the robber answer is against a different cop answer)

Sandbox questions

  • Is this too far-fetched?

Somewhat shamelessly stolen Derived from this question

\$\endgroup\$
3
  • \$\begingroup\$ If the cop is forced to accept the last applicant if they haven't previously accepted anyone, isn't having exactly one applicant with a salary of $1m an unbeatable strategy for a robber? \$\endgroup\$
    – Dingus
    Oct 24, 2021 at 3:49
  • \$\begingroup\$ Changed - "at least 100 applicants" and "at least one applicant that requests <$100" \$\endgroup\$
    – W D
    Oct 27, 2021 at 5:27
  • 1
    \$\begingroup\$ The cops can consider only the bound of $100, as at least one robber will be <$100. \$\endgroup\$
    – pajonk
    Oct 27, 2021 at 9:03
-1
\$\begingroup\$

Output a random integer in a range that is a multiple of all in one set and not a multiple of any in another set

Given an integer range and two sets of integers, generate a random integer inclusive within the range that is a multiple of all the numbers in the first set but is not a multiple of any number in the second set, or specify that such a value does not exist.

Examples:

  • Range: 100 - 200
  • Divisors: 3, 5
  • Non-divisors: 9, 10

Possible values are: 105, 165, 195 (output one at random)

Rules

  1. Mathematically elegant solutions are preferred, but brute force solutions are accepted.
  2. If outputting one of multiple values is possible (as shown above), the solution should return a different value with each execution so that, probabilistically, all possible values are eventually output.
  3. This is code golf, so lowest byte count wins.

NOTE I have a solution for this in C#, but I'm curious of what other solutions there are. I had a heck of a time working out the math for this and thought it would be a good bit of puzzling for this community.

\$\endgroup\$
5
  • \$\begingroup\$ The First Rule is unnecessary. \$\endgroup\$
    – Fmbalbuena
    Nov 5, 2021 at 18:49
  • \$\begingroup\$ Why do you say so? If not included, I expect only brute force solutions will be provided. \$\endgroup\$ Nov 7, 2021 at 19:12
  • 1
    \$\begingroup\$ If the first code is included and others may think is fastest-code tag \$\endgroup\$
    – Fmbalbuena
    Nov 9, 2021 at 15:32
  • \$\begingroup\$ I suppose that is one of the end goals. Maybe that's a win condition I need to add. I've never seen that in code golf. I'll have to research that tag for examples. \$\endgroup\$ Nov 9, 2021 at 19:26
  • \$\begingroup\$ This needs testcases (pick one at random) and add tag random. \$\endgroup\$
    – Fmbalbuena
    Nov 11, 2021 at 21:59
-1
\$\begingroup\$

Quantum boolean

Background

Have you ever dream of quantum state? If that's true for you, you are probably weird...

Anyway, I came up with an idea: what if we make a quantum in code?

Task

Create a data type, function, or class, anything that can be put in a condition.

What should it do:

(def your thing here, I'll name it "X" for now)


if X:
  part a
else:
  part b

part a and b should both be executed, although the chance of which being first should be 50/50.


if X:
  a=5
else:
  a=10
  b=5

a should have 50% chance to be 5, 50% 10, but b will always be 5

x can be different everytime mention, or always the same on parallel universe

if X:
  part a
else if X:
  part b
else:
  part c

Could be:

execute a,b,c with a 50% being first execute,b,c 25% each.(second X and first X both being quantum)

In this case a will never be the second one executed.

possible case:

a,b,c
a,c,b
b,c,a
c,b,a
     / a True 50%
init           / b True 25%
     \ a False 
               \ b False - c 25%
     First X     Second X

Or:

X True for a

X False for c

b will never be executed.

     / X True - a
init 
     \ X False - c

Example

X as your submit

if X: # or X()
  print(1)
else:
  print(2)

return

1
2

or

2
1

Extra

A whole compiler/transpiler (changing code to fit in quantum state) is allowed, but will compete on it's own(with other compiler style anwser).

Rule

  • Standard rules.

Goal

golf your quantum as smaller as possible!

Meta

  • Is this clear?
  • Is this hard?
  • Is this fun?
\$\endgroup\$
2
  • \$\begingroup\$ This doesn't make a whole lot of sense to me. You seem to be describing a code construct that takes a list of statements and executes them all in random order. By design that isn't how if/else statements work: 'part a and b should both be executed' can't happen no matter how you define X. \$\endgroup\$
    – Dingus
    Nov 18, 2021 at 3:30
  • \$\begingroup\$ @Dingus one of the possible way is to have function X read self source code, you don’t have to run excatly same code on excatly position, you can copy statement and execute it at other file/place, or just rerun program with modifications upon called. \$\endgroup\$
    – okie
    Nov 18, 2021 at 5:50
-1
\$\begingroup\$

Silly Sentence Generator

Your challenge is to input a sentence and find all words enclosed within angle brackets. (< and >)

Here is an example:

The <adjective> <noun> biked across the bridge.

Next, replace all <noun>s with a random noun, all <verb>s with a random verb, all <adjectives>s with a random adjective, and all <adverb>s with a random adverb.

According to the above rule, The <adjective> <noun> biked across the bridge. could become The daring monkey biked across the bridge.

Your program will input a list of nouns, verbs, adjectives, and adverbs.

Make sure the words follow capitalization. So if the random noun in <noun> <verb>ed is monkey, it should then become Monkey. Another rule is that if a verb (like slide) ends with e, and the bit after the <verb> is ing or s, (e. g <verb>ing) do not keep the final e. (e. g slideing becomes sliding).

Examples

Note that these examples assume the nouns are monkey and ai, the verbs jumped and sliding, the adjective daring, and any list of adverbs (since the examples don't use them.)

The <noun> was <verb>ed by the <adjective> <noun>. => The monkey was jumped by the daring ai.

<verb>ing <noun>s play together. => Sliding monkeys play together.

Shortest code wins!

\$\endgroup\$
6
  • \$\begingroup\$ I would suggest replacing the "Test cases" section with "Examples" to show some possible outputs. \$\endgroup\$ Sep 17, 2021 at 17:44
  • \$\begingroup\$ @AaronMiller Added some test cases and additional rules. \$\endgroup\$
    – Bgil Midol
    Sep 17, 2021 at 17:53
  • \$\begingroup\$ You don't specify in these cases whether you want to be including the propagation of the word lists, etc. into the code golf challenge. If this is a requisite that the population of the lists be included in the bytes, this is going to make every 'golfed' solution pretty huge, even with small word lists you've provided. \$\endgroup\$ Sep 17, 2021 at 18:15
  • \$\begingroup\$ @ThomasWard Edited. \$\endgroup\$
    – Bgil Midol
    Sep 17, 2021 at 19:00
  • \$\begingroup\$ I think it would be better to instead take the lists of words as additional inputs \$\endgroup\$
    – Mayube
    Dec 1, 2021 at 18:33
  • \$\begingroup\$ It's still not clear if we're hardcoding the words or not \$\endgroup\$ Dec 1, 2021 at 18:34
-1
\$\begingroup\$

Output sequence from a name

You are given a sequence of numbers(0-9) which you have to convert to its literal form.

Example

Input : 1246
Output : 26666

We interpret the input as one 2 four 6, thus giving the output 2 one time and 6 four times

Testcase

Input Output
1234567809 2444666668888888
2345 335555

P.S.

  1. Is this descriptive enough?
  2. Would it be fun to do?
\$\endgroup\$
1
-1
\$\begingroup\$

Can I obtain this Minecraft item?

Given a list of items I have access to, determine if I can obtain a certain amount of some other item via crafting, mining, trading, and some other actions.

Actions

This is a list of all actions which may be performed, and what items they involve

Crafting:

  • Log × 1 to Planks × 4
  • Planks × 2 to Stick × 4
  • Dirt × 2, Gravel × 2 to Coarse Dirt × 4
  • Glass × 6 to Glass Pane × 16

Mining:

The following require a wood pickaxe, or above:

  • Stone × 1 to Cobblestone × 1
  • Coal Ore × 1 to Coal × 1

The following require an iron pickaxe, or above:

  • Diamond Ore × 1 to Diamond × 1
  • Emerald Ore × 1 to Emerald × 1

The following do not require a tool:

  • Coarse Dirt × 1 to Dirt × 1
  • Gravel × 1 to Flint × 1

Smelting:

Smelting requires fuel, see below. These are the items that can be smelted:

  • Cobblestone × 1 to Stone × 1
  • Sand × 1 to Glass × 1
  • Coal Ore × 1 to Coal × 1
  • Iron Ore × 1 to Iron Ingot × 1
  • Diamond Ore × 1 to Diamond × 1
  • Emerald Ore × 1 to Emerald × 1
  • Kelp × 1 to Dried Kelp × 1

(unfinished)

\$\endgroup\$
-1
\$\begingroup\$

Biggest 25 byte number

You are allowed 25 bytes of source code.

With these you have to calculate the biggest finite number possible, assuming infinite number precision[1], runtime and memory.

You will not be taking input and do not have to output the final result.

You are not allowed to use a String representation, so "9".repeat(BIG_NUMBER) is disallowed.

Scoring will be based of the final number, bigger numbers ranking higher.

[1]: This means that for example in java you do not need to use BigInteger to represent big numbers, but using an int would be sufficient. Over- and underflows are ignored as if the int had infinite precision.

\$\endgroup\$
-1
\$\begingroup\$

[1], [2], [1, 1], [3, 2] Sequence

Challenge:

The sequence starts with [1]

And multiply by the reversed indices plus one.

And make an extra list containing 0 length of the list times.

If the number is greater than reversed indice plus two, then modulo by indice plus two, add number integer divided by indice plus two to extra list (Previous indice).

Then the next list will be the list plus an extra list.

Example (step-by-step)

RETURN [1]
[1]
[2] [0]
[2] [0]
RETURN [2]
[2]
[4] [0]
[1] [1, 0]
RETURN  [1, 1]
[1, 1]
[3, 2] [0, 0]
[3, 2] [0, 0]
RETURN [3, 2]

Test cases

TODO

Meta:

  • Suggestions?

  • Which test cases I should add?

\$\endgroup\$
2
  • \$\begingroup\$ Adding more step-by-step examples would be nice. After [3, 2], I can get to [9, 4], but I'm not sure what to do with [1, 0] ([9, 4] modulo 4) and [2, 1] ([9, 4] div 4). Also, test cases in a sequence challenge are just a list of first X terms (20 terms would be enough here I think). \$\endgroup\$
    – Bubbler
    Dec 28, 2021 at 1:51
  • \$\begingroup\$ I think a reference implementation (even in pseudocode) would be helpful. \$\endgroup\$ Jan 10 at 12:49
-1
\$\begingroup\$

Mahjong Checker

\$\endgroup\$
4
  • \$\begingroup\$ As a real mahjong player I can tell you that it may not be enoigh to have four sets and the eye pair – flowers and animals may be needed to win. \$\endgroup\$ Feb 6 at 9:48
  • \$\begingroup\$ flowers and animals are excluded in this case, makes it a little more tricky to add more possiblities to the challenge \$\endgroup\$
    – DialFrost
    Feb 6 at 9:53
  • \$\begingroup\$ I know, but this is just for your information. \$\endgroup\$ Feb 6 at 9:54
  • \$\begingroup\$ ah ok lol thx anyways i rarely play mahjong in the first place \$\endgroup\$
    – DialFrost
    Feb 6 at 10:15
-1
\$\begingroup\$

Zhiwei Sun Squares

Given a positive integer n, find the number of ordered tuples (a, b, c, d, e) over non-negative integers for which a² + b² + c² + d² = n and b + 3c + 5d = e².

Note: A conjecture by 孙智伟 (Sūn, Zhìwěi) states that this count is always at least 1.

For example, if n is 9, there are 3 solutions, namely:

(0, 0, 3, 0, 3)
(1, 0, 2, 2, 4)
(3, 0, 0, 0, 0)

Test cases:

9 -> 3
4 -> 2
24 -> 1
25 -> 5
144 -> 3
128 -> 1
365 -> 9
366 -> 21

Scoring:

This is code-golf, so shortest code wins!

Credits to this puzzle

\$\endgroup\$
-1
\$\begingroup\$

The travelling sales man problem

The travelling salesman problem (TSP) asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?"

In this puzzle not necessarily the shortest route is the answer but an approximation using a greedy algorithm (which in fact could be the shortest route as well).

This greedy algorithm starts at the first input given and always chooses the nearest point from the current point. This continues until no points are left and the last point is connected to the first point.

Use the Euclidian distance, i.e. sqrt(deltaX^2 + deltaY^2), as the distance between two cities. If there are points with the same distance, always pick the one occurring first in the list.

In general, the greedy algorithm does not find the optimal solution, but nonetheless a greedy heuristic may yield locally optimal solutions that approximate a global optimal solution in a reasonable time.

Input & Output

  • You are given an integer n and on the next n lines, you are given the x and y coordinate of the city

Test cases

5
9 12
24 15
12 30
4 3
13 27
->
71

5
25 2
5 9
22 12
15 19
0 1
->
69

12
4 5
12 80
65 18
39 29
99 11
84 31
9 9
54 49
16 27
31 67
0 71
60 0
->
403

Others

  • You are allowed to take in the input as a list of n integers

Scoring:

This is code-golf, so shortest code wins!

Credits to this puzzle

\$\endgroup\$
-1
\$\begingroup\$

Draw an Erlenmeyer flask

Given the level of liquid in the Erlenmeyer flask L in the range 0-6. Your program should draw the following ASCII art.

When L=0:

      __________
     |_        _|
       |      |
       |      |
       |      |
       |      |
       |      |
       /      \
      /        \
     /          \
    /            \
   /              \
  /                \
 /                  \
/                    \
\____________________/

When L=1:

      __________
     |_        _|
       |      |
       |      |
       |      |
       |      |
       |      |
       /      \
      /        \
     /          \
    /            \
   /              \
  /                \
 /  %%%%%%%%%%%%%%  \
/  %%%%%%%%%%%%%%%%  \
\____________________/

When L=6:

      __________
     |_        _|
       |      |
       |  %%  |
       |  %%  |
       |  %%  |
       |  %%  |
       /  %%  \
      /  %%%%  \
     /  %%%%%%  \
    /  %%%%%%%%  \
   /  %%%%%%%%%%  \
  /  %%%%%%%%%%%%  \
 /  %%%%%%%%%%%%%%  \
/  %%%%%%%%%%%%%%%%  \
\____________________/

You can change the character % to any other (excluding space), it's up to you. Trailing spaces are allowed.

This is a code-golf challenge so the shortest solution wins.

\$\endgroup\$
-1
\$\begingroup\$

Implement a complex search engine


Your job is to implement a search engine. The search engine should come with a few extra features to ensure that users can obtain the most relevant results.

Input, part 1

Your program will take a string as input. The string is composed of a bunch of words separated by spaces. Parsing the string is part of the task, so inputting as a list of words will not be allowed.

What's a word?

A word is composed of one or more lowercase letters. There may be a minus at the start of the word. If there is no minus, then there can be a double-quote at the beginning and/or end of the word. Double-quotes are closed, so "abc de is not a valid input because the double-quote is never closed, but "abc def" is valid because the double quote is closed.

The minus

A minus at the beginning of a word tells the search engine to not return results that contain that word.

Double-quotes

Double-quotes around strings tell the search engine to only return results that contain that string exactly.

Extra rules

There will never be any minus words contained within a quoted string. The minuses and quotes will never contradict, so -abc "abc" will never be given (it tells the search engine to exclude results containing abc while telling it to return only results containing abc).

The string contains only minus signs, quotes, spaces, and lowercase letters. There is at least one word that is not excluded by means of a minus.

Input, part 2

The second input will be a list of strings from which the search engine will search. The strings contain only lowercase letters and spaces. You may take a newline-separated list of strings or a list of strings in your language's native input format, or any other reasonable method to input strings. (Lists of words are not allowed.)

Output

Return all results matching the input. Your output format can be a newline-separated list of strings, or a list of strings in your language's list format. Lists of words are forbidden.

Any results that it returns must:

  • contain all of the unquoted words that do not have a minus, but not necessarily in the given order;
  • contain all quoted strings exactly;
  • not contain any excluded words indicated by a minus.

Testcases

Search query: abcdefg
List of strings: [abcdefg, abcdef, bcdefg, abcd efg]
Output: [abcdefg]

Search query: blah blah blah
List of strings: [blah, blah blah, blah blah blah, bla hbla h]
Output: [blah, blah blah, blah blah blah]

Search query: "blah blah" blah
List of strings: [blah, blah blah, blah blah blah, bla hbla h]
Output: [blah blah, blah blah blah]

Search query: my name is -not ophact
List of strings: [my name is ophact, my name is not ophact, my name is op, ophact is indeed my name]
Output: [my name is ophact, ophact is indeed my name]

Search query: "oh please help" me or "otherwise someone else"
List of strings: [oh please help me or otherwise someone who is else, oh please otherwise someone else, help me or otherwise oh someone else, or]
Output: []

Search query: -remove -all -the -most -common -words but keep "everything else"
List of strings: [guide how to remove an item from a list, words are the rest, keep everything else but not that, remove all the most common words but keep everything else]
Output: [keep everything else but not that]

This challenge is , so the shortest code, measured in bytes, wins.


Any feedback? Clarification needed? Other tags are suitable? Wrong testcase?

\$\endgroup\$
-1
\$\begingroup\$

Fort-Defense KoTH

There are two teams, red and blue. Each team has a fortress, and if one team's fortress is destroyed, (health reaches zero) the other team wins.

The red team attacks the blue team first, blue attacks red, red attacks blue, and so on until one team's fortress is destroyed. Every team has half of the total number of bots. (For an odd number of bots, one team has one more bot.)

The grid looks like this:

FBBBBB|BBBBF
FBBBBB|BBBBF
FBBBBB|BBBBF
FBBBBB|BBBBF

where B is a bot, F is the fort, and | as the border between the two teams.

\$\endgroup\$
9
  • \$\begingroup\$ What would the attacks be like? Right now it doesn't seem like much strategy is involved. \$\endgroup\$ Apr 26 at 19:14
  • \$\begingroup\$ @RadvylfPrograms i know, it isn't finished yet. \$\endgroup\$
    – Bgil Midol
    Apr 26 at 19:16
  • \$\begingroup\$ Are you planning on a 2D grid or for attacks to just be an action? If the first option, it would probably make sense for the defenders to be able to "send out" some bots to fight the attackers while others man the fort. If not, the strategy probably has to come from designing your team to work together well and to decide how many resources to allocate to fighting vs. how many for defense. \$\endgroup\$
    – Romanp
    Apr 26 at 19:20
  • \$\begingroup\$ @Romanp 2d grid \$\endgroup\$
    – Bgil Midol
    Apr 26 at 19:26
  • \$\begingroup\$ You also can choose between real-time and turn-based strategy. There haven't been many RTS KoTHs that I have seen, but it seems like an interesting idea. \$\endgroup\$
    – Romanp
    Apr 26 at 19:35
  • \$\begingroup\$ @Romanp Ooh yeah, RTS would mean writing performant bots is a major goal, something that hasn't really been explored. I've proposed an RTS KotH before, but never really did anything with the idea. \$\endgroup\$ Apr 26 at 19:45
  • \$\begingroup\$ Now I want to make a RTS game, but I'm still running my current KoTH and am planning on a fix/reboot of King of the Ziggurat (if I can get permission)... \$\endgroup\$
    – Romanp
    Apr 26 at 20:01
  • \$\begingroup\$ @Romanp whats a RTS? \$\endgroup\$
    – Bgil Midol
    Apr 26 at 20:57
  • \$\begingroup\$ Real time strategy. Pretty much, all the bots are moving at once (probably with floating point numbers) and everything is continuous. The bots probably have position/velocity values which automatically move them every tick, that sort of thing. \$\endgroup\$
    – Romanp
    Apr 26 at 20:59
-1
\$\begingroup\$

Roman Numerals... But With A Twist

I'm assuming you have some knowledge of roman numerals, but more is at Appendix A.

Fine. What's the twist?

I want it short

So, I don't want to express 1 as IIIIIIIIIX, I want it I.

And we are not Romans, come on...

Instead, you will create a program that takes in, either as a function parameter or from STDIN:

  • A dictionary to represent Roman Numerals. You can take it in any (reasonable) format, for instance: {"I":1,"V":5,"X":10,"L":50,"C":100}, "I1 V5 X10 L50 C100", or even "0111 1011 0010 0010 0100 1001 0010 0010 0011 1010 0011 0001 0010 1100 0010 0010 0101 0110 0010 0010 0011 1010 0011 0101 0010 1100 0010 0010 0101 1000 0010 0010 0011 1010 0011 0001 0011 0000 0010 1100 0010 0010 0100 1100 0010 0010 0011 1010 0011 0101 0011 0000 0010 1100 0010 0010 0100 0011 0010 0010 0011 1010 0011 0001 0011 0000 0011 0000 0111 1101". You may cast any assumption on the input format, for instance, the letters must be in increasing order, or the odd numbers come first (even though, come on, why?) Assume all numbers to be positive.

  • The number to represent. For instance, 128724235. Assume all numbers to be positive. The number will be guaranteed to be accomplishable. For instance, for the dict {"A":10,"B":58}, 2 might be given (which your program should output).

Your output would be the shortest Roman Numeral representation for the given numeral and mapping.

Example Program:

Up later...

Appendix A

  • The mapping of letters to characters is {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}

  • Every letter is added or subtracted from a total

  • The total is the value of the numeral

For the adding or subtracting, we create the following standards:

  • If there is a character that stands for a higher value at the right, for instance an X on the right of the V, the value of V will be subtracted.

  • Else, it will be added. for instance, VV is 10 and V is 5, as there are no higher numbers at the right.

Let's just keep things clear by giving an example:

10 is X, 5 is V, 1 is I, 6 is VI, 4 is IV, 2 can be IIIV, 19 is XIX, 4 can also be expressed as IVX. Note the last three.

To make things even clearer this is a decoder:

def roman_to_integer(numeral,mapping=None):
 if not mapping: mapping = {'I':1, 'V':5, 'X':10, 
  'L':50, 'C':100, 'D':500, 'M':1000}
 result = 0
 for index, character in enumerate(numeral):
  if index+1==len(numeral) or \
   mapping[character]>=max(map(lambda x: 
   mapping[x], numeral[index:])): 
    result+=mapping[character]
  else: result-=mapping[character]
 return result
\$\endgroup\$
2
  • \$\begingroup\$ I suggest specifying clearly with some words (maybe in several bullet-points) the algorithm you use for your definition of Roman numerals. \$\endgroup\$
    – pajonk
    Jun 6 at 6:37
  • \$\begingroup\$ Oh OK good point \$\endgroup\$ Jun 6 at 6:39
-1
\$\begingroup\$

Left and Right, Spsp Style

WARNING

This question is written by the Spsp language creator TvoozMagnificent` and might includes severe advertising.

Spsp

What's Spsp? Spsp is designed to be a 2D fourth generation golfing language.

What are the commands?

Good question, it is in developement, and if you want to help me, come (here)[https://chat.stackexchange.com/rooms/136645/superior-simple]. Thank you.

But three commands have been kept in Spsp and is likely to stay that way. For the Spsp in this challenge, we have simplified things.

The commands are L, R, and S, which stand for left, right, and stop. You will be given a program, for instance this: (You would probably take it as a list instead, for instance [[' ','R','S'],[' ','L','S'],['L','S',' ']]) Assume the lines to be padded to the same length.

+-+-+-+
| |R|S|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

The IP, which stands for the Instruction Pointer, Starts out at the top left cell, pointing right, so let's draw it as >. Thus, the current map looks like this:

+-+-+-+
|>|R|S|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

Now the IP tries to advance. It hits an R block, so it doesn't advance, and turns right. Now it points down:

+-+-+-+
|v|R|S|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

Now the IP can advance:

+-+-+-+
| |R|S|
+-+-+-+
|v|L|S|
+-+-+-+
|L|S| |
+-+-+-+

Now the IP can't advance again, so it turns left. This is because it points towards an L, the L at the side has no effect:

+-+-+-+
| |R|S|
+-+-+-+
|>|L|S|
+-+-+-+
|L|S| |
+-+-+-+

And turns left again to point upwards:

+-+-+-+
| |R|S|
+-+-+-+
|^|L|S|
+-+-+-+
|L|S| |
+-+-+-+

It advances:

+-+-+-+
|^|R|S|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

If the IP hits a wall, it raps. (Pun Intended) So if the IP advances, he would end up on the L marked X on this map:

+-+-+-+
|^|R|S|
+-+-+-+
| |L|S|
+-+-+-+
|X|S| |
+-+-+-+

And thus the pointer turns left:

+-+-+-+
|<|R|S|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

And the pointer advances and hits the S:

+-+-+-+
| |R|X|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

Thus the pointer stops. Your chllenge is to output the ending coordinate in some way, whether it is the mathematical coordinate system (2,2) or the index [1,3] or [0,2].

There's a small twist however. What does this program do?

+-+-+
| |R|
+-+-+
|L|S|
+-+-+

Well, the IP turns right, and then turns left, and then... yikes, that's an infinite loop! What do we output then? Well, don't output anything, but terminate the program instead of running forever. It is easy to know that if the same IP state is achieved twice, then a loop will happen.

Or, take this:

+-+
| |
+-+
|S|
+-+

The IP just wraps around and loops on the first line.

\$\endgroup\$
-1
\$\begingroup\$

Minimal number of moves needed by a knight


Given an \$N × N\$ board, what is the minimum number of moves needed by a knight to reach every square (on any given square)?

In other words, the A232007 sequence from OEIS.

Input/Output can be taken in any reasonable format, taking the size of the board and returning the number of moves (you don't need to handle 2, and 3 because the knight can't travel all of the \$2 × 2\$ and \$3 × 3\$ board)

Testcase:

8 -> 6
5 -> 4

This is , so shortest answer (in bytes) wins!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ I'd suggest removing the -1 output, and not requiring answers to handle those inputs. Adding edge cases like this tends to make the challenge quite boring to golf, because a lot of the code gets taken up by them \$\endgroup\$
    – pxeger
    Jun 6 at 17:43
  • \$\begingroup\$ Do you mean minimum or maximal? \$\endgroup\$
    – tsh
    Jun 7 at 10:31
  • 2
    \$\begingroup\$ I think this may be too simple, as it is just ceiling(2n/3) per the OEIS page. \$\endgroup\$
    – pajonk
    Jun 8 at 9:04
-1
\$\begingroup\$

The prime frog 🐸 -- Integrated.

From the original question, we make the following changes:

The "prime frog" is a strange animal that jumps between integers*, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integers n > 1 and b > 1:

  1. Let f be the position of the frog. It is initially set to n
  2. if f has been hopped on: return the smallest lilypad hopped after and including the f hopped on last time
  3. if f is prime : the frog jumps to the position b×f+1. Go back to step 2.
  4. if f is composite : let d be f's biggest prime divisor. The frog jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5, b = 4:

5 > 21 > 14 > 7 > 29 > 117 > 13x8 > 13x7 > 13x6 > 13x5 > 13x4 > 13x3 > 13x2 > 13 (I'm a bit lazy there) > 53 > 213 > 142 > 71 > 285 > 14x19 > 13x19 > snip > 38 > 19 > 77 > 66 > 55 > 44 > 33 > 22 > 11 > 45 > 40 > 35 > 28 > 21 (loop), returns 7. 

Thus the program should output 7.

Another example with n = 23, b = 3:

 23 > 70 > 63 > 56 > 49 > 42 > 35 > 28 > 21 > 14 > 7 > 22 > 11 > 34 > 17 > 52 > 39 > 26 > 13 > 40 > 35 (loop), returns 7. 

Again, the program should output 7.

Test cases:

Coming up later

Meta: is it possible for a number to go up infinitely?

\$\endgroup\$
1
-1
\$\begingroup\$

Erverse Hte Ifrst Wto Eltters fo Aech Owrd

Inspired by this accidental misspelling

If you could read the title, then you already know what the challenge is about. If not, then I'll tell you. Easy: simply take each word (space delimited), and swap the positions of the first two letters. You may assume that the input will contain only lowercase ASCII letters and spaces and that there will be no one-letter words.

Testcases

hello world -> ehloo owrld
this is an easy challenge -> htis si na aesy hcallenge
reverse the first two letters of each word -> erverse hte ifrst wto eltters fo aech owrd
\$\endgroup\$
-2
\$\begingroup\$

Every number is interesting

We know that every number is interesting but how?

You should write a program or function which:

  • takes a list of N positive integers (>0 and <2^31)
  • outputs N lines each of them showing how the corresponding input number is interesting
  • is not longer than 1024 bytes
  • uses no more than 1 second per number
  • doesn't use external sources

Examples

172: 444 in base6
5776: 76*76
9801: 9 * 1089 (reverse)
68101: no 11 in base2 (10000101000000101)
491033: 317 * 1549 (product of 2 big primes)
467808816: no digit 5 from base6 to base10

Inputs

You should include the output for the following input in your post:

58 92 120 224 358 490 912 1578 7812 222008 1645060 19796411 550453633 

If you care to run your program on a bigger sample and share the result with us use this input data (2500 numbers). (You can upload your output to e.g. pastebin.)

This is a popularity-contest so highest voted answer wins.

Tags: popularity-contest, number

\$\endgroup\$
6
  • 1
    \$\begingroup\$ What sort of criteria are necessary for defining a number as 'interesting'? I see things like square numbers, other bases, etc. But are there any specifics? I'm interested in this challenge (but worried it might be closed as too broad). \$\endgroup\$ Apr 7, 2015 at 13:18
  • \$\begingroup\$ @ASCIIThenANSI There wasn't a clear definition. That's part of the reason why I abandoned the challenge. \$\endgroup\$
    – randomra
    Apr 8, 2015 at 1:55
  • 1
    \$\begingroup\$ Would you mind if I tried taking it up? I would have to post as a new answer, because I can't directly edit. \$\endgroup\$ Apr 8, 2015 at 2:00
  • \$\begingroup\$ @ASCIIThenANSI Not at all. \$\endgroup\$
    – randomra
    Apr 8, 2015 at 2:01
  • \$\begingroup\$ @ASCIIThenANSI Where did you post it? \$\endgroup\$
    – wizzwizz4
    Jul 24, 2019 at 13:33
  • \$\begingroup\$ @ASCIIThenANSI I am also curious \$\endgroup\$
    – MilkyWay90
    Aug 27, 2019 at 23:41
-2
\$\begingroup\$

Create a Drawing Guide for a Polygram

Poor old Jim, he's just terrible at drawing polygrams, and he's asked you to create a "drawing guide" for him - an ascii polygram with numbered edges, so he can follow the instructions.

Challenge

Write a program to produce an ascii polygram with P <= 10; each edge of the polygram should be made of a single digit 0-9, showing the order in which the edges should be drawn.

Input

Your program should receive (via STDIN, as function arguments, or some other language-appropriate method): P, the number of edges/vertices of the polygram, and Q, the spacing. In the notation as per the Wikipedia link, you'll be drawing a {p/q} polygram.

Output

Either print to STDOUT or return (or something else language-appropriate) a multiline string showing the drawing guide for the given polygram. The string can be any size you like, as long as it's large enough to display a clear polygram.

Notes

Your code should be able to handle compound regular polygons as well as regular regular polygons, and also inputs of q > p/2 (poor old Jim doesn't realize that the polygram for {p/q} is the same as for {p/p-q}).

Example Output for {10,3}

              5              
             5 4             
                4            
     21     5        888     
     2 11115     8888  7     
     2    5111888 4    7     
     2     888111  4   7     
     2  888      111   7     
     8885           4117     
  8882               4 711   
 8   2 5               7  111
     25               47     
 9   5                 7    0
  9  2                 74  0 
    52                 7  0  
   9 2                 7 4   
  5 92                 7 04  
     9                 70  4 
 5   2                 7     
5    29                7    4
6666 2 9              07   33
    666              0 7333  
     2 696           337     
     2   9666     333  7     
     2    9  66633 0   7     
     2      333 666    7     
     2   339       666 7     
     2333   9    0    67     
             9  0            
               0 

Scoring

This is code-golf, so shortest in bytes wins. Tiebreaker goes to the most votes.

\$\endgroup\$
2
  • \$\begingroup\$ I have a python solution to this which is ~600 bytes, so it's definitely doable, and it's not easy... \$\endgroup\$ Apr 27, 2015 at 4:31
  • 5
    \$\begingroup\$ I think the spec needs to be more prescriptive for this to make a good question, especially since the example seems to indicate that you're not currently even prohibiting the lines from having gaps. At a minimum I would say that you should require the lines to be equivalent to those produced by Bresenham's algorithm, and specify how overlaps should be handled; at the extreme, you could tie it down so tightly that it becomes a parameterised kolmogorov-complexity. \$\endgroup\$ Apr 27, 2015 at 9:34
-2
\$\begingroup\$

Pointer to pointers to pointers to pointers

You should choose a language supporting pointers like C. And your task is simple: demonstrate a legitimate use of the most level of pointers.

You should justify your code by describing an algorithm that:

  • Has only plain text, number or an array of those as input and output.
  • You think it will make things easier to write those code as a part of the implementation of this algorithm.
  • This implementation would have optimum memory usage (only declared variables and parameters, explicitly allocated space, and the return addresses for recursive functions count).

Other rules:

  • They must be pointers to pointers directly, i.e. a pointer to an object containing a pointer doesn't count. It's better if nobody using this code will want to extend some pointer to an object later.
  • Each pointer must have a different type (if your language can somehow make them the same type).
  • You should create at least one pointer, and either dereference or compare two non-null pointers once in each level.
  • Using pointers as arrays is only half as interesting.
  • Iterators, etc, are considered in essence pointers and allowed in this challenge. But you can't define new types implementing iterators for this purpose.

\$\endgroup\$
3
  • 3
    \$\begingroup\$ Could you specify "legitimate"? This sounds a bit like code bowling (and seems to have the same issues). With enough imagination I'm sure I can justify any depth of pointers. \$\endgroup\$ Apr 30, 2015 at 17:43
  • \$\begingroup\$ @MartinBüttner Edited but, basically, it is subjective. \$\endgroup\$
    – jimmy23013
    Apr 30, 2015 at 17:57
  • \$\begingroup\$ @MartinBüttner Added a restriction to have optimum memory usage. I'm not sure whether it works. \$\endgroup\$
    – jimmy23013
    Apr 30, 2015 at 18:19
-2
\$\begingroup\$

Winning Tic-Tac-Toe lines

For a given tic-tac-toe board of size N**D (for example, a normal tic-tac-toe game is 3**2), the number of winning lines of length N is given by the expression:

$$ 2^{D-1} + \sum_{S=1}^{D-1}2^{S-1}DN^{D-S} $$

(Basically, you are summing the number of lines in each S-dimensional slice of the board.)

The challenge:

Given N and D, your answer should output a list of D-dimensional coordinates for each winning line. Input and output are any reasonable format. You can assume that both N and D are positive integers, with N > 1. (Degenerate cases of N=1, D>1 not included.)

Since this is , fastest answer wins. Please explain your algorithm!

\$\endgroup\$
7
  • \$\begingroup\$ How do you intend to determine which of two answers is fastest? \$\endgroup\$ May 12, 2015 at 19:37
  • \$\begingroup\$ yes, @randomra made the same point on chat. i'll edit this in, but i guess... i'll put together some test cases and then time them? i dunno, i was going back and forth between this and code-golf, but i'd prefer interesting and readable algorithms. \$\endgroup\$ May 12, 2015 at 20:10
  • \$\begingroup\$ i posted this here because i really want the answer, and i hate coming up with brute force solutions... :D \$\endgroup\$ May 12, 2015 at 20:16
  • 2
    \$\begingroup\$ Um. Given that you're asking people to enumerate an exponentially large set, in what sense will the answers not be brute force? \$\endgroup\$ May 12, 2015 at 20:28
  • \$\begingroup\$ well, there's brute force and then there's brute force. but really it's because i don't want to do it myself, haha. \$\endgroup\$ May 12, 2015 at 20:34
  • \$\begingroup\$ also, making use of symmetry can severely reduce the computation. \$\endgroup\$ May 12, 2015 at 20:40
  • 1
    \$\begingroup\$ I imagine that the runtime in any such algorithm will be basically proportional to the number of things you print, so there won't be any good way to improve by algorithm and the speed will be very platform-dependent. \$\endgroup\$
    – xnor
    May 12, 2015 at 23:40
-2
\$\begingroup\$

Ayn Random number generator


Inspired by xkcd 1277:

enter image description here

Write a random number generator that takes no input and generates a random integer between 1 and 100. When run less than 200 times, the frequency of all numbers needs to be between 0 and 2, but when it's ran 50 000 times, the number 42 (obviously) should have a frequence that's more than 4 standard deviations higher than the mean.

Format is code-golf. Your score is the bytecount of your code.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ 1. I think it's difficult to decide objectively whether a PRNG appears to be fair at first sight. 2. The term more often should probably be quantified. \$\endgroup\$
    – Dennis
    May 18, 2015 at 21:49
  • \$\begingroup\$ I see lots of C rand()%1000 and the like incoming... \$\endgroup\$
    – rorlork
    May 18, 2015 at 22:05
  • \$\begingroup\$ @Ypnypn I have changed the criteria to have much lower numbers so they're easier to verify. \$\endgroup\$
    – Nzall
    Jun 6, 2015 at 13:04
  • 1
    \$\begingroup\$ @Dennis I have rewritten the question to clarify what "being fair" is and what "more often" actually entails. \$\endgroup\$
    – Nzall
    Jun 6, 2015 at 13:05
  • 1
    \$\begingroup\$ 1. Are you thinking of a standalone program that you run multiple times or a function that is allowed to keep a state? In the first case, not even a perfect RNG will, with overwhelming probability, satisfy the first condition. 2. Do you mean the mean and standard deviation of a perfect, uniform RNG or the one the code implements? \$\endgroup\$
    – Dennis
    Jun 6, 2015 at 23:44
  • \$\begingroup\$ @Dennis I'm thinking of just a function AynRandom() that gets called. The frequency of numbers with a small number of iterations is subject to change, maybe from 0 to 4. The mean and Standard Deviation must be the one the code implements. \$\endgroup\$
    – Nzall
    Jun 7, 2015 at 9:49
  • \$\begingroup\$ between 0 and 2 ? so print 42 would be a valid program ? \$\endgroup\$
    – Falco
    Jun 11, 2015 at 15:32
  • \$\begingroup\$ @Falco No, because 42 would appear more than 2 times (unless you only run it twice). The problem is that I need a way to indicate that the RNG is fair with a low iteration count, but unfair with higher iteration counts. The only way I can make it work is by stating that with low iteration counts, all numbers should appear about equally often, which is either 0, 1 or 2 times. \$\endgroup\$
    – Nzall
    Jun 11, 2015 at 15:36
-2
\$\begingroup\$

Please nitpick this. If there's anything that wouldn't work or would be inconvenient, however small of an issue it is, tell me about it!
Also, suggestions for [adjective] are more than welcome.


Determine how [adjective] a number is ()

A number would be considered [adjective] if 0 is the result of multiplying its digits together, then multiplying the digits of the resulting number, then repeating until a single-digit number is produced. The more steps it takes to reach 0, the more [adjective] the number is; if the resulting number is not 0, though, the number is not [adjective] regardless of how long it took to finish.
The formula used to determine [adjective]-ness is 10-10/T where T is however many numbers it took to reach 0 (including 0 and the initial input)

Your goal is, as the title says, to write a program or function that determines how [adjective] a number is, and prints every iteration along the way. Here are some example inputs/ouputs:

in: 879
out: 879    <-       (T=1)
     504    <- 8*7*9 (T=2)
     0      <- 5*0*4 (T=3)
            <- optional newline
     6.6... <- 10-10/3 (repeating decimals can be expressed in any way you want)

in: 2468
out: 2468   <-  T=1
     96     <- (T=2) 2*4*6*8
     54     <- (T=3) 9*6
     20     <- (T=4) 5*4
     0      <- (T=5) 2*0

     8      <- 10-10/5

in: -888
out: -888  
     -512   <- -8*-8*-8
     -10    <- -5*-1*-2
     0      <- -1*0

     6.6... <- 10-10/3

in: 1344
out: 1344
     48
     32
     6

     0    <- did not produce 0, so the prog/func returns 0

Your program must follow these rules:

-Takes input from STDIN.
-Throws an "error" (printed to STDOUT) and halts immediately after input if the input has one or more 0s in it or if it's less than three digits in length. The error must be a string, and as it's supposed to be printed to stdout, cannot be one generated by the language itself (eg 1/int(min(input())) to check if it's zero). Lastly, the error message has to clearly define what the error is; ERR:0 and ERR:LEN, for example, would suffice.

Bonuses/Penalties:

-25 if it properly handles decimals. For instance, an input of 99.22 would first turn into 9*9 + 0.(2*2), or 9*9 + 0.4, and so on.


This is , so the shortest answer in bytes wins.

\$\endgroup\$
7
  • 4
    \$\begingroup\$ I don't like the +15 penalty. Whether strings are used is vague in some languages. The constant amount +15 is too little deterrent for some languages but huge for very concise ones. The fact that you've found a short solution you don't like is sign you should rethink the problem, not try to plug the hole. \$\endgroup\$
    – xnor
    Jun 17, 2015 at 7:48
  • \$\begingroup\$ @xnor that's reasonable. I suppose it is a valid way of doing it, anyway, so I removed all mention of strings in that section. Should I also inc/decrease the bonus for decimals? \$\endgroup\$
    – user39326
    Jun 17, 2015 at 22:29
  • \$\begingroup\$ The programming languages I know either don't allow throwing user-defined errors or print them to STDERR. Now, if you just want us to print a message and exit immediately... \$\endgroup\$
    – Dennis
    Jun 17, 2015 at 23:32
  • \$\begingroup\$ ...and should be printed to STDOUT. I had a feeling that wasn't clear; I edited it, is it better now? \$\endgroup\$
    – user39326
    Jun 17, 2015 at 23:33
  • \$\begingroup\$ It's the word throw that throws me off (no pun intended). To throw an error usually means something rather specific. Print an error message to STDOUT (or closest alternative) would be less confusing in my opinion. Also, since this is code golf, I think you should require specific error messages. There's no fun in losing a contest because you chose ERR:LEN and somebody else got away with EL. \$\endgroup\$
    – Dennis
    Jun 18, 2015 at 3:16
  • 5
    \$\begingroup\$ Remove bonuses altogether. It's in the list of things to avoid. \$\endgroup\$
    – mbomb007
    Mar 1, 2016 at 21:31
  • \$\begingroup\$ The error if the input contains a zero seems like a separate challenge. It may be better received if there is only one challenge. There is community support for avoiding Chameleon challenges. \$\endgroup\$
    – trichoplax
    Aug 10, 2016 at 11:40
1
121 122
123
124 125
132

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .