# Sandbox for Proposed Challenges

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

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
• Problems that could make the challenge uninteresting or unfit for the site

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

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

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

## Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

Get the Sandbox Viewer to view the sandbox more easily!

Your challenge is to write a method that compresses/decompresses strings. It will get two arguments: any string (with any ASCII characters) to compress/decompress, and a boolean. If the boolean is true, compress, else decompress.

It can either print the output to stdout or return the data.

The twist is that your score is equal to the byte count of your source code + the byte count of your source code compressed by the compressor. So if your code was c=>c (which is invalid btw), your score would be 4 + 4 = 8.

## Rules

• Standard loopholes not allowed

• The decompression and compression should work.

• Your code should not just return the same data. So this

c=>c


is invalid

## Test function to check the score

If you like, here's a function which checks your (javascript) answer.

function checkCompressor(compressor) {
const source = compressor.toString();
const compressed = compressor(source, true);
const decompressed = compressor(compressed, false);
if (source !== decompressed) return false;
return compressed; // Have to get byte count manually
}

• What are the possible input ranges for the compressor and the decompressor? Is it allowed for a compressor to output something longer than the input for some inputs? Under the current rules, it looks like I can get a score of 0 by doing if input == itself, return empty string; otherwise do something else. Jul 30, 2021 at 4:20
• @Bubbler nice catch! I've updated the question a bit, to account for these cases Jul 30, 2021 at 4:32
• "any characters" doesn't look objective to me. Does it include full Unicode range, or just ASCII or Latin-1, for example? Is the length of the compression measured in characters or bytes? Jul 30, 2021 at 4:36
• @Bubbler Any characters were supposed to mean any and all characters, but I think that's a bit too much, so i'm changing it to ascii for now. The length of compression is measured in bytes Jul 30, 2021 at 6:44

# Determine the length of a Puyo Puyo chain

Puyo Puyo is a Japanese tile-matching puzzle game currently developed by Sega. The gameplay seems simple but it is actually quite complex.

You have a 12x6 board which you can fill with various colors (typically red, green, blue, yellow, and purple) of Puyo (round slime-like creatures with eyes). Each turn, you control a pair of Puyo that you can manipulate and place on the board not unlike Tetris.

When a pair is placed, gravity is applied to the board. If there is an empty gap underneath one or more Puyo in a column, they fall to fill the gap.

When two Puyo of the same color are adjacent to each other, they link together. When 4 or more Puyo are linked, they pop (disappear). After a group of Puyo pops, if gravity causes another group to pop, then you have created a chain. The goal of Puyo Puyo is to place Puyo so that you create as long of a chain as possible to overwhelm your opponent with nuisance Puyo.

Nuisance Puyo are a special case - they are colorless (usually gray or transparent), but more importantly they do not link together. Instead, they pop when an adjacent colored Puyo pops.

## Challenge

Given a Puyo Puyo board in any reasonable format (12 lines of 6 character strings, a 12x6 matrix of characters/numbers, 12 6-character strings in an array, etc.) output the chain length as a number. Standard loopholes apply.

This is code-golf, so shortest source code wins.

Bonus: In Puyo Puyo Tsuu, a hidden 13th row was added above the playfield to allow for longer chains. You will get a -5% score bonus if your program can optionally accept a 13th row.

## Test cases

Note: Intermediate board states are shown to demonstrate the game mechanics; you are not required to output them.

Key: Red, Green, Blue, Yellow, Purple, Nuisance, . empty

Output: 4

...... ...... ...... ...... ......
...... ...... ...... ...... ......
...... ...... ...... ...... ......
...... ...... ...... ...... ......
......>......>......>......>......
...... ...... ...... ...... ......
...... ...... ...... ...... ......
...... ...... ...... ...... ......
..GBR. ...BR. ....R. ...... ......
..RGBR ...GBR ....BR .....R ......
..RGBR ...GBR ....BR .....R ......
.RRGBR ..GGBR ...BBR ....RR ......


Output: 4

...... ...... ...... ...... ......
...... ...... ...... ...... ......
...... ...... ...... ...... ......
...... ...... ...... ...... ......
......>......>......>......>......
.G.... ...... ...... ...... ......
YG.... ...... ...... ...... ......
NGY... ..Y... ..Y... ...... ......
NGR... Y.R... ..R... ..Y... ......
YBR... YBR... ..R... ..R... ......
YYBR.. YYBR.. .BBR.. ..RR.. ......
BBRR.. BBRR.. BBRR.. ..RR.. ..Y...


Output: 0

......
......
......
......
......
......
......
......
.B....
BR....
BR....
BR....


Output: 19 (requires bonus; sorry, no intermediate states)

..YRYY
GBBYRG
RBYRYY
GBYRYG
RYRGBG
YRGBYG
RYRGBY
RYRGBY
RGGBGB
GBYRBB
RGBYRG
RGBYRG
RGBYRG


The Puyo Nexus chain simulator might be useful while debugging.

The Lisp language has a family of functions car, cdr, cadr, etc for accessing arrays. For each one, an a defines taking the first item of an array, and a d defines taking the rest.

For example, running cadr on [[1,3,4],5,7] will return [3,4] as the a gets the first item ([1,3,4]) and the d removes the first item.

We've already had a challenge regarding running a cadaddadadaddddaddddddr on a list, but what about the reverse?

Your challenge is to, given a string of the type above (starting with a c, ending with a r, with only ad in the middle), and a single value, create an array such that running the string as a cadaddadadaddddaddddddr on the array returns said value.

For example, given the input cadar, 1 a possible output could be [[0,[1]]] since running cadar on that gives 1.

# Scoring

This is , shortest wins!

# Testcases

These are possible outputs, all that matters is that your program returns an array which works for the condition.

car, 3 => [3]
cdddar, 5 => [0,0,0,5]
caaaaaaaaar, 2 => [[[[[[[[[[2]]]]]]]]]]


Let me know if any of these are wrong.

• one "]" is missing at the end in the 3rd and 4th test, if i'm not mistaken Aug 13, 2021 at 12:37
• @Basto Ok, thanks! Aug 13, 2021 at 22:05
• "only ad in the middle" ~> "only a, d in the middle"? Else I would read it as matching /c(ad)*r/. Sep 5, 2021 at 22:35
• @JonathanFrech This is abandoned, feel free to take it up if you want. Sep 5, 2021 at 22:43
• Ok. I would have liked to solve it. Thanks for the offer to take it up but I respectfully decline. Sep 5, 2021 at 22:44
• Sep 5, 2021 at 22:46
• But with some polish it would be a good question, I think. Sep 5, 2021 at 22:47

# Convince me that this vector theorem is true

### Background Information

From Wikipedia:

A sequence of vectors $$\\mathbf v_1,\mathbf v_2,\mathbf v_3,\dots,\mathbf v_k\$$ from a vector space $$\V\$$ is said to be linearly dependent, if there exists scalars $$\a_1,a_2,\dots,a_k\$$ such that: $$a_1\mathbf v_1+a_2\mathbf v_2+\cdots+a_k\mathbf v_k=\mathbf 0$$ where $$\\mathbf 0\$$ denotes the zero vector.

Based on many sources1 around the internet, it is true that

If there are more vectors than dimensions, the vectors are linearly dependent.

In other words, if the vector space is $$\\mathbb R^n\$$(the number of entries in each vector is $$\n\$$), then the sequence of vectors $$\\mathbf v_1,\mathbf v_2,\dots,\mathbf v_p\$$ is always linearly dependent if $$\p>n\ge2\$$.

After looking around, I'm still not entirely convinced that the above statement is true. Please convince me with a program that takes in: the dimension $$\n\$$(you don't have to take this in if you don't need to), and $$\p\$$ $$\n\$$-dimensional vectors $$\\mathbf v_1,\mathbf v_2,\dots,\mathbf v_p\$$, where $$\p>n\ge2\$$. You can take in $$\p\$$ in your program if you want to. You can assume that all vector entries in each vector are integer values. The input format can be whatever you choose, as long as there is a clear distinction between each vector. The program should return a list of scalars $$\a_1,a_2,\dots,a_p\$$, with at least one of them non-zero, such that $$a_1\mathbf v_1+a_2\mathbf v_2+\cdots+a_p\mathbf v_p=\mathbf 0$$ to show linear dependency. If there are multiple outputs that work, you can output any one of them. The output format is also flexible, as long as it is clear what the values of each scalar are.

This is , so the shortest code in bytes wins!

### Example I/O

Input:
$$\n=2\$$
$$\p=3\$$
$$\\mathbf v_1,\mathbf v_2,\dots,\mathbf v_p=\pmatrix{4\\5},\pmatrix{8\\10},\pmatrix{6\\7}\$$

Output:
One possible solution is $$\a_1,a_2,\dots,a_p=2,-1,0\$$. We can quickly test that this does work: $$2\pmatrix{4\\5}+(-1)\pmatrix{8\\10}+0\pmatrix{6\\7}=\pmatrix{8\\10}-\pmatrix{8\\10}+\pmatrix{0\\0}=\pmatrix{0\\0}=\mathbf 0$$

### Test Cases:

Work in progress

n, vectors -> scalars
2, [(4,5),(8,10),(6,7)] -> [2,-1,0]
2, [(3,6),(6,7),(3,9),(2,4),(5,5)] -> [2,0,0,-3,0]
3, [(1,2,3),(2,3,4),(3,4,5),(4,5,6),(5,6,7),(6,7,8),(7,8,9),(8,9,10)] -> [1,-1,-1,1,1,-1,-1,1]


1: Some sources: this, this, this, this

# Concerns

• Has a similar challenge been done before?
• Is it clear what the challenge is specifying?
• I want to change the title to be more specific, but I'm not sure what to change it to.
• I need some test cases, but I'm not sure what test cases would be good for this.
• A possible title would be "Solve a linear equation system" or "Find a kernel vector" Aug 15, 2021 at 22:13
• "$n\geq 2$" is superfluous. Sep 5, 2021 at 22:30
• I do not quite understand the premise, since a vector space's dimension is defined to be its basis' length. Thus if you are not convinced your statement is true you should not accept $K^n$ to have dimension $n$. Sep 5, 2021 at 22:33

# All valid N * N Flow Free Boards.

Since there are several other Flow Free question, either here or on main, but none, as far as I can tell, that do this, I will ask the question some of us have pondered at night: How many valid Flow Free Boards are there?

# What is a valid board?

From what I can tell from my attempts at time trial, a valid board has all of these:

1. Has between floor(2N/3) and ceil(3N/2) flows (where a flow is two distinct points, defined as it's ends, between which a line can be drawn connecting them).

2. No two endpoints of a flow can be adjacent.

3. The board must be solvable - that is, there must be a way that all endpoints of the flows can be connected together such that every square of the board is filled once and only once, and no two paths intersect at all.

# Input/Output

Your program will receive N, the side length of the board. The board will always be square (as that is the case in most boards), and it must return all valid boards, and the number of such boards.

As always, you can take input and output in any reasonable format, and shortest byte count wins!

# Meta

Has this been done before?

Anything that needs specifying?

Who Won Tic-Tac-Toe?

Your job is to be the judge of a game of Tic-Tac-Toe.

Given an input consisting of three lines (9 characters not including newlines), determine the winner of the game of Tic-Tac-Toe.

For example, for the input

XOO
-XO
O-X


your program should either return or print X.

For tie games or games where no one has won, do not print or return anything.

The only input characters will be 'X', 'O', and '-' (along with two newlines), and the only outputs your program should give are 'X' and 'O' (or nothing).

Also note that the given board will be a valid game of Tic-Tac-Toe, so there will be no situations where both players have winning positions.

More examples:

OOO
---
---


=> O

OXO
--X
---


=> (nothing)

OXO
X-O
X-O


=> O

OXO
XOX
XOX


=> (nothing)

# Tic-Tac Clock

given a time of the day (0-12 inclusive) output the closest fitting clock. This means 0/12, 3, 6 and 9 should be straight up/to the side. The one's in between go in the corners!

The clock should look as follows:

      #|#
0  -> #+#
###

##/
1  -> #+#
###

##/
2  -> #+#
###

###
3  -> #+-
###

###
4  -> #+#
##\

###
5  -> #+#
##\

###
6  -> #+#
#|#

###
7  -> #+#
/##

###
8  -> #+#
/##

###
9  -> -+#
###

\##
10 -> #+#
###

\##
11 -> #+#
###

#|#
12 -> #+#
###


This is code-golf so the shortest answer (per language) in bytes wins.

## questions

This is my first question so I'd appreciate some feedback, mainly if this challenge would be too tedious to do.

• Given that the input is limited to 1 through 12, I'd suggest just showing what each output should be for all the possible inputs, just to avoid any confusion Aug 22, 2021 at 1:29
• That sounds reasonable. Will edit it. Do you think this would be good to post on the main site otherwise?
– 0xff
Aug 22, 2021 at 7:57
• Overall, looks good (though I haven't done any dupe searching). One thing I'd clarify a bit would be the output format - can it be any characters, or does it have to match as shown? Can the output be a list of lines, or does it have to be a multi line string? Etc. Aug 22, 2021 at 8:28

Add 2 numbers using a graphics card

# Introduction

Graphics cards have great performance when doing big calculations. So lets make a small calculation

# Challenge

• Inputs: 2 floats of choice

• output: the addition of the two floats.

• The addition should be calculated on the graphics card, but it doesn't matter if it doesn't work on all gpu's

• Lowest score in bytes wins

# Example Input and Output

2.5 and 3.2 -> 5.7

# Implement the LC-3 VM [1] using 16-bit subneg4 [2] only & test it

• Welcome to Code Golf, and thank you for using the Sandbox! We require challenges to be self-contained; you should fully explain the terms/acronyms used, as well as anything else relevant to the challenge - in short, imagine you're explaining this to someone who knows nothing about it. I'd also suggest removing the time limit, and explain the winning criteria better Aug 18, 2021 at 0:36
• Welcome to Code Golf! The scoring criteria are kinda confusing for people who are new to such system, you may want to add some scoring examples because it's very unique compare to ordinary code-golf.
– okie
Aug 18, 2021 at 2:36

# What will the radio play next week?

Each week, Billboard publishes the US music industry standard ranking of the 100 most popular songs based on sales, radio play, and online streaming. The current chart can be found here.

For each song on the chart, Billboard reports the song's current ranking (from 1 to 100, with 1 being the best), the previous week's ranking of that song (labeled "last week"), the best ranking that the song has ever received by Billboard (labeled "peak"), and the number of weeks that the song has appeared on Billboard charts to date (labeled "wks on chart").

Pop stations in the US generally play the top 40 most popular songs on a given week. In this challenge, we will predict what the radio will play next week given previous Billboard charts.

## The Data

This text file provides the "last week" data for every chart from July 25, 2015 though July 17, 2021 (based on data provided here). There are 313 lines (one for each week) with 100 comma-separated numbers in each line. The first line corresponds to July 25, 2015, and on that week's chart, "Cheerleader" by OMI was ranked #1 (up from #2 the previous week), while Chris Young's "I'm Comin' Over" made its debut on the chart at #100. In the first line of the data provided, this is reflected with the first entry being 2 and the last entry being 101 (throughout, 101 indicates that the song did not chart on the previous week). The next line of the data starts with a 1, indicating that OMI's "Cheerleader" was still ranked #1 on the August 1, 2015 chart. In this way, the data captures how songs move up and down the chart from week to week.

## The Challenge

Write a program or function that, for each n from 0 to 312, receives the first n lines of the data as input and outputs the first 40 numbers from line n+1.

Standard rules apply. The shortest code in bytes wins.

# Binary integer subtraction a - b with 0 < b < a using string processing logic code-golfsubtractionintegerstring

## My Work

I noticed that for this subtraction problem it is not necessary to use twos-complement and that the result can be stored in the same memory required to store a; all that is required is to employ symbolic/logic processing on bit/char-strings.

I wrote a Python program that uses divmod, but that was just a way of 'shifting-off' the right most bit from the bitstring, so the code-golf answers should not use any arithmetical operations.

Here is my program, which can be taken to solve an implicit string processing specification:

minuend =    int(10**1111)
subtrahend = int(10**1110)

if True: #debugging
minuend =    0b110101
subtrahend = 0b000111
M = minuend
S = subtrahend

difference = ''
while 1: #State 0
if minuend == 0:
break
minuend, m_right_bit = divmod(minuend, 2)
subtrahend, s_right_bit = divmod(subtrahend, 2)
if     m_right_bit == 0 and s_right_bit == 0:
difference = '0' + difference
elif   m_right_bit == 1 and s_right_bit == 0:
difference = '1' + difference
elif   m_right_bit == 1 and s_right_bit == 1:
difference = '0' + difference
else:# m_right_bit == 0 and s_right_bit == 1:
#State 1
difference = '1' + difference
while 1: #State 1
if minuend == 0:
break
minuend, m_right_bit = divmod(minuend, 2)
subtrahend, s_right_bit = divmod(subtrahend, 2)
if     m_right_bit == 0 and s_right_bit == 0:
difference = '1' + difference
elif   m_right_bit == 0 and s_right_bit == 1:
difference = '0' + difference
elif   m_right_bit == 1 and s_right_bit == 1:
difference = '1' + difference
else:# m_right_bit == 1 and s_right_bit == 0:
difference = '0' + difference
break # back to State 0
continue
continue

if True: #debugging
if int(difference, 2) != M -S:
print('Program failed...')

raise SystemExit


## Challenge

Code to perform the same subtraction as my Python program; no output should be produced.

Standard rules apply. The shortest code in bytes wins.

• Unfortunately, this is not how challenges work on our site. A code-golf challenge should be defined in terms of input and output, not by some internal behavior. Behavior (or algorithm) requirements are non-observable. Sep 14, 2021 at 1:12

# Multiple Averages

In math, the average or mean of a range of numbers is in the middle of all of the numbers. The farthest number in the range from the average is as close as possible to it. So, to find multiple averages of a range of numbers, one would have to find numbers that best represent the numbers in the collection that are closest to them.

For example, the two averages of the range from 1 to 5 are 2 and 4. 2 represents the numbers 1-3, while 4 represents the numbers 3-5. Below is a diagram to help understand why these numbers best represent the range.

A simple way to calculate the averages is to divide the range into equal parts and calculate the average of each part. For the previous example, the average of 1-3 is 2 and the average of 3-5 is 4.

## Challenge

Create a program that takes three inputs: a number f, another number l and a positive integer n, and outputs the n averages of the range of integers from f to l, inclusive. Assume that there are n or more numbers within this range.

## Rules

• Output can be a list/array or a string of numbers separated by spaces.
• The order of the output does not matter.
• Standard loopholes are not allowed.
• This is code-golf, so the shortest code wins.

## Test Cases

f l n Output
1 3 2 1.5, 2.5
5 5 1 5
4 25 2 9.25, 19.75
42 -4 3 3.666..., 19, 34.333...
0 27 4 3.375, 10.125, 16.875, 23.625
7 2.5 3 3.25, 4.75, 6.25

## Sandbox Questions

• Is the explanation clear enough?
• Is this challenge fit for ?
• Is this challenge too hard or easy?
• What should be changed?
• I don't understand the explanation at all (I know this isn't helpful feedback). Perhaps a test case, ideally with a step-by-step on how to get from the input to the output, will help us improve the explanation. Primarily, I don't understand how exactly you get multiple averages out of a list; isn't there just the one average being the sum divided by the count?
– hyper-neutrino Mod
Sep 7, 2021 at 3:05
• Answer to questions: 1. No, I can't understand what's gonna happen. 2. Yes, it is since it's most likely to be tasked with the shortest code possible. 3. It sounds easy, but no worries, challenges are not weighed by the difficulty, but it's fun. 4. Explanation, and you may want to add rule and winning criteria.
– okie
Sep 7, 2021 at 3:11
• I'll try to fix the explanation and make it clearer. Thanks for the suggestions. Sep 7, 2021 at 14:39

# Most Contrasting Background Color

When putting colored text on a background, the text can sometimes be hard to read because the text color does not contrast with the background color well. Thus, this challenge will be to create a function or program that can find the most contrasting background color for a given text color.

## Challenge

Create a function or program that takes a text color (in RGB format) and outputs the farthest color from the text color, which would be either "black" or "white" as a string. This will be based on the relative luminance of the text color, which is an approximation of how light or dark a color is based on human perception. The relative luminance can be calculated with this formula:

$$\Y=0.2126R+0.7152G+0.0722B\$$

If the relative luminance is closer to 255 (white), then the program should output "black" and vice versa.

## Rules

• Output should be a string: "black" or "white".
• Standard loopholes are not allowed.
• This is code-golf, so the shortest code wins.

## Test Cases

Input Output
255, 0, 0 "white"
0, 0, 0 "white"
255, 255, 255 "black"
0, 255, 255 "black"
133, 193, 230 "black"
100, 62, 139 "white"
128, 128, 128 "black"

## Sandbox Questions

• Is this a dupe?
• Is the challenge clear enough?
• What should be changed?
• You should probably add an explanation for what relative luminance actually is. Sep 9, 2021 at 16:25

# Unlolify a lolified message!

• Welcome to the site! And thank you for using the sandbox. I'm not sure what is meant by rule #2 could you clarify it further?
– Wheat Wizard Mod
Sep 7, 2021 at 12:30
• @WheatWizard Updated 1 and 2, trying to clarify it. Let me know if it's better :) Sep 7, 2021 at 13:42
• Ok, this is clearer. Unicode however is not an encoding. UTF-8 and UTF-16 are encodings both of which are ASCII compliant. Do you mean to say that the decoded string will only ever contain bytes less than 256?
– Wheat Wizard Mod
Sep 7, 2021 at 14:08
• Yes, I mean to say the decoded string will only have bytes less than 256! I meant to say that the whole Unicode isn't supported, but you are right -- ASCII is contained within it anyway. Edited trying to make that more clear, please let me know if you think if it's clear or what could improve! Sep 8, 2021 at 11:48

# Implement a tag system simulator

• I've edited this down to a stub now that it's been posted to save space Sep 12, 2021 at 16:26
• Thanks, I forgot to do that. Sep 12, 2021 at 16:44

# Convert chessboards to algebraic notation

Note: this is "simple" algebraic notation. It is only based off of my very limited knowledge. En passant, draw offers, disambiguation etc are not included and no bonuses will be given for handling those cases.

Algebraic notation is a compact, universal chess notation which provides an easy method of communication between two chess players. There are many apps that can convert a game of chess into algebraic notation given a list of boards; in this challenge you will write one as well.

Before I go over the challenge details, here's a quick crash course of algebraic notation.

Castling: there are two types of castling: kingside castling, the "short" way, and queenside castling, the "long" way. The short way is denoted as O-O (or 0-0) and the long way is O-O-O (or 0-0-0). When castling is performed, the king and rook both move at the same time, making castling the only occasion when two pieces can move at the same time.

K..R -> .RK. (kingside)
R...K -> ..KR. (queenside)


Other moves: the rest of the time, only a single piece moves. The move's anatomy in algebraic notation looks like this:

• the first character is the piece type, except when a pawn is moving. In the case of the pawn the piece type is not included. Otherwise, a knight is N, king is K, rook is R, queen is Q and bishop is B.
• next, we add x if the move is a capture. If not add nothing.
• Then, as a chessboard "coordinate", the position that piece is moving to. For example a4, b5 etc:
a8 b8 c8 d8 e8 f8 g8 h8
a7 b7 c7 d7 e7 f7 g7 h7
a6 b6 c6 d6 e6 f6 g6 h6
a5 b5 c5 d5 e5 f5 g5 h5
a4 b4 c4 d4 e4 f4 g4 h4
a3 b3 c3 d3 e3 f3 g3 h3
a2 b2 c2 d2 e2 f2 g2 h2
a1 b1 c1 d1 e1 f1 g1 h1


So a pawn moving to e4 would be e4, a bishop moving to h5 capturing a piece there would be Bxh5, a rook moving to g6 would be Rg6, etc. Note that pawn capturing at e4 would be xe4.

An additional character is placed at the end in certain circumstances: if the move makes the moving side "check" the opposing side then a + is added. For checkmates we add # instead. Note that this applies to castling as well (O-O+).

I will ignore en passant for this challenge.

## Now, for the challenge itself...

You will take in a sequence of boards representing an entire game, and output its corresponding algebraic notation.

I don't really care how you take the boards. You could take in a FEN string:

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR


or a 8-line, 8-column board:

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR


or a list of pieces:

['W', 'R', 'a8'], ...


or whatever else is reasonable. I will not accept taking in algebraic notation-like strings like Ra8 Kb7, for instance. You can take in a list of boards, double-newline separated, etc.

For each board you must output the algebraic notation of the move from the previous board to the current board by inferring the move from the difference between the boards, along with any necessary pluses and hashes in case the move is a check or checkmate. You must output the correct algebraic notation, but the end "list" can be of any format: a list, space-separated, newline-separated, etc. I don't really care as long as it is reasonable.

## Example

Two boards have been given.

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR

rnbqkbnr
pppppppp
........
........
........
.......N
PPPPPPPP
RNBQKB.R


Output:

Nh3


Another example:

....k...
........
........
K.......
....b...
....R...
........
.q......

....k...
........
........
K.......
....R...
........
........
.q......


Output:

Rxe4+


And finally, the Fool's mate with black castling once:

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR

rnbqkbnr
pppppppp
........
........
........
.....P..
PPPPP.PP
RNBQKBNR

rnbqkbnr
pppp.ppp
....p...
........
........
.....P..
PPPPP.PP
RNBQKBNR

rnbqkbnr
pppp.ppp
....p...
........
......P.
.....P..
PPPPP..P
RNBQKBNR

rnbqkb.r
pppp.ppp
....p..n
........
......P.
.....P..
PPPPP..P
RNBQKBNR

rnbqkb.r
pppp.ppp
....p..n
........
......P.
P....P..
.PPPP..P
RNBQKBNR

rnbqk..r
pppp.ppp
...bp..n
........
......P.
P....P..
.PPPP..P
RNBQKBNR

rnbqk..r
pppp.ppp
...bp..n
........
......P.
PP...P..
..PPP..P
RNBQKBNR

rnbq.rk.
pppp.ppp
...bp..n
........
......P.
PP...P..
..PPP..P
RNBQKBNR

rnbq.rk.
pppp.ppp
...bp..n
........
......P.
PP...P..
R.PPP..P
.NBQKBNR

rnb..rk.
pppp.ppp
...bp..n
........
......Pq
PP...P..
R.PPP..P
.NBQKBNR


Output:

f3 e6 g4 Nh6 a3 Bd6 b3 O-O Ra2 Qh4#


This is , so the winner is the answer with the least bytes.

Meta: is this a duplicate? How could I improve the challenge further?

• Not a dupe, but a lot more complex than it seems. Also, there are several ways to get to one position, and some involve backtracking - for example, how would an algorithm know how to get to a position with one black pawn advanced two squares? Sep 13, 2021 at 10:24
• @emanresuA This is "simple" algebraic notation, in the sense that any more complex types of moves are not considered. I'm not much of a chess expert myself. Sep 13, 2021 at 10:26
• What about, say, Nf4 d5 Ng1, with backtracking, and that's the only way to make it valid? Sep 13, 2021 at 10:50
• I know a little about chess, and no nothing about algebraic notation before. I'm confused that won't this cause ambiguous? Also, "check" and "checkmate" makes this challenge too complex, imo.
– tsh
Sep 17, 2021 at 3:24
• @tsh: I think it makes it more interesting, and more accurate as well as we are producing "more real" algebraic notation. I agree about ambiguities, but in the opening I decided that there would be no "disambiguation", partly because I'm not very familiar with the topic myself. Sep 17, 2021 at 15:11

# Make a number serious

I'm a big fan of silly challenges, but I'm afraid we're going to have to get serious. It's time to get rid of the lols.

Or rather, the 101s, which look quite a bit like lols.

Take an integer as input. You'll make this number serious by removing the 101s from the number's binary representation. Now, particularly good jokes sometimes elicit lolols or even l(ol)+s from numbers, so we must get rid of these too.

• I suspect everything will be along the lines of x.toString(2).replace(/(10)+1/g,'') Sep 14, 2021 at 7:39
• Clarification: do we output the binary or the base10? Or whatever base we want? Sep 14, 2021 at 11:13
• @ykcul Must be number/decimal input and output, not a binary string Sep 14, 2021 at 13:26
• @emanresuA Well, parseInt(x.toString(2).replace(/(10)+1/g,''),2) :p Sep 14, 2021 at 13:27

C character constants.

I'm not sure if we had something like this before.

Given a value n between 1 and output the shortest possible c type character constant.

Examples:
1 -> '\1'
7 -> '\7'
8 -> '\b'
9 -> '\t'
65 -> 'A'

The character constants can only contain ASCII characters from 32 - 127.

• But using 65 is shorter that using 'A'
– tsh
Sep 17, 2021 at 3:11
• @tsh but 65 is not a character constant ;-)
– jdt
Sep 17, 2021 at 10:18
• You probably need to include an explanation of the valid character constants. Sep 17, 2021 at 14:56
• As far as I can see, replacing 'A' by 65 would work in every cases of C codes (as C, not C++, doesn't support auto type). So, if you prefer shorter, you should really consider 65 instead of 'A'.
– tsh
Sep 18, 2021 at 1:21

# Introduction

The fast inverse square root algorithm is a function developed in C for Quake III. It was at the time the fastest way to compute the inverse square root of a function, which is needed for most vector operations.

The code as written in 1999, from the quake 3 source, is as follows:

float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;

x2 = number * 0.5F;
y  = number;
i  = * ( long * ) &y;                       // evil floating point bit level hacking
i  = 0x5f3759df - ( i >> 1 );               // what the fuck?
y  = * ( float * ) &i;
y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
//  y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed

return y;
}


# Challenge

Given a floating-point number in any form you wish, calculate its inverse square root and return it as a float to at least 4 decimal places.

Input:

3

Output:

0.5773502691

# Judging

This is a challenge for creativity as well as code size.

For example, I would rate a 1:1 copy in c# about a 3/5, but a brainfuck copy 5/5 for the challenge and creativity.

• I think this could be a cool challenge, it'll need some work though. I see you deleted the one you posted on main, if you want we can work through the problems it had here, then undelete it and edit it. I can tell you put a lot of work in to this, and it could be a good first draft of a great challenge! Sep 17, 2021 at 2:24
• The precision requirement "to at least 4 decimal places" isn't a good requirement since to verify it one would need to test the algorithm on every floating point number. Usually, a simpler way to handle floating point accuracy is to just give a large number of test cases and require that submissions meet all of them. Sep 17, 2021 at 14:48
• The "judging" section is extremely unclear at the moment. You mention that code size is important, but your examples make no mention of it. The examples you give are also for copying the algorithm, which I can't reasonably conclude to be creative. I'm not sure where you want to take this, but what you have now won't work. Sep 17, 2021 at 14:53
• might be one of the few that Rust does well in compared to other compiled languages, fn s(x:f64)->f64{1./x.sqrt()} Sep 27, 2021 at 7:08

# Apply gravity to this matrix

• I'm pretty sure this has been done, but I can't seem to find it right now.
Sep 17, 2021 at 12:58
• FWIW, this is a fairly simple challenge (transpose, sort each row, transpose in most languages, some may even have a way of sorting each column directly) Sep 17, 2021 at 13:10
• Are the brackets required? Sep 18, 2021 at 0:27
• No, that was just to visualize Arrays. Input and output can be in any reasonable form.
– 0xff
Sep 18, 2021 at 9:18

# A *character*-less quine

Similar to “What did we forget?

## Output

Your program must be a quine - that is, print its own source code with no input or unused input.

Although this is , you are allowed to read your own source code. Assume the file is named “q” and that no extension is needed. There is no bonus for not reading the source code.

If you remove all occurrences of a character that is in your program, it should print the character removed. It is allowed to then raise an error; however, there is no bonus for this either.

To the sandbox: do I need this? => Your program must have at least 3 different characters.

Lowest number of bytes wins (this is , after all)

## Sanbdox things

• Anything I should change?
• This used to be “Numberless” (see edit history) - should I change it back?
• I'm afraid it's a duplicate of this challenge. PS: these type of challenges were characters are removed are tagged radiation-hardening. Sep 22, 2021 at 7:20
• Duplicate no longer…? The original source code must now be a quine.
– W D
Sep 22, 2021 at 8:14
• Yep, seems to be no longer a duplicate. :) There are some radition-harderning + quine challenges, but most require to output the original program or current program after removing a single character. Sep 22, 2021 at 9:57
• Why are programs allowed to read their own source? This rule seems a little disconnected to the rest of the challenge.
– Wheat Wizard Mod
Sep 22, 2021 at 21:44
• So it’s a little easier, I don’t want to be too harsh - it’s much harder if you can’t read your own source
– W D
Sep 23, 2021 at 0:18

Find out if a function always returns its input.

# Input/Output Information

Input is a math expression as a string with operators + - ( ) /.
The multiplication symbol is *, or x if you specify.

The input will always will only contain whitespace spaces, decimal points, numbers (0123456789), math symbols (+ - ( ) / and one of the following: * or x) and one lowercase letter that is the variable.

Whitespace in the input must be ignored.

Output is whether the function will always return its input.

The expression will never have a division by a polynomial with its degree >1.
Example: x*x*x/x*x <= this will never be input.

# Example Input/Output

Input: n /3 + 2*n/3 + 175 - 175*(n+ 1-n)
Output: truthy
Explain: Simplifies to "n"

Input: f
Output: truthy
Explain: Any variable is allowed

Input: j*(j-3.1)/(j-   3.1)
Output: falsey
Explain: In normal math, this evaluates to j
However, when j is 3.1, it is undefined
Therefore, it doesn’t ALWAYS return its input
This is because when j is 3.1, the output is not 3.1

Input: 1j
Output: truthy
Explain: 1j = j which is the input

Input: n/2 + n/2
Output: truthy
Explain: Simplifies to 2n/2 = n which is the input


# Scoring

This is , so lowest amount of bytes wins!

## Sandbox Questions

I brought this back from a long time ago.

• There's some inconsistency in the examples: the first one is being treated as if it's a maths expression whereas the third one is not. Suppose the input is n/2 + n/2. Should the output be true? In some languages the output will not necessarily be the same as the input: / might get you floor division or conversion to a float. You can avoid these issues by treating the input as maths. But in that case, example 3 should simplify to j. Jan 5, 2021 at 9:38
• Why is there an x in your first test case? Right now it'll become n-175(x-1) (n/3+2*n/3 becomes n and 175-175x(n+1-n) becomes -175(x-1)).. I assume that x either should be gone or a *? Also, you may want to clarify what's in the input. You mention +-*/ and whitespaces, but all the lowercase letters and parenthesis aren't mentioned anywhere. And assuming that first test case was a mistake, is the input guaranteed to not contain more than one unique lowercase letter? Sep 22, 2021 at 7:14
• Thanks @KevinC, I clarified that just now
– W D
Sep 22, 2021 at 8:20
• Looks good, +1 from me. As for the */x, I would just put the * in the string with the other operators, and just mention something like "if your language is using a different operator character (i.e. x instead of *), you are allowed to use it instead. If you're unsure whether a character is allowed, leave a comment.", or something along those lines. The operator characters used aren't too relevant for the core of the challenge, and some languages might use */x/×/· for multiplication or //÷ for division. Or just ASMD for add/subtract/multiplication/division. Sep 22, 2021 at 8:36
• Then again, most answers will probably do something along the lines of: replace the lowercase letter with the input; eval; check if it equals the input. 🤷 Sep 22, 2021 at 8:37
• No, that wouldn’t work because n*n/n, or maybe n*((n+149485)/(n+149485))
– W D
Sep 22, 2021 at 8:39
• What would be the domain and range of these mathematical functions? Sep 22, 2021 at 8:58
• Depends which mathematical function you are talking about…?
– W D
Sep 22, 2021 at 9:21

# Alternating Digit Divisibility

TODO: Could use a better title..

## Challenge:

Given a list of at least two positive integers, output a pair of lists of digits. Both inner lists in the output are the digits which evenly divide each number in the alternating converted lists. The first converted list will be [sum(digits(n)), n, sum(digits(n)), ...], and the second will be [n, sum(digits(n)), n, ...].

Step-by-step example:

Input: [611,44,381]

Step 1: Convert it to the two alternating lists:

[[sum([6,1,1]),44,sum([3,8,1])],    →    [[8,44,12],
[611,sum([4,4]),381]]                    [611,8,381]]


Step 2: Check for each number which digits evenly divides it:

[[[1,2,4,8],[1,2,4],[1,2,3,4,6]],
[[1],[1,2,4],[1,3]]]


Step 3: Leave the digits present in each of the inner lists of lists, which is our output:

[[1,2,4],
[1]]


Output: [[1,2,4],[1]]

## Challenge rules:

• I/O is flexible. Input can be a list of strings, integers, 2D list of digits, etc. Output can be a list of lists of digits, a single flattened list of digits (i.e. [1,2,4,1] in the example above), two lists printed on separated lines, each digit printed separated, a string or single (big) integer (i.e. 1241), etc. etc.
• You're allowed to swap the order of the alternation if it's convenient in your language of choice (i.e. the example above would output [[1],[1,2,4]]/[1,1,2,4]/1124/etc. instead).
• 0 will never be in the output.

## General rules:

• This is , so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
• Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
• Default Loopholes are forbidden.

## Test cases:

Input:                      Output:

[611,044,381]               [[1,2,4]], [1]]
[200,32000,4000]            [[1,2], [1,5]]


TODO: More to come, including some larger ones

• Isn't it two challenges in one? The alternating digits lists and then extracting common divisors of two lists? Sep 22, 2021 at 11:58

# Draw me a circle

Given a radius $$\r\in\mathbb{N}\$$ and $$\r\geq 3\$$, draw an ASCII circle for me, using $$\x\$$'s. Your circle does not have to look perfect, it just has to be identifiable as one. To make the circle look good, you have to use a $$\2:1\$$ ratio for width and height of the circles. This is due to characters being taller than wide.

One thing that is required though is an appropriate angle increment. I reccomend $$\r\times3\$$.

You do not have to account for float rounding errors!

Given the radius $$\5\$$, your output should look similar to this:

     x x x x x x
x           x
xx               xx
x                 x
x                   x
x                 x
xx               xx
x           x
x x x x x x


## IO

Input and output can be in any reasonable form.

## More test-cases

Note that these don't have to be an exact match!

3 ->
x x xx
xx       xx
x           x
xx       xx
xx x x

7 ->
xx x x x x xx
x               x
x                   x
xx                     xx
x                         x
x                         x
x                           x
x                         x
x                         x
xx                     xx
x                   x
x               x
xx x x x x xx

• what does "appropriate angle increment?" mean? does it rule out drawing a circle without using angles? Sep 27, 2021 at 2:09
• how many percent of it should match? i could fill the entire board and say it match. I recommand giving a fixed shape and enlarge it with size increase.
– okie
Sep 28, 2021 at 1:02

# Drop down the numbers

• What happens when two non-zero entries ought to go to the same place? For example" What if a column is 2, 1, 0? What does that column become?
– Wheat Wizard Mod
Sep 22, 2021 at 21:34
• Also what if a number can't move down far enough? e.g. a 1 in the bottom row, or a 2 in the bottom two rows.
– Wheat Wizard Mod
Sep 22, 2021 at 21:35
• @WheatWizard Edited to clarify. Sep 22, 2021 at 22:06
• what do you mean by big number decide? Can you give out a simple example to explain it? thanks :D
– okie
Sep 23, 2021 at 5:36
• @okie Explained Sep 23, 2021 at 13:08
• Thanks for the explanation, it's much clearer now, anyway, i think the second example's 4th row is wrong?
– okie
Sep 24, 2021 at 0:09
• @okie Fixed. Any other problems with the test cases? Sep 24, 2021 at 0:12
• @AlanBagel I think it's good to go now! just remember to add rules and any extra stuff that you want to mention. For example: standard rules applys and such
– okie
Sep 24, 2021 at 0:20
• I've edited this down to a stub now that it's been posted to save space Sep 26, 2021 at 14:03

# Irreducibile Polynomials

## todo, add several test cases. and figure out how to deal with verifying answers. figure out how references work, not just using plain hyperlinks.

As you may know, Polynomials are mathematical expressions of the sum of a variable raised to various powers and multiplied by various coefficients. For example consider the variable $$\x\$$

$$\begin{array}{11} 3x^2 & \mbox{ exponent is 2, leading coefficient is 3 } \\ 3x^2 + 16x & \mbox { add a term with exponent = 1, coefficient = 16 } \\ 3x^2 + 16x + 7 & \mbox { add another term, with exponent = 0, constant coefficient = 7 } \\ \end{array}$$

In general we can write a polynomial named $$\P\$$ as a function of $$\x\$$ as follows: $$P(x) = a_mx^m + a_{m-1} x^{m-1} ... + a_1 x^1 + a_0 x ^ 0$$

Polynomials are somewhat similar to integers in that they can be factored into smaller polynomials that when multiplied together give the original polynomial. This process can be repeated until the integer or polynomial cannot be factored anymore. For integers this smallest factor is called a Prime, but for Polynomials it is called Irreducible. For integer polynomials over the integers, which is what this challenge is limited to, we have the following examples:

$$\begin{array}{11} \mbox{polynomial} & \mbox{irreducible factors} \\ x^2-1 & (x-1),(x+1) \\ x^5-x^4-2x^3-8x^2+6x-1 & (x^2 - 3x + 1),(x^3 + 2x^2 + 3x - 1) \\ 6x^2 + 243x - 378 & (x+42),3,(2x-3) \\ \end{array}$$

How do we know a polynomial is irreducible? We could do trial polynomial-division on all possible smaller polynomials, but it turns out that there are several algorithms that can quickly tell us if a polynomial is irreducible.

This challenge is to write a program that returns True if a given Polynomial meets any of the four irreducibility criteria given below.

This is Code Golf - fewest number of bytes wins!

## Criteria 1: Gotthold Eisenstein

First your program should determine if the input polynomial meets the irreducibility criteria of Gotthold Eisenstein. This criteria looks for the existence of a special number $$\q\$$ such that the following are true:

• $$\q\$$ is prime
• $$\q\$$ is not a factor of the Leading Coefficient
• $$\q\$$ is a factor of all the non-Leading Coefficients
• $$\q^2\$$ is not a factor of the Constant Coefficient

For example:

$$P(x) = 3x^3 + 15x^2 - 25x + 10$$

has a $$\q\$$ of 5, where

• 5 is prime
• 5 is not a factor of the leading coefficient 3,
• 5 is a factor of the non-leading coefficients 15, -25, and 10
• 5 squared is not a factor of the constant coefficient 10

Therefore $$\P\$$ is irreducible, and your program should return True

## Criteria 2: Oskar Perron

In 1907 Oskar Perron's paper describes a criteria that does not require factoring the coefficients. Recall that polynomial P can be written as

$$P(x) = a_{m}x^m + a_{m-1} x^{m-1} ... + a_1 x^1 + a_0 x^0$$

• Assume $$\P\$$ is monic, which means the leading coefficient $$\a_{m}\$$ is $$\1\$$.
• Assume $$\a_0\$$ is not $$\0\$$
• If the absolute value of $$\a_{m-1}\$$ is greater than the sum of all the other coefficient's absolute value, then $$\P\$$ is irreducible
• In more mathy language:

$$|a_{m-1}| > \sum_{\substack{i=0\\i\neq{m-1}}}^{m} |a_i| \implies P \mbox{ is irreducible}$$

Example:

• $$\P(x)=x^{38797389} - 55x^2 + 2x - 9\$$
• $$\a_m=1\$$ and $$\a_0 \ne 0\$$
• $$\|a_{m-1}| = 55\$$
• Sum of other coefficients absolute value is $$\1+2+9 = 12\$$
• $$\55 > 12\$$

Therefore $$\P\$$ is irreducible, and your program should return True

## Criteria 3: Michael Filaseta 1988

Next we visit Michael Filaseta's 1988 paper in which he describes the following wonderful criteria: If $$\P(x)\$$ is an integer polynomial of degree $$\<= 31\$$ which has non-negative coefficients, and $$\P(10)\$$ is prime, then $$\P\$$ is irreducible.

For example:

• $$\ P(x) = x^8+2x^4+23 \$$
• $$\P\$$ is of degree 8, which is less than or equal to 31
• $$\ P(10) = 100020023 \$$
• $$\100020023\$$ is prime

Therefore $$\P\$$ is irreducible, and your program should return True

### Criteria 4: Filaseta and Gross

In 2014 Filaseta and Samuel Gross published the following remarkable criteria, which doesn't depend on the degree of the polynomial:

• Consider $$\P(x)\$$ an integer polynomial with coefficients between $$\0\$$ and $$\49598666989151226098104244512918\$$.
• If $$\P(10)\$$ is prime then $$\P\$$ is irreducible

For example

• $$\ P(x) = 54x^{38} + 78783x^{33} + 035033459404x^{21} + 1190354877x^{11} + 56007093177 \$$
• all coefficients are between $$\0\$$ and $$\49598666989151226098104244512918\$$
• $$\ P(10)= 5478783035033459404119035487756007093177 \$$
• $$\5478783035033459404119035487756007093177\$$ is prime

Therefore $$\P\$$ is irreducible, and your program should return True

### Input format

The input format can be whatever is easiest for your language, and if your language has built-in polynomials, that is allowed. The test-case polynomials can be converted to your chosen format before processing into your program. You can take input as an argument to a function, as standard input, or whatever is easiest for your language.

If your language has no built-in polynomial format, one suggestion is to look at the PolyNumber format - that is, an array listing the coefficients, and the position within the array indicating the exponent. Lowest powers come first. For example

$$x^2+1 \mbox { is } [1,1]$$ $$2x^3+5x^2+7x+4 \mbox { is } [4,7,5,2]$$ $$x^4 + 5 \mbox{ is } [ 5,0,0,0,4 ]$$

### Extra notes

First, please note these criteria are sufficient but not necessary. This means that if a polynomial meets the criteria, then it is irreducible. However, just because it doesn't meet the criteria, that doesn't mean it's not irreducible. For the challenge, your program just needs to return True if an irreducibility criteria is satisfied. Returning a non-True value will simply indicate the criteria were not satisfied, it won't necessarily mean that the input polynomial is or isn't irreducible.

Second, a quick glossary of terminology, for polynomial $$\P\$$ we have the function

$$P(x) = a_mx^m + a_{m-1} x^{m-1} ... + a_1 x^1 + a_0 x ^ 0$$

• Leading Coefficient - the coefficient of the highest power term: $$\a_m\$$
• Constant Coefficient - the coefficient of the 0th power term: $$\a_0\$$
• Degree - The value of the highest exponent: $$\m\$$
• Integer Polynomial - a polynomial where all coefficients are integers
• Monic Polynomial - a polynomial with Leading Coefficient of 1

For example let us create an integer polynomial with degree 9, a leading coefficient of 42, and a constant coefficient of -7, as follows:

$$42x^9-7$$

## Refs

Filaseta, M. (1988). Irreducibility Criteria for Polynomials with non-negative Coefficients. Canadian Journal of Mathematics, 40(2), 339-351. doi:10.4153/CJM-1988-013-6

https://bigprimes.org/

https://www.sciencedirect.com/science/article/pii/S0022314X13002539

• It's clear that a lot of work has gone into this, but I question whether asking for solutions to test against multiple rigid criteria (one of which includes a 32 byte constant) isn't pulling in the opposite direction to code golf. It's unclear to me how much scope there is for creativity here, since each criterion includes a prescribed set of conditions that are mostly independent of each other. Have you considered just asking whether a given polynomial is irreducible? Oct 12, 2021 at 5:43
• well its a good point but... but i was hoping that these four techniques are not as independent as they appear to be at first glance. Also asking "is this irreducible" only has one answer, to fully factor the polynomial, which systems like Mathematica automatically will win. Oct 14, 2021 at 8:10

# Hearts KotH

Your challenge, should you choose to accept it, is to write a Java bot to play a simplified version of hearts.

Hearts is a four-player trick-based card game. To start a round of hearts, each player is dealt 13 cards. The player who has the two of clubs starts by playing the two of clubs. Going around the circle each player plays another card, in the same suit as as the first card if possible. Once every player has played one card, the trick is complete, and goes to the player who placed the highest valued card in the original suit (aces are high). The player who takes the trick is responsible for all of the points contained in the trick, as well as leading the next trick. This continues until all players are out of cards, at which point the hand is complete.

During a hand, each heart taken is worth 1 point and the queen of spades 13 points. If during the course of a hand one player receives all 26 points, they shoot the moon and receive zero while everyone else receives 26 points. The game ends once a player clears 100 points, at which point the player with the lowest score wins.

## The Challenge ​

Write a Java 11 bot extending a (todo) abstract class. A new bot will be instantiated for each hand. Every combination of 4 bots will play one game with each other. After all of the games are complete, the bots will be scored on the total number of wins (higher is better), with the tiebreaker being the average score per game (lower is better).

Tampering with the controller, tampering or instantiating other bots, damaging my computer, taking an excessively long time to complete a turn, failing to compile, violating standard loopholes, or throwing a runtime Error is strictly prohibited and will result in disqualification. Throwing an exception will result in a 1 point penalty and the controller playing for you in an unspecified manner. Nondeterministic bots and storing data between both Hands and games are permitted.

## Meta:

Is this clear enough?

I haven't written the controller yet, is there any data in particular that you would like to see the bots receive (among other things, a way to determine the legality of the move, as well as cards played are already passed in)?

• How are the cards distributed? If it's random, I'm worried there won't be much strategy possible and it'll mostly just be a random outcome. Oct 5, 2021 at 17:22
• @RedwolfPrograms the plan right now is random, but it doesn't have to be. My theory was that since there are typically 5-10 hands per game in real life, the law of large numbers would win out. In real life, while the game is slightly more complicated all strategies boil down to card counting and probability-based heuristics anyway, and you can get quite good at it. Oct 5, 2021 at 17:33
• It seems like card counting and probability based heuristics would both make for a pretty boring KotH, since while they'd be challenging to keep track of as a human, a bot could be optimized without too much work being necessary. Oct 5, 2021 at 19:04
• @RedwolfPrograms the way things are set up currently, the relatively boring task of counting cards is mostly handled by the controller. Also, most KotH challenges have been probability based heuristics, like the various rock paper scissors challenges and the various prisoner's dilemma based challenges. Still, if the consensus seems to be that this won't do very well I will head back to the drawing board. Oct 5, 2021 at 20:35

# Optimize my Cruise Control

My cars cruise-control functionality has 4 different methods of adjustment, all using a single stalk. They are as follows:

• Hard press up (press until you feel the click): +5 mph
• Soft press up (press lightly, but not to the click): +1 mph
• Soft press down (press lightly, but not to the click): -1 mph
• Hard press down (press until you feel the click): -5 mph

If your current speed is not a multiple of 5, a hard press will take you up/down to the nearest 5 multiple.

The challenge is to write a function that takes your current speed and target speed as parameters, and outputs the shortest sequence of stalk inputs to get from current -> target speed.

Rules:

• Take 2 integers as input
• Return a list/iterable/whatever of the minimum actions needed to get to target speed

Examples: (U is hard up, u is soft up, d is soft down, D is hard down)

[5, 6] -> [u]
[20, 37] -> [U,U,U,u,u]
[42, 45] -> [U]
[16,23] -> [U,u,u,u] or [U,U,d,d]


## currently known issues

• needs more examples
• similar to the Optimal Change problem.

## Other possible improvements

• Maybe make it a more generalized function that takes 4 inputs [v_current, v_target, delta_small, delta_large]. This would have the effect of complicating the logic and making the problem a bit less trivial.

# Write an interpreter for "MathScript"

I had an idea for a new language, it's called MathScript! I got the idea from Mathematica.

Basically, this is how it works:

• Functions are called by using the following syntax: FunctionName{some, arguments, separated, by, commas}
• The builtin functions are Display, Add, Sub, Mul, IntDiv, FloorDiv, Pow, Factorial, FibN, and OddEvenQ

The first few function names are pretty descriptive. IntDiv and FloorDiv calculate the integer division and floor division, respectively. FibN calculates the N'th Fibonacci number, and OddEvenQ returns 1 if a number is even and 0 if it is odd.

• Variables are created as so: <Name> :: <Value>
• The syntax for changing variables is the same as the syntax to change variables.
• The syntax for for loops are as following: LoopN{<n>} :: [some, statements, separated, by, commas]

# Test Cases

---
---

---
a :: 1
LoopN{3} :: [a :: Add{a, 1}, Display{a}] => 2 <newline> 3 <newline> 4 <newline>
---

---
odd_or_even0 :: OddEvenQ{num}
num :: Factorial{num}
odd_or_even1 :: OddEvenQ{num}
Display{odd_or_even0} => 0
Display{odd_or_even1} => 1
---


# Scoring

This is , so the fastest answer wins. The testing will be on an i7 processer Windows 10 machine. The test case will be LoopN{10} :: [LoopN{10} :: [Display{Add(2, Pow{3, 4})}]].

# Some clarification

Whitespace is ignored. Trailing commas in function arguments is allowed. You can assume that the input will always be correct. Display outputs something to stdout. Case is significant. (e. g Loopn != LoopN) If there are multiple statements, they can be separated by newlines or nothing at all. Blank lines can be anywhere.

# Language types

The types are the string (specified between double quotes or single quotes), the integer, and the float. Integers can be specified using normal numbers like 5 and 7383. The integer limit is [-232, 232] (32-bit). Floats can be specified using normal math notation, so these are all valid floats:

2.0
3.4
3.141592653
.8
2.


The LoopN function's first argument can be a integer literal, or a predefined variable.

# One Final Note

Compilers are allowed.

# Meta

• Any suggestions?
• Anything to clarify?
• Is whitespace significant, or only used to separate tokens? Are trailing commas allowed? Will the input ever have a syntax error? What does display do? I assume it prints out something, but how does it print it out? Is case significant? If so, shouldn't your second test case should read LoopN? In your first test case you use Print, did you mean Display? The second test case seems to have multiple statements; how are statements separated? Are they always separated by newlines, or can it be any token separator? If they're always separated by newlines, can newlines appear anywhere else? Sep 26, 2021 at 21:28
• Every challenge has to have an objective scoring criterion; what is it for this challenge? Consider code-golf or fastest-code. Sep 26, 2021 at 21:29
• I see that you've tagged this fastest-code; this scoring criterion often involves a bit more work for the author, as all answers have to be scored on the same machine for fairness. If you use this scoring criterion, you should specify what machine you'll be running submissions on, as well as what test cases the input will be run on. Sep 26, 2021 at 21:33
• Some feedback re the language itself: there's no obvious conditional construct, though one can use LoopN{<cond>} :: [ <body> ] if cond is known to be either 0 or 1, and Pow{0, Pow{0, Pow{<cond>, 2}}} to convert <cond> to 1 if non-zero, or 0 if 0. Additionally, there's no obvious way to check for equality, other than using something like Pow{0, Pow{Sub{A, B}, 2}}, and no obvious way to check for greater than or less than. Sep 26, 2021 at 21:42
• More questions re the challenge: What are numbers? Are they all ints? All floats? What's the difference between IntDiv and FloorDiv? What are all of the valid ways to specify a number? What precision should be supported for numbers? Possible options include arbitrary precision (this would be helpful towards making the language turing-complete), implementation-defined (e.g. whatever your language supports), or something specific like IEEE-754 double precision floats. Sep 26, 2021 at 21:46
• How does LoopN work? Can you pass it a computed value, or does it have to be a number literal? If it's a computed value, is it recomputed every time, or stored after the first time? If it's recomputed, you could create while loops, which would be helpful for turing-completeness. Sep 26, 2021 at 21:48
• How many arguments do each of the functions take? What happens if a function is called with an incorrect number of arguments? Can that be assumed not to happen, or should some kind of error be outputted? Sep 26, 2021 at 21:50
• Does FibN support a non-positive index? If not, can it be assumed to not be called with that, or should an error be outputted? What happens if you divide by zero? Sep 26, 2021 at 21:52
• What happens if you call Factorial with a negative number? Does Factorial support an input of 0? (it probably should) Sep 26, 2021 at 21:53
• If floats exist in the language, what does OddEvenQ do if you pass it a non-integer? Sep 26, 2021 at 21:54
• Are compilers allowed? Sep 26, 2021 at 22:07
• The second test case are looking weird, isn't the output should be 2 \n 3 \n 4 \n?
– okie
Oct 4, 2021 at 4:59
• I feel like you should add more MathScript programs to test with. An answer could optimize solely for the single test case you've given.
– user
Oct 6, 2021 at 1:01