instruction stringlengths 34 53.1k |
|---|
Recently I had a Maths test and noticed that a certain number on the test matched an interesting pattern. The number (28384) matched a generic digit sequence that looks like this
(n)(x)(n+1)(x)(n+2)(x)(n+3) etc...
where n and x are single digit integers. The sequence can begin with either x or n and end with either x ... |
Take a matrix of positive integers as input, and make it explode!
The way you explode a matrix is by simply adding zeros around every element, including the outside borders.
Input/output formats are optional as always!
Test cases:
1
-----
0 0 0
0 1 0
0 0 0
--------------
1 4
5 2
-----
0 0 0 0 0
0 1 0 4 0
0 0 0 0 0
0 ... |
Suppose we have a matrix like this:
11111
12221
12321
12221
11111
This matrix represents a terrain, and each cell represents a portion of terrain. The number in each cell represents the time the portion of terrain needs to be completely burnt (in minutes, if a measurement unit is needed), according to its combustibili... |
In this challenge, you must parse a list of lists, into a simpler list format.
This challenge is based on my sadflak parser. In my sadflak parser, it has all the () removed, replaced with the sum of the ()s at the start of the list, to make the program run faster.
To parse into a Sad-List, you have to do this (python i... |
Consider the following 3x3 blocks which the marching squares algorithm would identify for every cell (with 0-based labeled ID):
0:
...
...
...
1:
...
...
\..
2:
...
...
../
3:
...
---
...
4:
..\
...
...
5:
/..
...
../
6:
.|.
.|.
.|.
7:
/..
...
...
8:
/..
...
...
9:
.|.
.|.
.|.
10:
..\
...
\..
11:
..\
...
...... |
The Zachtronics game TIS-100 contains a graphics display called the visualization module. I could try and explain the specs of this module, but the game's manual will do a better job:
(As you may have guessed, the motivation of this problem is to create a code golf challenge in which TIS-100 is the optimal language.)
... |
Output/print this block of text:
1234567890
2468013579
3691470258
4815926037
5049382716
6172839405
7306295184
8520741963
9753108642
0987654321
Acceptable formats include:
Trailing newlines/whitespace
List of strings
List of lists of characters
List of lists of integers
However, list of integers is not acceptable bec... |
Problem
Recreate the UI from a torrent program
Given no input, output the following:
+----------+----------+----------+
|a.exe |##########|seeding |
+----------+----------+----------+
|b.exe 10% |# |leeching |
+----------+----------+----------+
|c.exe |##########|seeding |
+----------+----------+--... |
Inspired by this and the following chat:
Your task is to output the following:
_ _ _
/_/_/_/\
/_/_/_/\/\
/_/_/_/\/\/\
\_\_\_\/\/\/
\_\_\_\/\/
\_\_\_\/
Extra leading or trailing whitespace is allowed, as long as it does not change the appearance of the cube. As usual, returning the above or a list of strings ... |
Given an integer array and two numbers as input, remove a certain amount of the first and last elements, specified by the numbers. The input can be in any order you want.
You should remove the first x elements, where x is the first numerical input, and also remove the last y elements, where y is the second numerical in... |
Note: When I refer to a bridge, I mean it in the non-mathematical sense
Introduction
You are on a network of islands which are connected by wooden bridges and you want to see if you can burn every bridge in the island network. However, you can only burn a bridge once you've walked over it.
Once a bridge has been burned... |
This is a simple one: Take a matrix of integers as input, and output the index of the row with the most non-zero elements. You may assume that there will only be one row with the most non-zero elements.
Test cases:
These are 1-indexed, you may choose if you want 0 or 1-indexed.
1
0
row = 1
---
0 -1
0 0
row = 1
---
1... |
In this question each answer will get a "toolbox" that can be used to construct a program/function. The toolbox will consist of two things:
a list of programming languages
a list of valid characters
You must write a valid program/function in one of the languages provided using only the characters in the toolbox. Yo... |
Write a program that prints "Hello, World!".
But also, if you take only the first, third, fifth, etc. characters of your program, the resulting program should still print "Hello, World!".
If your program is:
abc
def
It should output "Hello, World!", but so should
acdf
No solutions with fewer than 2 characters.
|
In the misty years of yore, when fanfold terminals walked the earth, there lived a strange creature. Oddly crippled and yet oddly powerful, the line editor teemed across the programming landscape in untold numbers; covering the earth as far as the eye could see.
Now it is fallen on hard times. That vast population hunt... |
You will be given a String that only contains letters of the English Alphabet, both lowercase and uppercase (ASCII 65-90 and 97-122). Your task is to output the Fizz-Buzzified version of the String.
How to Fizz-Buzzify a String?
Each letter that has an even index in the English alphabet (the alphabet must be 1-indexed... |
This challenge is related to a project I did last year (in Ruby). To make it more fun I decided to do it in as few bytes as possible. I didn't know about code golf back then so now that I found out about it and found this community I was wondering if anybody can beat me :)
The program should return the current time if ... |
Coders are always trying to flatten arrays into boring 1-dimensional entities and it makes me sad.
Your task is to unflatten an arbitrary string of characters, outputting a lovely city skyscape.
Consider the string: aaabbbbbccqrrssstttttttPPw
It looks much better like this:
tt
tt
bb tt
... |
Given a strictly positive integer, return the shortest possible Roman numeral using only the additive rule. Output must consist of zero or more of each of the characters MDCLXVI in that order. The number 14 must therefore give XIIII rather than XIV.
The characters' numeric values are M=1000, D=500, C=100, L=50, X=10, V... |
If you've come here, you probably know what code-golf is, and that's what I'm going to assume.
Story
(I guess)
Keyboards are input devices we use all the time. They existed before mice and touch screen, etc.
Their fundamentals have not changed: when you press a key down, a signal is sent to the computer. When you rele... |
Given an positive integer as input determine if it is a magnanimous number.
A magnanimous number is a number such that any insertion of a + sign between any two digits in base 10 results in an expression of a prime integer.
For example 40427 is magnanimous because
4+0427 = 431 is prime
40+427 = 467 is prime
404+27 ... |
Take a matrix A consisting positive integers, and a single positive integer N as input, and determine if there are at least N consecutive occurrences of the same number in any row or column in the matrix.
You need only test horizontally and vertically.
Test cases
N = 1
A =
1
Result: True
----------------
N = 3
A =
1 ... |
Given one of the following as input:
AK,AR,AS,AZ,CA,CT,DC,FL,GA,IL,IN,IA,KS,KY,LA,MD,MI,MN,MS,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PA,PR,RI,SC,TN,TX,UT,VT,VA,WA,WI
(with quotes)
"AK","AR","AS","AZ","CA","CT","DC","FL","GA","IL","IN","IA","KS","KY","LA","MD","MI","MN","MS","NV","NH","NJ","NM","NY","NC","ND","MP","OH","OK",... |
Given a double-precision float, find the closest double-precision float whose binary representation is a palindrome.
Input
A floating point number x. You may use any format you like for input, but the format you chose must be able to represent every possible IEEE 754 binary64 value, including denormals, distinct repres... |
Write a program that adds or removes whitespace to format code nicely. Rules for what the code should look like when you're done:
No line should contain more than one of { and }.
A { should always be the last thing on a line.
A } should always be the only thing on a line (besides whitespace that comes before it).
The ... |
Degree of Unsaturation
This is not a particularly hard code puzzle - but I'm interested to see your multiple ways of solving it.
The Degree of Unsaturation is the number of double chemical bonds between atoms, and/or the number rings in a chemical compound.
You will be given the molecular formula of a chemical compoun... |
Challenge
This is a simple challenge. Given two positive integers w and h create an ASCII fence with a width of w and a height of h. The fence should be constructed using the following rules:
The + character will represent a post.
The - character will be used to represent the width of the fence.
The | will be used to ... |
Input:
A positive integer n consisting of digits in the range 0-9.
Challenge:
If d is the highest digit in the integer, assume the base of the number is d+1. E.g. if the integer is 1256 then you shall assume it's in base-7, if it's 10110 then you shall assume it's base-2 (binary), and if it's 159 then it's decimal.
Now... |
Surprisingly we haven't had a simple "find the highest digit" challenge yet, but I think that's a little too trivial.
Given input of a non-negative integer, return the highest unique (ie not repeated) digit found in the integer. If there are no unique digits, your program can do anything (undefined behaviour), other th... |
We are all used to the old-school telephone keypad, right? For reference, here is what it looks like:
Given a String consisting only of lowercase ASCII letters and single spaces, your task is to return the number of taps one should make in order to type down the full String with a telephone keypad as the one above.
F... |
TL;DR: Given an array of chars and a robot in a starting position of the array, write an algorithm than can read a string with movements (F for "go forward", R for "rotate 90 degrees right" and L for "rotate 90 degrees left") and calculate the ending position of the robot. More details in the complete text.
We have a... |
A classic example to introduce people to the concept of a discrete probability distribution is the bean machine. This machine has a large amount of marbles fall from a narrow passageway at the top, after which they hit rows of interlaced pins, where at each pin the marble hits it might fall to the left or the right of ... |
The dragon curve sequence (or the regular paper folding sequence) is a binary sequence. a(n) is given by negation of the bit left of the least significant 1 of n. For example to calculate a(2136) we first convert to binary:
100001011000
We find our least significant bit
100001011000
^
Take the bit to its le... |
Alternesting, is the act of taking a string and nesting it in alternating brackets. Here is how you alternest a string.
For a string of length N, take the center N characters, and surround them in parenthesis. So if our string was Hello world! (12 characters), we'll end up with
(Hello world!)
Then, take the remaining... |
Overview
Some of you might be aware of the Kolakoski Sequence (A000002), a well know self-referential sequence that has the following property:
It is a sequence containing only 1's and 2's, and for each group of 1's and twos, if you add up the length of runs, it equals itself, only half the length. In other words, the... |
Your input will be an English sentence, phrase, or word. It will only contain a-zA-Z' -,.!?. Your task is to take the input, remove spaces, and then redistribute capitalization such that letters at indexes that were capitalized before (and only letters at indexes that were capitalized before) are capitalized.
For examp... |
Convert short date format into English long date in as few bytes as possible.
Input
Input will be in the form of a string with format, yyyy-mm-dd, with zero padding optional for all values. You can assume that this is syntactically correct, but not necessarily a valid date. Negative year values do not need to be suppor... |
A triangular number is a number that is the sum of n natural numbers from 1 to n. For example 1 + 2 + 3 + 4 = 10 so 10 is a triangular number.
Given a positive integer (0 < n <= 10000) as input (can be taken as an integer, or as a string), return the smallest possible triangular number that can be added to the input to... |
Dungeon Master was one of the first ever real-time role-playing games, originally released in 1987 on the Atari ST. Among other exciting things for the time, it offered a rather sophisticated spell system based on runes.
Your task today is to write a program or function that evaluates the number of Mana points required... |
The world of art is full of colour, but the world of the network is even fuller than the world of art of diferent colours and it's renderings. That's why we need to know how to convert one type of colour format to another.
The challenge is self-evident:
Write a program / function than converts an given HEX code (#00ff0... |
Here is an example of an input of monoliths. There are 4 in this example.
_
| | _
| | _ | |
| | | | | | _
_| |_| |___| |____| |_
The first monolith is 4 units high, the second is 2, the third is 3, and the last is 1.
The task
Your program should output the heights of the monoliths in order from l... |
In a desolate, war-torn world, where cities have been overrun by thugs and thieves, civilization has reinvented itself in the form of small, isolated, industrial cooperatives, scattered throughout the previously uninhabited landscape. The existence of these communities is reliant on teams of mercenary workers called "s... |
I have written a few challenges related to matrices, and common for all are that I use a format like the one below when representing the matrices, both in examples and in test cases:
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
This is likely a cumbersome format in many languages.
Challenge... |
Challenge
Given the number of an XKCD comic, output the title text of that comic (the mouseover text).
However, the program must throw an error when given the numbers 859 or 404.
Rules
The number given will always be an existing comic (except 404).
Your program must not throw an error for any other numbers than 859 or... |
A number is a de Polignac number if and only if it is odd and cannot be represented in the form p + 2n where n is a non-negative integer and p is a prime integer.
Task
Write some code that takes a positive integer and determines if it is a de Polignac number. You may output two distinct values one for true and one for... |
Given Color codes in CMYK, convert it to RGB value.
Input:
string of 4 integers(ranging from 0-100) separated by space
86 86 0 43
28 14 0 6
0 41 73 4
Output:
#141592
#ABCDEF
#F49043
Shortest code wins!
HINT: For converting CMYK to RGB you may use formula such as:
Red = 255 x (1 - Cyan/100) x (1 - Black/100) ... |
I found it quite hard to achieve a range of numbers as rows in MySQL.
For example the range 1-5 is achieved by:
SELECT 1
UNION
SELECT 2
UNION
SELECT 3
UNION
SELECT 4
UNION
SELECT 5
will result in:
1
2
3
4
5
for 0-99 I can cross join two 0-9 tables:
CREATE TABLE nums as
SELECT 0 as num
UNION
SELECT 1
UNION
SELECT ... |
Given a set of two strings guaranteed to be the same length, print their criss cross.
The criss cross of two strings is obtained as follows.
Yield the second character of the second string, then the first character of the first string.
Yield the first character of the second string, then the second character of the fi... |
Challenge
Given a string and a number, divide the string into that many equal-sized parts. For example, if the number is 3, you should divide the string into 3 pieces no matter how long the string is.
If the length of the string does not divide evenly into the number provided, you should round down the size of each pie... |
Challenge
Print or return the Stack Exchange favicon, as provided below:
___________________
/ \
---------------------
| |
---------------------
| |
---------------------
\__________ _____/
| /
| /
|/
This is code-golf, so the ... |
The challenge
Write a program or function which takes a string input as a function parameter or from stdin and determines if it is a valid FEN string.
Input
You can assume the input will only ever include the following characters (case sensitive)
pkqrbnPKQRBN12345678/
The length of the input will always be a minimum of... |
For this challenge, you should write a program or function which outputs the diagonals of a given square matrix. However, if you transpose the rows and columns of your solution's source code, it should instead become a program or function which returns the matrix's antidiagonals. Read on for specifics...
Rules
The sou... |
Heavily inspired by Hello, World! (Every other character)
Write a program that outputs 1. When the first, third, fifth, etc. chars are removed, it outputs 2. When all chars where their (1-based) index in the source, mod N, are not 0, are removed, it should output N.
This is code-challenge. The winner is the program tha... |
A staircase number is a positive integer x such that its nth digit (one indexed starting with the least significant digit) is equal to x % (n + 1). Thats a bit of a mouthful so lets look at an example. Take 7211311, if we take the modular residues of 7211311 on the range 2-8 we get the following:
7211311 % 2 = 1
7211... |
A primitive element of a finite field is a generator of the multiplicative group of the field. In other words, alpha in F(q) is called a primitive element if it is a primitive q−1th root of unity in F(q). This means that all the non-zero elements of F(q) can be written as alpha^i for some (positive) integer i.
All ele... |
You are the roughest, toughest, coolest cowboy west of the Mississippi. However, some weird guy on a wacky nerd website decided that it would be cool to plop you into random unfinished landscapes and fight. No matter, you'll still win. However, to help you win those grueling gunfights you'll write home about, it's help... |
I somewhat miss those old demos showing the capabilities of computers when they were called x86 instead of i3, i5 and i7. One of the first I watched in my 386 was the Unreal demo from Future Crew that is now celebrating its 25th anniversary. At minute 0:43 the first part of the demo starts and we see a scrolling text f... |
I, uh....honestly can't believe we don't have this one yet.
Challenge
Write two functions or programs that:
Convert from decimal to percentage
Convert from percentage to decimal
You may also write a single program that does both of the above.
Format
Percentages must be taken and returned with a percent sign. (In many... |
As a kind of part 2 to Hello, World! (Every other character), write a program such that all three of these programs print "Hello, World!": the entire program, the 1st, 3rd, 5th, etc. characters of your program, and the 2nd, 4th, 6th, etc.
If your program is:
abc
def
It should output "Hello, World!", but so should
acdf... |
The treewidth of an undirected graph is a very important concept in Graph Theory. Tons of graph algorithms have been invented which run fast if you have a decomposition of the graph with small treewidth.
The treewidth is often defined in terms of tree decompositions. Here's a graph and a tree decomposition of that grap... |
Challenge:
Take a rectangular figure consisting of the two characters # and (whitespace, ASCII-32), and identify which direction the lines are. The options are: 'Vertical', 'Horizontal', 'Left Diagonal' and 'Right Diagonal'.
Input:
The input will be a figure of size n-by-m where 5 <= m,n <= 20. There will be two space... |
Consider the integers modulo q where q is prime, a generator is any integer 1 < x < q so that x^1, x^2, ..., x^(q-1) covers all q-1 of the integers between 1 and q-1. For example, consider the integers modulo 7 (which we write as Z_7). Then 3, 3^2 mod 7 = 2, 3^3 = 27 mod 7 = 6, 3^4 = 81 mod 7 = 4, 3^5 = 243 mod 7 = ... |
What you need to do is create a function/program that takes a decimal as input, and outputs the result of repeatedly taking the reciprocal of the fractional part of the number, until the number becomes an integer.
More specifically, the process is as follows:
Let x be the input
If x is an integer, output it.
Otherwise... |
Most people are familiar with Pascal's triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Pascal's triangle is an automaton where the value of a cell is the sum of the cells to the upper left and upper right. Now we are going to define a similar triangle. Instead of just taking the cells to the upper left and the upp... |
The Lehmer-Comtet sequence is a sequence such that a(n) is the nth derivative of f(x) = xx with respect to x as evaluated at x = 1.
Task
Take a non-negative integer as input and output the nth term of the Lehmer-Comtet sequence.
This is code-golf so you should minimize the file size of your source code.
Test Cases
OEI... |
Challenge
The challenge is simple, using http://isup.me, determine whether an inputted website is up or down.
If the site is up, you should return a truthy value and if the site is down, you should return a falsey value.
Rules
The input will be a web address such as stackexchange.com or google.co.uk. The input will nev... |
Challenge
Convert and print out a time in a 12-hour format. HH:MM AM/PM
Examples
Input:
'Fri Jun 30 2017 21:14:20 GMT-0700 (PDT)'
'Fri Jun 30 2017 00:10:23 GMT-0700 (PDT)'
'Fri Jun 30 2017 12:10:23 GMT-0700 (PDT)'
'Sat Jun 31 2018 8:06:20 GMT-0700 (PDT)'
'Fri Jul 01 2017 01:14:20 GMT-0700 (PDT)'
'Sat Apr 10 2020 09:06... |
This is a very very simple algorithm, that I am sure can be solved in many many different languages. In Spain ID cards (known as DNI) consist of 8 numbers and a control character. The control character is calculated with the following algorithm: divide the number by 23, take the remainder of the operation and replace i... |
Inspired by the bugged output in @Carcigenicate's Clojure answer for the Print this diamond challenge.
Print this exact text:
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 ... |
Write a program, that sends its own source code over network.
Network example is TCP/UDP or web socket. Ethernet, Bluetooth, Wi-Fi and internet over USB are allowed.
No need to write receiver program. You can use any encoding protocol, but decoder will be realizable.
Rules
Network is not a stdout, screen, USB, UART, G... |
Write a function that calculates a row of the pascal triangle and returns the middle number, if there are 2 it should return their sum.
Example:
5
would return
20
Example 2:
4
would return
6
EDIT:
To be clear:
a) if the number inputted is odd then find then return the middle number of a row on the pascal triangle.
... |
Background
Celebrating the release of Dyalog APL 16.0, where the solution to this problem is {⊢⌺(≢⍵)⊢⍵}Explanation
Task
Given a printable ASCII string of odd length n, make an n × n square with the string centered horizontally, duplicated to be centered vertically, and with acrostics of the same string in each row and ... |
Given a positive integer as input, your task is to output a truthy value if the number is divisible by the double of the sum of its digits, and a falsy value otherwise (OEIS A134516). In other words:
(sum_of_digits)*2 | number
Instead of truthy / falsy values for the true and false cases, you may instead specify any ... |
The Goldbach conjecture states that:
every even number that is greater than 2 is the sum of two primes.
We will consider a Goldbach partition of a number n to be a pair of two primes adding to n. We are concerned with numbers is of increasing Goldbach partition. We measure the size of a number's Goldbach partitions ... |
Overview
Given a 3 line string, figure out if the structure falls to the left, balances, or falls to the right.
Input structure
You can imagine the structure as metal rod with stuff on top, all being balanced on top of a vertical rod.
1 7 4 a
===============
|
The first line is the items. Each item's w... |
Given a string s and a positive integer N, gradually duplicate each character more and more until N duplicates, and then staying at N duplicates until N characters away from the end, then step down again.
For example, given abalone and 3:
a we start with 1 copy
bb then 2 copies
aaa then 3 copies, which is our sec... |
The task is the following. Given an integer x (such that x modulo 100000000003 is not equal to 0) presented to your code in any way you find convenient, output another integer y < 100000000003 so that (x * y) mod 100000000003 = 1.
You code must take less than 30 minutes to run on a standard desktop machine for any in... |
Challenge:
Given a square input matrix \$A\$, pad the matrix with one row and one column on all four sides.
The value of each element in the top and bottom row should be the sum of the elements in each corresponding column.
The value of each element in the left and right column should be the sum of the elements in eac... |
Program A outputs program B's code when run, and B outputs A's source.
Requirements:
Only one language across both programs
Programs are different. One program that outputs itself does not qualify.
Both programs are non-empty, or at least 1 byte in length. Trailing newlines in both source and output are ignored
st... |
You will be given a positive, whole number (that will never contain a 0) as input. Your task is to check whether it is a Lynch-Bell number or not.
A number is a Lynch-Bell number if all of its digits are unique and the number is divisible by each of its digits.
In fact, there are actually only 548 Lynch-Bell numbers, s... |
Overview
Given a list of digits, find the fewest operations to make 100
Input
A string of digits, which may or may not be in numerical order. The order of the digits cannot be changed, however plus (+) or minus (-) operators may be added between each so that the total sum is equal to 100.
Output
The number of operators... |
A balanced string is a string of parentheses () so that every parenthesis is can be matched with another one. More rigorously they are the strings spanned by this grammar:
S → (S)S | ε
We can turn a string "inside out" by:
Switching all occurrences of ( and ) with each other
Moving characters from the front of the s... |
NOTE: This question is different than Draw an ASCII Rectangle because the user has to input only 1 number to generate a box, unlike the other question, where the user has to input the x and y size of the box.
Your task is to create a box based upon user input. Let's say I inputted 2. The box generated would look like:
... |
Given, in any way and order,
dimensions (in whichever order you want)
a probability (in whatever format you want)
number of iterations (you may choose whether to count the initial state or not)
do one of the following:
animate, or
output each step of, or
return a list of states of
a spaces-filled sky of those... |
Given an input string containing only alphanumeric ASCII characters and starting with a letter, swap each letter run with the digit run which follows.
A run is a sequence of consecutive letters or digits. Note that in the case where the input string ends with a run of letters, this run is left untouched.
Walk-through e... |
Cyclic Polyglot Challenge
This is the robbers thread. You can find the cops thread here.
Cyclic Polyglot
A N-element cyclic polyglot is a complete program that can be run in N different languages. In each language, when the program is run with no input (possibly subject to this exception), it should print the name of a... |
Cyclic Polyglot Challenge
This is the cops thread. You can find the robbers thread here.
Cyclic Polyglot
A N-element cyclic polyglot is a complete program that can be run in N different languages. In each language, when the program is run with no input (possibly subject to this exception), it should print the name of a... |
Warning: This challenge is only valid for languages with a compiler.
Make a program (which is perfectly valid code) that outputs Hello, World, even before runtime.
How? Let me explain.
Many languages have a compiler. Some operations are made in the compile-time, and others, in runtime. You trick the compiler to outpu... |
Compress a sparse matrix using Compressed sparse row (CSR, CRS or Yale format).
These are all the same form of compression (ignore new Yale).
Input may be any 2d data structure (list of lists, etc): e.g
[[0 0 0 0],
[5 8 0 0],
[0 0 3 0],
[0 6 0 0]]
And the output should be three 1d data structures (list etc), that d... |
Continuing my It was just a bug challenge:
Input:
A string consisting of printable ASCII characters without white-spaces nor new-lines.
Output:
First turn the input into a palindrome by reverting the input, and adding it before itself, excluding the middle character (i.e. with an input 1234567890, it will becomes 09876... |
Goal
You are given an integer n (n > 1). You must output how many permutations of the integers 1 to n there are which start at 1, end at n, and don't have two consecutive integers which differ by 1.
Alternatively, if you take the complete graph K_n and remove the edges of the path 1-2-3-...-n you must count the Hamilto... |
Warm up: Regex, Paper, Scissors
This is the challenge I originally wanted to post, before realising that some very short solution exist. Nevertheless, it can be an interesting problem to think about in preparation for the actual challenge below.
Write three regexes R, P and S such that they match each other in a cyclic... |
You might already be familiar with the game: Basketball FRVR in facebook. There are two types of score you can make:
A virgin-shot:(we call it so in our country :D) When the ball enters the basket without touching the rim or
A stale shot: When the ball enters the basket, but after touching the rim.
The game is over ... |
In golf, the standard scratch of a course is calculated using this formula:
(3*num_of_3_par_holes + 4*num_of_4_par_holes + 5*num_of_5_par_holes) - difficulty_rating
Your task is to calculate the standard scratch of a golf course, given these 4 inputs.
You should take input in any standard form in the format
[num_of_3_... |
In this challenge, you are given two overlapping rectangles, and you need to calculate the rectangles created by removing one from the other.
For example, if you remove the red rectangle from the black one:
You end up with one of the following two rectangle sets:
You'll also need to handle the following:
To be more... |
Getting the average of a list (e.g [2,6,7])
Get the length of the list: [2,6,7] -> 3
Sum the numbers in the list: 2 + 6 + 7 = 15.
Divide the sum by their count: 15 / 3 = 5.
You should compare the averages of two lists of positive integers N and M, by returning a value if N has a higher average, another value if M ha... |
Pascal's Rhombus (which is actually a triangle) is obtained by adding in the pattern:
*
***
x
instead of
* *
x
This means that each cell is the sum of the three cells on the row directly above it and one cell on the row 2 above it. Just like Pascal's triangle the zeroth row has a single 1 on it that generates... |
Given a positive integer, find its smallest positive integer multiple which is a run of 9 followed by an optional run of 0. In other words, find its smallest positive integer multiple which is matched by the regex /^9+0*$/.
For example, if the given positive integer is 2, then return 90, since 90 is a positive integer ... |
Note: Anders Kaseorg warns me that this could be a duplicate of another previous question. It seems so, and I'm sorry I did not find that question before posting this one. Nonetheless, that question only received one answer and this one is simpler, just in case you all want to try this time. I'll understand if this qu... |
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.