This challenge is intended to be solved by using, manipulating, accepting as input, or outputting numeric values.

learn more… | top users | synonyms

11
votes
2answers
526 views

Smoothing out a list

You should write a program or function which takes a non-negative integer k and a sorted integer list Las input and outputs or returns a smoothed list M. M is created from the ascending list L by ...
15
votes
9answers
1k views

Compute the Hausdorff Distance

Introduction The Hausdorff distance measures the difference between two subsets of a metric space. Intuitively, a metric space is just some set with a built-in distance function; in this challenge, ...
12
votes
1answer
481 views

Two-zero-one-five puzzle

Background This puzzle is a variation on the four fours puzzle (itself the topic of a past question). Like that puzzle, the aim is to find mathematical expressions for different whole numbers, using ...
19
votes
9answers
2k views

Generate a pair of integers from a non-negative one

You should write a program or function which takes a non-negative integer N as input and outputs or returns two integers (negative, zero or positive) X and Y. Integers are meant in the mathematical ...
16
votes
2answers
467 views

Prepare to… die?

Background One source of ennui in tabletop role-playing games is dealing with rolls involving many dice. Casting a Disintegration spell may be instantaneous, but rolling and adding together 40 dice ...
10
votes
9answers
923 views

Generate The SUDSI Sequence

The SUDSI sequence (sum, difference, swap, increment) is a curious integer sequence that appears to exhibit rather chaotic behavior. It can be generated as follows: Let S be an infinite list of the ...
0
votes
0answers
63 views

Random arithmetic quiz [duplicate]

Given a and b as two random numbers from 0 to 10 and op as a random symbol of arithmetic operations, you should display 10 questions in the format: a op b = to the user, after each question if the ...
17
votes
6answers
2k views

Chinese Remainder Theorem

The Chinese Remainder Theorem tells us that we can always find a number that produces any required remainders under different prime moduli. Your goal is to write code to output such a number in ...
15
votes
6answers
505 views

Sorted Lexical Partition of a Number

The challenge is really simple: given a number, you split its digits into an array of smaller numbers such that the resulting numbers are non-decreasing. The catch is that you have to split it such ...
6
votes
3answers
519 views

Finding Collatz-like rules with many loops

This code-challenge is related to the code-golf question Analyzing Collatz-like sequences but the goal is quite different here. If you are familiar with Collatz-like sequences you can skip to the ...
17
votes
51answers
2k views

Print number triangle

Given a number N, output a NxN right angled triangle, where each row i is filled with numbers up to i. Example n = 0 (no output) n = 4 1 1 2 1 2 3 1 2 3 4 n = 10 1 1 2 1 2 3 . . . 1 2 3 4 5 6 ...
3
votes
17answers
862 views

Randomised list, formatted nicely

Challenge Task Given a number N, output 2 NxN squares; each line of each square is a random permutation of [0, N); the squares are separated by a newline Rules Produce a randomised list of length ...
5
votes
7answers
620 views

Digit sum of powers in bases

You should write a program or function which outputs or returns the sum of the digits in base b representation of the first n natural power of a in ascending order. Example for a = 2, b = 3 and n = ...
12
votes
4answers
793 views

Find the maximum of ax+b

You are given a list of (a,b), and a list of x. Compute the maximum ax+b for each x. You can assume a, b and x are non-negative integers. Your program or function must run in expected (to the ...
13
votes
21answers
464 views

Bookkeeping for the Sex Bob-ombs (check if a running sum ever gets too low)

Believe it or not, the Sex Bob-ombs have become a world famous band and are currently on world tour! As their bookkeeper you must oversee their day to day finances and provide regular reports. Every ...
34
votes
18answers
4k views

Shotgun Numbers

The Shotgun numbers are a sequence with a rather simple definition but some interesting structure. Start with the natural numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ...
13
votes
1answer
168 views

Analyzing Collatz-like sequences

We define a Collatz-like sequence s with 4 positive integers: n starting value d > 1 divisor m > 1 multiplier i increment (In the original Collatz sequence d = 2 m = 3 and i = 1.) Given ...
7
votes
7answers
246 views

Pseudo-cyclic Number Evaluator

For the purposes of this challenge, let's define a cyclic number as an integer that passes the basic part of Midy's Theorem, but not necessarily the extended theorem. This means: the digits in the ...
14
votes
16answers
2k views

Different Way Forward

Given a list of integers produce a Forward Difference at a specified order/depth. For the list of integers: (10, 18, -12, 4, 8, -3, -5, 67, 9, 14) The Forward Differences at the various ...
13
votes
11answers
978 views

Random Golf of the Day #3: Integer Partitions

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
1
vote
0answers
148 views

LCD Numbers - get my lost 190 bytes back [duplicate]

Years ago I read the "Best of Ruby Quiz" book by James Edward Gray II (also available online by now). For problem 2 in the book (which is problem 14 on his original RubyQuiz site), he mentions a ...
19
votes
18answers
3k views

Generate Lucky Numbers

Story: Lucy asked George what his Lucky Number was. After some contemplation, George replied that he had several Lucky Numbers. After some brief confusion, Lucy asked George what his first n Lucky ...
10
votes
12answers
1k views

Apportionment paradox

Given: A natural number S. A list of N rational weights W that sum to 1. Return a list L of N non-negative integers, such that: (1) sum(L) = S (2) sum((S⋅W_i - L_i)^2) is minimal In other ...
14
votes
4answers
559 views

Factorize it! …badly

A curious kid uses a program which can factorize a number or an expression into the following form: p1^e1 * p2^e2 * ... * pn^en. Exponents equal to 1 are omitted e.g. 360 = 2^3 * 3^2 * 5 The kid ...
10
votes
22answers
1k views

Random Golf of the Day #2: Numbers from a Normal Distribution

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
-1
votes
1answer
219 views

Find the inverse of a matrix

Write a full program to calculate the inverse of a 4-by-4 matrix. Rules The sixteen values of the initial matrix must be hard-coded to variables, as follows: _ _ |a b c d| |e f g h| |i j k l| ...
8
votes
8answers
514 views

Pair-golfing Twin primes and the Collatz sequence

This is a new kind of challenge inspired by the Recover the mutated source code problem. You should write two programs or functions both in the same language. The first one should solve Task #1 and ...
8
votes
9answers
430 views

Ordering an array of negatives, zero and positives integers with one iteration

Take an array of integers containing negative numbers, positive numbers and zeros. Group it with one iteration and in place such that all of the negative numbers come first, followed by all of the ...
1
vote
0answers
98 views

KOTH: Number fight [closed]

Number fight game Setup Each ai is given a random number from 1 to 100. The starting number is the average of these two numbers. Gameplay Each ai knowing its own target, the opposite target ...
10
votes
22answers
2k views

Generate the Stöhr sequence

I am learning Ruby and wrote my first nontrivial code to solve this problem. The challenge is to generate the first n elements of the Stöhr sequence, S, which is defined as follows: S[0] = 1 ...
3
votes
3answers
535 views

Generate all 4-perfect numbers

Your program or function should output all the 36 4-perfect numbers in increasing order separated by newlines. An n positive integer is a k-perfect number (multiply perfect number) if the sum of its ...
-1
votes
6answers
139 views

Double Factorial [duplicate]

Challenge The objective is simple, in the shortest amount of bytes, write a function or program that takes a number and prints its double factorial. The input must be taken from stdin or a function ...
14
votes
7answers
626 views

Sum the powers to n

Directions Write a program that, given an input integer n (n >= 0), outputs the smallest positive integer m where: n = a[1]^b[1] + a[2]^b[2] + a[3]^b[3] + ... + a[k]^b[k] a and b are finite ...
36
votes
14answers
5k views

Into how many pieces can you cut this string?

Consider a piece of string (as in "rope", not as in "a bunch of characters"), which is folded back and forth on the real line. We can describe the shape of the string with a list of points it passes ...
8
votes
5answers
1k views

All primes from 0 to 1000

Is it possible to make this C code smaller? It prints out all primes from 0 to 1000. C, 89 chars int i,p,c;for(i=2;i<1e3;i++){c=0;for(p=2;p<i;p++)if(i%p==0)c++;if(c==0)printf("%u\n",i);}
0
votes
1answer
190 views

Cycles and stuff - What does this program do? [closed]

I just found one of my first C++ programs in some deep caves on my disk... #include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <string> ...
9
votes
36answers
3k views

Calculate the square of an integer with restrictions [closed]

The Puzzle You have to write a program or function p(n) that returns the square of what is entered into it and you may assume that the input is a non-negative integer. Put in simpler terms, return ...
-5
votes
1answer
210 views

Number guessing game with memory [closed]

Your programme should ask the user's name and then play a number guessing game: (>) means that the computer writes it. > What's your name? Brown > Brown you are welcome. What is your number? ...
8
votes
18answers
1k views

Convert RGB integer value into RGB values

For example, in traditional web hexadecimal, a certain base-16 number represents an RGB value. For example, 45A19C equals (69,161,156) in RGB. You'll be converting from that number to RGB value, ...
20
votes
14answers
1k views

Recycling for the New Year

A good resolution for 2015 is to live more sustainably. We'll start by recycling. Recycling code, that is! Your task is to print the number 2015 to STDOUT, with or without trailing newline (and only ...
22
votes
21answers
2k views

Print rotation-safe numbers

Background You are working for some board-game manufacturer and need to produce wooden tiles with the numbers from 0 to n engraved on them for some game. However, without further ado, some tiles ...
17
votes
6answers
1k views

Time Travelling Stock Trader

Story Long time ago Bobby created a Bitcoin wallet with 1 Satoshi (1e-8 BTC, smallest currency unit) and forgot about it. Like many others he later though "Damn, if only I invested more back then...". ...
13
votes
18answers
2k views

Generate any random integer

Your program/function should output exactly one integer output any integer with positive probability output an integer greater than 1.000.000 or less than -1.000.000 with at least with 50% ...
4
votes
6answers
1k views

Print all odd numbers from 0 to 100000

My teacher gave me a simple problem which I should solve with a code tiny as possible. I should print all odd numbers from 0 to 100000 into a HTML document using javascript. for(var y = 0; y < ...
32
votes
28answers
2k views

At least h with at least h

Input A list of nonnegative integers. Output The largest nonnegative integer h such that at least h of the numbers in the list are greater than or equal to h. Test Cases [0,0,0,0] -> 0 ...
6
votes
5answers
668 views

Implement t9-like functionality

Your challenge today is to implement a t9-like functionality. You will implement a function that will only have 2 parameters. You will receive 1 phone number in a string and the content of a text ...
33
votes
6answers
2k views

Numbers as Circular Graphics

First, study this puzzle to get a feel for what you will be producing. Your challenge is to write a program or function which will output a circular graphic like the ones from the puzzle, given a ...
-4
votes
2answers
116 views

Magical Squares [closed]

A perfect square is a number that is the square of an integer. However, let's define something called a Magical Square, which is a perfect square with the following restriction: The perfect square ...
11
votes
8answers
782 views

Balanced Ternary Converter

Credits for the challenge idea go to @AndrewPiliser. His original proposal in the sandbox was abandoned and since he has not been active here for several months, I have taken over the challenge. ...
16
votes
4answers
532 views

Decompose a number with bit-xor without the digits 0, 3, 7

Challenge Write a function or program which takes a positive decimal number, call it A, and output two positive numbers, B and C, such that: A == B bitxor C B and C must not contain any of the ...