Tagged Questions
Binary is the base 2 number system. Use this tag for challenges involving base 2.
9
votes
6answers
626 views
Super Folding Numbers
We have already defined a folding number here.
But now we are going to define a Super Folding Number. A Super Folding number is a number that if folded enough times it will eventually reach one less ...
34
votes
22answers
2k views
Folding Numbers
Given a number determine if it is a folding number.
A folding number is a number such that if you take it binary representation and "fold" it in half, That is take the result of XNOR multiplication ...
32
votes
11answers
2k views
Incrementing Gray Codes
Introduction
A Gray Code is an alternative to binary representation in which a number is incremented by toggling only one bit, rather than a variable amount of bits. Here are some gray codes along ...
44
votes
19answers
10k views
+50
i love yOu i lOve you i love yOu!
It's exactly 100 93 weekdays until Valentine's day today (as I'm sure you all know). Let's celebrate with a binary heart!
XKCD #99, with the title "Binary Heart" shows a simple image of ones and ...
8
votes
20answers
651 views
String and ASCII [duplicate]
The Challenge
Given a non-empty string containing only lowercase or uppercase letters and no spaces:
Sum up the ASCII values for each character instance in the input string.
The sum will be ...
21
votes
4answers
523 views
Telegraphy Golf: Decode Baudot Code
Background
In 1870 Émile Baudot invented Baudot Code, a fixed-length character
encoding for telegraphy. He designed the code to be entered from a
manual keyboard with just five keys; two operated ...
10
votes
18answers
1k views
All Binary Combinations to Decimal
Disclaimer
This question is not a duplicate of this question. I'm not counting specific digits, as we already have those set in the initial parameters. This question is focusing on the decimal ...
11
votes
10answers
1k views
Given an integer, compute its Levenshtein code
Disclaimer: Levenshtein coding is completely unrelated to the Levenshtein edit distance metric.
<Insert long story about why Levenshtein codes need to be calculated here.>
The code
Levenshtein ...
38
votes
7answers
2k views
Only Even Bytes
The scenario
Lately you have been noticing some strange behavior with your favorite text editor. At first it seemed that it was ignoring random characters in your code when writing to disk. After a ...
17
votes
2answers
213 views
Given a truth table, output a Stackylogic program that satisfies it
Stackylogic is a programming language I made up in a previous challenge: Run Stackylogic. Read that post for full details and examples, but here is how it works paraphrased:
Stackylogic takes 0's ...
39
votes
11answers
1k views
Run Stackylogic
Stackylogic is a logic-based programming language I made up that take in 0's and 1's for input and outputs a single 0 or 1 upon completion.
A Stackylogic program consists of lines that can only ...
17
votes
14answers
1k views
Bit-Reversal Permutations
Your goal is to create a function or a program to reverse the bits in a range of integers given an integer n. In other words, you want to find the bit-reversal permutation of a range of 2n items, zero-...
23
votes
19answers
1k views
Swap bits with their neighbours
Task description
Given an integer, swap its (2k–1)-th and 2k-th least significant bits for all integers k > 0. This is sequence A057300 in the OEIS.
(The number is assumed to have “...
9
votes
9answers
427 views
What's the Binary Time?
What's the Binary Time?
Everybody knows what the normal time is. It's up there in the top-right (or wherever you put it) of your screen. But a question people rarely seem to ask themselves is this: ...
26
votes
35answers
2k views
Mean bits: an average challenge
Given an integer N >= 1, output the mean number of bits in an integer from 0 to N - 1
Specification
The output can be calculated as the sum of the number of bits in the binary representation of ...
1
vote
0answers
45 views
Find the shortest variable length encoding [duplicate]
There is an algorithm, which, given the probabilities of certain outcomes, returns the optimal variable length encoding.
Say we have a five character alphabet, with these letter probabilites:
A | 0....
27
votes
24answers
1k views
Decompose binary into alternating subsequences
This was inspired by Problem 13 - Non-Repeating Binary of HP CodeWars' recent competition.
Let's take a random decimal number, say
727429805944311
and look at its binary representation:
...
16
votes
11answers
745 views
Sum of Binary Substrings
This challenge is simple, given a decimal number, convert to binary, and calculate the sum of the sub-strings of the binary number, whose length is shorter than the original number. Here is an example:...
19
votes
12answers
4k views
When will I have a binary car?
I noticed that my car's odometer was at 101101 when I got to work today. Which is a cool number because it's binary (and a palindrome, but that's not important). Now, I want to know when the next time ...
7
votes
1answer
253 views
Model a probability table using 15-bit fixed probabilities
A histogram is an array of integers that counts the number of times a symbol occurs. For example, for the string "aaabbbabbdebabbbebebdbaaabbabaaaaeebeaabaaba" a histogram is a: 18, b: 18, c: 0, d: 2, ...
8
votes
4answers
319 views
Shortest binary number in range
Given two arbitrarily precise decimal numbers 0 ≤ x < y ≤ 1, compute the shortest (in digits) binary number b such that x ≤ b < y.
Output the binary digits of b after the binary ...
12
votes
12answers
1k views
Preparing a multiple choice test
Introduction
Note: this is not some kind of method to encourage cheating. As Cᴏɴᴏʀ O'Bʀɪᴇɴ already said, studying is the best solution for passing a test :3.
Consider the following answers to the ...
25
votes
6answers
3k views
1+1 = 10, 1+2 = 3
Write a function or program than can do simple arithmetic (addition, subtraction, multiplication and division) in both base 10 and base 2.
The function will take a mathematical expression as input, ...
9
votes
3answers
199 views
I-Ching pair binary computer
Introduction
I Ching is an ancient divination text and the oldest of the Chinese classics. It uses a type of divination called cleromancy, which produces apparently random numbers.
The basic unit of ...
3
votes
5answers
148 views
Binary Run-Length Encoding [duplicate]
Overview
Run-length encoding — sequences in which the same data value occurs in many consecutive data elements are stored as a single data value and count
When using run-length encoding:
Input: ...
22
votes
21answers
1k views
Compute the Binary Sierpinski Triangle Sequence
The Binary Sierpinski Triangle sequence is the sequence of numbers whose binary representations give the rows of the Binary Sierpinski Triangle, which is given by starting with a 1 in an infinite row ...
16
votes
29answers
2k views
Write out the Thue-Morse sequence
There's quite a few challenges on this site that ask you to print out a sequence, and this is no exception.
(The following explanation of the sequence for this challenge assumes the symbols in the ...
26
votes
26answers
2k views
Parenthifiable Binary Numbers
If you express some positive integer in binary with no leading zeros and replace every 1 with a ( and every 0 with a ), then will all the parentheses match?
In most cases they won't. For example, 9 ...
18
votes
16answers
2k views
Simplify binary
Challenge
Given a binary number as input through any means, "simplify" the number using a full program or a function.
Input
[binary]
binary is a number in binary that is over 0.
Output
Take ...
22
votes
13answers
808 views
Counting +1 primes
Define that the natural number p is a +1 prime of the natural number n if p is a prime number and the standard binary representation (i.e., without leading zeroes) of p can be obtained by adding (i.e.,...
19
votes
20answers
1k views
Reverse and Invert a String
Reverse and Invert a String
Challenge
In this challenge. You'll be writing a program which will output or return the input, reversed and inverted.
First, each character should be converted to its ...
6
votes
3answers
304 views
Symmetric boolean functions as Zhegalkin polynomials
Let 𝔹 = ℤ2 = {0, 1} be the set of booleans. A symmetric boolean function in n arguments is a function fS : 𝔹n ↦ 𝔹 that checks if the number of its true arguments is in S, i. e. a ...
32
votes
23answers
3k views
Biplex: an important useless operator
Input
A list of between 1 and 255 positive integers (inclusive), each in the range 1 to 232 - 1 (inclusive).
Your input format does not need to be identical to the test cases.
Input without leading ...
31
votes
29answers
2k views
Numbers with multiple runs of ones
Task
Find the set of numbers such that the binary representation contains two or more runs of 1 separated by at least one 0.
For example, the for the numbers that are 4 bits long:
0 0000 (...
19
votes
2answers
832 views
Koopa Shell Sequence
In various Super Mario games green and red Koopa Troopa shells can slide frictionlessly on flat surfaces and destroy brick blocks that are in their way. When a shell hits a brick block the block ...
8
votes
3answers
178 views
Counting cycles in a folding and squashing process
In chaos theory, the horseshoe map is an example of how chaos arises in a simple process of folding and squashing. It goes like this: take an imaginary piece of dough, fold it, and finally squash it ...
39
votes
14answers
2k views
Generate the Temple Skyline Sequence
Consider the following process:
Take some non-negative integer N.
e.g. N = 571
Express it in binary with no leading zeroes. (Zero itself is the only exception, becoming 0.)
e.g. 571 = 1000111011 ...
27
votes
23answers
2k views
16-bit binary grid
Given any unsigned 16 bit integer, convert its decimal form (i.e., base-10) number into a 4x4 ASCII grid of its bits, with the most-significant bit (MSB) at the top left, least-significant bit (LSB) ...
7
votes
5answers
378 views
Print a table of numbers in decimal and 2**i bases
Computers live by binary. All programmers know binary.
But the 2**x bases are often neglected as non-practical, while they have beautiful relations to binary.
To show you one example of such a ...
0
votes
2answers
109 views
Generate ordered binary combinations without repetitions [closed]
Challenge
Write the shortest program that receives two signed integers n and i and for each i between 1 and 2^n - 1 returns the next ordered permutation based on the binary representation of the ...
16
votes
3answers
345 views
Toggle, Print, Repeat
This challenge is loosely inspired by the unimplemented esolang Pada.
Consider an array of 8 bits, all initialised to zero. We'll introduce a very minimalistic instruction set to print arbitrary ...
16
votes
7answers
1k views
Binary Images of Triangle Counts
My challenges tend to be a little bit hard and unattractive. So here something easy and fun.
Alcuin's sequence
Alcuin's sequence A(n) is defined by counting triangles. A(n) is the number of ...
7
votes
3answers
333 views
Nameless to Brainf**k converter
This is inspired by the Brainf*** to tinyBF converter challenge.
Brainf**k (which will be henceforth referred to as BF) is a well-known estoric programming language, so I won't go over it too much ...
23
votes
19answers
2k views
Find the next 1-sparse binary number
A positive integer N is K-sparse if there are at least K 0s between any two consecutive 1s in its binary representation.
So, the number 1010101 is 1-sparse whereas 101101 is not.
Your task is to ...
15
votes
45answers
5k views
Count the number of ones in an unsigned 16-bit integer
Write some statement(s) which will count the number of ones in an unsigned sixteen-bit integer.
For example, if the input is 1337, then the result is 6 because 1337 as a sixteen bit binary number is ...
10
votes
11answers
687 views
Binary encryption
This is based on xkcd #153.
Make a program or named function which takes 2 parameters, each of which is a string or a list or array of bytes or characters. The second parameter will only contain ...
11
votes
22answers
1k views
String to Binary
This is a code golf challenge. Just like the title says, write a program to covert a string of ascii characters into binary.
For example:
"Hello World!"
should turn into
1001000 1100101 1101100 ...
18
votes
4answers
2k views
Convert numbers to binary… but you're allowed to use twos as well
Based on the "binary, but with twos" notation mentioned in this numberphile video, write a function that takes a single number as input and outputs all variations of that number in a "binary" system ...
6
votes
7answers
738 views
Find the simplest value between two values
Goal
Your goal is to find the simplest value in an open interval. In other words, given two values a,b with a<b, output the simplest x with a<x<b. This is a code golf, so fewest bytes wins.
...
17
votes
30answers
3k views
Convert a string of binary characters to the ASCII equivalents
Take a string of binary characters separated by a space, and convert it to an ASCII string.
For example...
1001000 1100101 1101100 1101100 1101111 100000 1010111 1101111 1110010 1101100 1100100
...