All Questions

Filter by
Sorted by
Tagged with
-1 votes
0 answers
58 views

Program a compiler compiler

Program a compiler compiler Write a program, function, or likewise that takes in a BNF-like grammar specification(see below) and outputs a program or function in a language of your choice that takes ...
user avatar
  • 457
2 votes
0 answers
140 views

Solve the Greek Computer Puzzle Toy [closed]

Solve the Greek Computer Puzzle Toy There is a small toy of a series of stacked dials -- loosely inspired by the Antikythera Device. The puzzle, made by Project Genius, has a series of dials that must ...
user avatar
23 votes
22 answers
2k views

A challenge for rookies

Print or return the following string: ...
user avatar
  • 12.2k
1 vote
0 answers
103 views

Is there a way to optimize this? [closed]

I tried solving the following problem by following the suggested approach to solving the problem in the problem tutorial. However, the online judge still says my solution exceeds the time limit. Is ...
user avatar
  • 19
4 votes
5 answers
191 views

Rotatable numbers (Upside down) [duplicate]

Searching for rotatable numbers, like: 68089 If you consider numbers upside-down, 6 looks like ...
user avatar
20 votes
13 answers
2k views

smallest number of steps for a knight in chess

If you place a knight on any square of a chessboard, what is the smallest amount of steps to reach every position? Rules It is an 8 by 8 board. The knight starts at an arbitrary position, taken as ...
user avatar
  • 301
4 votes
1 answer
113 views

Generate a Kirkman triple system

Given a universe of \$v\$ elements, a Kirkman triple system is a set of \$(v-1)/2\$ classes each having \$v/3\$ blocks each having three elements, so that every pair of elements appears in exactly ...
user avatar
2 votes
1 answer
218 views

Optimal strategy to defeat the wizard

Consider the following setup. An evil wizard has ten opaque boxes in front of him. Hidden from you, he chooses a random number of coins \$x \in \{1 \dots 10\}\$ and spreads them uniformly at random ...
user avatar
  • 643
9 votes
9 answers
444 views

CGCC Rocket Biking

Something I found while looking through some old files. It seemed like a neat idea for a code golf challenge. The intro One of the most popular events at the annual Cyclist's Grand Competition for ...
user avatar
  • 1,003
8 votes
4 answers
243 views

Change the quotations as if in Microsoft Word

I noticed that in Microsoft Word, single quotations are either or , but not in Notepad. Your task today is: given a string <...
user avatar
15 votes
7 answers
659 views

A better Hexagony template

We once made a Hexagony template without actually knowing it. But after a bit of experience with Hexagony, it becomes apparent that it is not enough; sometimes the source code is too short for the ...
user avatar
  • 64.8k
-2 votes
0 answers
71 views

Benchmark games, but polyglot code [closed]

Benchmark games can be fun: https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/nbody.html But it's only monoglot code :( Can't we try to do them in polyglot instead? :)
user avatar
23 votes
8 answers
2k views

Seeing the queen's lasers

In chess, the queen piece can move arbitrarily far in each cardinal and intercardinal direction. What does this mean? Well, I'll show you with an ASCII drawing: ...
user avatar
18 votes
30 answers
2k views

Divisor of a string

Challenge Given a positive-length string \$S\$, a divisor of \$S\$ is another (not necessarily distinct) string for which there exists a number \$a\$ such that when we repeat the divisor \$a\$ times, ...
user avatar
  • 1,017
13 votes
19 answers
840 views

Cartesian - polar conversion couple

We don't have a challenge for conversion between Cartesian and polar coordinates, so ... The challenge Write two programs (or functions) in the same language: one that converts from polar to ...
user avatar
  • 100k
0 votes
0 answers
60 views

Polyglot for C and PHP [closed]

I was thinking of a compiler that spits out C/PHP polyglots, but not sure if possible. Main issue is the PHP opening/closing brackets, <?php and ...
user avatar
19 votes
22 answers
2k views

Anti-divisors of a number

Given a positive integer n, output all of its anti-divisors in any order. From OEIS A006272: Anti-divisors are the numbers that do not divide a number by the ...
user avatar
  • 64.8k
21 votes
14 answers
2k views

Add parentheses to Polish notation

In most programming languages, arithmetic is written with infix notation -- i.e. the operator is put in between the operands -- e.g. 1+2. In contrast, with Polish ...
user avatar
  • 1,423
1 vote
5 answers
198 views

Find number components with lowest distribution

Let us assume that we have number X. Let us assume that we have positive integer "components" (C) of this ...
user avatar
  • 143
21 votes
11 answers
2k views

Optimal strategy for wandering robots

Consider four agents sitting on four different number lines, all starting at the origin. In this game your only move is to choose one of the four agents to move. When you do that the agent you have ...
user avatar
  • 643
4 votes
3 answers
887 views

Python: can I shorten this code further for checking substrings

So the golf question was like this: You are given a number T and then a total of T number of 17-character strings. For each of ...
user avatar
15 votes
38 answers
2k views

Implement String Projection

Given two strings: a string s and an alphabet a, implement string projection in the shortest code possible. String projection ...
user avatar
  • 3,233
5 votes
1 answer
666 views

Help me golf this C program checking for string patterns in a sorted hand of cards

I could not think of a better title. This is a tips question. I'm asking for tips on golfing my code. I recently took part in a code golf competition in C. The competition ended and I lost. The ...
user avatar
  • 3,816
3 votes
9 answers
1k views

PUT-PIXEL in every language

During work on some project I needed to draw pixels on screen. I found some put-pixel function in JS, but code was quite big and clumsy - so I wonder, how small put-pixel function can be... Challenge ...
user avatar
9 votes
7 answers
732 views

Tips for golfing in Knight

Knight is the Language of the Month for August 2022, and I noticed that it didn't have a tips page, so here it is! I'm looking for ideas which can be applied to code-golf problems and which are also ...
user avatar
  • 5,712
18 votes
9 answers
1k views

Cryptic Multiplications

Given two non-negative integers e.g. 27, 96 their multiplication expression would be 27 x 96 = 2592. If now each digits is ...
user avatar
  • 2,153
15 votes
5 answers
1k views

Find The Average String Between Two Strings

Inspired by this Your task today: given two strings, find the string with the lowest maximum Levenshtein distance to the input strings. For example, using Steffan ...
user avatar
  • 3,347
6 votes
2 answers
216 views

Case Conversion Polyglot

Your task is to write a program that performs case conversion from plain text, and other case formats, into one of the specified formats below. Inputs will be either plain lowercase text, or one of ...
user avatar
  • 22.6k
7 votes
4 answers
439 views

Train Route Planning

We can model a rail network as a directed graph, where each node is a train station and each edge is a train connecting two train stations. We'll assume that each train travels between its ...
user avatar
  • 3,197
22 votes
16 answers
2k views

Remove redundant parentheses

Given a string containing some parentheses and some other ASCII printable characters, like this: (abc((123))(k)) your task is to remove any sets of parentheses that ...
user avatar
  • 1,635
12 votes
7 answers
293 views

Encode the systematic binary Varshamov–Tenengolts code

Background Here on CGCC, a commonly seen subgenre is radiation-hardening – writing a program that works even if one character is deleted. A similar problem is studied in the field of coding theory: ...
user avatar
23 votes
19 answers
3k views

Transform characters of your choice into "Hello, world!"

Write a program or function that takes a character as input and outputs a character. Also, choose a list of 13 distinct ASCII printable characters (32-126). When a character from this list is passed ...
user avatar
  • 1,335
1 vote
0 answers
201 views

Decompose number N into the sum of three triangular numbers

It is known that any natural number can be decomposed into the sum of three triangular numbers (assuming 0 is triangular), according to Fermat's Polygonal Number Theorem. Your task is to come up with ...
user avatar
  • 35
40 votes
11 answers
2k views

IE's Extra Robust Color Parsing®

Recently, I've found a rant from 2004 about Internet Explorer's color parsing. Turns out, MS made sure that just about anything will be parsed as a color somehow and I think it makes for a neat ...
user avatar
  • 1,003
17 votes
21 answers
2k views

Generate all Possibilities of Words

This is not the same as m-ss-ng-lette-s Challenge: Given a string with masked characters, generate all possible words, inclusive of non-meaningfull words. Rules: The sequence of the characters in the ...
user avatar
10 votes
36 answers
3k views

Repeat Hello World according to another string's length

This was related to a program I am writing. Although the title is simple, the challenge is a lot more complicated. Your challenge You must write a program that takes an input, and your answer must ...
user avatar
7 votes
4 answers
258 views

Generate number set with conditions using n numbers

Generate \$T=\{T_1,...,T_x\}\$, the minimum number of \$k\$-length subsets of \$\{1,...,n\}\$ such that every \$v\$-length subset of \$\{1,...,n\}\$ is a subset of some set in \$T\$ Here, \$n > k &...
user avatar
  • 179
20 votes
26 answers
2k views

Triangle area from side lengths

Output the area \$A\$ of a triangle given its side lengths \$a, b, c\$ as inputs. This can be computed using Heron's formula: $$ A=\sqrt{s(s-a)(s-b)(s-c)}\textrm{, where } s=\frac{a+b+c}{2}.$$ This ...
user avatar
  • 138k
9 votes
5 answers
309 views

Find the closest swap

Take as input two strings \$A\$ and \$B\$. Output a string \$C\$ that is \$A\$ but with two characters swapped such that the Levenshtein distance \$d(C,B)\$ is as small as possible. You must swap ...
user avatar
  • 89.4k
7 votes
7 answers
808 views

Swap every two elements in the list every possible way

Inspired by this question. Challenge Let L be a list of n distinct elements. Let P be the ...
user avatar
  • 89
31 votes
13 answers
4k views

Have you heard of tralindromes?

I haven't. :P So I decided to define one: A tralindrome is a string which contains three equal-length sections X, Y, Z such that all characters in the string are included in at least one of the three ...
user avatar
  • 64.8k
12 votes
12 answers
293 views

Runs of Ones (What Fun!) [duplicate]

Suppose you have an array with some known set of values (e.g. a string of \$0\$ and \$1\$) and you want to get all the locations of \$1\$s. Instead of storing a list of all the indices, if the \$1\$s ...
user avatar
  • 1,423
18 votes
37 answers
2k views

Shifted auto-sum

Let’s take a positive integer such as 123. We define the shifted auto-sum of this integer as follows: 123 has 3 digits. We thus consider 3 copies of 123. We stack ...
user avatar
  • 36.6k
19 votes
22 answers
2k views

Rearrange to a palindrome

Given a string, shuffle it so that it becomes a palindrome. For example, adadbcc can be arranged into dacbcad, or ...
user avatar
  • 31.5k
12 votes
6 answers
736 views

Exponential transform of an integer sequence

The exponential generating function (e.g.f.) of a sequence \$a_n\$ is defined as the formal power series \$f(x) = \sum_{n=0}^{\infty} \frac{a_n}{n!} x^n\$. When \$a_0 = 0\$, we can apply the ...
user avatar
19 votes
19 answers
2k views

Multiply numbers by their depth

Given a ragged list, we can define an element's depth as the number of arrays above it, or the amount that it is nested. For example, with the list ...
user avatar
  • 31.5k
21 votes
24 answers
2k views

Generate an arbitrary half of a string

Given a string \$ x \$, we say another string \$ y \$ is half of it, if both of the following properties are true: \$ y \$ is a (not necessarily continuous) subsequence of \$ x \$ - there exists a ...
user avatar
17 votes
9 answers
4k views

Super Mario 64 RNG

Introduction Super Mario 64 has a heavily overcomplicated RNG, ably explained here by Pannenkoek. I thought it might be interesting to implement it. Challenge Implement the RNG function, except for ...
user avatar
20 votes
23 answers
1k views

Letters to numbers to letters (poorly)

Every now and again, I'll encounter a large string of alphabetical text encoded as numbers from 1-26. Before I knew that I could just google a translator online, I had to personally, painstakingly ...
user avatar
8 votes
1 answer
402 views

Next Special String

Special String We call a binary string \$S\$ of length \$N\$ special if : substring \$S[0:i+1]\$ is lexicographically strictly smaller than substring \$S[i+1:N]\$ for \$ 0\leq i\leq N-2\$, Note: \$ ...
user avatar
  • 599

15 30 50 per page
1
2 3 4 5
265