571
\$\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\$
2
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    Commented May 15 at 14:05
  • \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$
    – mousetail
    Commented May 29 at 13:27

4705 Answers 4705

1
144 145
146
147 148
157
-1
\$\begingroup\$

Poly-functional Polyglots

I don't have a ton of time to work on this, so I decided to remove it temporarily while I rework the scoring.

\$\endgroup\$
2
  • \$\begingroup\$ I think the scoring system is too convoluted. Optimizing for the bonuses seems like more of a challenge than completing the core task. And if number of languages is the denominator, it’s hard to know how to calculate that upfront. How many shells does echo “Hello World” work in? If I later learn about another one, does that retroactively lower my score? \$\endgroup\$ Commented Apr 2, 2021 at 16:53
  • \$\begingroup\$ @water_ghosts thanks for saying so. I was worried that that would be the case, especially after reading the discussion on things to avoid in questions. I'm going to try and rework this. \$\endgroup\$ Commented Apr 8, 2021 at 19:26
-1
\$\begingroup\$

Generate a Printing Program In Some Language

Task

Given some rules:

1: Hello
2: World
4: Code
7: Golf
9: Whatever

Your program should output a program or a function (the output), which should be a valid program (or function) in some language. When the output is run, it should

  1. Ask for some input (i),
  2. Then output the string in the ith index in rules. (If there are none, don't output anything - even an error.)
  3. Return to step 1.

Example:

Rules:

1: Hello
5: World
19: Code

One possible output (python):

while True:
  i = int(input())
  if i == 1:
    print("Hello")
  if i == 5:
    print("World")
  if i == 19:
    print("Code")

Scoring

Your score is the bytes in your answer (not the output).


Obviously this question should be clarified.

\$\endgroup\$
6
  • \$\begingroup\$ Can we take input as an array of rules (2d, like [[1, "hello"], [2, "weijfiwef"]])? If the index is not in the rules list, can we output an empty string? \$\endgroup\$
    – user100690
    Commented May 16, 2021 at 7:42
  • \$\begingroup\$ Well I thought about that, but some strong-type languages don't allow different types in a same array. If the index is not in the rules list, you can't output anything (as said in step 2). \$\endgroup\$
    – atzlt
    Commented May 16, 2021 at 8:33
  • \$\begingroup\$ Is my output required to be a full program or it is allowed to be a function? \$\endgroup\$
    – tsh
    Commented May 17, 2021 at 7:21
  • \$\begingroup\$ Yes @tsh, can be either full program or function. \$\endgroup\$
    – atzlt
    Commented May 17, 2021 at 14:09
  • \$\begingroup\$ Why downvotes? Could you please explain why? I'll improve \$\endgroup\$
    – atzlt
    Commented May 17, 2021 at 14:19
  • \$\begingroup\$ @SketchySketch Not a downvoter, but it seems to be a boring challenge. \$\endgroup\$
    – Xwtek
    Commented May 20, 2021 at 9:18
-1
\$\begingroup\$

Given two reals \$a\$ and \$b\$, output some reals \$r_i\$, such that \$\sum r_i=a\$ and \$\prod\left(r_i+1\right)=b\$. You can assume that it's possible. You can also assume that your float type have infinite precision.

Test cases:

2,3 => 2 or etc.
2,4 => 1,1 or 1/2,(sqrt(57)+9)/12,(9-sqrt(57))/12 or etc.
2,5 => 1/3,1/2,2/3,1/2,0 or etc.
2,8 => sqrt(17)+2,2-sqrt(17),-2 or etc.
2,2 => sqrt(2)+1,1-sqrt(2) or etc.
e,2e => 1,e-1 or etc. (e is natural base, though any number>1 work)
-4,9 => -2,-2 or etc.
0,-1 => sqrt(2),-sqrt(2) or etc.

Shortest code wins.

Notes

  • Though I only removed two positives from the existing question, it's a huge change to the result.
  • I decide to keep the assume possible part just to make the note above correct. It can actually be proven that it's always possible.
\$\endgroup\$
-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\$ Commented 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\$ Commented 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
  • 1
    \$\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\$ Commented Jul 31, 2021 at 16:38
  • 1
    \$\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
    Commented Jul 31, 2021 at 19:58
  • 1
    \$\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\$ Commented 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
    Commented 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\$ Commented Aug 18, 2021 at 19:03
  • \$\begingroup\$ Ok, well that's fine. \$\endgroup\$ Commented 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
    Commented 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\$ Commented 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
    Commented Sep 23, 2021 at 19:26
  • \$\begingroup\$ It can go in different directions. \$\endgroup\$ Commented 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
    Commented 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
    Commented Oct 24, 2021 at 3:49
  • \$\begingroup\$ Changed - "at least 100 applicants" and "at least one applicant that requests <$100" \$\endgroup\$
    – W D
    Commented 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
    Commented 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
    Commented 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\$ Commented Nov 7, 2021 at 19:12
  • 1
    \$\begingroup\$ If the first code is included and others may think is fastest-code tag \$\endgroup\$
    – Fmbalbuena
    Commented 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\$ Commented Nov 9, 2021 at 19:26
  • \$\begingroup\$ This needs testcases (pick one at random) and add tag random. \$\endgroup\$
    – Fmbalbuena
    Commented 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
    Commented 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
    Commented 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\$ Commented Sep 17, 2021 at 17:44
  • \$\begingroup\$ @AaronMiller Added some test cases and additional rules. \$\endgroup\$ Commented 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\$ Commented Sep 17, 2021 at 18:15
  • \$\begingroup\$ @ThomasWard Edited. \$\endgroup\$ Commented 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
    Commented Dec 1, 2021 at 18:33
  • \$\begingroup\$ It's still not clear if we're hardcoding the words or not \$\endgroup\$ Commented 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
    Commented Dec 28, 2021 at 1:51
  • \$\begingroup\$ I think a reference implementation (even in pseudocode) would be helpful. \$\endgroup\$ Commented Jan 10, 2022 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\$ Commented Feb 6, 2022 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
    Commented Feb 6, 2022 at 9:53
  • \$\begingroup\$ I know, but this is just for your information. \$\endgroup\$ Commented Feb 6, 2022 at 9:54
  • \$\begingroup\$ ah ok lol thx anyways i rarely play mahjong in the first place \$\endgroup\$
    – DialFrost
    Commented Feb 6, 2022 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\$ Commented Apr 26, 2022 at 19:14
  • \$\begingroup\$ @RadvylfPrograms i know, it isn't finished yet. \$\endgroup\$ Commented Apr 26, 2022 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
    Commented Apr 26, 2022 at 19:20
  • \$\begingroup\$ @Romanp 2d grid \$\endgroup\$ Commented Apr 26, 2022 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
    Commented Apr 26, 2022 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\$ Commented Apr 26, 2022 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
    Commented Apr 26, 2022 at 20:01
  • \$\begingroup\$ @Romanp whats a RTS? \$\endgroup\$ Commented Apr 26, 2022 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
    Commented Apr 26, 2022 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
    Commented Jun 6, 2022 at 6:37
  • \$\begingroup\$ Oh OK good point \$\endgroup\$ Commented Jun 6, 2022 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
    Commented Jun 6, 2022 at 17:43
  • \$\begingroup\$ Do you mean minimum or maximal? \$\endgroup\$
    – tsh
    Commented Jun 7, 2022 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
    Commented Jun 8, 2022 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
  • \$\begingroup\$ Downvoters, why? \$\endgroup\$ Commented Jun 17, 2022 at 1:14
-1
\$\begingroup\$

Build a file/directory tree

Task

In this challenge, your task is to write a program or function which takes an array of paths with an additional boolean indicating it is a file or directory and outputs a file/directory tree in any reasonable format.

Remarks

  • Some directories can end with a forward slash ("/") but this is not always the case
  • A parent directory is not always explicitly defined but should be in the tree
  • "." and ".." as file name or directory name are not allowed
  • Standard loopholes are not allowed

Input

An unsorted array of paths. Each item is a tuple of path and a boolean which is True for a file and False for a directory.

[
    ['Root Folder/Sub Folder/', False],
    ['Root Folder/Sub Folder/hello.txt', True],
    ['Root Folder/Sub Folder/SubSub Folder/SubSubSub Folder/', False],
    ['Root Folder/Sub Folder/world.txt', True],
    ['Root Folder/Sub Folder 2', False],
]

Output

Any output which shows or defines a tree based upon input is valid.

Text formatted example

[D] Root Folder
    [D] Sub Folder
        [D] SubSub Folder
            [D] SubSubSub Folder
        [F] hello.txt
        [F] world.txt
    [D] Sub Folder 2

Data structure formatted example

[
    'Root Folder',
    [
        [
            'Sub Folder',
            [
                [
                    'SubSub Folder',
                    [
                        [
                            'SubSubSub Folder', [], []
                        ]
                    ],
                    []
                ]
            ],
            ['hello.txt', 'world.txt']
        ],
        [
            'Sub Folder 2',
            [],
            []
        ]
    ],
    []
]

This is a code golf. Shortest code in bytes wins.

Meta

  • Is this an interesting question?
  • Is this question clear enough?
  • Anything i can do to improve this question?
\$\endgroup\$
2
  • \$\begingroup\$ I think it would be good to simplify input and output as much as possible. For example the input being just list of strings and directories identified by ending with slash. And also specifying list of characters which can/can't appear in path would allow to use some of those as string separator (perhaps best as separator would be space and newline). This would mean that data can be easily read from STDIN. \$\endgroup\$
    – Jiří
    Commented Jul 8, 2022 at 19:52
  • \$\begingroup\$ You should also write a bit about how the algorithm generating the tree works. For example: "You split all paths by character /, which gives you list of directories and possibly file. The you choose first part of any path and output this, then you have to find all paths which begin with the same directory..." (I think it can be written a bit better than I did and also I didn't described it fully) Also then the output can be maybe a bit simplified or a bit better defined too, but I am not sure how (maybe not differentiating between directories and files). \$\endgroup\$
    – Jiří
    Commented Jul 8, 2022 at 19:57
-1
\$\begingroup\$

Write a program on any language that accepts some input and give some different output. The challenge is that the text of the program must form a square: all rows must be the same length and the number of rows must equal the number of columns (ie length of rows). Adding extra spaces or comments to pad lines is not allowed.

This is Code Golf so the one with the shortest functioning program (ie smallest square) wins!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to the site! To edit your post there is edit button. You have posted two similar versions of same post, so I recommend deleting the older (this one). I will post further recommendations under your new post. \$\endgroup\$
    – Jiří
    Commented Aug 7, 2022 at 20:03
-1
\$\begingroup\$

Convert English to integer

When saying a number out loud in English, or writing it out in words, speakers use a certain method.
Since there's lots of variations from person to person on the specific method, I'll define the format I'm using here:

  • [TODO]

Some things to note about the format:

  • There are no commas, only lowercase letters and spaces.
  • There is no "and" separating the hundreds and tens.
  • 1234 is described as "one thousand two hundred thirty four", not "twelve hundred thirty four".

Here's some rather sloppy code that, given a number, generates the associated English phrase.

The challenge

Taking an input \$s\$ which a string describing some integer \$n\$ written using the format above, output \$n\$. In other words, convert from an English description of a number back to its integer form. Your code should be able to handle string associated with non-negative integers up to but not including a quadrillion (i.e. \$0 \leq n \leq 999,999,999,999\$), or the maximum value that an integer can have in your programming language. You can assume the input will always follow the format above.

Test cases

Input Output
zero 0
eight 8
ten 10
sixteen 16
twenty 20
thirty five 35
one hundred 100
four hundred nine 409
five hundred thirteen 513
seven hundred seventy seven 777
six thousand five hundred thirty four 6534
one hundred thousand ten 10010
twenty four thousand three hundred sixty five 24365
eighty eight million two hundred twenty thousand one hundred 88222100
seven hundred million eleven thousand ninety nine 700011099
eight hundred ninety four billion three hundred twelve million five hundred sixty seven thousand eight hundred ninety one 894312567891
one trillion 1000000000000
five hundred trillion one 500000000000001

Standard I/O rules apply, standard loopholes are forbidden. The shortest program wins.

Questions

Do I need to describe the format besides saying how it deals with the major variants (e.g. including/excluding "and")? I really don't want to formally write out all that stuff. I also don't like the wording of the first sentence at all, but I feel like I need some introduction.

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

find overlap between 2 grids

You have 2 grids with numbers inside, and you want to find the overlapping parts.

For example
The firdst grid

1 2 3 4
1 2 3 4
1 2 3 4

The second grid

2 3 4 1
2 3 4 2
9 8 6 4

This part is the overlapping part:

2 3 4
2 3 4

And when you combine, you sould get this:

1 2 3 4
1 2 3 4 1
1 2 3 4 2
  9 8 6 4

Rules

  • The grids are minimum 2*2 and MUST be a rectangle or a square.
  • The input can be the size of the grids (and random generated content), or the content of the grids itself (your choice)
  • The output can be visual just like my example or sommerhing else (but explain how to read it).
  • If there is no overlap you output what you want but it needs to be clear.

goal It is code golf so the byte size is important.

\$\endgroup\$
8
  • \$\begingroup\$ What do we output if there is no common part, like 1 2 3 newline 4 5 6 and 7 8 9 newline 4 8 3 where newline is a grid row separator? \$\endgroup\$ Commented Sep 9, 2022 at 10:10
  • \$\begingroup\$ Or is the input guaranteed to have at least one overlapping value? \$\endgroup\$ Commented Sep 9, 2022 at 10:19
  • \$\begingroup\$ It needs to be clear, I wouls say domething like "-1" or can be tex or so. \$\endgroup\$
    – Bjop
    Commented Sep 9, 2022 at 10:33
  • \$\begingroup\$ Won't it be more sensible to output truthy/falsey values for whether there exists overlapping values? That way you can account for all possible inputs. \$\endgroup\$ Commented Sep 9, 2022 at 10:41
  • \$\begingroup\$ Like I statet in the question, "find the overlapping parts", not if there is overlap or not. \$\endgroup\$
    – Bjop
    Commented Sep 9, 2022 at 10:52
  • 1
    \$\begingroup\$ I only suggested it; it's up to you if you want to modify the challenge. \$\endgroup\$ Commented Sep 9, 2022 at 11:06
  • \$\begingroup\$ Do you think it is better to change it? To my logic you have to know if there is overlapping before you know where. So it is part of it. \$\endgroup\$
    – Bjop
    Commented Sep 9, 2022 at 11:47
  • 1
    \$\begingroup\$ So include the expected output for not having overlapping grids \$\endgroup\$ Commented Sep 9, 2022 at 11:50
1
144 145
146
147 148
157

You must log in to answer this question.

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