This challenge is intended to be solved by using, manipulating, accepting as input, or outputting numeric values.
10
votes
8answers
277 views
Convert to and from the factorial number system
The Factorial Number System, also called factoradic, is a mixed radix numeral system. The factorials determine the place value of a number.
In this system, the right most digit can be either 0 or 1, ...
-2
votes
0answers
91 views
What happens when you perform “++” operation on an integer with it's max possible value? [closed]
So, it's a classic but I can't find an answer anywhere.
Suppose I've an integer 'x' and int takes 32 bits on this platform. I'm performing the "++" operation in a loop.
Something like this:
int ...
2
votes
7answers
369 views
Compute the number of ways how you can express a number as a sum
For a given natural number n, compute the number of ways how one can express n as a sum of positive natural numbers. For example, for n = 1 there is just one way. For n = 4 we have 5 possible ways:
1 ...
8
votes
14answers
648 views
Print an arch of ascending / descending numbers
I figured an "arch" was the best way to describe this pattern of numbers:
1234567887654321
1234567 7654321
123456 654321
12345 54321
1234 4321
123 321
12 21
1 ...
-4
votes
6answers
131 views
Return the number of digits in any given number
Objective
Given any terminating, rational number, return the number of digits the number contains. Do not count zeros if they're the last digits.
Examples
0 returns 1
-1 returns 1
6.23 returns 3
...
-2
votes
0answers
103 views
Generate and print unique numbers that lie within a given range [closed]
Generate and print unique numbers that are withing a given range.
Unique numbers are numbers in which no two digits are the same.
15
votes
12answers
914 views
Convert number to a base where its representation has most “4”s
Inspired by this. There is a number, given as either integer, string or array of digits (your choice). Find the base in which the representation of the number will have most "4"s and return that base.
...
6
votes
11answers
485 views
Test if given number if a Keith number
Since Fibonacci numbers and sequences seems like a popular subject for code golf I thought that it might be a fun challenge to code golf with Keith numbers.
So I propose a challenge that is to create ...
3
votes
4answers
289 views
Convert the Binary Champernowne Constant to Decimal
The Champernowne constant is a transcendental decimal number whose digits are the concatination of all positive integers.
C10 = 0.12345678910111213141516...10
The binary version of this is
C2 = ...
7
votes
6answers
459 views
Find the Pisano Period of a number
Input: An integer 0 < n < 2^30, taken from stdin.
Output: The Pisano period of n (the length of the cycle of the Fibonacci sequence mod n)
Input is smaller than 2^30 so that intermediate ...
11
votes
5answers
458 views
Score a game of Bowling
Your task is to sum up and output one player's score in a game of 10-pin bowling after up to 21 rolls.
The rolls are represented as space separated integers on a single line of input.
Each integer ...
5
votes
6answers
252 views
Return each number from a group of numbers
The challenge
The program must return all numbers included into a group (comma and hyphen separated sequence) of numbers.
Rules
s is the sequence string;
all numbers included in s are positive;
...
6
votes
6answers
441 views
Score a game of Yahtzee
For each of the 13 rows of a Yahtzee scoresheet you are given (from stdin)
a space separated list of 5 numbers (dice).
Your task is to calculate the score for each line and output the Grand Total of ...
33
votes
30answers
3k views
Can you Golf Golf?
You are required to generate a random 18-hole golf course.
Example output:
[3 4 3 5 5 4 4 4 5 3 3 4 4 3 4 5 5 4]
Rules:
Your program must output a list of hole lengths for exactly 18 holes
Each ...
3
votes
6answers
414 views
Generate a Kolakoski sequence
Definition1
A Kolakoski sequence is a self-describing infinite sequence {kn} of alternating blocks of 1's and 2's, given by the following rules:
k0 = 1
kn = the length of the (n+1)'th ...
1
vote
9answers
413 views
Generate a valid sequence of numbers with specific rules
The challenge
The program must return a valid sequence of numbers into some rules
Rules
x is the size of the sequence;
x cannot be less than 4 or greater than 9 (Thanks David Carraher);
Digits of ...
1
vote
3answers
292 views
Traverse all numbers with only one bit flip per step
You can count 0, 1, 2, 3, 4.
But to get from 3 to 4 you have to change 3 bits at once.
Given a number of bits, how can you go through all numbers once,
but change at each step only 1! bit.
Here is an ...
-2
votes
14answers
386 views
Given a number, program must return the alphabet letter correspondent
The program
Given a number, program must return the alphabet letter correspondent.
Rules
The challenge here is to make it as short as possible, everyone knows it is a very easy program to do.
The ...
8
votes
9answers
520 views
Working Week Completion
I work a standard nine to five. Monday through Friday. I take a half hour for lunch from 12:30 to 13:00.
Write me a program which, when run, calculates the percentage of the working week that I have ...
4
votes
7answers
595 views
Find the nth Fibonnaci Prime, in the shortest code
The challenge is rather simple:
Take a positive whole number n as input.
Output the nth Fibonacci prime number.
Input can be as an parameter to a function (and the output will be the return ...
2
votes
9answers
959 views
Triangle Puzzle
Triangle Puzzle
Consider the triangle below.
This triangle would be represented by the following input file.
5
9 6
4 6 8
0 7 1 5
By starting at the top and ...
6
votes
7answers
554 views
Determining the continued fractions of square roots
The continued fraction of a number n is a fraction of the following form:
which converges to n.
The sequence a in a continued fraction is typically written as: [a0; a1, a2, a3, ... an].
We will ...
1
vote
5answers
209 views
All non-empty finite sets of positive integers
The challenge is to create an iterator(/generator) which iterates (in any order so as to reach all of them... ie no set should occur at infinity) over all possible non-empty finite sets(/tuples/lists) ...
4
votes
3answers
464 views
Implementing Binary Arithmetic
Given two binary numbers (strings containing 0s and 1s), perform operations on them, with one problem: You must keep them in binary. That means no going binary(integer(n1)+integer(n2)) or anything ...
3
votes
11answers
612 views
Range of numbers
Came over a similar problem in a project I'm working on and found it quite hard to solve it without excesive use of if. I'm eager to see if anyone can come up with more elegant solutions to this, with ...
3
votes
12answers
620 views
add commas to Numbers without String manipulation
This challenge consist in adding commas to numbers every 3 spaces like:
123456789 => 123,456,789
Specifications:
The possible inputs will be 1,000 <= input <= 100,000,000
You can ONLY ...
5
votes
12answers
2k views
Random sampling without replacement
Create a function that will output a set of distinct random numbers drawn from a range. The order of the elements in the set is unimportant (they can even be sorted), but it must be possible for the ...
6
votes
13answers
899 views
Outputting ordinal numbers (1st, 2nd, 3rd)
I would like to generate (as a return result of a function, or simply as the output of a program) the ordinal suffix of a positive integer concatenated to the number.
Samples:
1st
2nd
3rd
4th ...
1
vote
8answers
319 views
The group of sequential positive numbers with the highest sum?
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 ...
8
votes
32answers
2k views
Print the amount of ones in a binary number without using bitwise operators
Description
Given a number, print the amount of 1s it has in binary representation.
Input
A number >= 0 in base 10 that won't exceed the highest number your language is able to handle.
Output
...
5
votes
15answers
874 views
Hexadecimal To Decimal
Read input of up to 8 characters presented as hexadecimal number and print this number as decimal number. In case that input can not be presented as hexadecimal input it has to print 0
Rules:
It is ...
1
vote
0answers
159 views
Minimize the number of coins for a purchase [closed]
We have a set of 5 coin denominations: penny, nickel, dime, quarter, and half-dollar. The number of coins for a purchase is the number of coins given from the buyer to the seller, plus the number ...
-1
votes
3answers
295 views
Programming puzzle to print all numbers from 1 to n of a random system
I have a number system with the symbols {a,b,c,d,...n} I want to print the sequence
a
b
c
.
.
.
n
aa
ab
ac
..
nn
aaa
aab
aac
...
nnn
...
and so on.
A pseudocode/algorithm is what I am looking ...
3
votes
26answers
1k views
Enumerate all palindromic numbers (in decimal) between 0 and n
Given a non-negative integer n, enumerate all palindromic numbers (in decimal) between 0 and n (inclusive range). A palindromic number remains the same when its digits are reversed.
The first ...
3
votes
11answers
506 views
Machine Epsilon
Machine epsilon is an important floating point number to know when doing numerical calculations. One way to understand it is when this relation
1 + machine_epsilon > 1
does not hold. One ...
16
votes
41answers
4k views
Shortest way to reverse a number
Write a function (or equivalent subprogram) to accept a single integer valued argument and return a (similarly typed) value found by reversing the order of the base-10 digits of the argument.
For ...
5
votes
7answers
433 views
Formatting numbers
Today computers use millions of bytes of memory, and decimal or hexadecimal notations get less and less informative.
Most human-readable formatting just display the number with the highest unit ...
5
votes
2answers
298 views
The Prime Grid Game
I had fun solving this, so i offer this golf challenge.
The objective of this golf is to find the largest prime number that can be constructed using the given instructions.
You should accept 3x3 ...
2
votes
4answers
449 views
Amicable number calculator
Write a program that calculates amicable numbers, starting from [0,0], intil the maximum value for an integer is reached in the language you chose to write it in.
Amicable numbers are two different ...
7
votes
6answers
993 views
Arbitrary Base Conversion
Create a routine that takes an array of blocks in one numeric base system, and convert them to an array of blocks in another numeric base system. Both the from and to systems are arbitrary and should ...
6
votes
1answer
238 views
Floating point addition, without floats!
Your task is to write a program, in any language, that adds two floating point numbers together WITHOUT using any fractional or floating point maths. Integer maths is allowed.
Format
The format for ...
4
votes
5answers
801 views
Calculate the last digits of Graham's Number
Graham's number ends in a 7. It is a massive number, in theory requiring more information to store than the size of the universe itself. However it is possible to calculate the last few digits of ...
6
votes
10answers
430 views
Output nearby primes
Write a program which takes an input (which may or may not be prime), and lists the immediate prime following and preceding it.
Example input:
1259
Example output:
1249 1277
Shortest program ...
4
votes
33answers
2k views
Print largest integer you can with the fewest characters [closed]
Find a way to output a large integer with few characters. Solutions will be scored based on the magnitude of the number and shortness of code.
EDIT: Let's impose a time limit of a minute on sensible ...