
7 votes

Advent of Code 2019
35 votes 
Programming Challenge: Convert between units
Hi everyone! It's been a long time since last programming challenge list, and here's a nice one I've encountered. If you search for something like 7km to AU, you'll get your answer. But how is it...
Hi everyone! It's been a long time since last programming challenge ^{list}, and here's a nice one I've encountered.
If you search for something like 7km to AU, you'll get your answer. But how is it done? I don't think they hardcoded all 23 units of distance and every conversion factor between them.
If you were programming a conversion system  how would you do it?
First of all, you have input in format that you can specify, for example something like this:
meter kilometer 1000 mile kilometer 1.609344 second minute 60 ...
Then you should be able answer queries. For example
7 mile meter
should convert 7 miles to meters, which is11265.41
.Can you design an algorithm that will convert any unit into any other unit?
Edit: Some conversion rates I extracted from wikipedia:
ångström 0.1nm astronomical unit 149597870700m attometre 0.000000000000000001m barleycorn 8.4m bohr 0.00846 cable length (imperial) 185.3184m cable length 185.2m cable length (US) 219.456m chain (Gunters) 20.11684m cubit 0.5m ell 1.143m fathom 1.8288m femtometre 0.00000000000001m fermi 0.00000000000001m finger 0.022225m finger (cloth) 0.1143m foot (Benoit) 0.304799735m foot (Cape) (H) 0.314858m foot (Clarke's) (H) 0.3047972654m foot (Indian) (H) 0.304799514m foot,metric 0.31622776602m foot,metric (long) 0.3m foot,metric (short) 0.30m foot (International) 0.3048m foot (Sear's) (H) 0.30479947m foot (US Survey) 0.304800610 french 0.0003m furlong 201.168m hand 0.1016m inch 0.0254m league 4828m lightday 25902068371200m lighthour 107925284880m lightminute 17987547480 lightsecond 299792458m lightyear 31557600lightsecond line 0.002116m link (Gunter's) 0.2011684m link (Ramsden's; Engineer's) 0.3048m metre 1m m 1metre km 1000m mickey 0.000127 micrometre 0.000001 mil; thou 0.0000254 mil 10km mile (geographical) 6082foot (International) quarter 0.2286m rod 5.0292m rope 6.096m shaku 0.303 0303m span (H) 0.2286m stick (H) 0.0508m toise 1.949 0363m twip 1.76310 yard 0.9144m
17 votes 
Challenge: defuse this fork bomb
On lobste.rs I found link to an article from Vidar Holen, the author of shellcheck. He made a fork bomb that is really interesting. Here's the bomb: DO NOT RUN THIS. eval $(echo...
On lobste.rs I found link to an article from Vidar Holen, the author of shellcheck. He made a fork bomb that is really interesting. Here's the bomb:
DO NOT RUN THIS.
eval $(echo "I<RA('1E<W3t`rYWdl&r()(Y29j&r{,3Rl7Ig}&r{,T31wo});r`26<F]F;=="  uudecode)
This may look pretty obvious, but it's harder than you think. I fell for it. ^{twice.} Can you find out how this bomb works?
Warning: executing the bomb will slow down your computer and will force you to restart.
You can limit impact of the fork bomb by settingFUNCNEST
.export FUNCNEST=3
Have fun!
12 votes 
Programming Challenge: Text compression
In an effort to make these weekly, I present a new programming challenge. The challenge this week is to compress some text using a prefix code. Prefix codes associate each letter with a given bit...
In an effort to make these weekly, I present a new programming challenge.
The challenge this week is to compress some text using a prefix code. Prefix codes associate each letter with a given bit string, such that no encoded bitstring is the prefix of any other. These bit strings are then concatenated into one long integer which is separated into bytes for ease of reading. These bytes can be represented as hex values as well. The provided prefix encoding is as follows:
char value char value ' ' 11 'e' 101 't' 1001 'o' 10001 'n' 10000 'a' 011 's' 0101 'i' 01001 'r' 01000 'h' 0011 'd' 00101 'l' 001001 '~' 001000 'u' 00011 'c' 000101 'f' 000100 'm' 000011 'p' 0000101 'g' 0000100 'w' 0000011 'b' 0000010 'y' 0000001 'v' 00000001 'j' 000000001 'k' 0000000001 'x' 00000000001 'q' 000000000001 'z' 000000000000 Challenge
Your program should accept a lowercase string (including the ~ character), and should output the formatted compressed bit string in binary and hex. Your final byte should be 0 padded so that it has 8 bits as required. For your convenience, here is the above table in a text file for easy readin.
Example
Here is an example:
$> tildes ~comp 10010100 10010010 01011010 10111001 00000010 11000100 00110000 10100000 94 92 5A B9 02 C4 30 A0
Bonuses
 Print the data compression ratio for a given compression, assuming the original input was encoded in 8 bit ASCII (one byte per character).
2. Output the ASCII string corresponding to the encoded byte string in addition to the above outputs.  @onyxleopard points out that many bytes won't actually be valid ASCII. Instead, do as they suggested and treat each byte as an ordinal value and print it as if encoded as UTF8.
 An input prefixed by 'D' should be interpreted as an already compressed string using this encoding, and should be decompressed (by inverting the above procedure).
Previous Challenges (I am aware of prior existing ones, but it is hard to collect them as they were irregular. Thus I list last week's challenge as 'Week 1')
Week 113 votes  Print the data compression ratio for a given compression, assuming the original input was encoded in 8 bit ASCII (one byte per character).

Programming Challenge: Dice Roller
Its been a while since we did one of these, which is a shame. Create a program that takes is an input of the type: "d6 + 3" or "2d20  5", and return a valid roll. The result should display both...
Its been a while since we did one of these, which is a shame.
Create a program that takes is an input of the type: "d6 + 3" or "2d20  5", and return a valid roll.
The result should display both the actual rolls as well as the final result. The program should accept any valid roll of the type 'xdx'
Bonuses: Multiplication "d6 * 3"
 Division "d12 / 6"
 Polish notation "4d6 * (5d4  3)"
As a side note, it would be really cool if weekly programming challenges became a thing
33 votes 
Coding Challenge  Design network communication protocol
Previous challenges It's time for another coding challenge! This challenge isn't mine, it's this challenge (year 5, season 3, challenge 3) by ČVUT FIKS. The task is to design a network...
It's time for another coding challenge!
This challenge isn't mine, it's this challenge (year 5, season 3, challenge 3) by ČVUT FIKS.
The task is to design a network communication protocol. You're sending large amount of bits over the network. The problem is that network is not perfect and the message sometimes arrives corrupted. Design a network protocol, that will guarantee that the decoded message will be exactly same as the message that was encoded.
MESSAGE => (encoding) => message corrupted => (decoding) => MESSAGE
Corruption
Transmitting the message might corrupt it and introduce errors. Each error in a message (there might be more than one error in a single message) will flip all following bits of the message.
Example:
011101 => 011010
(

is place where an error occured).There might be more than one error in a message, but there are some rules:

Minimum distance between two errors in a single message is
k

Number of bits between two errors is always odd number
According to these rules, describe a communication protocol, that will encode a message, and later decode message with errors.
Bonus

Guarantee your protocol will work always  even when errors are as common as possible

Try to make the protocol as short as possible.
8 votes 

Programming Challenge: Build an Interpreter
Hello everyone! It has been a while since last programming challenge, it's time for another one! This week's goal would be to build your own interpreter. Interpreter is program that receives input...
Hello everyone! It has been a while since last programming challenge, it's time for another one!
This week's goal would be to build your own interpreter.
Interpreter is program that receives input and executes it. For example Python is interpreted language, meaning you are actually writing instructions for the interpreter, which does the magic.
Probably the easiest interpereter to write is Brainfuck interpreter. If someone here doesn't know, Brainfuck is programming language, which contains following instructions:
,.<>[]+
. Other characters are ignored. It has memory in form of array of integers. At the start, pointer that points to one specific memory cell points to cell 0. We can use<
to move pointer to left (decrement) and>
to move pointer to right (increment)..
can be used to print value of cell the pointer is currently pointing to (ascii).,
can be used to read one character from stdin and write it to memory.[
is beggining of loop and]
is end of loop. Loops can be nested. Loop is terminated when we reach]
character and current value in memory is equal to 0.
can be used to decrement value in memory by 1 and+
can be used to increment value in memory by 1. Here's Hello World:++++++++++[>+++++++>++++++++++>+++>+<<<< ]>++.>+.+++++++..+++.>++.<<++++++++++++ +++.>.+++...>+.>.
People with nothing to do today can attemp to make an interpreter for the Taxi programming language.
You can even make your own language! There are no limits for this challenge.
23 votes 
Programming Challenge  Find path from city A to city B with least traffic controls inbetween.
Previous challenges Hi, it's been very long time from last Programming Challenge, and I'd like to revive the tradition. The point of programming challenge is to create your own solution, and if...
Hi, it's been very long time from last Programming Challenge, and I'd like to revive the tradition.
The point of programming challenge is to create your own solution, and if you're bored, even program it in your favourite programming language. Today's challenge isn't mine. It was created by ČVUT FIKS (year 5, season 2, challenge #4).
You need to transport plans for your quantum computer through Totalitatia. The problem is, that Totalitatia's government would love to have the plans. And they know you're going to transport the computer through the country. You'll receive number
N
, which denotes number of cities on the map. Then, you'll getM
paths, each going from one city to another. Each path hask
traffic controls. They're not that much effective, but the less of them you have to pass, the better. Find path from cityA
to cityB
, so the maximum number of traffic controls between any two cities is minimal. CityA
is always the first one (0
) and cityB
is always the last one (N1
).Input format:
N M A1 B1 K1 A2 B2 K2 ...
On the first two lines, you'll get numbers N (number of cities) and M (number of paths). Than, on next
M
lines, you'll get definition of a path. The definition looks like1 2 6
, where1
is id of first city and2
is id of second city (delimited by a space). You can go from city 1 to city 2, or from city 2 to city 1. The third number (6
) is number of traffic controls.Output format:
Single number, which denotes maximum number of traffic controls encountered on one path.
Hint: This means, that path that goes via roads with numbers of traffic controls
4 4 4
is better than path via roads with numbers of traffic controls1 5 1
. First example would have output4
, the second one would have output5
.Example:
IN:
4 5 0 1 3 0 2 2 1 2 1 1 3 4 2 3 5
OUT:
4
Solution: The optimal path is either
0 2 1 3
or0 1 3
.Bonus
 Describe time complexity of your algorithm.
 If multiple optimal paths exist, find the shortest one.
 Does your algorithm work without changing the core logic, if the source city and the target city is not known beforehand (it changes on each input)?
 Do you use special collection to speed up minimum value search?
Hints
13 votes 
Programming Challenge: Anagram checking.
It's been over a week since the last programming challenge and the previous one was a bit more difficult, so let's do something easier and more accessible to newer programmers in particular. Write...
It's been over a week since the last programming challenge and the previous one was a bit more difficult, so let's do something easier and more accessible to newer programmers in particular. Write a function that takes two strings as input and returns
true
if they're anagrams of each other, orfalse
if they're not.Extra credit tasks:
 Don't consider the strings anagrams if they're the same barring punctuation.
 Write an efficient implementation (in terms of time and/or space complexity).
 Minimize your use of builtin functions and methods to bare essentials.
 Write the worstbut still workingimplementation that you can conceive of.
24 votes 
Xmas rush : a nice programming challenge going on right now. Only 7 days left!
6 votes 
Advent of Code 2018  a Christmas Themed HackerRanklike mini project
14 votes 
Programming Challenge  It's raining!
Hi everyone, it's been 12 days since last programming challenge. So here's another one. The task is to make an algorithm that'll count how long would it take to fill system of lakes with water....
Hi everyone, it's been 12 days since last programming challenge. So here's another one. The task is to make an algorithm that'll count how long would it take to fill system of lakes with water.
It's raining in the forest. The forest is full of lakes, which are close to each other. Every lake is below the previous one (so 1st lake is higher than 2nd lake, which is higher than 3rd lake). Lakes are empty at the beginning, and they're filling at rate of 1l/h. Once a lake is full, all water that'd normally fall into the lake will flow to the next lake.
For example, you have lakes A, B, and C. Lake A can hold 1 l of water, lake B can hold 3 l of water and lake C can hold 5 l of water. How long would it take to fill all the lakes?
After one hour, the lakes would be:A (1/1), B (1/3), C(1/5)
. After two hours, the lakes would be:A(1/1), B(3/3), C(2/5)
(because this hour, B received 2l/h  1l/h from the rain and 1l/h from lake A). After three hours, the lakes would be:A(1/1), B(3/3), C(5/5)
. So the answer is3
. Please note, that the answer can be any rational number. For example if lake C could hold only 4l instead of 5, the answer would be2.66666...
.Hour 0:
\ / (A) \ / \ / \ / (B) \ / \ / \ /     (C)
Hour 1:
\============/ (A) \ / \ / \============/ (B) \ / \ / \ /   ======= (C)
Hour 2:
============== \============/  (A)  \================/ \==============/ \============/ (B) \ / \ / \ / ======= ======= (C)
Hour 3:
============== \============/  (A)  ======== \================/  \==============/  \============/  (B)  \===========/ \=========/ \=======/ ======= ======= (C)
Good luck everyone! Tell me if you need clarification or a hint. I already have a solution, but it sometimes doesn't work, so I'm really interested in seeing yours :)
21 votes 
Programming Challenge: Shape detection.
The programming challenges have kind of come to a grinding halt recently. I think it's time to get another challenge started! Given a grid of symbols, representing a simple binary state of...
The programming challenges have kind of come to a grinding halt recently. I think it's time to get another challenge started!
Given a grid of symbols, representing a simple binary state of "filled" or "unfilled", determine whether or not a square is present on the grid. Squares must be 2x2 in size or larger, must be completely solid (i.e. all symbols in the NxN space are "filled"), and must not be directly adjacent to any other filled spaces.
Example, where
0
is "empty" and1
is "filled":000000 011100 011100 011100 000010 // Returns true.
000000 011100 011100 011110 000000 // Returns false.
000000 011100 010100 011100 000000 // Returns false.
For those who want a greater challenge, try any of the following:
 Get a count of all squares.
 Detect squares that are touching (but not as a rectangle).
 Detect other specific shapes like triangles or circles (you will need to be creative).
 If doing (1) and (3), count shapes separately based on type.
 Detect shapes within unfilled space as well (a checkerboard pattern is a great use case).
13 votes 
Programming Challenge: Polygon analysis.
It's time for another programming challenge! Given a list of coordinate pairs on a 2D plane that describe the vertices of a polygon, determine whether the polygon is concave or convex. Since a...
It's time for another programming challenge!
Given a list of coordinate pairs on a 2D plane that describe the vertices of a polygon, determine whether the polygon is concave or convex.
Since a polygon could potentially be any shape if we don't specify which vertices connect to which, we'll assume that the coordinates are given in strict order such that adjacent coordinates in the list are connected. Specifically, if we call the list
V[1, n]
and say thatV[i] <> V[j]
means "vertex i and vertex j are connected", then for each arbitraryV[i]
we haveV[i1] <> V[i] <> V[i+1]
. Moreover, sinceV[1]
andV[n]
are at the ends of the list,V[1] <> V[n]
holds (i.e. the list "wraps around").Finally, for simplicity we can assume that all coordinates are unique, that all polygon descriptions generate valid polygons with 3 or more nonoverlapping sides, and that, yes, we're working with coordinates that exist in the set of real numbers only. Don't overcomplicate it :)
For those who want an even greater challenge, extend this out to work with 3D space!
8 votes 
Programming Challenge: Reverse Polish Notation Calculator
It's been nearly a week, so it's time for another programming challenge! This time, let's create a calculator that accepts reverse Polish notation (RPN), also known as postfix notation. For a bit...
It's been nearly a week, so it's time for another programming challenge!
This time, let's create a calculator that accepts reverse Polish notation (RPN), also known as postfix notation.
For a bit of background, RPN is where you take your two operands in an expression and place the operator after them. For example, the expression
3 + 5
would be written as3 5 +
. A more complicated expression like(5  3) x 8
would be written as5 3  8 x
, or8 5 3  x
.All your program has to do is accept a valid RPN string and apply the operations in the correct order to produce the expected result.
18 votes 
Programming Challenge: Counting isolated regions.
Another week, another challenge! This time, assume you're given a grid where each . represents an empty space and each # represents a "wall". We'll call any contiguous space of .s a "region". You...
Another week, another challenge!
This time, assume you're given a grid where each
.
represents an empty space and each#
represents a "wall". We'll call any contiguous space of.
s a "region". You can also think of a grid with no walls the "base" region. The walls may subdivide the base region into any number of isolated subregions of any shape or size.Write a program that will, given a grid description, compute the total number of isolated regions.
For example, the following grid has 5 isolated regions:
....#....# ....#.###. ....#.#.#. #...#..#.. .#..#...#.
16 votes 
Programming Challenge: Merge an arbitrary number of arrays in sorted order.
It looks like it's been over a week and a half since our last coding challenge, so let's get one going. This challenge is a relatively simple one, but it's complex enough that you can take a...
It looks like it's been over a week and a half since our last coding challenge, so let's get one going. This challenge is a relatively simple one, but it's complex enough that you can take a variety of different approaches to it.
As the title suggests, write a program that accepts an arbitrary number of arrays, in whatever form or manner you see fit (if you want to e.g. parse a potentially massive CSV file, then go nuts!), and returns a single array containing all of the elements of the other arrays in sorted order. That's it!
Bonus points for creative, efficient, or generalized solutions!
24 votes 
Programming Challenge: Compute the shortest path to visit all target spots on a grid.
Let's do something a little more challenging this time. Given an MxN grid of arbitrary size, and given a random starting place on that grid and a list of points to visit, find the shortest path...
Let's do something a little more challenging this time.
Given an MxN grid of arbitrary size, and given a random starting place on that grid and a list of points to visit, find the shortest path such that you visit all of them. Path lengths will be computed using taxicab distances rather than strict coordinate distance calculations.
There are no restrictions on expected input this time. Output should be the total distance traveled between points.
Example
Assume that we use the character
#
to denote a spot on the grid, the character@
to denote your starting point, and the character*
to denote a place on the grid that you're required to visit. One such grid may look something like this:###### ###### **#### #*#### #*#*## #@#### ######
In this case, let's say that the bottomleft point on the grid is point
(0, 0)
and we're starting on point(1, 1)
. One valid solution would be to move to point(3, 2)
, then(1, 2)
, then(1, 3)
, then(1, 4)
, and finally(0, 4)
. The shortest path available is thus8
. Note that it's not enough just to visit the next nearest point on the grid!15 votes 
Programming MiniChallenge: KnightBot
Another programming minichallenge for you. It's been a month since the first one and that seemed to be rather successful. (I appreciate that there are other challenges on here but trying to sync...
Another programming minichallenge for you. It's been a month since the first one and that seemed to be rather successful. (I appreciate that there are other challenges on here but trying to sync with them seems tricky!)
A reminder:
I'm certain that many of you might find these pretty straight forward, but I still think there's merit in sharing different approaches to simple problems, including weirdandwonderful ones.
KnightBot
Info
You will be writing a small part of a Chess program, specifically focusing on the Knight, on an 8 x 8 board.
Input
The topleft square of the board will have index 0, and the bottomright square will have index 63.
 The first input is the starting square of the knight.
 The second input is the requested finishing square of the knight.
 The third input is the number of maximum moves allowed.
Output
The expected outcome is either True or False, determined by whether or not the Knight can reach the requested finishing square within the number of allowed moves when stating on the starting square.
e.g. The expected output for the input 16, 21, 4 is True since the Knight can move 16>33>27>21, which is 3 moves.
Extensions
Some additional ideas for extending this challenge...
 Instead of an 8x8, what if the board was nxn?
 Instead of "within x moves", what if it was "with exactly x moves?"
 Instead of a traditional Knight's move (2 long, 1 short), what if it was n long and m short?
 What if the board was infinite?
 What if the board looped back around when crossing the edges? (e.g. the square to the right of 7 is 0)
17 votes 
Programming Challenge: Make a game in 1 hour!
Background There's been some talk on ~ before, and it seems like there are quite a few people who are either interested in, learning, or working in game development, so I thought this could be a...
Background
There's been some talk on ~ before, and it seems like there are quite a few people who are either interested in, learning, or working in game development, so I thought this could be a fun programming challenge.
This one is fairly openended: make a game in 1 hour. Any game, any engine, don't worry about art or sound or anything.
Doing is the best way to learn. Most people's first project is something overly ambitious, and when they find that it's more difficult than they thought, they can get discouraged, or even give up entirely. This is why the 1 hour limit is important: it forces you to finish something, even if it's small. When you're done, you can come out of it saying you made a game, and you learned from it.
Chances are the game might not be fun, look bad, be buggy, etc. But don't worry about that, everyone's game will have problems, and if you do create something really fun or innovative, congratulations, you have a prototype that you can expand on later!
"Rules"
Like I said before, these "rules" are pretty simple: make a game in (approximately) 1 hour. You can use any tools you want. If you use external assets (art, sound), it's probably best you use something you have the rights to (see resources). If you're completely new to game development/programming, your goal could even be to finish a tutorial.
If you're the kind of person who tends to get carried away with these things, you might want to post a comment saying you're starting, then another one once you've finished your game.
Please share your finished game, I'm sure everyone would love to try them! If your game is webbased, it can be hosted for free on Github Pages or Itch.io. If downloadable, it can be hosted for free on Google Drive, Mega, Dropbox, Itch.io, etc.
Resources
Engines
If you're a beginner, a good engine to start with is LÖVE. It's very simple, and uses Lua, which is very easy to learn.
If you're familiar with another language, you could use a library to make it in that language. Some examples:
Javascript: kontra, Phaser, pixi.js
Python: pygame
If you want something more complex, consider Godot, Unity, or Unreal.
You can also try something visual like Construct, Clickteam Fusion, or GDevelop
Art
For such a short time constraint, I'd suggest you use your own "programmer art": just use some basic shapes. Your primary focus should be gameplay.
If you think you have time to find something, try looking on OpenGameArt.
Sound
You can make simple sound effects very quickly with sfxr (or in this case, a web port of sfxr called jsfxr).
27 votes 
Programming MiniChallenge: TicTacToeBot
I've seen the programming challenges on ~comp as well as quite a few users who are interested in getting started with programming. I thought it would be interesting to post some 'minichallenges'...
I've seen the programming challenges on ~comp as well as quite a few users who are interested in getting started with programming. I thought it would be interesting to post some 'minichallenges' that all could have a go at. I'm certain that many of you might find these pretty straight forward, but I still think there's merit in sharing different approaches to simple problems, including weirdandwonderful ones.
This is my first post and I'm a mathsguy who dabbles in programming, so I'm not promising anything mindblowing. If these gain any sort of traction I'll post some more.
Starting of with...
TicTacToeBot
Info
You will be writing code for a programme that will check to see if a player has won a game of tictactoe.
Input
The input will be 9 characters that denote the situation of each square on the grid.
 'X' represents the Xplayer has moved on that square.
 'O' represents the Oplayer has moved on that square.
 '#' represents that this square is empty.
Example:
O X XXO The input for this grid will be O#XXXOO## O  
Output
The expected output is the character representing the winning player, or "#" if the game is not won.
(e.g. The expected output for the example above is '#' since no player has won)
29 votes 
Programming Challenge: Two Wizards algorithm challenge
I'm running out of ideas, if you have any, please make your own programming challenge. This challenge is about designing algorithm to solve this problem. Let's have game field of size x, y (like...
I'm running out of ideas, if you have any, please make your own programming challenge.
This challenge is about designing algorithm to solve this problem.
Let's have game field of size x, y (like in chess). There are two wizards, that are standing at
[ 0, 0 ]
and are teleporting themselves using spells. The goal is to not be the one who teleports them outside of the map. Each spell teleports wizard by at least +1 tile. Given map size and collection of spells, who wins (they do not make any mistakes)?Here are few examples:
Example 1
x:4,y:5
Spells:
{ 0, 2 }
Output:
false
Description: Wizard A starts, teleporting both of them to 0, 2. Wizard B teleports them to 0, 4. Wizard A has to teleport them to 0,6, which overflows from the map, so he loses the game. Because starting wizard (wizard A) loses, output is
false
.Example 2
x:4,y:4
Spells:
{ 1,1 }
Output:
true
Example 3
x:4,y:5
Spells:
{ 1,1 },{ 3,2 },{ 1,4 },{ 0,2 },{ 6,5 },{ 3,1 }
Output:
true
Example 4
x:400,y:400
Spells:
{9,2},{15,1},{1,4},{7,20},{3,100},{6,4},{9,0},{7,0},{8,3},{8,44}
Ouput:
true
Good luck! I'll comment here my solution in about a day.
Note: This challenge comes from fiks, programming competition by Czech college ČVUT (CTU).
15 votes 
Weekly Programming Challenge  making our own data format
Hi everyone! There was no coding challenge last week, so I decided to make one this week. If someone wants to make his own challenge, wait few days and post it. I'm running out of ideas and I'd...
Hi everyone! There was no coding challenge last week, so I decided to make one this week. If someone wants to make his own challenge, wait few days and post it. I'm running out of ideas and I'd like to keep these challenges running on Tildes.
Everyone here knows data formats  I'm talking about XML or JSON. The task is to make your own format. The format can be as compact as possible, as humanreadable as possible, or something that's really unique. Bonus points for writing encoder/decoder for your data format!
How do you handle long texts? Various unicode characters? Complex objects? Cyclic references? It's up to you if you make it fast and simple, or really complex.
I'm looking forward to your data formats. I'm sure they will beat at least csv. Good luck!
8 votes 
Programming Challenge: creative FizzBuzz
Pretty standard: Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which...
Pretty standard:
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
The twist: come up with the most creative or unusual way to solve this in your language of choice.
39 votes 
Programming Challenge: Freestyle textual analysis.
I just realized that I completely glossed over this week's programming challenge. For this week, let's do something more flexible: write a program that accepts a file as inputeither through a...
I just realized that I completely glossed over this week's programming challenge. For this week, let's do something more flexible: write a program that accepts a file as inputeither through a file name/path or through standard inputand perform any form of analysis you want on its contents. That's it!
For instance, you could count the occurrences of each word and find the most common ones, or you could determine the average sentence length, or the average unique words per sentence. You could even perform an analysis on changes in words and sentence structure over time (could be useful for e.g. poetry where metre may play an important role). You can stick with simple numbers or dive right into the grittiest forms of textual analysis currently available. You could output raw text or even a graphical representation. You could even do a bit of everything!
How simple or complex your solution ends up being is completely up to you, but I encourage you to challenge yourself by e.g. learning a new language or about different textual analysis techniques, or by focusing on code quality rather than complexity, or even by taking a completely different approach to the problem than you ordinarily would. There are a lot of learning opportunities available here.
11 votes 
Programming Challenge  Let's build some AI!
Hi everyone! In this challenge, we will build simple genetic algorithm. The goal is to create genetic algorithm that will learn and output predefined text ("Hello World!"). The goal can be...
Hi everyone! In this challenge, we will build simple genetic algorithm.
The goal is to create genetic algorithm that will learn and output predefined text ("Hello World!").
The goal can be achieved with any language and you'll need just simple loops, collection and knowledge how to create and use objects, even beginners can try to complete this challenge.
How?
I'll try to explain it as best as I can. Genetic algorithms are approximation algorithms  they often do not find the best solution, but they can find very good solutions, fast. It's used when traditional algorithms are either way too slow, or they even don't exist. It's used to, for example, design antennas, or wind turbines. We will use it to write "Hello World".
First of all, we define our
Entity
. It is solution to given problem, it can be list of integers that describe antenna shape, decision tree, or string ("Hello World"). Each entity contains the solution (string solution
) and fitness function. Fitness function says, how good our entity is. Our fitness function will return, how similar is entitysolution
text to "Hello World" string.But how will the program work? First of all, we will create list of entities
List<Entity>
. We will make, for example, 1000 entities (randomly generated). TheirEntity.solution
will be randomized string of length 11 (because "Hello World" is 11 characters long).Once we have these entities, we will repeat following steps, until the best entity has
fitness == 1.0
, or 100% similarity to target string.First of all, we compute fitness function of all entities. Then, we will create empty list of entities of length 1000. Now, we will 1000times pick two entities (probably weighted based on their fitness) and combine their strings. We will use the string to create new entity and we will add the new entity to the new list of entities.
Now, we delete old entities and replace them with entities we just made.
The last step is mutation  because what if no entity has the "W" character? We will never get our "Hello World". So we will go through every entity and change 5% (or whatever number you want) of characters in their solution to random characters.
We let it run for a while  and it is done!
So to sum up what we did:
entities < 1000 random entities while entities.best.fitness < 1: for every entity: compute fitness newEntities < empty list 1000times: choose two entities from "entities", based on their fitness combine solutions of these entities and make newEntity newEntities.add(newEntity) for every entity: mutate // Randomly change parts of their strings print(entities.best.solution) // Hello World!
Now go and create the best, fastest, and most pointless, genetic algorithm we've ever seen!
23 votes 
Programming Challenge: Construct and traverse a binary tree.
It's that time of week again! For this week's programming challenge, I thought I would focus on data structures. Goal: Construct a binary tree data structure. It may handle any data type you...
It's that time of week again! For this week's programming challenge, I thought I would focus on data structures.
Goal: Construct a binary tree data structure. It may handle any data type you choose, but you must handle sorting correctly. You must also provide a print function that prints each value in the tree on a new line, and the values must be printed in strictly increasing order.
If you're unfamiliar with this data structure, it's a structure that starts with a single "root" node, and this root can have a left child, right child, both, or neither. Each of these child nodes is exactly the same as the root node, except the root has no parent. This branching structure is why it's called a tree. Furthermore, left descendants always have values smaller than the parent, and right descendants always have larger values.
12 votes 
Programming Challenge: Given a triangle of numbers, find the path from the top to the bottom of the triangle with the largest sum.
This problem is based on the Project Euler problem here. Goal: Given some input describing a triangle of numbers, find the path starting from the topmost row of the triangle and ending at the...
This problem is based on the Project Euler problem here.
Goal: Given some input describing a triangle of numbers, find the path starting from the topmost row of the triangle and ending at the bottommost row of the triangle that contains the largest sum of all of the numbers along the path. You may only move downward and you must select an adjacent position to move to. Efficiency is not a requirement for completion.
Constraints:
 The first line of input for a triangle will be a single integer telling you how many rows the triangle will have.
 Each following line of input will be the next row of the number triangle, starting at the first row.
 For each line describing the number triangle, the individual numbers will be separated by a single space.
Note: The constraints above are to keep hardcoded triangles out of submitted solutions while also ensuring that all languages can equally handle this problem without annoying workarounds for lowerlevel languages. The consistency also makes it easier for beginners to review and understand someone else's code, and makes it easier to receive help if you get stuck. They're not necessarily required, but are highly encouraged.
Example input:
4 1 3 2 4 5 6 7 8 9 10
Corresponding triangle:
1 3 2 4 5 6 7 8 9 10
Expected result:
19
(1 + 2 + 6 + 10)Extra Credit: As noted on the Project Euler page, you can solve this using a brute force method, but it's incredibly inefficient. Specifically, a brute force solution would be O(2^{n}) time (exponential). There exists a solution that can be solved in O(n^{2}) time (quadratic). Find this solution.
13 votes 
Programming Challenge: Implementing bitwise operators.
Background: Bitwise operators are operators that perform conditional operations at the binary level. These operators are bitwise AND &, bitwise OR , bitwise XOR ^, and bitwise NOT ~, not to be...
Background: Bitwise operators are operators that perform conditional operations at the binary level. These operators are bitwise AND
&
, bitwise OR
, bitwise XOR^
, and bitwise NOT~
, not to be confused with their logical operator counterparts, i.e.&&
,
,!=
, and!
respectively.Specifically, these operations take the binary values of the left and righthand terms and perform the conditional operation on each matching bit position between both values.
For instance,
3  4
takes the binary value010
from 2 and100
from 4. From left to right, we compare0  1
,1  0
, and0  0
to get110
as the resulting binary. This produces the integer value6
.Goal: Your challenge is to implement one or more of these bitwise operators without using the native operators provided to you by your language of choice. Logical operators are allowed, however. These operators should work on integer values. These operators will likely take on the form of a function or method that accepts two arguments.
Bonus challenges:
 Implement all of the operators.
 Don't use any native binary conversion utilities.
 Whether or not you implement all operators, write your code in such a way that allows for good code reusability.
 For statically typed languages, handle integers of different types (e.g. int vs. uint).
Edit: Minor correction for the sake of accuracy, courtesy of @teaearlgraycold.
12 votes 
Programming Challenge: Translate 24hour time into words
This is an adapted version of Talking Clock from /r/DailyProgrammer. The point of this thread is to post your code for solving the task. Other will comment with feedback and new ideas. Post what...
This is an adapted version of Talking Clock from /r/DailyProgrammer.
The point of this thread is to post your code for solving the task. Other will comment with feedback and new ideas. Post what language (and version, if relevant) your code is written in.
Task description
Your task is to translate a 24hour formatted time to words.
Input description
An hour between 00 and 23 followed by a colon followed by a minute between 0 and 59.
Output description
The time expressed in words, in 12hour format followed by "am" or "pm".
Sample input
00:00 01:30 12:05 14:01
Sample output
It's twelve am It's one thirty am It's twelve oh five pm It's two oh one pm
27 votes