568
\$\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".

\$\endgroup\$
0

4559 Answers 4559

1
38 39
40
41 42
152
2
\$\begingroup\$

Is this number part of a Collatz prime sequence?

A fast step of the Collatz sequence is defined as

$$s_\mathrm{Collatz}:\mathbb{N}_\mathrm{odd}\to\mathbb{N},\quad n \mapsto \frac{3\cdot n+1}{2}.$$

Given an odd positive integer \$n\in\mathbb{N}_\mathrm{odd}\$, your task is to decide whether or not both \$n\$ and \$s_\mathrm{Collatz}(n)\$ are prime numbers.

Your program should output two distinct and unique values to represent truthiness and falseness, whereby falseness may also be represented by signalling an error.

Since \$n+\frac12(n+1)=n+\lceil\frac n2\rceil\$ for odd \$n\$, the sorted sequence of all numbers which result in truthiness in the above sense is equal to the tail of A158709.

Test cases

-8 -> -        ; undefined behavior
1  -> false    ; (3*1 +1)/2 = 4 is not prime
3  -> true     ; (3*3 +1)/2 = 5 is prime
5  -> false    ; (3*5 +1)/2 = 8 is not prime
7  -> true     ; (3*7 +1)/2 = 11 is prime
11 -> true     ; (3*11+1)/2 = 17 is prime
15 -> false    ; 15 is not prime
91 -> false    ; (3*91+1)/2 = 137 is prime, yet 91 is not
97 -> false    ; (3*97+1)/2 = 146 is not prime
\$\endgroup\$
18
  • \$\begingroup\$ What is the definition defining? Is \$p\$ a Collatz prime iff it's a prime and \$\frac{3p+1}2\$ is a prime? If \$p\$ a Collatz prime iff it's a prime and \$\frac{2p-1}3\$ is a prime? Or is a prime Collatz if either of those conditions hold? \$\endgroup\$ Sep 13, 2019 at 10:56
  • \$\begingroup\$ @PeterTaylor are they not the same thing? \$\endgroup\$ Sep 13, 2019 at 11:09
  • \$\begingroup\$ Alternative phrasing: which of \$p_1\$ and \$p_2\$ are you calling a Collatz prime? \$\endgroup\$ Sep 13, 2019 at 11:11
  • \$\begingroup\$ @PeterTaylor I mean \$p_1\$ \$\endgroup\$ Sep 13, 2019 at 11:22
  • \$\begingroup\$ So neither the input prime nor the Collatz prime need to be prime? \$\endgroup\$ Sep 17, 2019 at 7:56
  • \$\begingroup\$ "Input MAY be non-prime, in which case the output is always false (see 15)" -- did you specifically define this behavior or why is the above the case? \$\endgroup\$ Sep 17, 2019 at 8:00
  • \$\begingroup\$ @JonathanFrech I'm (personally) only interested in going from prime to prime, but I wanted to define the haviour for non-prime input. When I say 'may be non-prime' I mean, it should be able to handle it, it's an allowed/expected input but not one that gives a True output. \$\endgroup\$ Sep 17, 2019 at 10:55
  • \$\begingroup\$ To me it feels like an unnatural extra constraint. \$\endgroup\$ Sep 17, 2019 at 12:54
  • \$\begingroup\$ @JonathanFrech it's just defining how to behave with certain inputs. \$\endgroup\$ Sep 18, 2019 at 9:12
  • \$\begingroup\$ Citing Exceptional edge cases; such out-of-place definitions are generally frowned upon. \$\endgroup\$ Sep 18, 2019 at 9:56
  • \$\begingroup\$ @JonathanFrech I've changed the initial ask, and now it shouldn't be an exception \$\endgroup\$ Sep 18, 2019 at 10:23
  • 1
    \$\begingroup\$ Cf. A158709. \$\endgroup\$ Sep 18, 2019 at 10:53
  • \$\begingroup\$ @JonathanFrech Do you think this is postable? \$\endgroup\$ Apr 27, 2021 at 1:17
  • 2
    \$\begingroup\$ cf. Things to avoid when writing challenges: Prime numbers. Unless there's a mathematical way to avoid any of the existing golfed primality test methods, a task involving primality test is not very interesting. \$\endgroup\$
    – Bubbler
    Apr 28, 2021 at 6:09
  • 1
    \$\begingroup\$ @Pureferret I would not post it -- unless you can think of an interesting golf opportunity. You could, however, improve the problem at hand: there are many questions one can ask about Collatz trajectories. And if you ask for something along the lines of "decide if the given number is a multiple of the length of its Collatz trajectory", you get a less arbitrary connection of concepts whilst preserving the topic of divisibility. \$\endgroup\$ Apr 28, 2021 at 14:28
2
\$\begingroup\$

Reject tab, return to linefeed

\$\endgroup\$
3
  • 3
    \$\begingroup\$ How exactly are "printing" and "returning" distinguished? Are submissions required to be a function that also outputs to STDOUT in addition to returning a value from the function? Also, I would strongly advise against subjective criteria like having an error message related to tabs, unless they are purely for brownie points; point bonuses, especially ones that can't be judged objectively, are discouraged. \$\endgroup\$
    – hyper-neutrino Mod
    Apr 17, 2021 at 17:26
  • \$\begingroup\$ Printing and returning can be considered identical to each other for the purposes of this challenge. \$\endgroup\$ Apr 17, 2021 at 18:58
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ Apr 28, 2021 at 14:15
2
\$\begingroup\$

Solve the Alien Probe puzzle

Posted.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ The description was clear to me, without watching either video. Doesn't seem like the wording needs much improvement. \$\endgroup\$ Apr 28, 2021 at 13:54
2
\$\begingroup\$

Drawing the Mathematics Stack Exchange logo (ASCII Logos 2)

The goal is to create the Mathematics Stack Exchange logo using ASCII characters.

It looks like this.

Mathematics Stack Exchange

The exact output should look like this:

                   _
                /=/ \=\
             /=/       \=\
            |             |
            |\=\       /=/|
            |   \=\ /=/   |
            |      |      |
       _    |      |      |    _
    /=/ \=\  \=\   |   /=/  /=/ \=\
 /=/       \=\  \=\|/=/  /=/       \=\
|             |    |    |             |
|\=\       /=/|         |\=\       /=/|
|   \=\ /=/   |         |   \=\ /=/   |
|      |      |         |      |      |
|      |      |         |      |      |
 \=\   |   /=/           \=\   |   /=/
    \=\|/=/                 \=\|/=/
 /=/   |   \=\           /=/   |   \=\
|             |         |             |
|\=\       /=/|         |\=\       /=/|
|   \=\ /=/   |         |   \=\ /=/   |
|      |      |         |      |      |
|      |      |    _    |      |      |
 \=\   |   /=/  /=/ \=\  \=\   |   /=/
    \=\|/=/  /=/       \=\  \=\|/=/
       |    |             |    |
            |\=\       /=/|
            |   \=\ /=/   |
            |      |      |
            |      |      |
             \=\   |   /=/
                \=\|/=/
                   |

You must make sure the cubes should be symmetrical just like the original logo, and must make space to create a 6-point star in the middle. Yes, the output looks messed up, but it's all I can do to really make a shape.

Remember, 6 boxes aligned as a hexagon.

Can you draw it with the least bytes possible?


Tags: ,

Any suggestions?

If this question reaches a score of 4, it will be posted on 12:00 PM UTC, 1 month after Stack Overflow's.

\$\endgroup\$
0
2
\$\begingroup\$

KoTH - JS WarBots

Based on King of the Hill: Robot Battle

Rules and Instructions

Program a bot as an object in JavaScript. The functions that can be called are:

  • left(name) Moves left 1 unit (x position -1)
  • right(name) Moves right 1 unit (x position +1)
  • up(name) Moves up 1 unit (y position -1)
  • down(name) Moves down 1 unit (y position +1)
  • forward(name) Moves forward 1 unit (z position -1)
  • backward(name) Moves backward 1 unit (z position +1)
  • mine(name) Places a mine at current position (bots can be blown up by their own mines, with a 1 tick delay before priming)
  • scan(name) Scans for mines and players in adjacent cells (cells a bot can move to). Returns an array [left, right, up, down, forward, backward]. Each element can be 0 (nothing there) 1 (mine) 2 (other bot).
  • pass(name) Do nothing

name is the name of the bot. Any bot whose action's name is not the name of the bot will be disqualified (if your bot is called "Foo" you must have pass("Foo") and not pass("foo") or pass("Bar"))

The 3D arena is a 1000x1000x1000 cube, centered at (0,0,0). Each turn of a game, every bot must select one of the above actions to perform. Every 10 turns (subject to change) minesweeping will occur, removing 50% of the existing mines to reduce camping.

A bot is eliminated from a game if:

  • It is in the same position as a mine.
  • It exits the game area.
  • It collides with another bot (both bots are eliminated).
  • The cell that it occupies does not have integer coordinates ((0,0,0) is valid, (0.5,0,0) is not)

Scoring

After 1000 turns, if a bot is not eliminated, it receives Math.floor(1000/bots) points, where bots is the number of bots left. If a bot eliminates another bot by mining it, it receives 100 points. If there are no bots left after 1000 turns, nobody gets any points.

Formatting your bots

Here are examples of bots (These will be playing too!):

RandomBot

var RandomBot = { // Same name as the name property
    name: "RandomBot",

    x: Math.floor(Math.random() * 1000 - 500), // If unspecified, defaults to 0.
    y: Math.floor(Math.random() * 1000 - 500), // If unspecified, defaults to 0.
    z: Math.floor(Math.random() * 1000 - 500), // If unspecified, defaults to 0.

    turn: () => {
        var action = Math.ceil(Math.random() * 9)
        if (action == 1) { left("RandomBot") }
        else if (action == 2) { right("RandomBot") }
        else if (action == 3) { up("RandomBot") }
        else if (action == 4) { down("RandomBot") }
        else if (action == 5) { forward("RandomBot") }
        else if (action == 6) { backward("RandomBot") }
        else if (action == 7) { mine("RandomBot") }
        else if (action == 8) { scan("RandomBot") }
        else { pass("RandomBot") }
    }
}

May the best bot win!

The challenge will be posted later when it receives sufficient votes and the controller is developed. If there are any questions regarding this challenge, please comment about it.

\$\endgroup\$
13
  • 2
    \$\begingroup\$ Is there anything preventing a bot from placing six mines around itself, then never moving? \$\endgroup\$ Apr 30, 2021 at 16:03
  • \$\begingroup\$ @RedwolfPrograms Do you have any suggestions on preventing that? \$\endgroup\$
    – WarpPrime
    Apr 30, 2021 at 16:33
  • \$\begingroup\$ @RedwolfPrograms I've created another rule regarding camping. \$\endgroup\$
    – WarpPrime
    Apr 30, 2021 at 16:44
  • 1
    \$\begingroup\$ I think the problem is less camping itself, and more just that I don't think there's very much strategy possible. The current restriction is trivially beatable by just enclosing yourself in a 1x1x2 space and moving back and forth. \$\endgroup\$ Apr 30, 2021 at 17:41
  • \$\begingroup\$ @RedwolfPrograms Maybe there should be a limit on how many mines you can place? \$\endgroup\$
    – WarpPrime
    Apr 30, 2021 at 17:57
  • 1
    \$\begingroup\$ That could lead to some interesting gameplay, but might actually make the camping problrm worse because it takes very few mines to do. I'd recommend writing a few rough bots on a sheet of paper, and running some games in your head, then seeing what makes it fun and what could use some improvement. I think there needs to be more room to do interesting things; currently there's not really much strategy beyond "don't run into mines". \$\endgroup\$ Apr 30, 2021 at 18:20
  • 1
    \$\begingroup\$ @RedwolfPrograms I came up with an idea regarding the issue that you brought up. There could be a minesweeper that runs every 10 or so turns where 50% of mines are removed. \$\endgroup\$
    – WarpPrime
    Apr 30, 2021 at 19:15
  • 1
    \$\begingroup\$ I think the idea behind that is good, but it has the same problem of being easily fixable by campers, and also removing plenty of mines set up by other players. \$\endgroup\$ Apr 30, 2021 at 20:39
  • 1
    \$\begingroup\$ @RedwolfPrograms I will consider new methods for the issues in the challenge. \$\endgroup\$
    – WarpPrime
    Apr 30, 2021 at 20:43
  • 1
    \$\begingroup\$ Should I move this to chat? \$\endgroup\$ Apr 30, 2021 at 20:48
  • \$\begingroup\$ Sure, I moved it.. \$\endgroup\$
    – WarpPrime
    Apr 30, 2021 at 20:51
  • \$\begingroup\$ Just wondering, why use functions rather than return values? e.g. having the bot return "left" rather than call left("name"). Also, right now, this just seems like a 3D version of Robot Battle. The three-dimensionality might actually be a bad thing, though, since it makes it harder to trap bots using mines. Like Redwolf, I also encourage you to think about the rules and the strategy of the game to try to allow for more strategy, and to differentiate it from the challenge it's based off of. \$\endgroup\$
    – user101133
    May 4, 2021 at 2:37
  • \$\begingroup\$ Also, the camping can be reduced to scanning, going into a corner, placing three mines around you, and waiting. \$\endgroup\$ May 4, 2021 at 5:54
2
\$\begingroup\$

xkcd 2385

\$\endgroup\$
1
  • \$\begingroup\$ Now that this has been posted, it should probably be edited down and deleted. \$\endgroup\$ May 3, 2021 at 1:38
2
\$\begingroup\$

How many Faro Shuffles for a cycle?

\$\endgroup\$
1
  • \$\begingroup\$ @Pureferret it has been! \$\endgroup\$
    – pxeger
    May 3, 2021 at 13:27
2
\$\begingroup\$

Produce a range

Your task is to take a list of integers and find inputs to a Python range call to produce that list. That is, output three values (start, stop, step) so that range(start, stop, step) equals the given list.

You can assume that this is possible, which means that consecutive numbers in the list all have the same nonzero difference. Be careful that your code works for negative step sizes, as well as for empty or singleton inputs.

How range works

Python's built-in range produces a list* of equally-spaced numbers. Called as range(start, stop, step), it counts from the start value in increments of step like

[start, start + step, start + 2 * step, ...]

This list continues as long as the value is below stop given positive step, or above stop given negative step. If the start value already fails this test, an empty list is produced. Note that the stop value itself is never included in the list, giving a half-open interval.

range(0, 5, 1)   = [0, 1, 2, 3, 4]
range(0, -5, -1) = [0, -1, -2, -3, -4]
range(0, 2, -1)  = []
range(0, -2, 1)  = []
range(3, 4, 10)  = [3, 7]
range(3, 4, 11)  = [3, 7]
range(3, 4, 12)  = [3, 7, 11]
range(1, -2, 0)  = [1]

*In Python 3, it actually makes a range object, but we'll ignore that distinction.

Test cases

Note that there can be multiple valid inputs. Different stop values can cut off the result at the same point when the step is not ±1. A singleton or empty list can be produced in many ways.

TODO

\$\endgroup\$
4
  • \$\begingroup\$ Is this return {a[0], a[-1]+sign(a[1]-a[0]), a[1]-a[0]}? \$\endgroup\$ May 7, 2020 at 15:43
  • \$\begingroup\$ @mypronounismonicareinstate I think that works for inputs with 2+ elements, though the empty list and singleton list also need to be handled. Is this too simple for a challenge? \$\endgroup\$
    – xnor
    May 7, 2020 at 19:32
  • \$\begingroup\$ (I just noticed this might work in languages with modular indexing) This is probably not too simple, and I like the idea, but it seems like most of the complexity here comes from these special cases. \$\endgroup\$ May 8, 2020 at 2:46
  • \$\begingroup\$ Both Python 2 and Python 3 disagree with step=0 in range. range(1, -2, 0) would raise ValueError instead. Is this intend behavior in this challenge? Also, some languages (Matlab) would support range with floating point values, which some floating point errors may introduced. If you are not aiming to work on floating point errors, maybe add a integer tag. \$\endgroup\$
    – tsh
    May 11, 2021 at 2:24
2
\$\begingroup\$

Are You My Mother? (very WIP)


(coincidentally, thought up around mother's day)

Oh no! All the newly-hatched ducklings have been mixed together, and they all look the same! The ducklings want to reunite with their own mother. But the mothers are also selfish and want as many ducklings as possible to go home with them. Since all the ducks look the same, the only way to tell who your mother is is by how she acts.

Your task is to write two bot algorithms: one for the mother duck and another for the ducklings.

The game

There are 5 ducklings for each mother duck

All submissions compete at the same time

Finding your mother

All of the ducklings line up in a 1-dimensional array in the pond, as do the mother ducks. They do not move around.

Each turn, each duck (either duckling or mother duck) can do one of the following actions:

  • Do nothing
  • Quack
  • Flutter its wings
  • Splash
  • Spin around
  • Shake its head
  • Put its head underwater
  • some other action

Each duckling will see the actions of each mother duck on each turn

After 20 turns, each duckling guesses which half of the mother duck array contains its mother (the upper half will get the mother duck in the middle when there are an odd number of mothers) and the process continues until each duckling has narrowed down to a single mother duck.

Duck(ling) limitations

Ducklings are young and have poor memory. They cannot remember how long they have been lined up and can only remember the last thing each mother duck did when deciding what action to take. The only working memory available to ducklings is a single integer between 0 and 15, inclusive.

Mother ducks have a bit more memory and can remember five integers between 0 and 15, inclusive.

Scoring

Score 1 point for each of your ducklings that went home with its mother. Score 1 point for each duckling (regardless of whose it is) that went home with your mother duck.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Controller/submission language? (suggesting ecmascript if you haven't already written one) \$\endgroup\$
    – Wezl
    May 7, 2021 at 23:19
  • \$\begingroup\$ @Wezl yeah, probably Javascript \$\endgroup\$
    – Beefster
    May 10, 2021 at 15:53
  • 1
    \$\begingroup\$ The narrowing logic might be a bit unfair if, say, a duckling is unsure about two ducks, but they are in different halves, while another duckling is unsure about two ducks that are next to each other, so has much more time to decide. Plus, I think, 4 bits are very little storage; I'd allow at least 16 or 32 bits, which is a bit more but still limiting. \$\endgroup\$
    – FZs
    May 18, 2021 at 16:05
  • \$\begingroup\$ @FZs I've considered the alternative of letting each duckling have 1-on-1 time with each mother duck, after which they can decide whether to go home with her or not. But they do not get a second chance. Not sure how to handle orphan ducklings there though. \$\endgroup\$
    – Beefster
    May 18, 2021 at 16:19
  • \$\begingroup\$ And what if the ducklings had to return a mother index on the choice-time? Or if the ducklings had to return an array of mother indices, and on the subsequent turns, it'd only receive info about the ones it chose previously; finally, after n turns, they have to decide? These are just ideas, so you don't have to accept them as they are... \$\endgroup\$
    – FZs
    May 18, 2021 at 17:38
2
\$\begingroup\$

Modify to Increment: Javascript Edition (WIP)


Your task is to insert bytes/characters into the previous answer such that it outputs the next number in sequence, spelled out in English, as its return value. The first answer must output one.

Coding restrictions

Your answer's code must be atomically irreducible, meaning that if it is possible to remove some subset of lexical tokens from the code and have it produce the same output, then it is an invalid answer. Note that this is a distinctly different concept from removing characters from the code, as it treats identifiers, string literals, numbers, and operators as indivisible entities. For the purposes of this challenge, a comment is considered a lexical token, so commenting out parts of the previous answer is not allowed by virtue of this restriction.

Some tokens are not subject to this restriction:

  • The declaration keywords let, var, and const
  • Semicolons

Note that removing an operator between two tokens does not merge the tokens together into one token, so removing the + from 1+1 would result in 1 1 rather than 11

SANDBOX NOTE: I'm debating whether this should be tightened up to character-wise irreducibility, but I'm thinking that may be too restrictive and be too difficult to chain. On the other hand, quoting and escaping into an ever-growing .substring call seems to be a pretty easily-exploited loophole here. Perhaps a simple bandaid solution would be to ban more than 3 consecutive backslashes. Though perhaps this isn't a problem at all because answers will be trying to make it as hard as possible to chain.

Multi-digit spelling

For numbers above 20, the result should be spelled with multiple words. You may use spaces, hyphens, or underscores to separate words and this does not need to be consistent. (e.g. twenty three can be followed by twenty-four, and one hundred-thirty four is valid even though the spelling looks weird)

Should this challenge reach more than 100 answers, the expected format should be like one hundred thirty six rather than a hundred thirty six. You may optionally insert and between hundred and the next word.

Example

Answer 1

_=>'one'

Answer 2

_=>'twone'.substring(0, 3)

Answer 3

_=>'threewone'.substring(0, 3+2)

Answer 4

_=>'thfoureewone'.substring(02, 3+2+1)

Answer 5

_=>'thfoureewone'.replace('our', 'iv').substring(02, 3+2+1)

Rules and Scoring

  • You may not comment out part or all of the previous answer.
    • This includes pseudo-commenting such as enclosing code in strings, using the comma operator to no-op parts of the code, or wrapping blocks in if(0)
  • The case of the output does not matter (e.g. OnE is just as valid as oNE)
  • No third-party libraries or vendor-specific features are allowed. The only features allowed are those found in the ECMAScript standard library as of May 14, 2021.

The first answer to go 7 days (i.e. 168 hours) without a successor is the winner.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ Looks like an interesting challenge idea! I think more formally defining what "pseudo-commenting" entails would help. For example, would [a, b][0] be invalid? What about 0 ? a : b? Also, I think you need to formalize what answers need to output; there are a couple different ways to spell english words. For example, is 147 "a hundred forty seven", "one hundred forty-seven", "one hundred and forty-seven"? etc. \$\endgroup\$
    – hyper-neutrino Mod
    May 13, 2021 at 19:09
  • 1
    \$\begingroup\$ I think an "irreducible" requirement may help this question. How should multi-digit numbers be spelled? \$\endgroup\$
    – Razetime
    May 14, 2021 at 11:54
  • \$\begingroup\$ @Razetime Could you elaborate on irreducibility? The only thing that comes to mind is to require that the solution will not output the correct number spelled out if some subset of characters are removed \$\endgroup\$
    – Beefster
    May 14, 2021 at 15:17
  • \$\begingroup\$ yeah that is pretty much the exact definition. \$\endgroup\$
    – Razetime
    May 14, 2021 at 15:19
  • \$\begingroup\$ I think strict irreducibility might make it too hard to chain, though it does trivially ban comments and pseudo-comments. \$\endgroup\$
    – Beefster
    May 14, 2021 at 15:28
  • \$\begingroup\$ Try x=>'Xforty-two'.slice((function(){/* w h a t e v e r p r e v i o u s a n s w e r w i t h s p a c e s i n s t e r e d i n t o e v e r y 2 c h a r a c t e r s */}+'').length===155) \$\endgroup\$
    – tsh
    May 17, 2021 at 7:30
  • \$\begingroup\$ @tsh maybe irreducibility isn't the right solution. Maybe the limitation needs to be a maximum number of characters added. \$\endgroup\$
    – Beefster
    May 17, 2021 at 14:38
  • \$\begingroup\$ An alternative would be to make adding to the solution also be atomic, so 'one' cannot become 'twone' \$\endgroup\$
    – Beefster
    May 17, 2021 at 14:47
2
\$\begingroup\$

Just Enough Ones

\$\endgroup\$
1
  • \$\begingroup\$ Looks good to me. Not a big fan of OEIS questions in general, but this is one of the better ones. \$\endgroup\$ May 12, 2021 at 19:09
2
\$\begingroup\$

An approximation for factorials of reals

One approximation for factorial function of reals is the following function:

\$ F_0(x) = \lfloor x \rfloor ! { \lceil x \rceil } ^ { x - \lfloor x \rfloor } \$

The function is less inaccurate for higher values of \$ x \$, meaning that you can get better approximations using the following recursive definition:

\$ F_{n+1}(x-1)=\frac1x{F_n(x)} \$

Examples:

\$ F_0(\frac72)=3!\times4^{1/2}=12 \$

\$ F_1(\frac52)=12/\frac72=\frac{24}7 \$

\$ F_2(\frac32)=\frac{24}7/\frac52=\frac{48}{35} \$

\$ F_3(\frac12)=\frac{48}{35}/\frac32=\frac{32}{35} \$

\$ F_4(-\frac12)=\frac{32}{35}/\frac12=\frac{64}{35} \$

Given non-negative integer \$n\$ and real (well, floating-point) \$x>-n\$, please calculate \$ F_n(x) \$.

This is , so the shortest program or function that breaks no standard loopholes wins!

Bonus brownie points for using your code to approximate \$ \lim_{n\to\infty}F_n(-\frac12) \$:

\$ F_1(-\frac12)=2 \$
\$ F_2(-\frac12)\approx1.89 \$
\$ F_3(-\frac12)\approx1.85 \$
\$ F_4(-\frac12)\approx1.83 \$
\$ F_5(-\frac12)\approx1.82 \$
\$ F_6(-\frac12)\approx1.81 \$
\$ F_7(-\frac12)\approx1.80 \$
\$ F_{10}(-\frac12)\approx1.79 \$
\$ F_{18}(-\frac12)\approx1.78 \$
\$ F_{88}(-\frac12)\approx1.77 \$

\$\endgroup\$
2
\$\begingroup\$

Optimal addition subtraction chain

Posted

\$\endgroup\$
7
  • \$\begingroup\$ Maybe consider order testcases simply from -4 to 16? (Without sorted on their output length) Also, maybe add some larger testcases (no need to list all possible solutions if there are too many. maybe you can show one possible solution, and answers need to having same length output) \$\endgroup\$
    – tsh
    May 14, 2021 at 4:01
  • \$\begingroup\$ @tsh I can add slightly bigger test cases, but there are no known efficient algorithms to calculate it, so I'm bounded by about 100 \$\endgroup\$ May 14, 2021 at 4:14
  • \$\begingroup\$ Okay, after larger testcases added, it is not equal to oeis.org/A056792 now. :) \$\endgroup\$
    – tsh
    May 14, 2021 at 5:30
  • \$\begingroup\$ I believe that one can construct the answer without brute force search. So don't worry about it bound. It is up to you to decide if brute force search is allowed: If allowed, you may say "your program should be able to calculate answers for |n| < 100, and your algorithm should apply to any size n in theory"; If not, you could say "your program should be able to compute up to \$\pm 10^8\$ in reasonable time (not time out on tio for example)" in the question. \$\endgroup\$
    – tsh
    May 14, 2021 at 5:45
  • \$\begingroup\$ @tsh from wikipedia: "the determination of a minimal addition-subtraction chain is a difficult problem for which no efficient algorithms are currently known" \$\endgroup\$ May 14, 2021 at 5:47
  • \$\begingroup\$ If i understand that statement correctly, it means an efficient (or polynomial) algorithms in \$O(P(\log_2 n))\$ is not exist. But A solution works under, say, \$O(n)\$ or maybe \$O(n^2)\$ is still possible. \$\endgroup\$
    – tsh
    May 14, 2021 at 5:58
  • \$\begingroup\$ Maybe, but I'm also not aware of any pseudopolynomial algorithm which solves it \$\endgroup\$ May 14, 2021 at 6:01
2
\$\begingroup\$

Convert version string to pack_format

Posted

\$\endgroup\$
1
  • \$\begingroup\$ @Arnauld thanks, fixed \$\endgroup\$ May 16, 2021 at 16:52
2
\$\begingroup\$

Telephone Cipher Encoder

The telephone cipher is a relatively basic cipher originating from the book The Terrible Two. The cipher is explained here as follows:

Does this keypad (below) look familiar? It does? Good. You’ve seen a phone before.

Keypad

Now, in the telephone cipher, there are two numbers for each letter. The first digit corresponds to the number on a telephone, while the second digit corresponds to the position on the key.

For example:

21 = A

Why? Because A is located on the number 2 on the keypad and A is in the first position of that particular key.

22 = B

B is located on the 2 key and is in the second position of that key.

53 = L

L is located on the 5 key and is in the third position on that key.

Given an input string s, the program should output the string encoded with the telephone cipher.

s may contain single spaces between words, but will not have leading or trailing whitespace and will use only lowercase letters a-z. s will always have a length greater than or equal to 1.

The output should contain no whitespace and be properly encoded with the telephone cipher as described above.

As an example, the following input:

hello world

Should result in:

42325353639163735331

All usual loopholes are disallowed. This is code golf so shortest answer in bytes wins. May the odds be ever in your favor!

\$\endgroup\$
2
  • \$\begingroup\$ What about the evens? :P \$\endgroup\$
    – Makonede
    May 18, 2021 at 21:15
  • 2
    \$\begingroup\$ Back to the days mobile didn't have a touch screen, I typed 4433555 555666 instead of 4232535363 for hello... \$\endgroup\$
    – tsh
    May 19, 2021 at 2:58
2
\$\begingroup\$

Calculate \$ \lfloor n \log_2(n) \rfloor \$, exactly

Given an integer \$ 2 \le n \$, you need to calculate \$ \lfloor n \log_2(n) \rfloor \$, assuming all integers in your language are unbounded.

However, you may not ignore floating-point errors - for example, in python lambda n:int(n*math.log2(n)) is an invalid solution, because for example for n=10**15, int(n*math.log2(n)) is 49828921423310432, while the actual answer is 49828921423310435.

Rules

Test cases

2 -> 2
3 -> 4
4 -> 8
5 -> 11
6 -> 15
7 -> 19
8 -> 24
9 -> 28
10 -> 33
100 -> 664
1000 -> 9965
10000 -> 132877

10 brownie points for beating my 4 byte 05AB1E answer.

This is code golf, so the shortest answer wins. Good luck!

\$\endgroup\$
2
\$\begingroup\$

Symmetrical Triangles, posted


Meta Questions

  • Dupe?
  • More tags?
  • Should I allow/disallow more output formats?
  • Is "An equilateral triangle array" clear, or is there a way I can clarify it?
  • Especially relevant test cases?
  • Is there an easy way to take up less vertical space and still have a good amount of test cases?
\$\endgroup\$
6
  • \$\begingroup\$ This might not actually be more clear, but I think you can describe it as "output w lists of sizes [1, 2, ..., w] of 1/0s such that the total number of 1s is equal to n and each sublist is a palindrome". \$\endgroup\$
    – hyper-neutrino Mod
    May 17, 2021 at 20:51
  • 1
    \$\begingroup\$ open-ended-function? \$\endgroup\$
    – pxeger
    May 19, 2021 at 15:29
  • \$\begingroup\$ @hyper-neutrino it doesn't have to have each sublist a palindrome to be symmetrical \$\endgroup\$
    – pxeger
    May 19, 2021 at 15:30
  • \$\begingroup\$ When I first read this, I thought that it only took one input n, and had to output a n-sized triangle with n 1s. Now I realise that the size is a different input, but I think it could be more interesting if n == w? \$\endgroup\$
    – pxeger
    May 19, 2021 at 15:31
  • \$\begingroup\$ @pxeger I don't think that makes it more interesting, especially since it removes the point of the challenge (arranging the 1s), by allowing them to be always placed at the bottom of the triangle. \$\endgroup\$
    – Wezl
    May 19, 2021 at 15:34
  • \$\begingroup\$ @Wzl ah, I didn't think of that \$\endgroup\$
    – pxeger
    May 19, 2021 at 15:43
2
\$\begingroup\$

Prime Factorization - but on the exponents too

\$\endgroup\$
3
  • \$\begingroup\$ There seems to be a stray double-quote here: "2^(2^2^2)*(3^2). Should it be removed, or should there be a matching one at the end? \$\endgroup\$
    – pxeger
    May 28, 2021 at 8:57
  • \$\begingroup\$ There shouldn't be in the output - it was just to show the string format \$\endgroup\$ May 28, 2021 at 8:58
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ Jun 1, 2021 at 23:12
2
\$\begingroup\$

Combinatorial Pipes

You're a plumber working on a house, and there's some pipes that must be connected at odd angles. You have 8°, 11.25°, 22.5°, 45°, and 90° fittings at your disposal, and you want to use as few as possible to match the angle as closely as possible.

Goal

  • Match the desired angle as closely as possible, with as few fittings as possible. It can be over or under the desired angle.
  • Accuracy is more important than the number of fittings
  • In the case of two different sets of fittings with the same resulting angle, whichever has the fewest number of fittings should be selected.
  • If the two sets use different fittings, match the same angle, and have the same number of fittings, either may be chosen.

Input

Your input is a random integer between (non-inclusive) 0 and 180, which represents the desired angle.

Output

Your output should be an array where [0]-># of 8° fittings, [1]-># of 11.25° fittings, etc. If your language does not support arrays, you may output a comma separated list, where the first value represents the number of 8° fittings, and so on and so forth.

Test Cases

90° ->[0,0,0,0,1]
24°-> [3,0,0,0,0] ([0,0,1,0,0] uses less fittings, but is less accurate and therefore incorrect)
140°->[2,1,2,0,1]
140°->"2,1,2,0,1" acceptable if language does not support arrays

Scoring

Lowest byte count for each language wins a high five from me if we ever bump into each other (and the challenge).

Sandbox Questions

Howdy! I feel like this could be an interesting golf, but I'm unsure if the language is clear and concise enough to get the idea across.

\$\endgroup\$
1
  • \$\begingroup\$ Might be interesting to make it more general, give a list of possible pipe fittings as an argument? \$\endgroup\$
    – rak1507
    Jun 16, 2021 at 9:12
2
\$\begingroup\$

Decode USB packets

Posted

\$\endgroup\$
2
\$\begingroup\$
\$\endgroup\$
2
  • \$\begingroup\$ Does this not basically boil down to base-conversion? \$\endgroup\$
    – pxeger
    Jun 9, 2021 at 12:59
  • \$\begingroup\$ @pxeger Base conversion will not work. For one base conversion generally ignores leading zeros, while 00010 /= 10, so its not a bijection. But even if you ignore that it's nowhere near monotonic. 11 > 100 but f(11) = 10 < 11 = f(100). \$\endgroup\$
    – Wheat Wizard Mod
    Jun 9, 2021 at 13:25
2
\$\begingroup\$

Remove All Comments From Smalltalk for Code Golf

Duplicate?

Edge cases?

Not interesting/challenging?

Tags?

\$\endgroup\$
6
  • 2
    \$\begingroup\$ May string contains \" as escaped characters? \$\endgroup\$
    – tsh
    May 31, 2021 at 8:05
  • \$\begingroup\$ I might suggest changing ` to a different character, simply because it's hard to use in markdown \$\endgroup\$
    – pxeger
    May 31, 2021 at 8:43
  • \$\begingroup\$ @tsh no ;) \$\endgroup\$
    – Wezl
    May 31, 2021 at 16:20
  • 1
    \$\begingroup\$ Suggest testcases with multiple groups of strings, multiple groups of comments, and their combination: "a"b"c", 'a'b'c', a'"'b'"'c, a"'"b"'"c \$\endgroup\$
    – tsh
    Jun 1, 2021 at 6:19
  • \$\begingroup\$ I'm not sure if this'd be very interesting, since it's just a matter of replacing /"[^"]"/ if I'm correct. \$\endgroup\$
    – user
    Jun 10, 2021 at 1:03
  • \$\begingroup\$ @user I think there's a misunderstanding. The program must also not remove comments in strings, such as 'a"b"c' is not changed \$\endgroup\$
    – Wezl
    Jun 10, 2021 at 1:23
2
\$\begingroup\$

Determine Centrosymmetric String

, ,

Let's define a centrosymmetric string as follows:

  • First, add spaces to the end of each line to make the input a rectangle \$ A_{m×n} \$.
  • The input is "centrosymmetric" string if and only if you get the original rectangle if you rotate the rectangle 180°. That is, it has 2-fold rotational symmetry, so \$ A_{i,j}=A_{m+1-i,n+1-j} \$ holds for all \$ A_{1\dots m, 1\dots n} \$.

Input

Input a non-empty string. You may assume it:

  • does not contain leading / trailing new lines;
  • does not contain trailing spaces on any lines;
  • only contains new line, space, and lowercase a-z.

You may choose to handle any of CR, LF, or CR-LF as the new line character in your program.

Input may be in any reasonable format, including but not limited to:

  • A built-in string type;
  • A NULL-terminated character array;
  • An array of integer code-points;

Note that you are not allowed to take the string padded already as it trivialises the challenge.

Output

Determine if the given input is a centrosymmetric string (as defined in this post), outputting two distinct values, or truthy vs. falsey values (they can be swapped relative to their normal meaning).

Test cases

Truthy

a
aba
a
b
a
ab
ba
abc
cba
abc
ded
cba
a a
a

a
a

 a
a c
 b
c a
a

 b
 b

  a
zzzzz
   z
  z
 z
zzzzz
n  n  oo   oo  n  n
nn n o  o o  o nn n
n nn o  o o  o n nn
n  n  oo   oo  n  n

Falsy

ab
a
a
b
a
 b
a
ab
ab
aa
bb
   a
  a a
 aaaaa
a     a
\$\endgroup\$
7
  • \$\begingroup\$ I think a worked-through example would be a good idea \$\endgroup\$
    – pxeger
    May 31, 2021 at 8:29
  • \$\begingroup\$ What is the meaning of the 2 in A_{m×n}2? \$\endgroup\$
    – pxeger
    May 31, 2021 at 8:37
  • \$\begingroup\$ Related \$\endgroup\$
    – pxeger
    May 31, 2021 at 8:39
  • \$\begingroup\$ When you say "square", do you actually mean "rectangle"? \$\endgroup\$
    – Bubbler
    May 31, 2021 at 8:40
  • 1
    \$\begingroup\$ @pxeger the 2. is accidentally left there after I remove the line break between 1. blah 2. blah. Should be removed. \$\endgroup\$
    – tsh
    May 31, 2021 at 8:44
  • \$\begingroup\$ @Bubbler changed to rectangle. I'm not quite sure about these words. \$\endgroup\$
    – tsh
    May 31, 2021 at 8:44
  • \$\begingroup\$ @tsh A square is a rectangle with all side lengths the same, so m == n. Sometimes in English, "square" is used as an adjective to simply mean "having right-angled corners", which is quite confusing \$\endgroup\$
    – pxeger
    May 31, 2021 at 8:46
2
\$\begingroup\$

Is there a left-right connection?

Task

Given a square array of 0s and 1s, determine whether or not there exists a path of 1s connecting the leftmost and rightmost columns. A path can take steps of one unit up, down, left or right, but not diagonally. Every symbol on the path must be a 1, and it must start somewhere in the first column and end somewhere in the last column.

Shortest code in each language wins.

Examples

000
111   ->  True
111

110
110   ->  False
110

101
010   ->  False
101

0     ->  False

1     ->  True

11110
00010
01110 ->  True
01000
01111

11110
00010
01100 ->  False
01000
01111

Notes

The array may be represented in any reasonable form, such as a list of lists [[0,0,0],[1,1,1],[1,1,1]] or a string '000 111 111'. It can optionally be in transposed form (so that the roles of rows and columns are exchanged; equivalently the code can instead determine whether there is a top-bottom connection). Any two distinct symbols can be used in place of 0 and 1. The output can be in any truthy/falsy form.

\$\endgroup\$
2
\$\begingroup\$

Consecutive Distance Rating

Posted

\$\endgroup\$
1
  • \$\begingroup\$ This is really neat! Simple, elegant, but nontrivial. It'd be interesting to look at the sum and its growth given an (OEIS) sequence. \$\endgroup\$
    – AviFS
    Jun 12, 2021 at 1:25
2
\$\begingroup\$

Title: Make a WebCrawler dictionary writer.

Notice: for any text within <> tags, please ignore any .'s. These are simply added so that they are treated as plain text, and not code.

Your goal is to make a program that acts as a regular WebCrawler, but also writes a dictionary using the websites.

You should have a list that is used to store words that have been added called Dictionary, and another list to store website urls called NextSites. You should also have a variable called sites, and a variable called input2. Any other variables or lists are optional.

It should ask for input upon running the program, allowing you to input a website url, from where it will start web crawling. How it asks for input does not matter, so long as you are able to use any website as input. It should then ask for input again, allowing you to chose how many sites it should continue for. The variable much should be set to this input.

Next, it should check the website for any text contained within <.p> tags. It should separate the text contained within the tag at any space contained in it. Next, it will compare each part that has been separated against the current text in the list used to store words. Any part that is not already in the list should be added to it.

After it has checked all of the text within the <.p> tags on the site, it should check for any <.a> tags on the site. Any urls that it finds in the 'href' part of the <.a> tag should be added to the website url list, so long as the url list is not larger than 99 urls. (This means that the maximum amount of urls that can be in the url list at any one time is 100).

When all of the <.a> tags on the site have been checked for urls, it should change the current site it is on to the first site in the list of urls. It should remove this url from the list, and move all other urls to the spot one less than them on the list, so that there is no empty space at the beginning. (eg: If you had 3 urls: 1. google.com , 2. wikipedia.com , 3.stackexchange.com, then after switching to google.com, the list would now be 1. wikipedia.com , 2.stackexchange.com .)

It should then repeat the above steps, and continue to do so until the variables sites and much are the same.

Next, it should should output the entire list of words that it found. The method used to output it does not matter, so long as all words in the list are outputted, with a new line for each word. E.g.: You may have found the words cat, mouse, and food. The output would look as follows:

cat

mouse

food

Scoring: The scoring follows regular code golf rules. The person with the smallest program in bytes wins. However, in the case of a tie between two programs, the program that can webcrawl and write the dictionary starting on wikipedia.com for 100 sites fastest will win.

\$\endgroup\$
1
  • \$\begingroup\$ running this type of program even once would probably ends up throttling the sites and blocking access to the crawler. Is there a good way to prevent that? \$\endgroup\$
    – Razetime
    Jun 17, 2021 at 2:32
2
\$\begingroup\$

Largest Number with No Repeating Digit Pairs

Inspired by the problem with the same name on Puzzling SE.

You are to find the largest number that only uses every digit pair once, in a given base. For example, in ternary we have 2212011002. We can do this greedily by simply starting with the largest number, and then adding the next largest number we can without repeating a pair, until we’ve gotten them all.

Challenge: Given a base from 1-10, output the largest number in that base with no repeating digit pairs.

As long as the digits make the number, you may output with anything, or nothing, in between. Whether regularly delimited, or irregularly gibberished.

You may also take input in any reasonable way. For example, you might take the base, the max digit, or an ordered list representing the digits available. For octal, this would mean 8, 7 or 76543210. If you feel like a challenge, you can take octal as input. I won't complain!

Note that it need only work for bases from 1-10. Invisible points for doing alphanumeric bases like hex, but not at all required.

This is , so least bytes per language wins.

Test Cases

Decimal: 10
99897969594939291908878685848382818077675747372717066564636261605545352515044342414033231302212011009


Octal: 8
77675747372717066564636261605545352515044342414033231302212011007


Quaternary: 4
33231302212011003


Ternary: 3
2212011002


Binary: 2
11001


Unary: 1
00
\$\endgroup\$
2
  • 1
    \$\begingroup\$ I was gonna suggest this be able to support even higher bases, up to 36 maybe. Though that might give some languages that have built-in support for higher number bases an unfair advantage? Because other languages might have to add special support for A = 9 + 1 rather than just using the ASCII values. Maybe just base 26, and use only letters, no numbers? Not sure if it's worth bothering... (Ah, I see you added that note after I posted this comment) \$\endgroup\$ Jun 16, 2021 at 19:27
  • \$\begingroup\$ @DarrelHoffman I did add the edit to make the question as is clearer, but whether or not to include higher bases is precisely my one hang-up! That's what we're discussing in TNB. Come join us! \$\endgroup\$
    – AviFS
    Jun 16, 2021 at 19:37
2
\$\begingroup\$

Draw an Ascii Grid

\$\endgroup\$
2
  • \$\begingroup\$ You can use this to visualise a tictactoe game -- might just do that. \$\endgroup\$ Jun 16, 2021 at 7:32
  • \$\begingroup\$ Looks great, just leave it for another 2 days before posting! \$\endgroup\$
    – user100690
    Jun 16, 2021 at 15:56
2
\$\begingroup\$

Implement a cleave function

\$\endgroup\$
13
  • \$\begingroup\$ @Adám You're right. Thanks! \$\endgroup\$
    – chunes
    Jun 16, 2021 at 7:27
  • \$\begingroup\$ If my language can directly apply a list of functions to a number, giving me a list of results, does that mean a 0-byte answer, or do I have to wrap the application in no-op code? \$\endgroup\$
    – Adám
    Jun 16, 2021 at 7:30
  • \$\begingroup\$ @Adám I have no idea if there's a precedent for 0-byte answers, but if the mere act of writing a list of functions immediately applies them to some object in your programming language, that's interesting and I would want to see it. Would writing a blurb about builtins/builtin behavior being allowed help? Something like "Builtin functionality is allowed but consider adding a less trivial answer as well."? \$\endgroup\$
    – chunes
    Jun 16, 2021 at 7:37
  • \$\begingroup\$ Yes, that would help, and asking for non-trivial things is nice. You might also want to ask for people to explain. \$\endgroup\$
    – Adám
    Jun 16, 2021 at 7:38
  • \$\begingroup\$ @Adám Added, thanks. \$\endgroup\$
    – chunes
    Jun 16, 2021 at 7:43
  • \$\begingroup\$ While tagged functional-programming, are we still allowed to submit a full program that prompts for \$L\$ and \$n\$? \$\endgroup\$
    – Adám
    Jun 16, 2021 at 7:44
  • \$\begingroup\$ @Adám I'm not sure. I took a look at some other higher-order function questions for inspiration, for example https://codegolf.stackexchange.com/questions/223881/implement-an-over-function and it uses the language "You may input and output in the most convenient format for your language, and in any convenient method,..." and that seemed to suffice there. \$\endgroup\$
    – chunes
    Jun 16, 2021 at 7:56
  • \$\begingroup\$ Funny thing is that while you call it a conceptual inverse of map, it is just a map, right? E.g. in JS: (L,n)=>L.map(f=>f(n)) \$\endgroup\$
    – Adám
    Jun 16, 2021 at 8:03
  • \$\begingroup\$ Indeed, it can be written in terms of map. Does it seem too trivial, you think? Does it need spicing up? \$\endgroup\$
    – chunes
    Jun 16, 2021 at 8:07
  • \$\begingroup\$ No, I think it is great. \$\endgroup\$
    – Adám
    Jun 16, 2021 at 8:07
  • \$\begingroup\$ How would one apply a list of functions to a number in something like Python, which is not a functional-programming language \$\endgroup\$ Jun 16, 2021 at 11:07
  • \$\begingroup\$ @StackMeter lambda l,n:map(lambda f:f(n),l) \$\endgroup\$
    – user100690
    Jun 17, 2021 at 5:31
  • \$\begingroup\$ I see now, thanks @RecursiveCo. \$\endgroup\$ Jun 17, 2021 at 6:06
2
\$\begingroup\$

On a Collapsing Platform

Rules

In this KoTH, your task is to not die. It seems simple, right? Well, no.

You're on a platform. A giant platform, of size 100 * (entries) ^ 1.1 units across (this may change if we get a lot of entries). And every few turns, a random tile is removed. As well as this, you, not a small mass in the scale of things, can cause a tile to fall down. Let me explain how this works.

You (the entrant to this KoTH) control a certain number of bots. You (the bots) can then move around on the platform and try not to die. You (still the bots) can move up to 10 units away at base, and can see up to 100 units away (units will be called u from now). However, jumping over a hole costs 2u more, meaning that the largest gap you can clear is three units (3 * 3 for the gap and 1 to land). Do not try and clear 4u+ gaps; you will die. Going off the edge of the platform also is an unwise choice - you will die.

By "you - not a small mass in the scale of things", I mean to say that every step you take takes you closer to your inevitable death - each tile you step on has a hidden durability stat, that will not be revealed to you during the course of the round. When it hits 0, the unlucky bot (hopefully not you (the bot)) on it will be removed with the tile. Do not do this; you will die.

Your weight is a random stat that is decided at the start of your game, and is subtracted from a tile's durability each time you step on it (weights are 150 at base, and durability values in the range of 15000 - 45000 * (entrants) ^ 1/2, or 15000 * 1-3 * entrants ^ 1/2, so it only becomes an issue in the long term, or when a lot of players exist.) Do not forget about this and start camping on the same 10 tiles on the end; you will die.

Everything takes place on a tick system - every 10 ticks, you can do an action (subject to change to 20ish if this is exploitable) and this may well be the most important part of the game - reduce it at all costs - the fewer ticks you waste, the less durability you take off, and the longer you can thread the needle between life and death. Do NOT, and I mean NOT in caps, forget about this - you will die.

There are a few items that you can get that will improve your chances and delay your inevitable death represented by these characters:

-: Removes 1-7% of your weight (or 1-7, whichever is lesser)

=: Increases your speed by 1 (at 13, this will in fact, prove me wrong and let you clear 4u jumps - still not got the + though).

? Increases vision by 5 (allowing you to see 5 more blocks in either direction.

> Reduces your tick delay by 0.1 or 1% of your tick rate, should it drop below 5 (however, before that, you will die most likely.)

+ Duplicates the bot - you start with 10 bots, and each bot left over at the end is worth 10 000 points (1 per tick survived), so this can, effectively, give you 10 000 points free.

Every 10-25 turns, a random platform is removed - unless necessary, this will not drop any bots - the platform chosen will always be empty (just so people don't get unlucky and die at turn 85) unless it is forced not to be - for example, in the endgame, where there is only 10 tiles left. Do not forget this; you will die

Input and Output

To begin with, you will get a string such as this

0, 111, 132, 122, 133, 211, 201, 212, 233, 310, 323, where:

The first number represents your unique player id, known as PID in the it gang. Then, you get 10 numbers, representing your bots' start positions.

Then, for each turn, for each bot that did not die, you (the player) get a string such as this (shortened to save space):

.___.+>-__u__...+>+-_._

representing the bot's vision.

You must then return an integer, representing how many units you wish to move forward (negative is backwards) (and do not forget that spaces take 2u more, or you will die.); do not try and move more than your speed, or it will be modulo-ed. Errors and invalid input return 0. Note, spaces are represented with ., in the examples and in game.

Helper functions (to delay your death, hopefully until the end):

info(): gives you a chunk of info, in this format:

PID: 0
Bots: 11
Score: 10000
[
BID: 1
Weight: 97
Speed: 12
Tick Delay: 8.8
Vision: 110
Pos: -932
Score: 830
]

[
BID: 3
...
]

The string is format as such:

  • First, your unique PID.

  • Then, the number of bots you still have.

  • Then, your total score.

  • Then, for each bot:

    • Its bot ID (or BID for the it gang). (Note, BID are cannot be reassigned, so if Bot 2 dies, and then Bot 1 duplicates, it will have a BID of 10, not 2 (also we count from 0) as it would be if they were.)

    • Its weight, speed, tick delay and vision, in that order.

    • Its position on the platform, in that order.

    • Its score.

position(): gives a position of every bot, ordered by their bot ID, or BID (again, only for the it gang).

position(ID): gives the x position for a bot with a specific ID. If that ID has died already, it will return "Dead" - plus the space where it died. If that bot never existed, it will return None.

tickdelay(), weight(), speed(), vision(), tickdelay(ID), weight(ID), speed(ID), vision(ID):

Does exactly what it says on the tin, returns that specific stat for all bots if no ID is given, or the one with that ID should it be given (again, if the bot is dead, it just returns its stats on the turn it died, and if it never existed, it returns None. Make of it what you will).

vision(ID) Gives a specific bot's vision - this is useful for sketching a map of the world in conjunction with position(ID). Note that other bots are represented as s, so if you're lucky enough to get your bot (u) in between two opposing bots (s), feel free to laugh.

You are allowed access to ALL the random functions (apart from random.seed(), however I will use a set of predetermined seeds in a random order to facilitate retesting. There will be a large number of trials done - this is just to aid improvements if you so desire to make them.

Bots can store variables and write to files, but ONLY in their directory. I will find any bot who does this and ban them.

Scoring

Bots gain 1 point for each turn they survive, increasing by 1 every 100-200 turns. This will be notified with the string Score/turn increased by 1. Every powerup gives +500, except for +, which duplicates the bot, including its score, thus adding its score to your total. At the end, when there is three or fewer tiles left, you gain 10000 + the bot's current score for each bot left alive. This is done for every bot that lives, so people getting 2 or more bots through gain more than those getting 1, and two opposing bots can both get points for their team.

At least 10000 games will be run per round (subject to change), each time resetting all the stats to the base, rerolling RNG and restarting from the beginning.

After as many rounds as I can get through on my PC, the scores will be added up, and the winner gets an accept.

Meta

Help with a Python controller would be appreciated.

Any specifications need to be made?

Should I edit any formulae?

\$\endgroup\$
1
38 39
40
41 42
152

You must log in to answer this question.

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