instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
The partition function:
In number theory, the partition function p(n) represents the number of possible partitions of a positive integer n into positive integers
For instance, p(4) = 5 because the integer 4 has five possible partitions:
1 + 1 + 1 + 1
1 + 1 + 2
1 + 3
2 + 2
4
Your task:
Accept an input (let's call i... | stackexchange_codegolf |
As you probably know, there is a war going on in Ukraine. I noticed that it seems nobody has posted a Ukrainian flag challenge yet, so I thought I'd do it myself in support of Ukraine.
The Challenge
Here is the flag:
The flag is divided horizontally across the middle into two equally sized stripes.
Stripe colors: (0,... | stackexchange_codegolf |
Given a string as an input (which can be any acceptable/convenient format in your language), implement pendulum encoding. The test cases are split into individual items (which aren't quoted) for a visually appealing explanation.
How do I do that?
The current iteration index starts at 0.
If the iteration index is even,... | stackexchange_codegolf |
Inspired by a tweet by Nathan W. Pyle
There is, now, a standard method of converting your boring, normal human name into a mysterious, ethereal Ghost Name™️. Ably described by Mr Pyle...
Use your first name:
a - add “t” after it
e - add “boo” after it
h - becomes “s”
n - add “oo” after it
r - add “eee” after it... | stackexchange_codegolf |
When you leave, my challenges fade to grey, 0A0AE16, 0A0A0AE16...
A while ago, I made this programming language (https://esolangs.org/wiki/Dragostea_din_tei) which uses an interesting number system. It is base two for integers, but for decimals it divides a base two integer by a power of ten.
The input should be a floa... | stackexchange_codegolf |
As you may or may not know, Valentine's day is getting close. So today, my task for you is:
Write a heart-shaped quine
Rules:
Code should look like an identifyable heart shape, i.e. Has two round parts on top and a pointy bottom. It does NOT have to be filled in, but this is not disallowed.
Standard Quine rules apply ... | stackexchange_codegolf |
Introduction
In the prisoner's dilemma, two partners in crime are being interrogated, and have the choice to either betray their partner or stay silent.
If both prisoners betray each other, they both get 2 years in prison.
If neither betrays (both stay silent), they both get 1 year in prison.
If only one betrays and t... | stackexchange_codegolf |
You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ.
Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost as popular as π and e. The exact value of \$φ\$ is \$\frac {1 + \sqrt 5} 2 = 1.618...\$
The Fibonacci sequence is a recursive ser... | stackexchange_codegolf |
You already know that the atoi function of stdlib.h converts a string to an integer.
atoi
(copied from here)
int atoi (const char * str);
Convert string to integer
Parses the C-string str interpreting its content as an integral number, which is returned as a value of type int.
Example
#include <stdio.h> /* pri... | stackexchange_codegolf |
In this challenge, you are given a limited amount of information about a particular game of chess, and you need to predict who won the game.
You are given two sets of data:
Piece counts (What pieces are still alive)
Board colors (The color of pieces on the board)
More importantly, you don't know where the pieces are ... | stackexchange_codegolf |
The challenge
The plastic number is a number related to the golden ratio, with many interesting mathematical properties. As such, there are many approaches that can be used to calculate the number.
In order to precisely specify the number for the purposes of this challenge, we'll use the following definition (although ... | stackexchange_codegolf |
This is cops-and-robbers. This is the Cops thread. For the robbers thread, go here.
I've noticed a number of OEIS (On-line Encyclopedia of Integer Sequences) challenges since I joined the site. It seems only fair that we have a cops-and-robbers challenge that determines who is the master of online integer sequences, on... | stackexchange_codegolf |
Confidant Numbers
Let x be an integer of an arbitrary base, such that D is an array of its digits. x is a Confidant Number if, for all n between 1 and the length of D:
D[n+1] = D[n] + D[n-1] + ... + D[1] + n
Take, for example, the number 349 in base 10. If we label the indices for this number, we have the following.
... | stackexchange_codegolf |
Background
There's a common riddle that goes something like this:
A snail is at the bottom of a 30 foot well. Every day the snail is able to climb up 3 feet. At night when they sleep, they slide back down 2 feet. How many days does it take for the snail to get out of the well?
The intuitive answer is
30 days, becau... | stackexchange_codegolf |
Task
Continuously print a random character (a-z, A-Z, 0-9) not separated by a newline (\n).
Expected output
b7gFDRtgFc67h90h8H76f5dD55f7GJ6GRT86hG7TH6T7302f2f4 ...
Note: output should be randomised.
Requirements/Rules
Output must be continuous (i.e. never ending),
Output may not comprise of newlines,
Output must b... | stackexchange_codegolf |
Awhile back I encountered a simple programming puzzle to determine whether a string was a pangram, or a perfect pangram. (Although it's worth noting that this particular challenge gave a different meaning than the standard definition of a "perfect pangram," to mean any sentence where every letter appears n times for so... | stackexchange_codegolf |
Sequel to Verify Tents and Trees solution.
Background
Tents and Trees (try here) is a puzzle played on a square (or rectangular) grid, where the objective is to place tents horizontally or vertically adjacent to each of the trees, so that no two tents touch each other in 8 directions (horizontally, vertically, and diag... | stackexchange_codegolf |
In my Economics class, my friends and I like to come up with ways to rearrange the digits in the date (in MM/DD/YY) format to create a valid mathematical equation. For the most part, we are allowed to use addition, subtraction, multiplication, division, parentheses, and exponentiation in addition to concatenation.
Your... | stackexchange_codegolf |
Input:
Ten unique integer coordinates, between (0,0) and (100,100).
Output:
The coordinates arranged in the order/an order such that a path drawn between the coordinates in that order is the shortest path possible.
This is code golf so the shortest code wins!
| stackexchange_codegolf |
Introduction
In the strange world of integer numbers, divisors are like assets and
they use to call "rich" the numbers having more divisors than their reversal, while they call "poor" the ones having less divisors than their reversal.
For example, the number \$2401\$ has five divisors : \$1,7,49,343,2401\$, while its r... | stackexchange_codegolf |
You are given four numbers. The first three are \$a\$, \$b\$, and \$c\$ respectively, for the sequence:
$$T_n=an^2+bn+c$$
You may take input of these four numbers in any way. The output should be one of two distinct outputs mentioned in your answer, one means that the fourth number is a term in the sequence (the above ... | stackexchange_codegolf |
Task
When running the program must show the season according to the host computer's current time.
Rules
The output must be either: Spring, Winter, Summer or Autumn.
The capitalization does not matter.
The output must not contain anything else the the season names stated above.
A season is 3 months and january is in th... | stackexchange_codegolf |
So, like the title says, today you are going to guess my password (sort of). You need to make a big long list of every possible password I might be using on my 4 digit online vault.
Specifications:
It could contain any 26 letters of the alphabet in UPPER CASE.
It could contain any numbers 0-9.
So, basically, each di... | stackexchange_codegolf |
Wholly surprised this hasn't been posted already, given the large number of chess puzzles on the site. While I thought of this myself, credit to Anush for posting it to the sandbox back in March. But I figured it's been long enough that I could go ahead and do so myself.
A checkmate in chess is a position in which the ... | stackexchange_codegolf |
Goal is to write the shortest possible C89 and C99-compliant single-module C program which will compute and print out a single-line string whose sort order will correspond with the date given by the predefined __DATE__ macro (in other words, later dates will yield later-sorting strings). The programmer is free to arbi... | stackexchange_codegolf |
Write a program that generates and prints a random maze using the algorithm of your choice. The maze should be different for multiple runs of the program. Height and width are given as command line arguments. Use | for vertical wall, - for horizontal wall and + for corner. The maze is bounded by walls and the entrances... | stackexchange_codegolf |
An integer \$x\in[0,2^{32}-1]\$ divided by an integer \$d\in{[1,2^{31}]}\$ will produce an integral quotient \$q\$ and a remainder \$r\$, so that \$x=d\times q+r\$.
Any \$q\$, in fact, can be calculated by the following formula.
$$y=\left\lfloor\frac{mx}{2^{32}}\right\rfloor\\q=\left\lfloor\frac{y+f\lfloor(x-y)/2\rfloo... | stackexchange_codegolf |
Input a scientific notation number (base 10), output scientific notation in base 16 (as defined below).
Details
In scientific notation, all non-zero numbers are written in the form
$$ m \times 10^n $$
Where \$ n \$ is an integer, and \$ m \$ is a real number, \$ 1 \leq |m| < 10 \$.
Consider scientific notation in base ... | stackexchange_codegolf |
Problem: We have a two dimensional matrix of positive integer cells. On each turn any non-zero cell with a neighbor (top/bottom/left/right) of zero decreases by 1. We want count to the number of non-zero cells present and add them up across all turns.
Is there a faster solution than to use a priority queue?
Is there a... | stackexchange_codegolf |
The quaint hamlet of Кодгольф in the Russian far east has a problem: their population is low (below 66), and no new people have arrived for years. Moreover, after centuries of near-isolation, just about everybody is related to each other.
Mayor Стекобмен has a solution that should keep the morale high: organise a weddi... | stackexchange_codegolf |
Symja is a "computer algebra language & Java symbolic math library for Android NCalc calculator". It's a fun little language, so I'm wondering if y'all have any tips for golfing in Symja.
As per usual, "remove comments", etc, isn't really an answer. It turns out that there is no comment system in Symja, so "remove com... | stackexchange_codegolf |
This is a problem that the Hacker Cup team made for the 2018 Facebook Hacker Cup, but we ended up not using it (though Ethan struggles through a variety of other challenges). Normally code size isn't a factor in the Hacker Cup, but we thought this would make for an interesting code golf challenge. We look forward to se... | stackexchange_codegolf |
Guide the Alphabet
Given an array of directions, where the directions are defined as follows:
NW N NE
W . E
SW S SE
Or as indexes (you may use these indices for directions instead of the strings above):
0 1 2
3 . 4
5 6 7
You may choose either format, supporting both is not required by the challenge. Generate ... | stackexchange_codegolf |
An arithmetico-geometric sequence is the elementwise product of an arithmetic sequence and a geometric sequence. For example, 1 -4 12 -32 is the product of the arithmetic sequence 1 2 3 4 and the geometric sequence 1 -2 4 -8. The nth term of an integer arithmetico-geometric sequence can be expressed as
$$a_n = r^n \cdo... | stackexchange_codegolf |
Challenge
This challenge is pretty simple: Output the total number of possible Tweets. Given the fact that \$1{,}114{,}112\$ Unicode characters exist, and Tweets can be up to \$280\$ characters long, we calculate this number like so:
$$\sum_{l=1}^{280}1{,}114{,}112^l$$
Calculated, this number becomes:
13806352273767118... | stackexchange_codegolf |
Introduction:
In my recent Strikethrough the Word Search List challenge I mentioned the following:
When I do the word-search puzzles, I (almost) always go over the words in order, and strike them through one by one.
In some cases I do them in reversed order as a change of pace, although that doesn't matter too much r... | stackexchange_codegolf |
Introduction:
In general we usually speak of four dimensions: three space dimensions for x, y, and z; and one time dimension. For the sake of this challenge however, we'll split the time dimension into three as well: past, present, and future.
Input:
Two input-lists. One containing integer x,y,z coordinates, and one co... | stackexchange_codegolf |
Problem:
In your choice of language, write the shortest function that returns the floor of the base-2 logarithm of an unsigned 64-bit integer, or –1 if passed a 0. (Note: This means the return type must be capable of expressing a negative value.)
Test cases:
Your function must work correctly for all inputs, but here ar... | stackexchange_codegolf |
Logic gates are functions which perform basic logic operations. In this problem, we will account for the following 6 logic gates: AND, OR, XOR, NAND, NOR, and XNOR. Each of these takes two boolean inputs \$ a \$ and \$ b \$, and outputs a boolean. Below are the truth tables which show the output of each gate given two ... | stackexchange_codegolf |
Martin Ender's 2D programming language Alice has two different modes depending on what orientation the IP has: orthogonal (Cardinal mode) or diagonal (Ordinal mode). Commands in Alice change their meaning depending on which mode the program is in when they're executed. One especially interesting implementation of this ... | stackexchange_codegolf |
Background (feel free to skip)
Ordinals are the abstract representation of well-orders. A well-order of a set is a total order, which basically means that every element in the set can be compared against any other element in the set, and one of them is either smaller or larger. Also there are no cycles.
The crucial dif... | stackexchange_codegolf |
It can be in any language, plus the map must be in the output only not in the source code.
This is my first question here, so please feel free to edit it. Also, there might be some rules about scoreboard which I'm not familiar how to put it here.
Cheers!
| stackexchange_codegolf |
Given you have an infinite sequence of numbers defined as follows:
1: 1 = 1
2: 1 + 2 = 3
3: 1 + 3 = 4
4: 1 + 2 + 4 = 7
5: 1 + 5 = 6
6: 1 + 2 + 3 + 6 = 12
7: 1 + 7 = 8
...
The sequence is the sum of the divisors of n, including 1 and n.
Given a positive integer x as input, calculate the lowest number n which will produ... | stackexchange_codegolf |
Your task is to write a program or function. Its output/return value must follow these rules:
The program outputs 1
The program repeated n times outputs n
The program backwards outputs -1
The program backwards and repeated n times outputs -n
A mix of forward and backward programs will output number_forward - number_ba... | stackexchange_codegolf |
While doing some research for a different challenge I'm formulating, I came across a Cayley graph, specifically this one. Since I'm one of the top ascii-art challenge writers, of course I had to make an ASCII art challenge for this.
Your challenge is to produce this ASCII art depiction of a Cayley graph of the free gro... | stackexchange_codegolf |
Your challenge is to output a Base64-encoded version of your source code, and optionally a line break. You must output the correct padding, if any. Standard quine rules apply, shortest answer wins.
It must be a valid RFC 4648 encoded base64 string, with no linebreaks (except optionally a trailing newline).
Test cases:
... | stackexchange_codegolf |
The primorial \$p_n\#\$ is the product of the first \$n\$ primes. The sequence begins \$2, 6, 30, 210, 2310\$.
A Fortunate number, \$F_n\$, is the smallest integer \$m > 1\$ such that \$p_n\# + m\$ is prime. For example \$F_7 = 19\$ as:
$$p_7\# = 2\times3\times5\times7\times11\times13\times17 = 510510$$
Adding each num... | stackexchange_codegolf |
What general tips do you have for golfing in Scala 3? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Scala 3 (e.g. "remove comments" is not an answer). Please post one tip per answer.
Also see Tips for golfing in Scala
| stackexchange_codegolf |
Write a program that, for any \$n\$, generates a triangle made of hexagons as shown, \$2^n\$ to a side. The colors are to be determined as follows.
We may give the triangle barycentric coordinates so that every hexagon is described by a triple \$(x,y,z)\$ with \$x+y+z=2^n-1\$. (The three corners will be \$(2^n-1,0,0)\$... | stackexchange_codegolf |
First attempt at a question.
Calculating Transitive Closure
According to Wikipedia, "the transitive closure \$R^*\$ of a homogeneous binary relation \$R\$ on a set \$X\$ is the smallest relation on \$X\$ that contains \$R\$ and is transitive."
Also, "a relation \$R\$ on a set \$X\$ is transitive if, for all \$x, y, z... | stackexchange_codegolf |
The Task
The task is easy: given an Alpha-2 country code, output the Alpha-3 equivalent. The input may be in any case you choose, and the output in any consistent case of your choosing. Here are the codes:
[["AF", "AFG"], ["AX", "ALA"], ["AL", "ALB"], ["DZ", "DZA"], ["AS", "ASM"], ["AD", "AND"], ["AO", "AGO"], ["AI", "... | stackexchange_codegolf |
I am looking for tips to code in this golfing language Seriously, and was wondering what some of the ways for golfing this language is. "Remove comments" is not a tip. Actually is also included
| stackexchange_codegolf |
This is the inverse of "Encode the date in Christmas Eve format."
Write a program that takes as input the string Christmas, possibly followed by Eve between 1 and 365 times, and outputs the date encoded in YYYY-MM-DD format, or any format from which the year, month, and date can be easily obtained. Assume that the "Ch... | stackexchange_codegolf |
Given the following list of numbers, find the group of
sequential positive numbers with the highest sum.
Example input:
12 2 35 -1 20 9 76 5 4 -3 4 -5 19 80 32 -1
Example output:
131
The most succinct code wins.
My approach via Perl is 87 chars (with input as command-line args):
print((sort { $b <=> $a } do { push @s... | stackexchange_codegolf |
A long period prime is a prime number \$p\$ such that decimal expansion of \$1/p\$ has period of length \$(p-1)\$. Your task is to output this number sequence. For purposes of this challenge we will consider only odd primes.
Period of a decimal expansion of a rational number is the smallest period \$k\$ that makes the ... | stackexchange_codegolf |
You have been given N piles of coins. You have decided to divide each of those B1, B2, ..., BN piles among separate groups of people. The amount of people receiving coins has to be a prime number and the amount of money given to each person must be different in each pile.
Input: N, B1, B2, ..., BN (The amount of coins ... | stackexchange_codegolf |
In this question, we will only focus on losing weight by doing exercise, although there are still many ways to lose weight.
Different sports burn different amount of calories.
For example, playing billiards for an hour can burn 102 calories[1], while playing basketball for 15 minutes can already burn 119 calories [1], ... | stackexchange_codegolf |
In LLAMA, you want to dump cards from your hand as quickly as you can, but you might not be able to play what you want.
Each player starts a round with six cards in hand; the deck consists of llama cards and cards numbered 1-6, with eight copies of each. On a turn, the active player can play a card or draw a card. To p... | stackexchange_codegolf |
Based on this challenge and this Math.SE question. Idea originally come from a Numberphile video. The goal is to reproduce the logic of Professor McKee when he builds this prime.
Your task is to build the Trinity Hall Prime, at a much lower scale. You are given a single number N greater than 2, representing the length ... | stackexchange_codegolf |
Description
Your task is to output a 'depthmap' - that is, a heightmap of an object but not seen from its top but from its front.
For example, consider the following object as shown on the image. The height map is shown on the left. The corresponding depth map would be (as seen from standing at the arrow):
010
211 <-... | stackexchange_codegolf |
Given 2 random circle sections, return how many times they intersect. Rules/clarifications are as below.
You are provided 10 total values,
The center (x,y) of the circle section
Angles of the circle (i.e. (0,90) would be a quarter circle "facing" the top-right corner.
The radius of the circle section
The circle s... | stackexchange_codegolf |
The aim of this post is to gather all the tips that can often be applied to radiation-hardening challenges.
Please only post answers which can apply to a large number of languages, and one tip per answer.
| stackexchange_codegolf |
I've tried this question on two forums and have been told this is the best place for this type of question. I'm trying to print from 0 to 1000 then back to 0 again (and all numbers in-between), printing 1000 only once. Also, each number must be on a separate line using vanilla PHP.
My current code is 60 characters long... | stackexchange_codegolf |
Inspired by this question on SO, your task is to produce a program that is valid in (at least) two major versions of your chosen language that produce different output.
Rules
Any language that has more than one major version can be used.
For the purposes of this challenge, I would suggest a "major version" is where ... | stackexchange_codegolf |
An Armstrong number (AKA Plus Perfect number, or narcissistic number) is a number which is equal to its sum of n-th power of the digits, where n is the number of digits of the number.
For example, 153 has 3 digits, and 153 = 1^3 + 5^3 + 3^3, so 153 is an Armstrong number.
For example, 8208 has 4 digits, and 8208 = 8^4 ... | stackexchange_codegolf |
Background
In Scrabble, players take turns placing tiles on a grid so that each contiguous set of (more than one) tiles in every row and column makes a word. In one play, tiles can be placed anywhere in a single row or column as long as there is a contiguous set of tiles that includes all of the ones placed.1 A word is... | stackexchange_codegolf |
As we know, a quine is a program that outputs its own source code. However, it's also possible to write a program that outputs another, different program, that outputs the first program again. For example, the Python 2 program
x = '''x = {}
print 'print '+'"'*3+x.format("'"*3+x+"'"*3)+'"'*3'''
print 'print '+'"'*3+x.fo... | stackexchange_codegolf |
Background
In Scrabble, players take turns placing tiles on a grid so that each contiguous set of (more than one) tiles in every row and column makes a word. In one play, tiles can be placed anywhere in a single row or column as long as there is a contiguous set of tiles that includes all of the ones placed.1 A word is... | stackexchange_codegolf |
Take two lists of non-negative integers, and output an ASCII-box as it's defined below.
Corners and intersections are pluses: + (ASCII-code 43)
Vertical lines are bars | (ASCII-code 124)
Horizontal lines are minuses - (ASCII-code 45)
The first input list specifies the number of minuses between each plus sign, in the ... | stackexchange_codegolf |
Challenge
Premise
I've got multiple pretty numbers all in a row. Each is a decimal digit.
0s are weakly attracted to 0s, 1s are attracted to 1s a little more strongly and so on until 9. I don't know why — it must be something I ate. As a result, a sort of two-way sideways sedimentation occurs until the higher values ar... | stackexchange_codegolf |
You must make the shortest program to always find the optimal solution to a simplified Frogger game on a 9x9 grid.
Course Elements:
L - Log (Length: 3-4). When you hop on a log, it carries you with it.
V - Vehicle (Length: 1-2)
Speed (1-2): On the left hand side of the row will be the speed that elements in the row... | stackexchange_codegolf |
Consider a permutation of the integers 1, ..., n, such as this one for n = 6:
[5,2,4,3,6,1]
If you view the permutation as a mapping from [1,2,3,4,5,6] to [5,2,4,3,6,1], the permutation can be decomponsed into disjoint cycles. A cycle is a subset of elements that map to each other. For example, 1 gets mapped to 5, whi... | stackexchange_codegolf |
It is ancient knowledge that every non-negative integer can be rewritten as the sum of four squared integers. For example the number 1 can be expressed as \$0^2+0^2+0^2+1^2\$. Or, in general, for any non-negative integer \$n\$, there exist integers \$a,b,c,d\$ such that
$$n = a^2+b^2+c^2+d^2$$
Joseph-Louis Lagrange pro... | stackexchange_codegolf |
First, some terminology (source):
A hip roof is (quoting Wikipedia) "a type of roof where all sides slope downwards to the walls, usually with a fairly gentle slope"
A slope is a planar surface that is a part of the roof
A ridge is an edge where two opposite roof slopes meet
A hip is a convex edge where two slopes bel... | stackexchange_codegolf |
The quaint hamlet of Кодгольф in the Russian far east has a problem: their population is low (below 66), and no new people have arrived for years. Moreover, after centuries of near-isolation, just about everybody is related to each other.
Mayor Стекобмен has a solution that should keep the morale high: organise a weddi... | stackexchange_codegolf |
SmileBASIC deserves more attention. I've only seen 3 users here (including myself!) providing SB answers, and while that doesn't surprise me, it disappoints me. It being a paid lang as well as being a BASIC dialect certainly turns people off, but for those who own it it's actually pretty flexible and, surprisingly, gol... | stackexchange_codegolf |
Objective
Given a matrix of connected box drawing characters, count its genus, the number of plane sections it encloses.
Valid input
The box drawing characters are ─│┌┐└┘├┤┬┴┼╴╵╶╷ (U+2500 U+2502 U+250C U+2510 U+2514 U+2518 U+251C U+2524 U+252C U+2534 U+253C U+2574 U+2575 U+2576 U+2577). The matrix shall contain these c... | stackexchange_codegolf |
Your task is to write a function that sorts an array.
Your function:
Cannot call other functions (excluding itself, of course);
Must receive an array of integers as input, and it must return the ordered array. Feel free to add other parameters as input, if you need them.
Cannot use any kind of loop (for, while...) ... | stackexchange_codegolf |
In this question I defined a "chain" function as a function that:
is a permutation, meaning that every value maps to and is mapped to by exactly one value.
and allows any value can be obtained from any other value by repeated applications of the function or its inverse.
There are a lot of functions that do this and s... | stackexchange_codegolf |
Consider a square grid on the plane, with unit spacing. A line segment of integer length \$L\$ is dropped at an arbitrary position with arbitrary orientation. The segment is said to "touch" a square if it intersects the interior of the square (not just its border).
The challenge
What is the maximum number of squares th... | stackexchange_codegolf |
You end up having a lot of very long, boring-looking conditionals in your code:
if flag == 1:
while have != needed:
if type == 7:
These can be transformed into their much more lovable <3 conditionals counterparts:
if abs(flag - 1) + 2 <3:
while 3 - abs(have - needed) <3:
if 2 + abs(type - 7) <3:
Task
Your task is... | stackexchange_codegolf |
Create a function which takes a polynomial equation, a value for x and returns the result of the operation.
Example: given 4x^2+2x-5 and x=3 output 37. This is the result of 4(3)^2+2(3)-5
Assume all polynomials are valid
Polynomial format will always be coefficient(variable)^exponent => 4x^2 except :
When exponent ... | stackexchange_codegolf |
Near the middle of the semester in chemistry, we get problems like:
Convert 1.283850057 to Scientific Notation
and
Convert 3.583✕106 to Standard Notation
This is just stupid busy work for people who already know how to do this. So…
The Challenge
Given an input in any reasonable, convenient format, in either standar... | stackexchange_codegolf |
The challenge
Make 2 programs which convert decimal to and from base 94, or a bidirectional program.
Base 94?
Base 94 is like any other base, but instead of 0 to 9 and letters, it uses ASCII characters 33 to 126. Not 127 because chr(127) is DEL. Not 32 because that's a space.
Examples
0 - ! or empty string
1 - "
93 - ~... | stackexchange_codegolf |
[ CODE GOLF]
BAM! - Fire and Smoke
Your Oscilloscope has exploded from one too many waves.
Re-create these waves assuming the following:
All waves are Sine Waves
An amplitude of 1 spans 3 lines (Therefore and amplitude of 2 would span 5 lines) [Vertically]
We want to see 100 characters worth of sine (Can be any ch... | stackexchange_codegolf |
Several years back, Hot Wheels made a simple flash game called "Formula Fuelers Racers"*. To play the game, you select three ingredients from a fridge to put into your car, which is then raced against the computer's randomly-generated car. It turns out the mechanics of this game are pretty simple. First off, the act... | stackexchange_codegolf |
Challenge
For this challenge, a mountainous string is one that conforms to the grammar rule M: x(Mx)* where at each production, the all x's are the same character. When indented, a mountainous string might look something like this:
A
B
C
D
C
E
F
E
C
B
A
As you can see, it looks a bit like a mounta... | stackexchange_codegolf |
Output a random triple \$(x,y,z)\$ of real numbers such that
\$x+y+z=\frac{3}{2}\$
Each of \$x,y,z\$, taken alone, is uniformly distributed from \$0\$ to \$1\$.
Please explain in your answer what distribution your code produces and why it meets these conditions. In particular, please include a demonstration that with... | stackexchange_codegolf |
Let us play a little golfing game.
Given a single line of N space separated numbers from STDIN, one must output those numbers on N lines.
So far, I came up with the three following bash solutions :
xargs -n1 (9)
tr \ \\n (8)
fmt -1 (6)
Can anyone do better? I am eager to learn new tricks
| stackexchange_codegolf |
Here is another simple one:
The Challenge
Given two points in an n-dimensional space, output the distance between them, also called the Euclidean distance.
The coordinates will be rational numbers; the only limits are the restrictions of your language.
Lowest dimension is 1, highest is whatever your language can handl... | stackexchange_codegolf |
Your task
Given a string of lowercase letters, output the "alphabet checksum" of that string, as a letter.
Example
Let's say we have the string "helloworld". With a = 0, b = 1, c = 2 ... z = 25, we can replace all of the letters with numbers:
h e l l o w o r l d
7 4 11 11 14 22 14 17 11 3
Now, we can sum th... | stackexchange_codegolf |
In music theory, an interval is the difference between two pitches. Each pitch is defined by the number of half-steps (The difference between C and C#) or whole steps (The difference between C and D). One whole step is the same as two half-steps. Here is a list of all the default intervals and the number of half-steps... | stackexchange_codegolf |
A string is pairable if it can be split into subtrings, each of which is a string repeated twice consecutively. For example, aabaaababbbaba is pairable as:
aaba aaba
b b
ba ba
Given a non-empty string of a's and b's, output a Truthy value if it's pairable and a Falsey value if it isn't.
Pairable:
aa
abaaba
bbababbb
aa... | stackexchange_codegolf |
Noel Constant did it without genius and without spies.
His system was so idiotically simple that some people can't understand it, no
matter how often is is explained. The people who can't understand it are people
who have to believe, for their own peace of mind, that tremendous wealth can be
produced only by thr... | stackexchange_codegolf |
You'll get a human-readable question matching one of the following syntaxes, and are expected to print/return the corresponding result. Finding similarities between the human-readable inputs and matching them with minimum size code is explicitly part of the task, so I won't give a formal definition.
"Will October begi... | stackexchange_codegolf |
Rules:
Any language you choose (Standard Libraries).
Output displayed in Terminal or Windows Command Processor or any other way you prefer.(width buffer = 80)
ASCII Characters are enough. (may add Unicode)
Shouldn't fill up the entire screen at start-up (Should look like a rain, duh!).
Colors gets bonus points (+5).
E... | stackexchange_codegolf |
I saw a problem which asks you to print "Hello World" using the fewest characters, including spaces. How can I further shorten this code? Thank you in advance!
#include<iostream>
int main(){printf("Hello World");}
| stackexchange_codegolf |
This is similar to prime factorization, where you find the smallest prime factors of a number (i.e. 8 = 2 x 2 x 2). But this time, you are to return an array/list of the smallest composite factors of any given positive integer n. If n is prime, simply return an empty list.
Examples:
Prime:
n = 2
Result: []
Composite ... | stackexchange_codegolf |
Inspired by this challenge (or, more specifically, by misreading it), I've come up with the following challenge:
Given an input string S, reverse the order of all uppercase characters, and all lowercase characters. Leave all non-letter characters in place. For instance:
Note that the uppercase W (the first uppercase l... | stackexchange_codegolf |
In this challenge you will be simulating a frog jumping from lily-pad to lily-pad in a pond. A frog's jump distance is uniquely determined by the size of the lily pad it jumps from. So for example there are lily-pads that let a frog jump 1 unit, lily-pads that let a frog jump 2 units etc. A frog can never jump more ... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.