528
\$\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 needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3422 Answers 3422

1
98 99
100
101 102
115
0
\$\begingroup\$

Subbasis. Generate. Discrete?

Objective

Given finitely many finite sets, interpret them as a subbasis to generate a space, and decide whether the resulting topology is discrete.

Introduction to Topology

Given a set \$X\$, a topology \$\mathcal{T}\$ over \$X\$ is a subset of the power set \$\mathcal{P}(X)\$ such that:

  • \$\emptyset, X \in \mathcal{T}\$.

  • For all \$\space \mathcal{U} \subset \mathcal{T}\$, \$\bigcup\mathcal{U} \in \mathcal{T}\$.

  • For all \$Y_1, Y_2 \in \mathcal{T}\$, \$Y_1 \cap Y_2 \in \mathcal{T}\$.

Members of a topology are said to be open. So the rules above in plaintext are:

  • The empty set and \$X\$ itself are open.

  • The union of arbitrarily many open sets is open.

  • The intersection of finitely many open sets is open.

Endowed with a topology, \$X\$ is said to be a (topological) space.

If \$\mathcal{T} = \mathcal{P}(X)\$, \$\mathcal{T}\$ is said to be discrete.

Basis and Subbasis

A subset \$\mathcal{B}\$ of the power set \$\mathcal{P}(X)\$ is said to be a basis (pl. bases) of a set \$X\$ if:

  • For all \$x \in X\$, there exists \$B \in \mathcal{B}\$ such that \$x \in B\$.

  • For all \$B_1, B_2 \in \mathcal{B}\$, there exists \$C \in \mathcal{B}\$ such that \$C \subset B_1 \cap B_2\$.

We take every subset \$\mathcal{U} \subset \mathcal{B}\$ and declare \$\bigcup\mathcal{U}\$ to be open to generate a topology \$\mathcal{T}\$. Note that \$\mathcal{B} \subset \mathcal{T}\$ always holds.

If we omit the second requirement, we have a subbasis of \$X\$. A subbasis generates a topology by also declaring the intersection of finitely many members to be open.

Input and Output

Given a set of finitely many finite sets \$\mathcal{S}\$, \$X\$ shall be implicitly defined as \$\bigcup\mathcal{S}\$. Note that by this, the first requirement for bases always holds.

The input/output format is flexible. In every case, inputs that don't fit in your input format fall in don't care situation.

Examples

Truthy

  • \$\emptyset\$ (Generates \$X = \emptyset\$ and \$\mathcal{T} = \{\emptyset\}\$)

  • \$\{\emptyset\}\$ (Ditto)

  • \$\{\{0\}\}\$ (Generates \$X = \{0\}\$ and \$\mathcal{T} = \{\emptyset, \{0\}\}\$)

  • \$\{\emptyset,\{0\}\}\$ (Ditto)

  • \$\{\{1\}\}\$ (Generates \$X = \{1\}\$ and \$\mathcal{T} = \{\emptyset, \{1\}\}\$)

  • \$\{\{0\},\{1\}\}\$ (Generates \$X = \{0,1\}\$ and \$\mathcal{T} = \{\emptyset, \{0\},\{1\},\{0,1\}\}\$)

  • \$\{\{0\},\{1\},\{0,1\}\}\$ (Ditto)

  • \$\{\{0\},\{1\},\{2\}\}\$ (Generates \$X = \{0,1,2\}\$ and \$\mathcal{T} = \{\emptyset, \{0\},\{1\},\{2\},\{0,1\},\{0,2\},\{1,2\},\{0,1,2\}\}\$)

  • \$\{\{0,1\},\{0,2\},\{1,2\}\}\$ (Ditto)

Falsy

  • \$\{\{0,1\}\}\$ (Generates \$X = \{0,1\}\$ and \$\mathcal{T} = \{\emptyset,\{0,1\}\}\$)

  • \$\{\{0,1\},\{1\}\}\$ (Generates \$X = \{0,1\}\$ and \$\mathcal{T} = \{\emptyset,\{1\},\{0,1\}\}\$)

  • \$\{\{0\},\{1,2\}\}\$ (Generates \$X = \{0,1,2\}\$ and \$\mathcal{T} = \{\emptyset, \{0\},\{1,2\},\{0,1,2\}\}\$)

  • \$\{\{0,1\},\{1\},\{2\}\}\$ (Generates \$X = \{0,1,2\}\$ and \$\mathcal{T} = \{\emptyset, \{1\},\{2\},\{0,1\},\{1,2\},\{0,1,2\}\}\$)

\$\endgroup\$
5
  • 2
    \$\begingroup\$ This looks math-heavy. To get a better chance of having it reviewed (because people, including me, tend to skip long sandbox posts) you can ask in chat and leave it in for a while. \$\endgroup\$ – user202729 Feb 18 at 3:28
  • \$\begingroup\$ So, if I'm understanding correctly, defining U(S) as the union of all members of S and P(S) as the powerset of S, you are asking whether {U(x) for x in P(X)} == P(U(X))? In this case a more to the point description like this one could be useful... You can leave the math background in (maybe shorten it a little bit) for people interested, but it shouldn't be the only description for the challenge. \$\endgroup\$ – Leo Feb 19 at 1:08
  • \$\begingroup\$ @Leo Figuring out a simple algorithm to solve the challenge can be part of it. (although after the first answer is posted people can just use the same algorithm, however nobody is forced to look at the answers; besides the "original" answer tend to be upvoted proportionally anyway) \$\endgroup\$ – user202729 Feb 19 at 9:13
  • 1
    \$\begingroup\$ @Leo (your notation is confusing because you use X for the input while OP uses it for U(input), but it looks correct) [please review other sandbox posts] \$\endgroup\$ – user202729 Feb 19 at 9:31
  • \$\begingroup\$ @user202729 I agree that figuring out the algorithm is part of the challenge, but having to understand several paragraph of relatively advanced math concepts is a bit detrimental to the challenge itself, in my opinion. Moreover, mine is not necessarily the best algorithm, just a simpler description of the requirements. You are right about the different notation, sorry for the ambiguity \$\endgroup\$ – Leo Feb 19 at 12:37
0
\$\begingroup\$

Decode an 8086 MOD R/M

I think this might be fun. Or, it might be torture, idk. 😛 If this is popular, I might add a sequel for the significantly more complex 32-bit encoding 😏

Time for a mini objdump.

An 8086 MOD R/M field is laid out like so:

MOD  REG  R/M |  OPTIONAL DISPLACEMENTS
mm   rrr  rrm | (iiiiiiii) | (iiiiiiii)
76   543  210 |  76543210  |  76543210

REG is a register. Quite unintuitively, the register names are not in alphabetical order.

Note that you can safely assume a word register, not a half byte register, and that the destination is a register.

REG |  0 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |
Name| AX | CX | DX | BX | SP | BP | SI | DI |

MOD determines the length and format of the instruction.

MOD | FORMAT
 0  | [MEM] or [ADDR]
 1  | [MEM+/-disp8] (signed 8-bit immediate)
 2  | [MEM+/-disp16] (signed 16-bit little endian immediate)
 3  | REG

MEM is parsed as so:

MEM  |    0    |    1    |    2    |    3    |   4  |   5  |   6   |   7  |
Name | [BX+SI] | [BX+DI] | [BP+SI] | [BP+DI] | [SI] | [DI] | [BP]* | [BX] |
*when MOD==0, [BP] is replaced by an absolute 16-bit address.

Just [BP] is encoded as [BP+0].

I am going to represent MOD R/M as octal, and addresses/displacements as hex. It really bugs me how few people write it this way, as it makes much more sense.

So, for example:

MOD  r  r/m
 3   0    0
reg  |    |
    AX,  AX

 0   2    0
mem  |    |
    DX,[BX+SI]

 1   3   7 , 23
M+D8 |   |   |
    BX, [BX+0x23]

 2   2   1 , BC 6A
M+D16|   |    | /
    DX,[BX+DI+0x6ABC]

Rules:

  • You may take your input as a packed integer, byte array, string in any mix of bases, or whatever. I'm not picky. I personally wrote them as mixed hex and octal.
  • You will always get 3 bytes, however, in true objdump spirit, those extra bytes will be random. The first byte is all you need to determine the length.
  • Not all cases will be the most efficient encoding.
  • In the output:
    • It may be returned as a single string, or printed.
    • It is case insensitive
    • It can have excess spaces or tabs, but it must be on one line.
    • It can have an optional trailing newline
    • Displacements and addresses can be in any base, however, do note that displacements are signed two's complement and will be subtracted if negative. So, for 100 FF, AX,[BX+SI+0xFF] is wrong.
    • Leading zeroes and displacements of zero are fine.

Test cases (irrelevant bytes are in italics):

300 73 A2 -> AX,AX
312 01 82 -> CX,DX
337 3E 1C -> BX,DI
020 24 AF -> DX,[BX+SI]
137 23 6B -> BX,[BX+0x23]
066 34 21 -> SI,[0x1234]
166 00 10 -> SI,[BP+0x00]
221 BC 6A -> DX,[BX+DI+0x6ABC]
124 FF EF -> CX,[SI-0x01]
224 FF FF -> CX,[SI-0x0001]
240 00 00 -> SP,[BX+SI+0x0000]
\$\endgroup\$
4
  • \$\begingroup\$ How is "300" 3 bytes? It looks like 3 octal digits. \$\endgroup\$ – user202729 Feb 20 at 9:43
  • \$\begingroup\$ Is that better? \$\endgroup\$ – EasyasPi Feb 20 at 10:43
  • \$\begingroup\$ What is R/M? Why is MEM 3 bits long? \$\endgroup\$ – user202729 Feb 20 at 11:25
  • 1
    \$\begingroup\$ Since you list out the bytes as bits (appropriately), it would probably be clearer if you also included the binary values in the tables for reg/mod/mem. Using the octal/hex format is probably also going to confuse people - I think labeling your examples with what base is being used may help. \$\endgroup\$ – FryAmTheEggman Feb 20 at 18:19
0
\$\begingroup\$

Create a QR quine

(a "qruine" if you will)

Design a QR code that legibly spells with its pixels (or the space between them) the text that it scans to.

For example, this QR code scans to the letter A, and also spells out A in white:

enter image description here

It does not matter what the scanned and displayed text is; it does not have to be coherent or readable.

The winner is the person with the longest text.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This is a really cool idea, but I'm not quite sure what you mean. (pulls out qr code scanner) Oh, never mind, it really does just scan as 'A'. This surprises me for how big it is. \$\endgroup\$ – Beefster Feb 24 at 22:55
  • \$\begingroup\$ Does this count as code-golf? \$\endgroup\$ – emanresu A Feb 25 at 4:08
0
\$\begingroup\$

Posted link

\$\endgroup\$
3
  • 1
    \$\begingroup\$ The test cases are rather confusing. Are they missing the expected output? In addition, your statement about "dots" is rather odd - do you mean all non-letter characters should be ignored, or just punctuation, or just periods? You should definitely also specify what characters can appear in the input. \$\endgroup\$ – FryAmTheEggman Feb 22 at 17:32
  • 1
    \$\begingroup\$ I think I get it, but it needs to be explained better. For each value of n less than the length of the word, the letters that are n slots from the beginning and n slots from the end of the word should both be made uppercase if either of them is upper case. \$\endgroup\$ – Xcali Feb 22 at 19:04
  • 1
    \$\begingroup\$ Perhaps replacing "slot" by "position"/"character" is easier (perhaps it's a perl term? I don't know), but otherwise clear enough. [please review other sandbox posts] \$\endgroup\$ – user202729 Feb 24 at 4:27
0
\$\begingroup\$

Is this code in the same language as my answer? (WIP)

Probably a bad idea, but the goal here is to output a truthy value if a given input string is valid syntax in the same language as your answer.

\$\endgroup\$
3
  • \$\begingroup\$ Maybe use neural networks and allow answers to have approx. 80% accuracy? I personally don't think this is all that interesting (and it would be very hard to score), but that's completely subjective. \$\endgroup\$ – user Feb 26 at 21:00
  • \$\begingroup\$ Terrible question in most languages. Either they use compile (eval might loop infinitely) or they just print a truthy value (in esoteric languages where all programs are valid) \$\endgroup\$ – user202729 Feb 27 at 12:21
  • \$\begingroup\$ nop in languages with no syntax \$\endgroup\$ – l4m2 Mar 16 at 2:06
0
\$\begingroup\$

I don't care how it started, but I'm going to end it!


Given a number between 0 and 10,000 (inclusive) as input, output that many arbitrary* printable ASCII characters, followed by the exact text:

I don't care how it started, but I'm going to end it!

* The arbitrary preceding text must not contain the ending text.

You do not need to verify the input value.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Nothing to review. (people will print sequence of a most likely) \$\endgroup\$ – user202729 Feb 27 at 12:20
0
\$\begingroup\$

Shortest and Asymptotically Fastest Sort of 3-Tuples

Tags:

Write the shortest and asymptotically fastest function or program that will sort a set of 3-tuples.

Input

Input is a set (or unique list, array, etc) of 3-tuples, containing positive integers.

Output

Output is a set (or unique list, array, etc) of 3-tuples sorted in the following way:

  • The first elements of each tuple are monotonically increasing.
  • For each value of the first elements, the second elements are monotonically increasing.
  • For each value of the second elements, the third elements are monotonically increasing.

Additional Rules

  • As well as a byte count, include the asymptotic time complexity spent by your program.
  • Explanations are encouraged! (Especially for showing the time complexity)
  • Standard loopholes are forbidden.
  • Input and output is flexible, as long as each 3-tuple is individually identifiable.
  • Scoring is time complexity, with byte length as a tie breaker.

Examples

Input - Output # Comment
[(1,2,3), (400,500,600), (0,0,0)] - [(0,0,0), (1,2,3), (400,500,600)]
[(1,0,255), (1,255,0), (1,10,123), (1,50,96)]
 - [(1,0,255), (1,10,123), (1,50,96), (1,255,0)] # sorted by second elements
[(1,0,255), (1,0,0), (1,0,123), (1,0,96)]
 - [(1,0,0), (1,0,96), (1,0,123), (1,0,255)] # sorted by third elements
[(1,0,255), (1,255,0), (1,10,123), (1,50,96), (2,0,255), (2,0,0), (2,0,123), (2,0,96)]
 - [(1,0,255), (1,10,123), (1,50,96), (1,255,0), (2,0,0), (2,0,96), (2,0,123), (2,0,255)] # sorting by first and second
[(1,0,255), (1,255,0), (255,23,232), (1,10,123), (1,50,96), (2,0,255), (2,0,0), (2,0,123), (2,0,96), (1,2,3), (400,500,600), (0,0,0)]
 - [(0,0,0), (1,0,255), (1,2,3), (1,10,123), (1,50,96), (1,255,0), (2,0,0), (2,0,96), (2,0,123), (2,0,255), (400,500,600), (255,23,232)]
\$\endgroup\$
6
  • \$\begingroup\$ Which scoring criterion would take priority? Or is there some way in which they are combined? \$\endgroup\$ – Unrelated String Feb 27 at 23:30
  • \$\begingroup\$ @UnrelatedString I'll add that in, lower time complexity is better. \$\endgroup\$ – bigyihsuan Feb 28 at 0:06
  • \$\begingroup\$ Because the input is bounded, all solutions will take O(1). \$\endgroup\$ – user202729 Feb 28 at 6:47
  • 1
    \$\begingroup\$ The scoring as written is ill-defined. Better saying "asymptotic time complexity is the winning criteria, the size is the tie-breaker" [please review other sandbox posts] \$\endgroup\$ – user202729 Feb 28 at 6:48
  • 1
    \$\begingroup\$ Otherwise, algorithms for sorting things are very well-studied already. Fastest-algorithm is not interesting. \$\endgroup\$ – user202729 Feb 28 at 6:50
  • \$\begingroup\$ Okay. The other comment (about well-studied) still applies. \$\endgroup\$ – user202729 Mar 1 at 3:08
0
\$\begingroup\$

First sequence with no square differences

\$\endgroup\$
3
  • \$\begingroup\$ Clear enough. (I can't find any with the OEIS name. Probably safe.) \$\endgroup\$ – user202729 Mar 3 at 11:16
  • \$\begingroup\$ By the way, it's recommended that challenges should be left for at least 72 hours before posting it on the main site (from the sandbox FAQ) \$\endgroup\$ – user202729 Mar 3 at 14:30
  • \$\begingroup\$ @user202729 I'm aware, but I used my judgement that the challenge is simple enough that it shouldn't need the full 3 days. \$\endgroup\$ – 79037662 Mar 3 at 14:34
0
\$\begingroup\$

Lists of power

Generate the following list of lists.

[[0], [1], [2, 4, 8, 6], [3, 9, 7, 1], [4, 6], [5], [6], [7, 9, 3, 1], [8, 4, 2, 6], [9, 1]]

This is , so shortest answer (as measured in bytes) wins.

\$\endgroup\$
4
  • \$\begingroup\$ Definitely clear enough. But... (I guess most people would be able to figure out the pattern. It's okay to let answerers to deduce something) \$\endgroup\$ – user202729 Mar 4 at 2:21
  • \$\begingroup\$ Should I print the exact string (which kolmogorov-complexity implies) or is it fine to write a function that returns an equivalent structure (or print the equivalent structure in the chosen language's way)? \$\endgroup\$ – Bubbler Mar 4 at 4:23
  • \$\begingroup\$ @Bubbler Ah, I thought kolmogorov-complexity just meant it does exactly one thing... The challenge is to write a program or function that creates the structure, not necessarily the string. \$\endgroup\$ – hakr14 Mar 4 at 6:44
  • 1
    \$\begingroup\$ @hakr14 I think you need to include the last sentence in your challenge. \$\endgroup\$ – Bubbler Mar 6 at 20:39
0
\$\begingroup\$

Sequential Multiplication Magic Squares

(Inspired by this question for a 5x5 and this question for a 4x4 magic square on the Puzzling SE sites.)

For this challenge, a sequential multiplication magic square is an NxN square filled with numbers 1..N² where the product of any M-th row equals the product of the M-th column. That is, the product of the first row is equal to the product of the first column, the product of the second row is equal to the product of the second column etc.

For example, one such 3x3 square might be as follows, but other similar results are valid as well:

9 8 3
4 5 2
6 1 7

Notably, there is no such square for N=2.

Challenge

Given a side size N of 1 or larger, output a valid NxN sequential multiplication magic square, or any distinct falsy value if none exists.

Standard loopholes apply, any convenient input-output, this is so the shortest code in bytes wins.

Sample cases

1 → [1]

2 → any distinct falsy value

3 → [[9, 8, 3],
     [4, 5, 2],
     [6, 1, 7]]

4 → [[16,  3, 12,  4],
     [ 9, 10, 14,  1],
     [ 8,  7, 11, 15],
     [ 2,  6,  5, 13]]

5 → [[ 7, 16,  6,  3, 25],
     [ 5, 13, 22, 12, 24],
     [ 9, 11, 17, 14,  4],
     [20, 18, 21, 19,  1],
     [ 8, 10,  2, 15, 23]]
\$\endgroup\$
3
  • 1
    \$\begingroup\$ There's quite a lot of questions on magic squares already, I couldn't find one that addresses the above scenario though. I'm not sure whether this is unique enough? \$\endgroup\$ – Etheryte Mar 4 at 16:47
  • \$\begingroup\$ I'm pretty sure it is not a dupe, but code-golf doesn't sound very interesting (mainly because one can generate all possible boards and find one that meets the condition). fastest-code would be more interesting, though in that case you'll need to run every single submission on your machine for fair comparison of speed. \$\endgroup\$ – Bubbler Mar 4 at 23:15
  • \$\begingroup\$ May I error in place of a "distinct falsy value"? \$\endgroup\$ – Bubbler Mar 4 at 23:27
0
\$\begingroup\$

Three, Three, No

\$\endgroup\$
10
  • \$\begingroup\$ Some test cases (with example outputs) would be nice. Also, it is discouraged to include input verification in a code golf challenge. \$\endgroup\$ – Bubbler Mar 3 at 4:56
  • \$\begingroup\$ Do you want to allow programs to take input in unary? \$\endgroup\$ – user202729 Mar 3 at 6:05
  • \$\begingroup\$ @Bubbler Actually I think that the input verification is a part of the challenge in this case. Because of the asymptotic time complexity requirement, you need some case-working in the algorithm anyway. \$\endgroup\$ – user202729 Mar 3 at 6:06
  • \$\begingroup\$ @user202729 It does require some casework, but if the existence of an answer is guaranteed, you can still cut an entire if-branch (a test and a code to report failure, the latter of which is superfluous and closer to a boilerplate than a core task IMO). \$\endgroup\$ – Bubbler Mar 3 at 9:32
  • \$\begingroup\$ @Bubbler Depends on what you consider to be valid input. The challenge is just "Given a sequence, print whether there exists a partition and the partition itself if there exists" \$\endgroup\$ – user202729 Mar 3 at 9:40
  • \$\begingroup\$ @Bubbler And op doesn't require some long error message to be printed, right? This is closer to the "general falsy value". \$\endgroup\$ – user202729 Mar 3 at 9:40
  • \$\begingroup\$ @Bubbler So I should change it to assume that all inputs have a permutation that works? \$\endgroup\$ – user101295 Mar 3 at 20:42
  • \$\begingroup\$ @Bubbler I've added some test cases. \$\endgroup\$ – user101295 Mar 3 at 20:47
  • \$\begingroup\$ @user101295 So I should change it to assume that all inputs have a permutation that works? -- You don't need to strictly follow it. You'll need to include a few more test cases for the "impossible" situation though. \$\endgroup\$ – Bubbler Mar 4 at 4:28
  • \$\begingroup\$ @Bubbler Updated. \$\endgroup\$ – user101295 Mar 4 at 22:33
0
\$\begingroup\$

Syslog PRI Conversion

This is my first CodeGolf post, so I expect some errors my content.

The rsyslogd utility has been a tool used throughout time to handle and parse logs either over an IP network or even locally. As many of you might know, this tool utilizes the basic syslog protocol.

The syslog protocol handles both a Facility and a Severity level in one integer, called Priority. The formula to extract these levels is as follows:

Priority = Facility * 8 + Level

In this challenge, your task is to write an application that converts a Priority value from the syslog protocol into a human readable format. The application must take input from STDIN, and output both the Severity and Facility string associated with the numerical code.

The numerical code/type table is as follows:

Int     Severity
0       Emergency
1       Alert
2       Critical
3       Error
4       Warning
5       Notice
6       Informational
7       Debug

Int     Facility
0       kernel messages
1       user-level messages
2       mail system
3       system daemons
4       security/authorization messages
5       internal
6       line printer subsystem
7       network news subsystem
8       UUCP subsystem
9       clock daemon
10      security/authorization messages
11      FTP daemon
12      NTP subsystem
13      log audit
14      log alert
15      clock daemon
16      local0
17      local1
18      local2
19      local3
20      local4
21      local5
22      local6
23      local7

The format of the outputted text may be any style you like, as long as it retains its human readable characteristics.

Examples

mail system, Critical\n

mail system\n
Critical\n

mail system - Critical\n

mail system Critical\n

Example

Given a PRI value of 103, your program must output:

NTP Subsystem, Debug

The shortest answer in bytes wins!

\$\endgroup\$
2
  • \$\begingroup\$ I don't see any glaring issues, though it isn't particularly interesting (outputting strings based on a lookup table has been done multiple times). \$\endgroup\$ – Bubbler Mar 9 at 0:34
  • \$\begingroup\$ Do you happen to have any suggestions that would make it more appealing? Also, Thanks for the feedback. \$\endgroup\$ – booshlinux Mar 9 at 15:09
0
\$\begingroup\$

Interpret the next answer

This is an challenge where the aim is to write an interpreter for a specific language ("language X") in another language ("language Y"). Languages X and Y must be completely distinct, that is they must not be different versions of the same language, nor the same language itself. The next answer should then write an interpreter for language Z in language Y, and so on.

Interpreters do not need to fully implement the language, just a Turing-complete subset. In order to be a valid interpreter, it must have some way of inputting a string of code and a number (potentially zero) of inputs. One example may be a function that takes the code and inputs as an argument.

You may not reuse languages (so each language will be in exactly 2 answers - as an interpreter and being interpreted). Different versions of languages count as the same language, so long as they are considered to be different versions of the same language (e.g. Python 2 and 3, or Seriously and Actually)

You must wait 3 hours between posting and cannot post twice in a row. The challenge ends after a week has passed with no new answers. Your score is equal to the number of answers you have posted, with a higher score being better

\$\endgroup\$
4
  • \$\begingroup\$ I'm confused. Do you mean that you first write an interpreter for language Y in language X, and then an interpreter for Z in Y? Or do you just write interpreters for X, Z, etc. all in Y? Could you give a small example to make it clearer? \$\endgroup\$ – user Mar 10 at 3:46
  • 1
    \$\begingroup\$ I think as well that you have "X" and "Y" swapped in your first sentence. Regarding "Interpreters do not need to fully implement the language, just a Turing-complete subset.", have you considered requiring the next answer to use the same Turing-complete subset in order to be interpretable by the previous one? \$\endgroup\$ – Leo Mar 10 at 4:15
  • 1
    \$\begingroup\$ This seems like a good challenge, but it's currently worded in a confusing manner. An example would probably fix that. Also, would making some sort of custom language be allowed? \$\endgroup\$ – Redwolf Programs Mar 10 at 4:21
  • 1
    \$\begingroup\$ If I’m writing a Python interpreter in JavaScript, can I write a polyglot implementation of Rule 110 and submit eval as my interpreter, since the “Turing complete subset” of Python I support is that single program? \$\endgroup\$ – water_ghosts Mar 10 at 15:17
0
\$\begingroup\$

SSD optimize

Given \$n\$ pages, each page containing \$m\$ sectors, write three functions: (Here x and y are sectors)

  1. insert(x) that stores the input(temporary sector) into a sector,
  2. remove(x) that removes one, and
  3. get(x) that return a sector containing the element.

You can call these functions:

  1. copy(y,x) that copy a sector from x to y, and
  2. clear(x) that clears the page containing x, can only be called \$k\$ times for each page.

There'll never be more than(can equal to) \$p\%mn\$ elements required to store. Your score is the numbers of call before you fail. Everyone can provide test case for any program.

\$n=256, m=16, p=75, k=100\$.

For example, if a solution don't do any clear and just place inputs into \$(1,1), (1,2), \cdots, (n,m)\$, someone else can write and remove till you use up all space:

insert\*3072, (delete, insert)*1025, get

The last get can't get anything and is a fail, so the score is 5122.

Highest score wins. Robber's winning criticia TODO.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ I work with SSD firmware as my job. I just wanted to point out a real story: it is a real PITA to optimize SSD lifetime depending on the user workload. The relevant components include multiple dozen C files, each file being up to tens of kilobytes. The algorithms involved have been accumulated for over a decade, and are still evolving. (This doesn't mean the challenge is inherently bad, as we can explore possible optimizations at the amateur level, which is interesting in its own right.) \$\endgroup\$ – Bubbler Mar 16 at 4:14
  • \$\begingroup\$ It is somewhat unclear how \$p=75\$ is applied in the insert\*3072, (delete, insert)*1025, get workload. Did you mean 75% of the entire space? (in which case \$p=3072\$ or \$p=0.75mn\$ would be more accurate) \$\endgroup\$ – Bubbler Mar 16 at 4:35
  • \$\begingroup\$ @Bubbler the % is missing \$\endgroup\$ – l4m2 Mar 16 at 4:36
  • \$\begingroup\$ For the winning criteria: you could make it a single-challenge CnR (like this). Initially, a cop posts a submission with their own estimate of the score. Then a robber tries to reduce the cops' scores by finding worse scenarios, and the robber takes the reduced score as their own score. A cop with the highest final score wins; a robber with the highest "robbed" total score wins. (Check out more specific rules in the linked challenge) \$\endgroup\$ – Bubbler Mar 16 at 4:55
  • \$\begingroup\$ You should really add some background story to your question. Currently, I cannot understand anything in it. What are pages? What are sectors? How are these 5 functions works? What does clear mean? And why should I clear it? What does get do? Am I designed to storage some data between each invokes? \$\endgroup\$ – tsh Mar 17 at 9:18
  • \$\begingroup\$ Your example \$ (1,1), (1,2), \cdots, (n,m) \$ is a list with 4096 elements in it. Won't it run up after 4096 iterations? What is 5122 here? Are \$ n=256, m=16, p=75, k=100 \$ some given parameter to these 3 functions? \$\endgroup\$ – tsh Mar 17 at 9:25
  • 1
    \$\begingroup\$ @tsh It's a promise that you don't store more than n*m*p% datas, so when reaching 3072 you have to erase some, adding movements \$\endgroup\$ – l4m2 Mar 17 at 9:29
0
\$\begingroup\$

Build a Markdown to HTML converter


The Stack Exchange network uses Markdown as the syntax for writing posts. For example, using a # at the beginning of a line creates a heading (<h1>) while two hashes ## creates a subheading (<h2>).
Your task is to write a program which takes input as a syntactically valid Markdown string and outputs its HTML equivalent. (This program might find use as a means to transfer SE posts to one's own website.)
The only Markdown "commands" you need to support are the backtick (becomes a tag named code, styling provided), the hashes (# becomes h1, ## becomes h2 and ### becomes h3), and the > (blockquote). The rest may be left intact.

For example, if the input is

# Some text
## Part 1
Lorem `ipsum` dolor sit amet
> consectetur adispicing

Then the output should be

<h1>Some text</h1>
<h2>Part 1</h1>
Lorem <code>ipsum</code> dolor sit amet
<blockquote>consectetur adispicing</blockquote>

Leading spaces are acceptable for the headings as they are mandatory in Markdown, but trailing spaces are not (you may assume the input has no trailing spaces). Except for the inline code, all commands will be displayed as blocks and will be on separate lines. For example

# Some text ## Another

is not a valid input because there is a block command on the same line as another block command. You may assume that the input contains no < or > except for blockquote notation, you must also follow the guidelines exactly, so no outputting HTML which renders the same result but in a different way.

Second test case:

### Subheading
> This is some heading with `code` in it.

becomes

<h3>Subheading</h3>
<blockquote>This is some heading with <code>code</code> in it.</blockquote>

This is , so the shortest answer in bytes wins.

\$\endgroup\$
6
  • \$\begingroup\$ HTML use <code> instead of <shortsnippet>. Are you defining yet another target language? \$\endgroup\$ – tsh Mar 16 at 11:34
  • \$\begingroup\$ May I assume input will never contains <> other than block quote notation? Or, what should I do if input contains one? For example, for input 3 < 2, should I yield something like 3 &lt; 2? \$\endgroup\$ – tsh Mar 16 at 11:36
  • \$\begingroup\$ @tsh Oops, didn't know about that one, editing that in. You may assume that the input will never contain < or > except for blockquote notation. \$\endgroup\$ – Recursive Co. Mar 16 at 12:10
  • \$\begingroup\$ "but trailing spaces are not" should I assume the input will not contains trailing spaces too? or should i strip spaces at end of inputs when i generate html? Does this only apply to space (U+0020) or any whitespace characters? \$\endgroup\$ – tsh Mar 17 at 1:32
  • \$\begingroup\$ Should I output exactly same string as example output? Or may I output something HTML may render same results? \$\endgroup\$ – tsh Mar 17 at 3:21
  • \$\begingroup\$ Will the code ever contain unmatched backticks on a line? \$\endgroup\$ – Redwolf Programs Mar 24 at 4:28
0
\$\begingroup\$

Output a random pair of twin primes. Every pair should possibly appear and the program should have zero possibility to fall into infinite loop. Notice that we don't know if there are infinite many pairs so you need some fallbacks to avoid finding a not-existing pair.

\$\endgroup\$
1
  • \$\begingroup\$ Define twin primes \$\endgroup\$ – Beefster Mar 22 at 19:25
0
\$\begingroup\$

Finding Distant Primes

\$\endgroup\$
2
  • \$\begingroup\$ I'm a bit confused, why is 23 a 9-distant prime when |2⁴ - 23| = 7. Why did you raise 2 to specifically the fifth power? Or is both, and also a 22, 21, 19, 15, 7, 9, 41, etc... distant prime? \$\endgroup\$ – Medix2 Mar 17 at 4:22
  • 1
    \$\begingroup\$ @Medix2 yes it is all of those. \$\endgroup\$ – Manish Kundu Mar 17 at 4:50
0
\$\begingroup\$

Add trailing whitespace

Sometimes, we accidentally have trailing whitespace in test cases, and some helpful person notices and fixes that. Thank you, helpful people.

But what if we want to take a string without trailing whitespace and add some?

Your challenge is to write a program that takes a string as input and adds between 1 and 10 spaces (randomly) to the end of each line.

Rules

Between 1 and 10 (inclusive) spaces (" ") must be added to each line. There must be a nonzero chance of getting any number of spaces on any line.

This is , shortest wins.

Apologies if this already exists - It's really hard to search.

\$\endgroup\$
3
  • \$\begingroup\$ "just before each newline and the end of file" "trailing whitespace"? \$\endgroup\$ – tsh Mar 23 at 1:42
  • \$\begingroup\$ @tsh Sorry for being confusing. Rewrote. Is this a good challenge? \$\endgroup\$ – emanresu A Mar 23 at 8:08
  • \$\begingroup\$ Maybe to make the challenge a bit harder require an additional line to the file with random number of spaces, because then less trivial answers \$\endgroup\$ – Recursive Co. Mar 23 at 16:16
0
\$\begingroup\$

2D Pathfinding with Momentum

Posted to main

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

Posted

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

Count What You See

You may have heard of the Look-and-say sequence, which is generated by reading off the digits of previous entries in the sequence. Here, you will be tasked to generate the "Count-and-say sequence".

In general, the sequence can be generated as follows:

  1. Start with an arbitrary sequence of numbers (e.g. 1, 1, 1, 3, 2, 1, 2).
  2. Count the occurrences of each number as adjective noun pairs -> "four 1, one 3, two 2", in order of 1st appearance. In the example, this means that you must first count 1s, then 3s, then 2s, since that is the order in which the numbers first appear in the sequence.
  3. Write out the result from step 2 numerically ("four 1, one 3, two 2" -> 4, 1, 1, 3, 2, 2).
  4. Append the result from step 3 to the original sequence to get 1, 1, 1, 3, 2, 1, 2, 4, 1, 1, 3, 2, 2.
  5. Repeat the steps above to continue the sequence.

Task

Your task is to output the "Count-and-say sequence", such that the sequence starts with 1. You may choose to:

  • Take an input \$ n \$ and output the first \$ n \$ integers.
  • Take an input \$ n \$ and output the \$ n \$-th integer.
  • Output the sequence indefinitely.

For convenience, here are the first 100 numbers in the sequence (also A217780):

1, 1, 1, 3, 1, 4, 1, 1, 3, 6, 1, 2, 3, 1, 4, 8, 1, 3, 3, 2, 4, 1, 6, 1, 2, 11, 1, 5, 3, 3, 4, 2, 6, 3, 2, 1, 8, 13, 1, 8, 3, 4, 4, 3, 6, 5, 2, 2, 8, 1, 11, 1, 5, 16, 1, 10, 3, 6, 4, 4, 6, 7, 2, 4, 8, 2, 11, 3, 5, 1, 13, 18, 1, 12, 3, 9, 4, 6, 6, 9, 2, 5, 8, 3, 11, 4, 5, 2, 13, 1, 16, 1, 10, 1, 7, 22, 1, 14, 3, 11
\$\endgroup\$
0
\$\begingroup\$

Equalizing fractions

\$\endgroup\$
1
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ – Dude coinheringaahing Apr 1 at 21:13
0
\$\begingroup\$

Node one-liner to fetch a URL, like curl

I'm interested in the shortest one-liner to output the contents at a given URL, using Node.js from the command line, for practical purposes. In other words, the equivalent of curl, written as a Node one-liner.

Not interested in other languages. Would this respect the site's rules, or does it belong on SO?

Rules:

  1. The URL is passed via the command line, so accessed via process.argv[1]
  2. Must invoke node with the -e argument, followed by the code, followed by the URL
  3. Only the length of the actual script passed to node via -e "..." is counted.

My best solution so far, with http://x.com as a conveniently short example, is:

node -r got -e "require('got')(process.argv[1]).then(r=>console.log(r.body))" http://x.com
\$\endgroup\$
1
  • \$\begingroup\$ You can make it a tips question \$\endgroup\$ – user Apr 2 at 12:03
0
\$\begingroup\$

Program-Write a program to display repeating terms of a given sentence.

Explanation-the program must output the repeating terms of two or more letters from the given input(input is a sentence seperated be spaces without any punctuation except the full-stop indicating the end.) For example, if input is the sentence "I am an ameture mathemagician" the outupt must be am, ma, an. ( not that em is not a valid output as it is separated by space)

Example-

input->International competitions are better than intercollege ones.

output-> Inter, ti, er, tion, io,on,ion, tio, co, on,.......etc (t, l must not be included as they are 1 letter.) (Upper lower Cases do not matter)

Test cases-

input-> aabcde cdec

output-> cde, cd, de

input-> aab aacab

output-> aa, ab

input-> aaa aabcaaa ababa

output-> aaa, aa, ab, aba, ba

Winning Criterion:- code golf

\$\endgroup\$
3
  • \$\begingroup\$ You say tt and ll aren't included, but then have aa as an example output. Also, what if two things overlap? In ababa, is aba included? \$\endgroup\$ – rak1507 Apr 3 at 13:33
  • \$\begingroup\$ Thanx edited accordingly. \$\endgroup\$ – Aatmaj Apr 3 at 13:44
  • \$\begingroup\$ Is the input always going to contain at least 1 space? And can input be taken as a list of words (e.g. ['aab', 'aacab']) instead of a space-separated string? Additionally, I'd suggest mentioning something about the case of the input. For example, case-wise, your example (International ...) only has inter repeated if case is ignored \$\endgroup\$ – Dude coinheringaahing Apr 4 at 0:20
0
\$\begingroup\$

Getting to the root of the problem

While I was sleeping in my bed, unwilling to wake up, an idea entered my head: why is the syntax for powers, especially roots, so cumbersome? It would save so many bytes if we could just use the square root symbol instead, and easier to understand too. So, your challenge is to encode this in whatever format you choose, in as few bytes possible.

Answers should be able to:

a) convert a string such as 2**(1/2) into √2 or some other format that distinguishes it from 2√2 (note, if you choose to write 2√2 as 2 * √2 and write things like 2**(1/3) as 3√2, that is allowed).

b) Work for arbitrary powers (2**(1/50) should work fine).

c) Simplify roots. (4**(1/4) = √2)

and should be able to perform this on inputted strings.

Deduct 10% from your score if you can handle addition of roots, deduct a further 10% off that if you can handle the ret of the basic operators (-, *, /), another 10% if you can simplify expressions such as (2 - √2)/(2 + √2), another 10% if you can write 16**1/4 (for example) as √(2^2), and, if you're amazing enough to implement exponentiation, you can subtract 50%.

Input will be presented in the form of [0-9]**([0-9]/[0-9]), where the 0-9s can be any number of digits. Output should ideally be in the form of [0-9] * [0-9]√[0-9], again, with the 0-9s being any number of digits, but I will let other forms slide so long as as 3√2 (that's the cube root of 2) is distinguishable from 3 * √2.

Tags:

Lowest score wins. Good luck!

\$\endgroup\$
5
  • \$\begingroup\$ This is a good challenge, at least part A looks good, but it will need to be clarified. Ideally put a regex that objectively tells what input we need to handle (like whether we should handle whitespace (which we probably shouldn't have to)). The bonuses are most likely unnescessary. \$\endgroup\$ – Wezl Apr 4 at 1:50
  • \$\begingroup\$ The bonuses might be unnecessary, but if someone can write a creative answer that does all of that, it'd probably be an even better answer than one that just does the minimum, and might score lower (I was generous with the bonuses to encourage going the extra mile, and you can get a reduction of over 70% from them). About the input, I'll fix that now. \$\endgroup\$ – StackMeter Apr 4 at 10:02
  • \$\begingroup\$ Also this is going to be important to my tie-in puzzle, "Returning to the root of the problem", and having those bonuses done now will improve your overall score (yes this may well be a series). \$\endgroup\$ – StackMeter Apr 4 at 10:12
  • \$\begingroup\$ Should 72**(1/6) be 2V2*3V3? \$\endgroup\$ – l4m2 Apr 6 at 13:33
  • \$\begingroup\$ You can do it as such if you want to. \$\endgroup\$ – StackMeter Apr 6 at 13:51
0
\$\begingroup\$

Computer Tree

Consider an infinite amount of same computers building a tree, running same program. Each computer has infinite memory and infinite pins 0 to Infinity, where pin 0 connect to its parent, or the IO we see for the root; and pin 1..Inf connect to its childs.

Each connection is bidirectional, and has buffer in each direction. Writer put the value into buffer, and reader gets from it.

The computers need to support these abilities: (Here dest is a variable in the memory, and src1, src2 are either variable or immediate integers. [x] mean the memory in address x.

dest = src1 op src2, op in +,-,*
[dest] = src1
dest = [src1]
if(src1 op src2) goto inst, op in <,==,<=,!=
if((not)pin src1 writing) goto inst
if((not)pin src1 reading) goto inst
write src2 to pin src1, block if already writing
read dest from pin src1, block if not reading

It's fine if you need several elements to do one job above, but each job defined above should use same amount of time(In this model timing matters). It's also fine if you take input as some other formats, but to avoid taking too ready functions, an same-type input shouldn't lead to an infinite loop. Input for root is given when started and will never need to wait unless all input used up, but it doesn't always halt.

Shortest code win.

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

Tags:

Interpret a Cangjie Input Method String

The Cangjie input method is a method for inputting Chinese characters using a standard QWERTY-like keyboard. Each Chinese character is encoded as a sequence of Latin letters, each letter representing a radical, or part, of the character's form. Each letter encodes both the radical character it represents, as well as other, related radicals (such as E encoding as well as , and more).

There are 24 radicals encoded in Cangjie, as well as 3 other characters for wild cards and other purposes. For the purposes of this challenge, only the subset of the main 4 groups are used, shown below with meanings:

Philosophical group
A   日 sun
B   月 moon
C   金 gold
D   木 wood
E   水 water
F   火 fire
G   土 land

Stroke group
H   竹 bamboo
I   戈 dagger axe
J   十 ten
K   大 big
L   中 centre
M   一 one
N   弓 bow

Body parts group
O   人 person
P   心 heart
Q   手 hand
R   口 mouth

Character shapes group
S   尸 corpse
T   廿 twenty
U   山 mountain
V   女 woman
W   田 field
Y   卜 fortune telling

Cangjie Basic Rules

Characters are analyzed as such to create a Cangjie code (based on the Wikipedia article above):

  • Direction of decomposition: left to right, top to bottom, outside to inside
  • Geometrically connected forms: takes 4 Cangjie codes from the 1st code to the last code
  • Geometrically unconnected forms:
    • Forms in exactly 2 subforms: Follow the direction of decomposition rules, then take the first and last codes of of the first subform, and the first, second, and last code of the second subform.
    • Forms in more than 2 subforms: take the first and last codes of the first subform according to direction of decomposition, then break the remainder into subforms. Take the first and last codes of the first remainder, and the last code of the last remainder.

The Challenge

Write a full program or function that, when given a valid Cangjie code string as input, outputs its corresponding traditional Chinese character.

Additional Rules

  • Use Cangjie version 5.
  • Standard loopholes are forbidden.
  • An invalid Cangjie code string (not in our subset of codes) is undefined behavior when used as input.
  • If multiple characters match a Cangjie code string, you can choose to output both, or choose one. If you choose one, it must only output that character when given that code.
  • This is , so shortest code wins!

Examples

Input - Output (notes)
JWJ - 車 (connected, top to bottom: 十田十)
YRHHI - 謝 (3 parts: first is disconnected, take first and last YR;
           second is is disconnected, take first and last HH; last part take last I)
AN - 門 (special case: fixed decomposition)
OMN - 气 (another fixed decomposition; using version 5)
A - 日
BOB - 肭
JPHI - 蜜
GUMPC - 顤
STKR - 匿 or 𡲢 (if multiple characters exist for that code, pick one deterministically)
HXH - (undefined behavior, since X is not in the set of codes above)

Meta

  • Is it clear? Anything that needs adding/removing?
  • Any weird test cases I didn't put in?
  • Anything else?
\$\endgroup\$
1
  • 2
    \$\begingroup\$ It's not clear enough how to actually do the conversion (without looking at the Wikipedia article). Remember to always assume no pre-existing subject knowledge when writing challenges, and don't require users to use external resources to find out about it. \$\endgroup\$ – pxeger Apr 7 at 17:20
0
\$\begingroup\$

Text in aLtErNaTiNg cApS

Sometimes, we want to convey sarcasm in a text message or in a YouTube/Reddit comment. To this end, "alternating caps" is often used. Your task, should you wish to accept it, is to write code that turns the input text into its "alternating caps" version.

(This is a deleted rule. You should ignore this for the challenge) For most sans-serif web fonts, it is hard to distinguish capital I (for India) and lower-case l (for Lima). So we want to avoid either of these letters in our output. To achieve this, we are allowed to sacrifice "exact alternating-ness" of the output. Details below.

Input:

  1. A string of words involving [a-zA-Z], with one space in between each word.
  2. You may not assume whether or not the string ends with a space/newline/etc.

Output:

  1. The input, turned into "alternating caps form", with the first letter of each word being lower-case.
  2. (Deleted; you should not implement it. I have included it just to illustrate my thought process) You may not output any capital I (I, for India) or lower-case l (l, for Lima). To avoid these, you may continue outputting the same letter-case as the previous letter, but you must switch the letter-case at the earliest possible instance. (note to self: this requirement means there are sometimes more than two letters of the same case, which I don't really want)

  3. Non-suppressible output can be ignored.

Rules:

  1. Standard loopholes are forbidden.
  2. You must take input from and output to natural places, according to your language.
  3. This is code-golf, so the lowest byte-count wins. Ties are broken by earliest submission.
  4. Please provide a way for readers to test your code (e.g. TIO).
  5. An ungolfed version and an explanation for your code is appreciated, although not required for the challenge.

Examples

Input -> Output
---------------
alternating -> aLtErNaTiNg
lower case letters -> lOwEr cAsE lEtTeRs

Examples that follow the deleted rule (which you should not implement -- these are just for your interest:

I used dcode to find some of these examples. holding -> hOLdiNg radii -> rAdii (has more than 2 lower-cases in a row, if using my rules) fall -> fALL (has more than 2 capitals in a row, if using my rules) volleyball -> [even if you are allowed to change the previous letter-cases to try to stop 'ALL' (3 capitals in a row) from appearing, there is a non-unique way of doing so]

Good luck!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Unfortunately this has been posted before: codegolf.stackexchange.com/q/122783 \$\endgroup\$ – pxeger Apr 8 at 8:36
  • \$\begingroup\$ @pxeger That challenge is slightly different, as this one asks for alternating characters rather than alternating letters. lower case letters in that challenge would become LoWeR cAsE lEtTeRs (or lOwEr CaSe LeTtErS), neither of which are acceptable outputs for this \$\endgroup\$ – Dude coinheringaahing Apr 11 at 14:02
0
\$\begingroup\$

Take two registers, zero-extend one to another one on x64 in a single instruction.

Here, registers are r0-r15(64-bit), r0d-r15d(32-bit), r0w-r15w(16-bit) and r0b-r15b(8-bit), where regs marking same number share same lowest part. In case there's no solution (e.g. writing into r0d, which the opcode would behave writing to r0), output something obviously not an opcode.

Opcodes:

90              do nothing
89 11sssddd     move 16/32/64-bit[1] from sss[2] to ddd[2]
88 11sssddd     move 8-bit from sss[2] to ddd[2]
0F B7 11dddsss  move from 16-bit sss[2] to 32/64-bit[1] ddd[2]
0F B6 11dddsss  move from 8-bit sss[2] to 16/32/64-bit[1] ddd[2]
101101dd 00     move from 8-bit 0dd[2] to 16-bit 0dd[2]             
[WIP]

Shortest code win. -35 Bytes if you support ax cx dx bx sp bi sp di aliasing r0w-r7w, and rax-rdi as r0-r7, eax-edi as r0d-r7d; - another 35 Bytes if you support al cl dl bl aliasing r0b-r3b and ah ch dh bh as theoretically r4b-r7b but without REXs.

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

Make an image with the pixels from another (WIP)


Given a target image and a source image, output an image that resembles the target image by rearranging the pixels of the source image.

You will be scored based on speed and accuracy.

$$ score = {similarity(Image_{target}, Image_{result}) \times {time_{reference} \over time_{program}}} $$

Higher scores are better

\$\endgroup\$
1
98 99
100
101 102
115

You must log in to answer this question.

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