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

learn more… | top users | synonyms

-1
votes
2answers
227 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. ...
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
307 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 ...
21
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
244 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 ...
8
votes
1answer
187 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
296 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
478 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
197 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
237 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 ...
4
votes
5answers
402 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: ...
9
votes
1answer
1k 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
281 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 ...
4
votes
1answer
622 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
322 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 ...
8
votes
11answers
4k 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 ...