571
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

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

4728 Answers 4728

1
2 3 4 5
158
0
\$\begingroup\$

Three up to 729 & sum to 2048

(flexibly) Output 3 random integers such that:

  • Each number is 1 to 729 inclusive
  • They add to 2048
  • Each possibility is equally likely to be outputted

This is - shortest code in bytes "wins"

Sandbox stuff

  • Nothing (for now)
\$\endgroup\$
2
  • 1
    \$\begingroup\$ fastest-code is for optimizing for speed, here it doesn't make much sense as there's nothing to optimize. i suggest going for code-golf. \$\endgroup\$ Commented Jul 12 at 10:07
  • 1
    \$\begingroup\$ as for the randomness part, that's up to the people attempting the challenge. if they want to attempt the challenge, they have to pick a language that is able to do it, for the same reason people don't typically attempt graphical output challenges in BF. \$\endgroup\$ Commented Jul 12 at 10:10
-2
\$\begingroup\$

Print the number 205891131832505

Print the following 15-digit number to the console:

205891131832505

Rules

You may either print the output, or return a string or integer from a function. A trailing newline is allowed.

This is , so shortest answer in bytes wins!

New contributor
Andrew Bayly is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
3
\$\begingroup\$

A robber flipped some bits. This is what happened to the cop's code.

Objective

Cops shall pose a code that outputs a truthy or falsy value deterministically, depending on the input. The output must be truthy on some inputs and falsy on some other inputs.

Flipping exactly half of the bits in the code shall result in negating the output for every input. Robbers shall find such bits.

Winning criterion

For cops, the submission whose the cardinality of all valid inputs is the biggest shall win. The shortness of the code is a tiebreaker. In other words, this is primarily and secondarily . (Note that there may be infinitely many valid inputs, and its cardinality cannot exceed aleph-naught.)

For robbers, the submission whose the maximum number of consecutive flipped bits is the smallest shall win.

Rule

Cops must specify what the valid inputs are.

\$\endgroup\$
6
  • \$\begingroup\$ I think you should elaborate the 'cardinality of valid inputs' scoring criterion better. In Husk, a cop answer could be = increment. All integers are valid inputs (so they are infinite), and only -1 results in falsy output (zero). I don't think there's a single-byte Husk command that would make -1 truthy and everything else falsy, so it seems uncrackable. \$\endgroup\$ Commented Sep 1, 2023 at 12:25
  • 1
    \$\begingroup\$ @DominicvanEssen they way I understood the second sentence of the objective, there has to be a way to crack the program for the submission to be valid \$\endgroup\$
    – bsoelch
    Commented Sep 3, 2023 at 8:31
  • 1
    \$\begingroup\$ @bsoelch - ah, that makes sense… \$\endgroup\$ Commented Sep 3, 2023 at 9:30
  • \$\begingroup\$ Why is higher cardinality better? I would think it would be the opposite. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Sep 3, 2023 at 18:56
  • \$\begingroup\$ @WheatWizard If smaller cardinality were better, cop submissions might take no input, which gives cardinality 1. That's too trivial. \$\endgroup\$ Commented Sep 4, 2023 at 1:17
  • \$\begingroup\$ Isn't trivial better? It makes it harder to disguise things. But if trivial is bad what's to prevent someone from "taking" the input and ignoring it. That makes no real difference to the cop but makes their score in that infinity. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Sep 4, 2023 at 2:10
0
\$\begingroup\$

ASCII/Unicode Progress Pride Flag


Take in a boolean value indicating whether unicode has full monospaced support, and output the appropriate flag:

 __________________________________________________________ 
|\   \   \                                                 |
|  \   \   \                                               |
|\   \   \   \ ____________________________________________|
|  \   \   \   \                                           |
|\   \   \   \   \                                         |
|  \   \   \   \   \ ______________________________________|
|    \   \   \   \   \                                     |
|      \   \   \   \   \                                   |
|        \   \   \   \   \_________________________________|
|        /   /   /   /   /                                 |
|      /   /   /   /   /                                   |
|    /   /   /   /   /_____________________________________|
|  /   /   /   /   /                                       |
|/   /   /   /   /                                         |
|  /   /   /   /___________________________________________|
|/   /   /   /                                             |
|  /   /   /                                               |
|/___/___/_________________________________________________|
ˏ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ˎ
│\\\                     │
│\\\\̅⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎤
│\\\\\─────────────────┤
│  \\\\\⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎦
│  /////               │
│/////─────────────────┤
│////̲̲⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎦
│///                     │
`‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾´

Note that the lower flag uses grave, acute, low grave, and low acute on the corners; horizontal scan line -1 & -9 for high and low lines; box drawings light horizontal for center lines; box drawings light vertical for vertical lines; one combining low line & one combining overline; and @sandbox look at the image and pick which you think looks nicest for connections on the right.

Since it appears stack exchange does not have unicode support in their monospace font, here's what that looks like in a fully monospace font: monospace font

previous challenges were graphical output

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

Double dequer sort

In this challenge Bubbler describes sorting a list by inserting its elements left to right into a double ended queue or "deque".

Take a number from the front of the array, and push it into one of the two ends of the deque. Repeat this until the array is empty.

That challenge asks if it is possible to sort a given array using this procedure. That is it possible to choose a pattern of fronts and backs which yields a sorted deque at the end.

In this challenge we ask whether it is possible to do sort a list by following this procedure twice. That is:

Take a number from the front of the array, and push it into one of the two ends of the deque. Repeat this until the array is empty.

Then take a number from the front of that deque and push it into one of the two ends of a new deque. Repeat this until the first deque is empty.

For example the list [4,5,6,1,2,3] cannot be sorted using one pass of this procedure. However with one pass we can get the list [3,2,1,4,5,6] which can be sorted with another pass.

Not all lists can be sorted in two passes however. For example [5,3,4,1,2] requires a minimum of 3 passes to sort.

Task

Given an array of positive integers determine if it can be sorted in two passes of the procedure. Output one of two distinct consistent values depending on whether the input is possible or impossible to sort in two passes.

This is . The goal is to minimize the size of your source code as measured in bytes.

Test cases

Possible

[1]
[1,2,3,4]
[4,3,2,1]
[10,10,10,10]
[3,4,2,5,1,6]
[4,3,5,2,6,1]
[5,4,4,5,3,5,3,6,2,6]
[1,3,2]
[3,4,5,1,2,3]

Impossible

[5,3,4,1,2]
[7,5,6,3,4,1,2]
[7,8,9,3,4,5,1,2,3]
\$\endgroup\$
2
\$\begingroup\$

Wait, ASCII was 128 characters all along?

This question was posted.

\$\endgroup\$
1
  • \$\begingroup\$ I think base 128 works better, since it's less likely to be a built in than base 256 \$\endgroup\$ Commented Jul 16 at 22:33
0
\$\begingroup\$

Three-valued Satisfiability problem

Objective

Given an expression involving ternary values and free variables, decide whether the expression is satisfiable.

The caveat is, the output is a ternary value by itself. So this isn't really a ; it's a problem.

Ternary Values

The three truth values in question are the values of Haskell's Ordering, namely LT, EQ, and GT. They stand for "less-than", "equal-to", and "greater-than", respectively. Furthermore, they themselves have an order; LT is the least, and GT is the greatest.

Operators

The binary operators for the ternary values are Haskell's min, max, compare, and (<>), all instantiated for Ordering. They're defined as:

min|LT EQ GT
---|--------
LT |LT LT LT
EQ |LT EQ EQ
GT |LT EQ GT
max|LT EQ GT
---|--------
LT |LT EQ GT
EQ |EQ EQ GT
GT |GT GT GT
compare|LT EQ GT
-------|--------
  LT   |EQ LT LT
  EQ   |GT EQ LT
  GT   |GT GT EQ
(<>)|LT EQ GT
----|--------
 LT |LT LT LT
 EQ |LT EQ GT
 GT |GT GT GT

Classification

If the free variables have a combination of ternary values that lets the inputted expression evaluate to GT, the output shall be GT.

Otherwise, if the free variables have a combination of ternary values that lets the inputted expression evaluate to EQ, the output shall be EQ.

Otherwise, the output shall be LT.

I/O Format

Flexible. You may represent the values and the operators in an arbitrary way.

Examples

Here, the free variables are V1, V2, V3, and so on.

Input -> Output

EQ `min` V1 -> EQ
V1 `min` V1 -> GT
V1 `min` V2 -> GT
EQ `max` V1 -> GT
V1 `compare` GT -> EQ
V1 `compare` EQ -> GT
LT `compare` V1 -> EQ
EQ <> V1 -> GT
V1 <> LT -> GT
LT <> V1 -> LT
V1 `min` (EQ `compare` V1) -> EQ
V1 `min` (EQ `compare` V2) -> GT
V1 `max` (EQ `compare` V1) -> GT
(LT <> V1) `max` (L1 <> V2) -> LT
(V1 `compare` GT) `compare` (V1 `compare` LT) -> LT
V1 `compare` V1 -> EQ
(V1 `compare` V1) <> LT -> LT
V1 <> V2 <> V3 -> GT
LT `compare` LT -> EQ
EQ -> EQ
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think this is not very different from this, because you can substitute the variables in all possible ways, evaluate them, and take the minimum to get the correct answer, and implementing the evaluator is likely the longest part. \$\endgroup\$
    – Bubbler
    Commented Jul 15 at 23:36
0
\$\begingroup\$

String animations

Heya, I just discovered a fun text animation while sketching up my personal website. It's a scroll-jacking website and as you scroll the text unrandomizes itself. The idea is to present bullet points of information. At the beginning the strings are shuffled and progressively sort themselve as you scroll.

You can see the animation at https://javascript.moe

This perfectly translates into a code golf challenge and your task is to write a function or program which takes as input an array of strings, and an integer for progress.

const animate = (strings: string[], progress: number) => {
    // Compute a partially shuffled string...
}

The function will be called with n strings and a progress between 0 and 1. It shall output a progressively sorted string as the progress increases towards 1.

The logic is as follows:

  1. The first n characters are sorted / partially equal to the input. The rest of the string is sorted semi randomly. - *Where n is floor(length * progress).
  2. If the function is called twice the unsorted part needs to be shuffled again.
  3. When sorting / shuffling the partial string, it shall decrease randomness as progress increases. A progress of 1 means perfectly sorted, a progress of 0 means completely random and a progress of 0.5 means the random position is weighed equally to the sorted position. So, as the progress increases each character gets placed closer to its correct place instead of a completely random place. Depending on the sorting algorithm. It is ok if half of the characters end up at the correct place and half are completely random. Instead of sorting each character closer. The order must change on each call even if the progress doesn't change.

Examples

Input: ['Hello World', 'Goodbye'], 0 Output: 'elodHr llWo'

Input: ['Hello World', 'Goodbye'], 0.25 Output: 'Heodlr lWol'

Input: ['Hello World', 'Goodbye'], 0.75 Output: 'Goobdey'

Input: ['Hello World', 'Goodbye'], 0.8 Output: 'Goodbey'

Input: ['Hello World', 'Goodbye'], 0.9 Output: 'Goodbye'


Tags:

New contributor
C5H8NNaO4 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
-1
\$\begingroup\$

Identify RARE Kpop Manifesto's AWK one-liners

RARE Kpop Manifesto is a Code Golf & Code Challenge StackExchange user who is known for an AWK golfer. He or she is famous for posting AWK answers with just variables of underscores, not trying to follow our style of posting, trying to play a game off from us, and advising AWK programming in Stack Overflow for over 1,000 times. Today I brought their 25 AWK codes; oldest one is posted on November 1, 2022 and newest one is on June 22, 2024.

How I brought code

As of July 10, 2024 they had posted 38 answers; I chose one-line AWK codes out of them. If the answer has several AWK codes I took first one.

If the program was

echo 'Hello, World!' |

gawk '{ print $0 }'

then I took

{ print $0 }

as a data. If the program had some assignments or flags, like

echo 1.1b2.2b3.3b4.4 |

mawk -F b 'BEGIN { __ = __^__ }; { for ( _=NF; _--; ORS = ORS ___ ) print $_ * ___; }' ___=`ps -Ao pid,etime,pcpu,vsz | cksum`

then I took

-F b 'BEGIN { __ = __^__ }; { for ( _=NF; _--; ORS = ORS ___ ) print $_ * ___; }' ___=`ps -Ao pid,etime,pcpu,vsz | cksum`

as data. The code may have some escapes because they were intended to be run from shell, but took as-is. E.g.

nawk \$_=RS=ORS

to

\$_=RS=ORS

Challenge

Given an one-line AWK program, identify on which answer post it appears.

Input

One of one-line AWK program shown in the dataset below, as a strings.

Output

An integer to indicate the post id of the answer corresponding to the input. However since every id is greater than 200,000 and less than 300,000, you may output only bottom five digits. E.g. if the answer is 234,567, then you may output 34,567 instead.

Scoring

Number of IDs your program or function answered correctly, which is N/25.

Tie-breaking

Dataset

The format is:

answer-id program

Here are 25 test cases:

253982 function __(_){return index("=anebarprayunulugepctovec",substr(_,2,2))/2}
254001 __=$(_^=___=_<_){++_;do{___+=__%_}while(__=int(__/_))}$!NF=___ ""
254007 -F\[^FU] NF=NF OFS=T
254012 NF+=sub("  ",OFS=" "tolower($2=$4=$1)" ")
255693 '{for(_=NF-2;1<_;_-=3)$_=","$_}NR' FS= OFS=
255694 ($_+=$2)_
255695 /%[dfrs]/
255696 -M 'function __(_){return _*_==_?+$_:$_*__(--_)}($_=__(NF*=!/0/))_' FS=
255709 $_*=$++_++/(_+_--)
256002 gsub("[^"$NF"]",_,$--NF)
256043 'function __(_){return $_=--_?_+=_=__(_):!_}__(NF=$_)' OFS=,
259913 ($_*=$2)_
260775 function ___(_,__) { gsub(".","\\&& ",__)gsub(".",__,_); return _ }$++NF = ___($++_, $++_)
260782 $__=sprintf("%.f",($5-($2$3))/(_+=$_)^!!_)
261246 BEGIN { print (_+=++_)!_!!_ _^_ }
261310 gsub(_,"!")
263592 func __(_){return(-_<_)-(_<-_)}
265230 function leap(_) { return _~"(([2468][048]|[13579][26]|(^|[0+-])[48])(00)?|0000|^[+-]?0*)$" ? "y" : "n" } ($2 = leap($1))^_
269628 '($++NF=(__=$++_)*(_!_)^((__=length(__))-$(_+_)%__)%((_!_)^__-_--))' FS=,
269629 NF=OFS=\$_
272251 $_=int(3E-3^-4)-102
273321 gsub(/./,"&&")_
273407 BEGIN{print$-($_=(_="*****")_)^gsub(/./,RS$_)}
273687 '$_=substr($2,$_,1)' FS=' ?"'
273743 'ORS=RT?length(RT):_' RS=0+

Notes

260775 was originally two-line answer but joined into one line. 265230 was originally three-line answer.

More rules

About source code

https://stackoverflow.com/help/licensing

Content contributed on or after 2018-05-02 (UTC) is distributed under the terms of CC BY-SA 4.0.

Meta

  • To @RareKpopManifesto: can I post this question?
  • Other tag ideas?
\$\endgroup\$
2
\$\begingroup\$

Is it a date format of YYMMDD, MMDDYY, and/or DDMMYY?

The date format varies between countries; the arrangement of date, month and year can be categorized into these three:

  • Year-month-date
  • Month-date-year
  • Date-month-year

In Gregorian calendar it's year of 2024 now (at this point I publish this problem); we often shorten the notation of year by using only bottom two digits: e.g. 24.

Month and date are usually represented as one or two digits.

Today you are having a triple desicion-problem who do something with date format.

Input

One of:

  • A string of six digits
  • An nonnegative integer up to 999999
  • Three nonnegative integers up to 99
  • Six nonnegative integers up to 9

Here is a Python snippet of generator to generate every input as string:

f"{d:06}" for d in range(999999+1)

Attempt This Online!

Output

A tuple of three boolean values whether it can be interpreted as YYMMDD, MMDDYY, and DDMMYY date format. As long as it is consistent, you can have flexible output. Examples but not limited to:

  • a set of data
  • an integer with possibly three bits
  • 0-3 characters of string consists of y, m and/or d to indicate it is truthy for YYMMDD, MMDDYY, and DDMMYY respectively
  • different exception classes

Specification

TLDR: Gregorian Calendar. YY is bottom two digits of the year. Handle leap year as usual. If YYMMDD is 000229 it is optional whether its format is valid or not.

A digit is a character one of 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

The YY format is any combination of two digits.

The MM format is one of 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, or 12.

The DD format varies depending on the YY and MM formats:

  1. if MM is one of 04, 06, 09, or 11, then the format is one of 01, 02, 03, ..., 09, 10, 11, 12, ..., 19, 20, 21, ..., 29, or 30.
  2. if MM is one of 01, 03, 05, 07, 08, 10, or 12 then the format is one of 01, 02, ..., 29, 30 or 31.
  3. if MM is 02 and YY is NOT a multiple of 4, then the format is one of 01, ..., 27, or 28.
  4. if MM is 02 and YY is 00 then the format is one of what rule 3 says or optionally a string of 29.
  5. if MM is 02 and YY is NOT 00 and is a multiple of 4, then the format is what rule 3 says or 29.

The YYMMDD format is a concatenation of the YY, MM and DD formats.

The MMDDYY format is a concatenation of the MM, DD and YY formats.

The DDMMYY format is a concatenation of the DD, MM and YY formats.

Test cases

In the following table, maybe means it is implementation-defined to output whether the value is truthy or falsey.

Input   YYMMDD MMDDYY DDMMYY
000000  false  false  false
000001  false  false  false
000099  false  false  false
000100  false  false  false
000101  true   false  false
000102  true   false  false
000131  true   false  false
000132  false  false  false
000199  false  false  false
000200  false  false  false
000201  true   false  false
000228  true   false  false
000229  maybe  false  false
000230  false  false  false
000300  false  false  false
000301  true   false  false
000331  true   false  false
000332  false  false  false
001130  true   false  false
001231  true   false  false
001232  false  false  false
010000  false  false  false
010001  false  false  false
010099  false  false  false
010100  false  true   true
010101  true   true   true
010102  true   true   true
010131  true   true   true
010132  false  true   true
010199  false  true   true
010200  false  true   true
010201  true   true   true
010228  true   true   true
010229  false  true   true
010300  false  true   true
010301  true   true   true
010331  true   true   true
010332  false  true   true
010430  true   true   true
010431  false  true   true
010531  true   true   true
010532  false  true   true
011231  true   true   true
011232  false  true   true
011299  false  true   true
011300  false  true   false
011399  false  true   false
011400  false  true   false
013199  false  true   false
013200  false  false  false
014567  false  false  false
019999  false  false  false
020000  false  false  false
020001  false  false  false
020099  false  false  false
020100  false  true   true
020101  true   true   true
020102  true   true   true
020128  true   true   true
020131  true   true   true
020132  false  true   true
020199  false  true   true
020200  false  true   true
020201  true   true   true
121212  true   true   true
121213  true   true   true
121230  true   true   true
121231  true   true   true
121232  false  true   true
121299  false  true   true
121300  false  true   false
121301  false  true   false
121399  false  true   false
121400  false  true   false
123100  false  true   false
123199  false  true   false
123200  false  false  false
129999  false  false  false
130000  false  false  false
130099  false  false  false
130100  false  false  true
990101  true   false  false
990202  true   false  false
991230  true   false  false
991231  true   false  false
991232  false  false  false
991233  false  false  false
999999  false  false  false

Every case truthy for all of YYMMDD, MMDDYY, and DDMMYY

Too long; pasted on GitHub Gists.

Test case generator

inputrange = list(range(200, 231)) + list(range(0, 1000000, 2763))

yymmdds, mmddyys, ddmmyys = [], [], []
maybey, maybem, maybed = [], [], []
for y in range(99+1):
  for m in range(1,12+1):
    if m == 2:
      dlast = 28 + (y%4==0)
    else:
      dlast = 31 - (m in [4,6,9,11])
    for d in range(1,dlast+1):
      yy, mm, dd = f"{y:02} {m:02} {d:02}".split(" ")
      ys, ms, ds=yy+mm+dd, mm+dd+yy, dd+mm+yy
      if (y,m,d) == (0,2,29):
        [maybel.append(s)for (maybel,s)in [[maybey,ys],[maybem,ms],[maybed,ds]]]
        continue
      yymmdds.append(ys)
      mmddyys.append(ms)
      ddmmyys.append(ds)

for x in [f"{x:06}" for x in inputrange]:
  y, m, d = ["maybe" if x in maybel else x in l for (maybel,l) in ((maybey,yymmdds),(maybem,mmddyys),(maybed,ddmmyys))]
  print(x, y, m, d)

Try it online!

Rules

See also

Challenges involving possibly ambiguous date format:

Meta

  • Is my specs adequant?
  • When I tried generating every test case (100K cases) to find it not realistic for my computer's ability; I need to enumerate every boundary test if possible.
  • More input formats; good idea for golfers?
\$\endgroup\$
1
0
\$\begingroup\$

Imagine a language that supports <> as brace and also as compare.

To avoid confusion like a<b>(c), <(less than) and >(greater than) are not allowed on same layer. a<b<c is still allowed, though. <> can't directly contain &, so a<b&c>(d) would be treated as lt and gt. Use a<(b&c)>(d) to mean the other.

Given an expression with lowercase letters and <>()+&, decide if it's valid.

Exact definition of valid is expr2 following:

expr1 = [a-z]* | +expr1 | expr1+expr1 | (expr2)
      | expr1<expr1> | expr1(expr2)
expr2a = expr1 | expr1 < expr2a
expr2b = expr1 | expr1 > expr2b
expr2 = expr2a | expr2b | expr2a & expr2 | expr2b & expr2

Test cases:

a<b>(c)      true
a<b<(c)      true
a<b<c        true
a<b>c        false
a<b&c>d      true
a<(b&c)>d    false
a>b<(c)      false
\$\endgroup\$
1
3
\$\begingroup\$

Sorting with a deque

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

When is My Holiday?

Background

I recently learned of a holiday, that occurred on August 20, 2023 and August 12, 2022. This got me wondering how on earth they were determining which day this holiday falls on.

The Challenge

In this challenge you will be given two dates which are from the same month but different years as input. You must construct the simplest possible description which applies to both dates.

Descriptions must be structured in a particular way. First, there are types of days

type cost
day 1
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday 1
weekday, weekend day 1
day which is a multiple of \$N\$ \$N\$

For the following we'll let \$D\$ be some type of day. We then have modifiers and constants.

modifier constant
the nth \$D\$ after the nth \$D\$
the nth \$D\$ before the nth to last \$D\$
the nearest \$D\$ to

A valid description consists of 0 or more modifiers followed by a single constant. The simplest description is the one with the lowest cost, which is the sum of the cost of each \$D\$ which appears in the description.

For the purposes of this challenge we define "nearest" to mean "nearer than all others" so if there is a tie, then neither day is nearest and the description is not valid. "Nearest" may include the day itself. "Before" and "after" do not include the day itself.

I/O

Standard I/O rules apply, the dates may be taken in any reasonable format. And since the challenge is not about supposed to be about date calculation you may choose to take in data about the month surrounding each day. Some examples of valid input formatting are as follows. A program would take two such inputs.

2023-08-22

8/22/23

22.8.23

[[xx, xx, 01, 02, 03, 04, 05]
 [06, 07, 08, 09, 10, 11, 12]
 [13, 14, 15, 16, 17, 18, 19]
 [20, 21, 22, 23, 24, 25, 26]
 [27, 28, 29, 30, 31, xx, xx]], 
[3, 2]

You may assume any input given will have a solution. Your description need not apply to all years, just the ones in the input (eg. August 2023 has no 5th monday, but "the 5th monday" is still correct for 2021-08-30, 2022-08-29). If two or more descriptions tie you may output any or all.

For output I'm going to be fairly lenient. You may choose your own encoding scheme to represent possible outputs. The most basic way to represent the output would just be to output the elements as seen in the tables above separated by spaces. But for golfing purposes you'll likely want to encode the outputs into some sequence which represents these elements. An example of what an encoding may look like is seen below.

element encoding
day wa
Monday wm
Tuesday wt
Wednesday ww
Thursday wh
Friday wf
Saturday ws
Sunday wu
weekday wd
weekend day we
day which is a multiple of \$N\$ w\$N\$
the nth \$D\$ after An\$D\$
the nth \$D\$ before Bn\$D\$
the nearest \$D\$ to Cn\$D\$
the nth \$D\$ Tn\$D\$
the nth to last \$D\$ Ln\$D\$
T4wa -> the 4th day
T5wm -> the 5th monday
B1w4T3wm -> the 1st day which is a multiple of 4 before the 3rd Monday

This is just an example, and you may design your own encoding scheme as long as it has a unique representation for all posiible outputs and it is at least halfway sensical. Please provide a description for your encoding scheme, and bonus points if you include a supplementary script to convert your ouput to the written out description.

Test Cases

These test cases follow the YYYY-MM-DD input format

2022-07-04, 2023-07-04 -> the 4th day
2021-08-30, 2022-08-29 -> the 5th monday
2022-08-12, 2023-08-20 -> the 1st day which is a multiple of 4 before the 3rd Monday


How clear is this?

I still plan to add more test cases.

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

Given array X, decide if there is real number x, s.t. X[i]=floor(x*i).

True cases: (1-index)

[1,2,3,4,5]
[1,2,3,5,6]
[0,0,0,1,1]
[1,3,5]

False cases:

[1,3,5,8]
[3,5]

Duplicate?

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

Draw a Regular Reuleaux Polygon

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

o y u

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

Is this a Hadamard matrix?

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

Automatic Pikmin Count

Inspired by the feature in Pikmin 4.

In Pikmin 4, you can have up to eight types of pikmin in an onion and up to three types of pikmin outside the onion. Each area recommends three types of pikmin to bring. The onion's interface has an "auto" button which selects pikmin in the following fashion:

  • If possible, select equal amounts of each suggested pikmin type.
  • If there aren't enough of one type, get all of them and equal amounts of the rest (e.g. if 30, 30, 30 isn't possible, it may do 20, 35, 35).
  • If there aren't enough of all the suggested types combined, grab everything there is.
  • If the number of pikmin to select isn't a multiple of three, it grabs more of the kind you have most of (e.g. if the number of pikmin of each type is 300, 200, 100 and it needs to select 100 pikmin, it selects 34, 33, 33)
  • ...unless there's a tie (e.g. if the pikmin counts are 200, 200, 100 and it needs to grab 100 pikmin, it selects 33, 33, 34).
  • If a tie needs to be broken arbitrarily (e.g. a three-way tie), select up to 1 more of the first tied type listed.

The challenge is to write a function or program that takes three inputs: the number of pikmin that can be brought out (an integer in \$\left[0, 100\right]\$), the number of pikmin of each type (eight positive integers), and the recommended pikmin types (three indices into the previous array). You can take the pikmin types as 0- or 1-based indices, and you may assume they are sorted. It should then return an array of eight numbers indicating how many pikmin of each type are to be selected, which will always have at least five 0's. This is , so your score is your answer's length.

Test cases

Using 0-based indices

# to select; counts; indices => selections

100; [400, 450, 300, 250, 100, 30, 0, 10]; [0, 1, 2] => [33, 34, 33, 0, 0, 0, 0, 0]
100; [400, 450, 300, 250, 100, 30, 0, 10]; [3, 4, 5] => [0, 0, 0, 35, 35, 30, 0, 0]
37; [30, 30, 10, 20, 100, 5, 1, 100]; [0, 1, 3] => [12, 12, 0, 13, 0, 0, 0, 0]
38; [30, 30, 10, 20, 100, 5, 1, 100]; [0, 1, 3] => [13, 13, 0, 12, 0, 0, 0, 0]
38; [30, 30, 10, 20, 100, 5, 1, 100]; [0, 1, 2] => [14, 14, 10, 0, 0, 0, 0, 0]
39; [30, 30, 10, 20, 100, 5, 1, 100]; [0, 2, 3] => [15, 0, 10, 14, 0, 0, 0, 0]
39; [30, 30, 10, 20, 100, 5, 1, 100]; [0, 1, 2] => [15, 14, 10, 0, 0, 0, 0, 0]
37; [30, 30, 10, 20, 100, 5, 1, 100]; [2, 6, 7] => [0, 0, 10, 0, 0, 0, 1, 26]
0; [400, 450, 300, 250, 100, 30, 0, 10]; [5, 6, 7] => [0, 0, 0, 0, 0, 0, 0, 0]
20; [400, 450, 300, 250, 100, 30, 0, 10]; [5, 6, 7] => [0, 0, 0, 0, 0, 10, 0, 10]
100; [10, 10, 10, 10, 10, 10, 10, 10]; [1, 2, 3] => [0, 10, 10, 10, 0, 0, 0, 0]

Sandbox questions

  • Besides , what else should this be tagged?
  • I feel like the wording is terrible and I would appreciate help cleaning up the specification and examples
  • Are there any edge cases I missed?
  • What should be the requirements for range for the total pikmin counts? In theory it can be up to 9999 of each type, but practically I don't think I've ever exceeded 500 or 600. Not that this matters for most languages, but I think it's best to be explicit.
\$\endgroup\$
1
\$\begingroup\$

The Winner of a Trick in Zole

The Challenge

Write a function that determines the winner of a single trick in the Zole card game.

Background

The idea for this challenge was suggested by a guy from one chat, who noticed my highly golfed code for this specific task. Initially, I wanted to write a highly optimized code for the task, getting rid of branches and stuff like that wherever I could. At the end, I wrote a proof-of-concept of a code in JS (with the aim to rewrite it later in C and make it truly branchless), and then, just for fun, I golfed the JS code as much as I could. I ended up writing a JS function which is 122 characters long (I'll submit my solution once the challenge is posted). It was a fun challenge for me, hopefully you'll like it as well.

A Short Intro into Zole

For those unfamiliar with Zole, a quick intro into the rules that are necessary for the task - the rules that determine the winner of a single trick. If you are interested, you can find the rest of the rules online, but they are not needed for a challenge.

Zole is a traditional Latvian card game, derived from the family of Schafkopf card games. The exact origins of Zole are unknown. This card game is highly popular in Latvia but is mostly unknown elsewhere.

Zole is played using 26 cards - 14 trumps and 12 non-trumps. The deck includes all Aces, Kings, Queens, Jacks, Tens, Nines, Diamond Eight and Diamond Seven. All Queens, Jacks and Diamonds are trumps, other cards are non-trumps. Each trick in played with each of three players playing one card, one player after another. Meaning, each trick consists of three cards, and the order of the cards in the trick is important. The winner of each trick is determined once all three cards are on the table.

The Rules

The rules of determining the winner are following:

  1. If there is at least one trump in a trick, the strongest trump in the trick wins. This case is the simplest because in Zole, all trumps have different strength, or there's no two trumps of equal strength. Trumps ordered by strength (lowest to highest) are:

7♦, 8♦, 9♦, K♦, 10♦, A♦, J♦, J♥, J♠, J♣, Q♦, Q♥, Q♠, Q♣

Yes, the ten is stronger than the king, and jacks and queens are stronger than the ace. Any trump is stronger than any non-trump. The queen of clubs is the strongest card in the game, and takes any trick it is in.

In case when there's at least one trump, the order of the cards plays no role to determine the winner. The strongest trump wins, the end.

Examples:

  • 10♦, Q♦, K♣ - The king of clubs is not a trump, and the queen is stronger than the ten, the queen wins.
  • 9♥, A♥, 7♦ - the seven is the only trump in a trick, it wins.
  • J♠, J♣, A♠ - The jack of clubs is stronger than the jack of spades, and the ace of spades is not a trump, the jack of clubs wins.
  1. When there's no trump in a trick, then the suit of a winning card (sometimes called the requested suit) is determined by the first played card in this trick. Cards by strength (lowest to highest) are: 9, K, 10, A (again, the ten is stronger than the king). The strongest card of a requested suit wins. All cards in a trick that are not trumps and are of another suit play no role in determining the winner.

Examples (note that there are no trumps in these cases):

  • 10♥, K♠, 10♣ - Requested suit is hearts, no one added other heart, so the first card (the ten of hearts) wins.
  • 9♠, 10♥, A♠ - Requested suit is spades, the ace of spades is stronger than the nine of spades, the ten is out of suit and plays no role, the ace of spades wins.
  • K♣, 9♣, 10♣ - Requested suit is clubs, the ten is stronger than the nine or the king, the ten wins.

If you understood these rules then it should be clear that there can be no case when the winner is not determined. Your goal is to write a function that gets three parameters (three random cards from 26-card Zole deck) and returns the number of a card that wins the trick (0, 1 or 2).

A Few Test Cases

 K♠  Q♥  Q♦ The winner is 1 ( Q♥)
 K♥  K♦  8♦ The winner is 1 ( K♦)
 K♠  A♣  9♠ The winner is 0 ( K♠)
10♠  9♠  A♦ The winner is 2 ( A♦)
 9♣ 10♣  A♠ The winner is 1 (10♣)
 Q♦  9♦ 10♠ The winner is 0 ( Q♦)
 Q♠  Q♥  J♠ The winner is 0 ( Q♠)
 8♦  A♦  J♣ The winner is 2 ( J♣)
 9♥  A♠ 10♠ The winner is 0 ( 9♥)

Additional Info

For the sake of simplicity, let's assume that the first argument of your function is the first played card in the trick, the second argument is the second card etc. Let's also ignore all the rules regarding who should go first, what cards are allowed to play etc. What we need to know is that any combination of three cards from 26-card Zole deck is theoretically possible in a game (some are just less probable, but we ignore the probability). So, the sought-for function shouldn't follow the whole game, but should simply process one single trick. Or, in our case, three random cards.

You can choose how to define the data type for cards (simple integer, character, object, structure etc). You can be creative in defining cards as integers or similar types. Add the description of your data type in the comment.

Your code need not include the output function - just return 0, 1 or 2. Your code can also ignore the validation and sanitization of the data, let's assume that the data is correct (famous last words), and the input contains three different, valid cards.

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

Is it an option for the ls utility specified in POSIX.1-2017?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I don't think it's relevant to add a bonus related to XSI; bonuses are frowned upon, and it doesn't significantly change the problem. i'm not sure if a new challenge would be that different either, but maybe you can spin it in a materially different challenge. \$\endgroup\$ Commented Jun 27 at 7:39
  • 1
    \$\begingroup\$ d appears twice in the string provided in the output section. \$\endgroup\$
    – Arnauld
    Commented Jun 28 at 8:29
0
\$\begingroup\$

Given some conditions with form %th of [A%, A%, A%] is %, decide if it's possible.

Test case 1: (Here 1st mean smallest)

1st of [A1, A2, A3] is 1
1st of [A2, A3] is 2
2nd of [A1, A3] is 3
=> true (A1=1, A2=2, A3=3)

Test case 2:

1st of [A1, A2, A3] is 1
2nd of [A2, A3] is 2
3rd of [A1, A2, A3] is 3
-> true (A1=3, A2=2, A3=1)

Test case 3:

1st of [A1, A2] is 1
1st of [A2, A3] is 2
1st of [A1, A2, A3] is 3
-> false

Test case 4:

1st of [A1, A2] is 1
2nd of [A2, A3] is 3
3rd of [A1, A2, A3] is 3
-> true (A1=1, A2=1 to 3, A3=3)

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

Given an array A={0,1,2,3,4,5,6,7}. Each time, you can swap two values or copy one value to another. Given another array, find the minimum steps to convert A into the given array. You can assume it's possible.

Test cases:

0,1,2,3,4,5,6,7 => 0 ()
1,0,2,3,4,5,6,7 => 1 (s01)
1,1,2,3,4,5,6,7 => 1 (m01)
1,2,2,3,4,5,6,7 => 2 (m01 m12)
1,2,0,3,4,5,6,7 => 2 (s01 s12)

Shortest code wins

Sandbox Notes:

  • Need output the solution?
\$\endgroup\$
0
\$\begingroup\$

Detect revokes in Jass

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

Plot the ground path of a satellite

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

Vo we l spa ci ng

To da y yo u a re ha vi ng a si lly pro ble m.

To da  y   yo    u     a      re       ha        vi         ng          a           si            lly             pro              ble               m.

Challenge

Given an English text, apply "vo wel spa ci
ng" (see below).

Input

One line of string with these constraints:

  • Consist of alphabet with both cases, space, comma and period.
  • At least 1 letter and at most (at your choice) 15, 16, 31, 32 or 50 letters.
  • Match /^([A-Za-z]+[.,]? )*[A-Za-z]+[.,]?$/ in POSIX ERE; in English, it's a list of space-separated words with just alphabets but no punctuation; some words may contain a punctuation of either a full stop or a comma but not both. No leading spaces, no trailing spaces, separated with exactly one space.

Output

Result of "vo wel spa ci ng". Your output may have trailing spaces but no leading spaces.

"Vo we l spa ci ng" specification

The "Vo we l spa ci ng" is an algorithm who takes a string of input to return a string of output. The procedure is:

  1. For each vowel that is not the last letter of its word, append a space.
  2. For each space (let it N-th space. 1-indexed), replace it with N spaces.
  3. The implementation of this algorithm may append some spaces to the end of the string.
  4. Return the final string.

In the procedure above,

  • A vowel is a letter that is one of the following ten letter: AEIOUaeiou.
  • A word is a consequence concatenation of one or more alphabets but nothing else: e.g. "word", "WORD", "wOrD", "w", "o", "r", or "d" but not "word,", "word.", or "w o r d"
  • The last letter of the word is: (a) if it has only a letter, then the letter is the last letter of the word. (b) Otherwise (i.e. it has two or more letters), the last letter of the word without first letter is the last letter of the word. E.g. "word" => "d", "A" => "A".
  • A space is an ASCII character with code point of 0x20 or equivalent in other encoding system.

Test cases

The format is:

Input
=> Output

Here are test cases. Very wide:

Input
=> In pu  t

Output
=> O u  tpu   t

Test cases
=> Te st  ca   se    s

Hello, world.
=> He llo,  wo   rld.

Vowel Spacing
=> Vo we  l   Spa    ci     ng

Today you are having a silly problem.
=> To da  y   yo    u     a      re       ha        vi         ng          a           si            lly             pro              ble               m.

Code Golf and Code Challenge StackExchange
=> Co de  Go   lf    a     nd      Co       de        Cha         lle          nge           Sta            ckE             xcha              nge

AAAAAAAAAAAAAAAAAAAAA
=> A A  A   A    A     A      A       A        A         A          A           A            A             A              A               A                A                 A                  A                   A                    A

BBBBBBBBBBBBBBBBBBBBBB
=> BBBBBBBBBBBBBBBBBBBBBB

QwErTyUiOp AsDfGhJkL zXcVbNm
=> QwE rTyU  i   O    p     A      sDfGhJkL       zXcVbNm

qWeRtYuIoP aSdFgHjKl ZxCvBnM
=> qWe RtYu  I   o    P     a      SdFgHjKl       ZxCvBnM

Given an English text,
=> Gi ve  n   a    n     E      ngli       sh        te         xt,

apply vo we l spa ci ng.
=> a pply  vo   we    l     spa      ci       ng.

rhythm
=> rhythm

FORTRAN LISP COBOL ALGOL
=> FO RTRA  N   LI    SP     CO      BO       L        A         LGO          L

This is code golf. Shortest code wins.
=> Thi s  i   s    co     de      go       lf.        Sho         rte          st           co            de             wi              ns.

I
=> I

am here to, kick out, leading spaces.
=> a m  he   re    to,     ki      ck       o        u         t,          le           a            di             ng              spa               ce                s.

Rules

See also

Meta

  • Does title get rendered as monospace?
\$\endgroup\$
1
\$\begingroup\$

Minimum number of select-all/copy/paste steps for a string containing n copies of the original

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

Median of all K-length ranges

Given an array of integers of length N and an odd integer K, return N - K + 1 integers, where the ith integer represents the median of a K-length subarray starting from i.

You may write a full program or a function.

The input is N, K and the input array. You can take input in any reasonable form, and you don't have to take the length if it's unnecessary.

Sample test (input is in the form N, K, then array)

10 3
3 5 8 2 4 7 5 2 7 4

Output

5 5 4 4 5 5 5 4

How the output is obtained:

  • The first number is the median of the range [1, 3], or [1, 1 + K - 1]
  • The second number is the median of the range [2, 4]
  • ...

This is , so shortest code wins! (In bytes.)

\$\endgroup\$
7
  • \$\begingroup\$ Can you clarify what you mean here? > the input array's range, i to i+K-1. Maybe show some of the steps of how to get to the sample output. \$\endgroup\$ Commented Jul 4 at 1:31
  • \$\begingroup\$ @noodleperson done, thanks for the advice! \$\endgroup\$
    – Redz
    Commented Jul 4 at 2:26
  • \$\begingroup\$ Ah yeah that makes sense now gotcha. Maybe say "K-wise windows" or "K-length overlapping subarrays" instead of "K-length ranges" to be a bit more clear what you're saying. \$\endgroup\$ Commented Jul 4 at 2:29
  • \$\begingroup\$ Much better now, a lot easier to tell what the task means, good edits. Make sure to add a scoring-criteria before posting the challenge — I assume you were going for [tag:code-golf]? \$\endgroup\$ Commented Jul 4 at 2:36
  • \$\begingroup\$ @noodleperson oh yep, thanks for the reminder! \$\endgroup\$
    – Redz
    Commented Jul 4 at 2:51
  • \$\begingroup\$ Are we required to take the length? \$\endgroup\$
    – lyxal
    Commented Jul 4 at 6:05
  • \$\begingroup\$ @lyxal good point, no \$\endgroup\$
    – Redz
    Commented Jul 4 at 6:07
4
\$\begingroup\$

Print a language's "uninteresting numbers" sequence

The interesting number paradox revolves around the idea of classifying natural numbers as either "interesting" or "uninteresting", with the paradox being that the first number which isn't classified as interesting, then becomes interesting as a result of being first.

To solve this paradox, we can define an objective way to classify numbers as interesting: a number is N-interesting if it can be represented in N bytes or less in a given programming language. For example, in JavaScript, 387420489 is a 4-interesting number, since it can be represented as 9**9. This gives us a natural (no pun intended) "uninteresting numbers" sequence for each programming language; the sequence of numbers such that the Nth number is the first natural number which is not N-interesting.

In this challenge, you'll choose a language (which may or may not be the language you write your solution in), and implement its uninteresting numbers sequence, with 0- or 1-indexed rules. For example, I could implement brainfuck's uninteresting numbers sequence in Python, or use eval to implement JavaScript's uninteresting numbers sequence in itself.

Your score is your solution's byte count, divided by the highest N for which you can prove that the sequence up to N items will be returned in a finite amount of time. The solution should never return an incorrect output, even after the highest N it can calculate in a finite amount of time.

\$\endgroup\$
5
  • \$\begingroup\$ Is it permitted for solutions to intentionally give blatantly incorrect results above N, or are they only allowed to either give correct results or fail to terminate? I assume it’s the former, but the wording is unclear (and initially seemed to suggest the latter). \$\endgroup\$ Commented Jul 3 at 19:31
  • 1
    \$\begingroup\$ @UnrelatedString It's the latter, they need to either give a correct answer or never terminate \$\endgroup\$ Commented Jul 3 at 19:43
  • 1
    \$\begingroup\$ A list of provable uninteresting numbers is likely pretty small to be hardcoded. Then the golfed solution would be something like f=n=>[1,10,100,1001][n]||f(n), which is observably not distinguishable from an interpreter that tries to run all possible programs. \$\endgroup\$
    – Bubbler
    Commented Jul 3 at 22:55
  • 2
    \$\begingroup\$ Also, is it OK to pick a "language" that always halts or whose halting problem is somehow solvable, and get the score of 0 (by dividing by positive infinity)? \$\endgroup\$
    – Bubbler
    Commented Jul 3 at 23:56
  • 1
    \$\begingroup\$ @Bubbler Yeah, both of these issues are ones I'm not sure how to solve yet. I'm thinking I'll change the scoring but not sure how \$\endgroup\$ Commented Jul 4 at 15:12
0
\$\begingroup\$

Color-shift an image

Input

  • An image. This can be represented in a number of ways, including:

    • an image object,
    • a 2D array of pixels,
    • a 3D array of the color channels of each pixel,
    • the filename of the image,
    • the path to the image, etc.

    See Miscellaneous restrictions for more details.

  • A real number in the range \$[0, 1)\$.

Output

  • A copy of the input image, where the hue of each pixel has been shifted "forward" by \$\text{(input number)}\%\$ of the color wheel.

You don't have to actually output anything—you are allowed to silently modify the input image, either in-place or as a copy.

How color shifting works

Color shifting works by converting the image to HSV. Then, the hue of each pixel is increased by:

  • \$\text{(input number)} \cdot 256\$ if the hue goes from 0 to 255,
  • \$\text{(input number)} \cdot 360\$ if the hue goes from 0 to 359, or
  • \$\text{(input number)} \cdot \text{(maximum hue)}\$ if the hue is always in the range \$[0, \text{(maximum hue)})\$.

The hue is then brought back into the range \$[0, \text{(maximum hue)})\$ using the modulo function.

The saturation and value of each pixel are left unchanged.

Example implementation (Python 3)

The code has only been tested with PNGs, though it might work for other formats.
This takes a filename and a number, and silently makes a copy of the image, with the filename <OLDFILENAME>-colorshifted.png.

from PIL import Image

# Get the file
filename = input('Insert filename: ')
if filename in ['', None]: # No input
    raise ValueError('Program needs filename to run.')

with open(filename, 'rb') as rawImage: # So we don't have to manually
                                       # close the image
    rgbImage = Image.open(filename)
    hsvImage = rgbImage.convert('HSV') # HSV is easier to color-shift
    shift = int(float(input('Insert the amount you want '
                            'to color-shift the image: ')) * 256) % 256

    # Actually shift the colors
    splitImage = hsvImage.split()
    newHueChannel = splitImage[0].point(lambda h: (h + shift) % 256)
    splitImage[0].paste(newHueChannel)
    newHSVImage = Image.merge('HSV', splitImage)
    finalImage = newHSVImage.convert('RGB')

    # Save it as a new file (<OLDFILENAME>-colorshifted.png)
    newFilename = filename[:filename.rfind('.')] + '-colorshifted.png'
    finalImage.save(newFilename)
    finalImage.show()

Test cases

Click on the thumbnails for full-size images.

Original image Shifted by 0.25 Shifted by 0.6 Shifted by 0.9

Input constraints

  • The size of the input image will be at least 1 × 1, and will be at most 4,096 × 4,096.
  • You have to support at least one format of image (.png, .jpg, .bmp, etc.). It's recommended to put the input format in your answer as well.

If your code receives inputs which don't follow these constraints, you can do whatever you want.

Miscellaneous restrictions

  • Standard loopholes are forbidden.
  • Default I/O policies apply.
  • You are allowed to write a function or a full program.
  • If the input format is HSL or HSV, the output format can't be HSL or HSV. This requires some amount of conversion to take place.

Scoring

This is , so for each programming language, the shortest code in bytes is the winner.

Sandbox Questions

  • What else could an image be?
  • Should HSL/HSV be disallowed in I/O altogether?
\$\endgroup\$
1
\$\begingroup\$

Interpret a Turing Complete Subset of your Language

  • Write a program which can interpret some programs exactly the same way as your (source?) language, where these can be used to model any computation.
  • Demonstrate how to do this.
  • Your Interpreter may have "features" your language doesn't have, but your demonstration may not use them.
  • You may not use a built-in which interprets the source language, like eval()

The feature set does not need to be made of characters or something, you just need to say what it is.

It's until i can think of something better.

Example: a javascript interpreter which only allows String.replace, functions, and the ternary conditional thing ? : may be able to be used as a convoluted slashes emulator.

Discussion:

  • This challenge was originally intended to make all languages equally interesting, but I think it still favors turing tarpits and golfing languages.

  • As with many Challenges which already exist, this one also gives actually interpreted languages kind of a leg up.

  • Making it illegal for turing completeness to arise from interpreter quirks is propably not that important. (like, ACE in my brainfuck interpreter?)

  • Banning eval might introduce rules-lawyering on what eval actually is, like, are Regexes allowed? is a built-in which evaluates arithmetic allowed? I'd say yes. It might also further favor turing tarpits, though it would nerf golfing languages which propably have an eval construct. It might also make the program more laborious to write, obviously, but

  • Allowing eval might make writing the program boring as well, as that's an established technique.

  • Making this is boring, maybe i should make it about the conciseness of an example program? It wouldn't devolve into HQ9+, but its discriminatory, like how is slashes supposed to calculate a factorial? I think is definitely the best option.

  • Adding the stipulation that the interpreter must be able to interpret itself turns this into a completely different, slightly harder, and maybe more interesting problem. For example: this Uiua Program

⍣⍢(⨬(⊂:"12"|⊂:"0"|⊂:"000")-@0⊙(◌°⊂)°⊂?|¬≍[])0"000"

runs the 2-tag system for collatz sequences (on unary) (on Wikipedia). The corresponding Interpreter for a subset of Uiua which can be used to emulate 2-tag systems could be made to expect the program to be of the form

⍣⍢(⨬(A)-@0⊙(◌°⊂)°⊂?|¬≍[])0"B"
where A is ⊂:"B" or ⍤,0 any number of times, separated by |
and B is a string of numbers

You may consider this to be boring. I might investigate whether the "self-interpreter" stipulation actually solves this problem.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Welcome to cgcc, and interesting idea. Can you define "useful" more (maybe even formally)? Also, don't forget to add a winning criterion (such as code-golf) \$\endgroup\$ Commented Sep 26, 2023 at 21:11
  • 1
    \$\begingroup\$ Doesn't this allow someone to claim they are interpreting a subset of JavaScript of the form f=>(<brainfuck interpreter>);f( <brainfuck code> ) and just write a brainfuck interpreter as their submission? \$\endgroup\$ Commented Jun 25 at 11:06
  • \$\begingroup\$ @noodleperson yes, it does. That's what I didn't realize I was also saying and you spelled it out more clearly. The variant where it must be able to self interpret solves this in every language except brainfuck, but it might also make the problem really hard in general. \$\endgroup\$
    – jan
    Commented Jun 25 at 18:14
1
2 3 4 5
158

You must log in to answer this question.

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