Today's my birthday (really!) and sadly I've had to organise my own party. Well, now you know, couldn't you at least make the cake? Given an integer as input, write a full program to output a birthday cake with candles on. A piece of cake with one candle on is: And a piece of cake with three candles on is: I'm sure you can work it out from that However, for input , you must output the following: For input less than , you should output a candleless cake: Nothing is allowed to be output to STDERR.
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Articles by Beta Decay
Horizontal histogram of word length
Python 3, 43 bytes: for w in input().split():print('*'*len(w)) Sample run: > This is an example histogram of word length **** ** ** ******* ********* ** **** ****** (The string below is entered as a literal, rather than as text) > 'example\twith\nweird\rwhite space' ******* **** ***** ********** Bonus: vertical histogram l=[len(x)for x in input().split()] for i in range(len(l)-1,-1,-1):print(''.join(['*'if j>=i else' 'for j in l])) Demo: > This is an example histogram of word length ** ** *...
Programming with Bits and Bytes
In this challenge you are going to write an interpreter for a simple language I've made up. The language is based on a single accumulator A, which is exactly one byte in length. At the start of a program, A = 0. These are the languages instructions: This instruction simply inverts every bit of the accumulator. Every zero becomes a one and every one becomes a zero. Simple! This instruction shifts every bit in A one place to the right. The leftmost bit becomes a zero and the rightmost bit is discarded.
Horizontal graph of word length
You can try it online (all you need to do is give input through the field near the bottom and then hit the button). Suggestions for further golfing are always welcome, especially ideas to remove those wasteful spaces in front of the second and third lines.
Find the occurrences of a character in an input string
Challenge Write a program that, given a string x which is 10 characters long and a character y, outputs the number of times character y occurs in string x. The shortest program in bytes to do so wins. Example Input: tttggloyoi, t Output: 3 Input: onomatopoe, o Output: 4
Comparing two numbers
var QUESTION_ID=55693;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),e.has_more?getAnswers():process()}})}function shouldHaveHeading(e){var...
Programming Puzzles & Code Golf Stack Exchange
So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most interesting code golf in the common languages, finding the shortest solution in certain esolangs can be a serious challenge. For instance, to my knowledge it is not known whether the shortest possible Brainfuck solution has been found yet.
Golfing strings in Fourier
Given a string as input, output the shortest possible Fourier program to output that string. In Fourier there is no easy way to output a string: you have to go through each character code and output that as a character. The language is based upon an accumulator, a global variable which is initialised to 0 at the start of the program. This is used by almost every operator in the language. Only some do not change the value of the accumulator.
Stop, stand there where you are!
Write a function which takes one parameter: an integer . Your function has to stop your program for seconds before continuing, similar to in Python and in BBC BASIC. You must not use any built in waiting functions and your program must resume after seconds. For testing your function, there is tolerance of 0.1 seconds more or less than the given on your own machine: variances between computers are fine.
Stop! Stand right where you are!
Write a function which takes one parameter: an integer . Your function has to stop your program for seconds before continuing, similar to in Python and in BBC BASIC. You must not use any built in waiting functions and your program must resume after seconds. For testing your function, there is tolerance of 0.1 seconds more or less than the given on your own machine: variances between computers are fine.
Shortening a long number
Perfect timing for this question. @isaacg just added a new feature today, that allows to shorten such numbers immensely. The basic technique is to convert the number to base 256 and convert it to chars. You can do this using the code . You can then use the resulting string in combination with , which does exactly the opposite (convert chars to int and interpret the result as base-256 number). So you get 13 chars: . Some of the chars are be unprintable. But notice that I said 13 CHARS, not bytes.
Two Makes All The Difference - Cops
Write a valid program which, when just two characters in the program are changed, removed or added, completely changes the output. The changed output must have a Levenshtein Distance of 15 or more from your original output. The output must be non empty and finite. Your program therefore must terminate within 1 minute. Your output must be deterministic, outputting the same thing each time you run the program. It also must not be platform dependent.
Two Makes All The Difference: Robbers
Write a valid program which, when just two characters in the program are changed, removed or added, completely changes the output. The changed output must have a Levenshtein Distance of 15 or more from your original output. The output must be non empty and finite. Your program therefore must terminate within 1 minute. Your output must be deterministic, outputting the same thing each time you run the program. It also must not be platform dependent.
Two Makes All The Difference: Cops
For the main robbers' challenge, click here Challenge Given the original program, its output and the output of the changed program, you have to find out which characters need to be changed, removed or added to get the expected output. When you crack someone's code, leave a comment with a link to your crack on their answer.
Two Makes All The Difference - Robbers
For the main cops' challenge, click here Challenge Given the original program, its output and the output of the changed program, you have to find out which characters need to be changed, removed or added to get the expected output. When you crack someone's code, leave a comment with a link to your crack on their answer.
Take It or Leave It II: A Game Show for Computers
This is the second in a series of puzzles that I will be posting every Monday at Midnight PST. The first puzzle is located Here. A reclusive billionaire has created a game show to attract the world's best and brightest programmers. On Mondays at the stroke of midnight, he chooses one person from a pool of applicants to be the contestant of the week, and provides them with a game. You are this week's lucky contestant! The host provides you with API access to a stack of 10,000 digital envelopes.
Golfing with Python Import
This can be useful if you want to use a module just once in an anonymous lambda function, as it allows you to avoid writing a separate statement: lambda x:__import__('SomeModule').foo(x,123) is one byte shorter than from SomeModule import*;f=lambda x:foo(x,123) If the code is a named function or program, then __import__ is unlikely to help except in the most extreme or contrived circumstances.
Nuggets of Code - Programming Puzzles & Code Golf Stack Exchange
It's a hypothetical situation where it is Friday evening, and you've invited over the usual golfing buddies to participate in your favourite hobby: code golfing. However, as this is such a brain-draining task, you need to pick up some brain food for the group so you can golf as much as possible off your code. Now, everyone's favourite snack is chicken nuggets, but there's a problem: There is no single pack of them which covers everyone's needs.
Is it possible to have infinite combinations in reality?
Say you added differing ranging amounts of ingredients x, y and z food items. For example, apple, strawberry, and kiwifruit. Then, to me at least, there is no limit to the different potential flavors, but I doubt if you tell the difference in taste caused by minute differences in concentration of the ingredients. As far as finite amount of matter goes, who knows how much matter the universe contains, we can't test it, so we don't know.
Format the given number of bytes to a human readable format
On Stack Overflow a popular question is: How to convert byte size into human readable format in java? The most up voted answer has a quite nice method for doing this, but this is codegolf and we can do better, can't we?
5318008 - Fun with Calculators
In schools across the world, children type a number into their LCD calculator, turn it upside down and erupt into laughter after creating the word 'Boobies'. Of course, this is the most popular word, but there are many other words which can be produced. All words must be less than 10 letters long, however (the dictionary does contain words long than this however, so you must perform a filter in your program).
Interstellar: Shouldn't the food have run out?
23 years later (after Millers planet, Murph is now grown), Tom is already regulary losing 1/3 of his corn harvest yearly (it's mentioned in the film, dialogue between Tom and Murph at the beginning of her visit at his farm). And as predicted by Prof Brand (Amelias father), Murphs generation will be indeed the last one surviving on Earth, Toms second child is also ill already, his son will not survive on the surface. I don't see a slip-up here.
Show More
loading
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with Beta
Contact Beta, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack