Code Golf scored by the number of tokens of your program, excluding any syntactical separators (`()[]{}. ;` is a general rule.)

learn more… | top users | synonyms

2
votes
1answer
142 views

Copy Memory Only Using Store And Subtraction

A peer of mine approached me with this challenge and I wasn't able to come up with an elegant solution. After discussing my approach, we began to wonder what the people at Code Golf would come up ...
-4
votes
7answers
168 views

Determine length of bitstring

Optimize the following function for number of tokens: int length(int x) { switch (x) { case 1: return 1; case 3: return 2; case 7: return 3; case 15: return 4; case 31: ...
8
votes
4answers
291 views

Collatz sequence on a two counter machine

The Collatz sequence starting from a positive integer n is defined in this way: if n is even then divide it by 2 (n' = n / 2) if n is odd then multiply it by 3 and add 1 (n' = 3n + 1) Repeat the ...
-1
votes
1answer
248 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| ...
4
votes
2answers
399 views

draw ASCII function plots

Consider a function plot like this: ########### ################# ...
5
votes
2answers
237 views

Create a universal two-dimensional cellular automaton cell using two-way universal logic processors

In Conway's Game of Life, a cell is in a state of either on or off, depending on the on-and-off state of the eight cells surrounding it. We can simulate this using a logic gate network with some sort ...
-1
votes
3answers
213 views

Meta-atomic code golf

In this meta-challenge, you will score your own atomic-code-golf submissions. More precisely, you will need to write a program P in language L such that the atomic-score of P is produced by P. Score ...
9
votes
3answers
757 views

“Atomic” code golf - determine the number of neutrons in an isotope

Your task is to take an string containing an isotope of an element as input, encoded like the following example with the atomic number followed by a space and the IUPAC chemical symbol for the ...
4
votes
0answers
170 views

How to golf string output in Chef

I'm attempting to solve a programming golf style programming puzzle. I need to write an 18 character phrase in Chef in less than 32 "lines" of code. In this case, a line counts as an ingredient or an ...
7
votes
3answers
1k views

Drive a hexadecimal 7-segment display using NAND logic gates

The ubiquitous 7-segment numerical display can unambiguously display all 16 hexadecimal digits as show in this wikipedia .gif Entries for this challenge will create a circuit diagram using NAND logic ...
22
votes
4answers
1k views

Multiply with restricted operations

Goal Your goal is to multiply two numbers using only a very limited set of arithmetic operations and variable assignment. Addition x,y -> x+y Reciprocal x -> 1/x (not division x,y -> ...
10
votes
6answers
1k views

Implement an 8 bit adder

The Challenge Implement a function which accepts two integers whose values range from 0 - 255 and returns the sum of those integers mod 256. You may only use bitwise negation (~), bitwise or (|), bit ...
-5
votes
3answers
341 views

Convert to uppercase and lowercase without branching and comparisons

Write two functions/programs which take an ASCII code of character (8-bit unsigned integer) and one of them converts char to uppercase and other to lowercase. That is, they must be equivalent to ...
4
votes
6answers
2k views

Solve quadratic equation using only 3 variables and arithmetic

Write function which solves equation of degree less than or equal to 2 (ax^2 + bx + c = 0). Input Function should get 3 parameters - floating point numbers which are coefficients of this equation. ...
-1
votes
2answers
254 views

Shortest test for primality for byte [duplicate]

Write a function which gets as input a number (0 <= n <= 255) stored in 32-bit variable and returns non-zero integer if n is prime number and 0 otherwise. Considern = 0 and n = 1 as non-primes. ...
19
votes
5answers
4k views

Shortest expression for {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}

Given list of integers {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}. For those who interested these numbers are used in weekday calculation. Weekday = (m[n] + d + y + y>>2 + y/400 - y/100) % 7;, where ...
15
votes
16answers
3k views

Find the maximum of 3 numbers without branching

This time around your goal is to find the maximum of 3 integers (from -(2^31) to 2^31 - 1 in binary 2's complement) without using branching or loops. You are only allowed to use ...
17
votes
15answers
4k views

Determine if an integer is divisible by 3

Your goal is to determine if a number is divisible by 3 without using conditionals. The input will be an unsigned 8 bit number from 0 to 255. Creativity encouraged! You are ONLY allowed to use ...
3
votes
5answers
375 views

Increment Bitwise

Make a function that increments a number using only bitwise, loops, and conditions. Rules: All entries must be as per the language spec defined below. Scoring is not of code length, but of the ...
22
votes
13answers
3k views

Calculate `n % 12`

Calculate n modulo 12 for an unsigned 32 bit integer. The Rules: Must work for all n between 0 and 23. Other numbers optional. Must only use any of the operators +-*, ~&^| or <<, ...
8
votes
1answer
328 views

Build an EBCDIC converter using NAND logic gates

In this question, a mapping is defined between EBCDIC and a superset of ISO-8859-1. Your task is to build a network of two-input NAND gates that will take eight inputs A1, A2, A4, ..., A128 ...
10
votes
1answer
346 views

Build a minifloat adding machine using NAND logic gates

A minifloat is a binary representation of a floating-point number that has very few bits. The minifloat in this question will be defined as an 6-bit number m, which has the following representation: ...
10
votes
3answers
660 views

Build a bit-counting comparator using NAND logic gates

A bit-counting comparator (BCC) is a logic circuit that takes some number of counting inputs A1, A2, A3, ..., An as well as inputs B1, B2, B4, B8, ... representing a number. It then returns 1 if the ...
6
votes
3answers
564 views

Build a 2-way universal logic processor using NAND logic gates

A 2-way universal logic processor (2ULP) is a network of logic gates that takes two input wires A and B, as well as four other inputs L_, L_a, L_b, and L_ab, and produces a single output L(a, b) using ...
6
votes
1answer
242 views

Turtle Graphics Version 2

Most of you have probably heard of the famous Turtle Graphics program, initially made popular by Logo. This challenge is to implement a Turtle Graphics program in your language of choice. Rules: ...
-1
votes
4answers
242 views

tree from string

A string like this one: "a, 4.25, ((true, 5), 3, (false, false, false)), abc" Describes a tree with 13 nodes, 9 of which are leaf nodes. In C# the leaf nodes in this example would be of types ...
8
votes
10answers
818 views

Write a hash function for Morse Code

Your goal is to write a hash function, that accepts morse code character and returns a hash code that you get to define. You can be sure, passed string will be: One of the Latin characters (A-Z) ...
4
votes
5answers
542 views

Turtle Graphics Program

Most of you have probably heard of the famous Turtle Graphics program, initially made popular by Logo. This challenge is to implement a Turtle Graphics program in your language of choice. Rules: ...
10
votes
1answer
2k views

Build a multiplying machine using NAND logic gates

Based on my previous question of the same type, Build an adding machine using NAND logic gates, this time you're being asked to multiply instead of add. Build a diagram of (two-wire) NAND logic gates ...
1
vote
2answers
333 views

Build a NAND gate using multiple NAND gates

A question that had popped up in my head once - how many NAND gates would it take to build a larger, "meta-NAND" gate? Your task is to build a black-box circuit that takes two input wires A and B and ...
5
votes
1answer
1k views

Build an adding machine using NAND logic gates

This is "programming" at its most fundamental. Build a diagram of (two-wire) NAND logic gates that will take the input wires A1, A2, A4, A8, B1, B2, B4, B8, representing two binary numbers A to B ...
6
votes
3answers
383 views

Pretty Printing Parentheses

The worst part about long lines or code or math equations are the parentheses. Nobody wants to read through 2x(3y+4*abs(x^[2*e^x])-5{3(x+y)-5})! So, the goal of this challenge is to make it at least ...
10
votes
12answers
5k views

Print NxN spiral of ascending numbers

The numbers should be printed with leading zeroes in a field with length = (number of digits of N^2). input (N): 4 output: 01 12 11 10 02 13 16 09 03 14 15 08 04 05 06 07 I am interested in ...