r/ProgrammingPrompts • • Nov 20 '14

[Easy(base task) to Difficult (challenge)][Dice Game] - 111 (one hundred and eleven)

11 Upvotes

This is another very simple dice game.

Game Rules

  • The goal is to reach 111 (one hundred and eleven - or eleventy-one) points before all others do.

  • A single die is used to play the game.

  • Each player is allowed as many rolls as they want, except when they roll a "1" (one), their round ends.

  • The points are accumulated during a player's round, but if a player rolls a "1" (one), they lose all the points that they accumulated during the round.

Example of a single round:

  • Player A rolls 2, 3, 4, 6, 5 which totals to 20 points. Player A wages another roll and rolls a 1. That's really bad luck as the round is over for player 1 and he loses all 20 points so that he ends the round with 0 points.

  • Player B rolls 5 and 6 and decides to stop. The 11 points are added to player B's score.

  • Player C rolls 4,6,3,5,6 and stops. He scores 24 pounds.

  • Player D rolls 4, decides to wage another roll and rolls 1. The round is over for player D with 0 points.

The rounds are repeated until one of the players reaches at least 111 points.


Programming Task:

Write a program that simulates a game of 111 in a language of your choice.

  • Any number of (human) players can participate

  • The computer should record the name and score for each player.

  • The computer should do the tallying and also end the round on a roll of 1

Optional tasks (easy):

  • Let the users decide on the winning number (default 111)

  • Let the users decide which number ends a round and voids all the points acquired in that round (default 1)

  • Invent a "mandatory re-roll" rule. If a player rolls a certain number (other than the losing number), they must re-roll. (let's say it defaults to 4 - chosen arbitrary)

  • Invent a "no re-roll" rule. Similar to the above, only the round ends and the player scores the accumulated points. (let's say, it defaults to 2 - chosen arbitrary)

  • The "mandatory re-roll" and "no re-roll" rules should be optional.

Optional tasks (challenge):

  • Change the program to allow for computer players as well as humans.

  • Computer players should have different strategies (selectable when creating the computer players, or randomized)
    Examples for strategies:

    • Always rolls again until he rolls a one (or hits the winning number) - quite a dumb strategy

    • Never rolls again - the coward - crawling his way to victory

    • Always rolls 2 (3, 4, 5 - whatever) times

    • Rolls <random number>(determined before the actual roll) times - different for each round.

    • Rolls again with a probability of 33% - rather cautious (takes a roll, then a random number decides whether to roll again or not - if the random number(in the range 0.0 inclusive to 1.0 exclusive) is less than or equal to 0.33, the computer rolls again.

    • Rolls again with a probability of 50% - see the explanation above

    • Rolls again with a probability of 66% - see the explanation above

    • Any other strategy you can think of.

Have fun coding!


r/ProgrammingPrompts • • Mar 10 '14

Write an implementation of the Ship, Captain, Crew game

11 Upvotes

Ship, Captain, Crew is a simple dice game, often played at parties.

Here are the rules: http://en.wikipedia.org/wiki/Ship,_captain,_and_crew

The game should accept any number of players - with names.

[Optional:] Create some AI for computer players (also any number) with maybe different strategies.


r/ProgrammingPrompts • • Dec 06 '16

Strong Password Detection

10 Upvotes

Write a function that uses regular expressions to make sure the password string it is passed is strong. A strong password is defined as one that is at least eight characters long, contains both uppercase and lowercase characters, and has at least one digit. You may need to test the string against multiple regex patterns to validate its strength.

Source: AutomateTheBoringStuff


r/ProgrammingPrompts • • May 01 '16

[Medium]Write a podcast ripper in C++

10 Upvotes

This is one of my favorite "learn a new language" projects: podcast rippers. The code outline is simple.

  1. Read podcast feed URL from command-line.

  2. Download the podcast feed.

  3. Parse through the XML

  4. Identify the elements holding the podcast URLs

  5. Identify the filename to use

  6. Download the podcast and save to file.

  7. Rinse and repeat!

The tricky part is doing it in C++. Use whatever libraries you like (like libCURL and TinyXML) unless their stated purpose is to rip podcasts or the like.

Bonus Points if you write it in straight C.


r/ProgrammingPrompts • • Dec 19 '14

[Christmas Prompt] - The Twelve Days of Christmas

10 Upvotes

This time, it will not be a game, but two small challenges revolving around the Song The Twelve Days of Christmas.

The song is a well-known Christmas carol.

In general, the structure is:

  • Verse 1:

    • On the first day of Christmas

    • my true love sent to me

    • a Partridge in a Pear Tree

  • Verse 2:

    • On the second day of Christmas

    • my true love sent to me

    • Two Turtle Doves

    • and

    • a Partridge in a Pear Tree

  • Verse 3:

    • On the second day of Christmas

    • my true love sent to me

    • Three French Hens,

    • Two Turtle Doves

    • and

    • a Partridge in a Pear Tree

And so on.

The remaining days are:

  • 4 Calling Birds

  • 5 Gold Rings

  • 6 Geese-a-Laying

  • 7 Swans-a-Swimming

  • 8 Maids-a-Milking

  • 9 Ladies Dancing

  • 10 Lords-a-Leaping

  • 11 Pipers Piping

  • 12 Drummers Drumming


And now for the puzzles:

  1. Write a program that displays the verse for any given day in the range 1 to 12 (both inclusive), or for all days. Challenge: The program should be as short as possible, the code should be as efficient (in terms of calculation) as possible.

  2. Write a program that calculates the total number of presents received at any given day in the range 1 to 2 (both inclusive), or the total number of presents received up to and including any given day, or the total number of presents in the whole song.

Have fun coding!


Merry Christmas everyone!


r/ProgrammingPrompts • • Nov 16 '14

[Easy][Dice Game] - Big Six

10 Upvotes

Big six is a very simple dice game with a single die.

The game has a gameboard like this:

+-------+-------+-------+-------+-------+-------+
|       |       |       |       |       |       |
|   1   |   2   |   3   |   4   |   5   |   6   |
|       |       |       |       |       |       |
+-------+-------+-------+-------+-------+-------+

At the beginning each player gets 5 tokens.

Each round, each player rolls a single die.

The result of the roll decides what the player has to do:

  • If roll result is 6, the player must place a token on the space number 6. This token is dead and lost.

  • For any other roll result, the following applies:

    • If the space with the number equal to the roll result is empty, the player must place a token there.

    • If the space with the number equal to the roll result has already a token, the player gets the token.

  • The game runs until the first player is out of tokens. The player with no tokens left is the winner.

So, the overall aim of the game is to lose all tokens.

Write a program for the game above in the language of your choice.

You can use the dice library from Game component: Die and Dicebag


  • The game should allow for several players in hotseat mode (only one computer, players take turns)

  • The game should also be able to simulate players (no strategy needed as the game is purely a game of luck), even a "computer only" mode should be possible.

  • The game should keep track of

    • player names

    • player tokens

    • rounds

    • statistics (win/lose per player)

  • The main game loop should carry out the:

    • handling of the player turns

    • die rolling

    • token handling

    • check for the winning condition

  • The game can run in a simple console window or GUI (or a webpage, on a TTY, basically wherever you want)

  • Optional: The number of tokens should be customizable.

Have fun coding!###


r/ProgrammingPrompts • • Mar 08 '14

[Html, CSS] Create an Analog Clock Using the Canvas

Thumbnail
kirupa.com
10 Upvotes

r/ProgrammingPrompts • • May 14 '24

My Two Dogs

9 Upvotes

I thought of this back when walking my dogs at my parents' mini-ranch.

Suppose we have a human walking two dogs. One is a slower bigger dog. The other is a faster smaller dog. The human is obviously the biggest and slowest. The human wants to walk the dogs in a wide circle (or whatever path you like) but the dogs keep tugging in all different directions.

Pick weights for all three. Maybe 60kg (for the human), 10kg (little dog), 25kg (bigger dog).

Pick lengths for the dog leashes. Maybe 2 meters each.

Plot or animate the three (circles or dots are fine) attempting to walk a circular path.

Or just plot the human getting dragged in whatever path the two dogs choose.

Some things to consider:

  • A dog will only exert force on the human if their leash is fully extended.

  • Both dogs will exert a different force based on their weight and speed.

  • The dogs will wander in random directions for random lengths of time.


r/ProgrammingPrompts • • May 31 '20

Do you have space-related prompts or challenges?

9 Upvotes

Hi, I'm quite into science and space and something related to that might be encouraging to keep on learning!


r/ProgrammingPrompts • • Dec 31 '18

Six degrees of separation Javascript problem

9 Upvotes

As I haven't been successful, I'm asking if anyone has any ideas. I have to write a Javascript application which returns a list of actors that have been in both a movie with Keanu Reeves and Nicolas Cage. Sort of like a six degrees of separation. I have an API that I'm making a request to and I'm getting some data in return but I'm not exactly sure where to go from there?


r/ProgrammingPrompts • • Jun 14 '18

[Medium] Fire Effect in TEXT

9 Upvotes

Back in the Mode 13h days, the fire routine used to be one of the fun "first projects" for people playing with graphics. A line of random data would be generated and then smoothed upward. The numbers would correspond to a palette of available colors. An extra vertical bump would give the flame a smoother, less smoky look.

But that's too easy. Let's do it in Text mode.

In text you have to set the Foreground color, the Background color, the Attribute (blinking, hi-intensity/bright) and then actual character.

You can either use a portable library like NCurses or the OS console API (for example: https://docs.microsoft.com/en-us/windows/console/console-reference ). Escape codes will maybe work if you're using Linux, but not Windows.

If you post your code, make sure to list which OS you're using.

Happy programming!


r/ProgrammingPrompts • • Feb 06 '15

Question: Was there a prompt here earlier that got deleted?

9 Upvotes

I believe I saw a prompt that said [Java] and had to do with finding different solutions to an equation with 9 variables. Does anyone have the post or the equation?


r/ProgrammingPrompts • • Apr 06 '14

Programming ideas on HN. Some are more advanced than others. A lot of interesting ideas in here!

9 Upvotes

r/ProgrammingPrompts • • Sep 05 '22

A script/bot to identify all addresses on Google Maps (in a range) that satisfy a given trait or keyword, targeting those keywords EVERYWHERE in the data associated with the address instead of just the name and default labels like Google seems to do.

8 Upvotes

I originally wanted something like this for urban exploration (post) because Google Maps has a built-in feature to identify a place as "Permanently closed," but doesn't allow you to filter for that. Simply searching "Permanently closed" shows some results but not others, and sometimes those addresses don't even display on the map (They only appear once you specifically search for it). I'm not a programmer by any means, but I was thinking that if you have a bot or script check every address in a range (either through whatever database or API Google Maps provides, or by entering addresses from an external database if it has more than Google does) it may be possible to get more results.

While that is the main draw for something like this to me, it seems like it could be useful in general as well. Searching for other keywords like "Restaurants" or "Barber" sometimes seem to do a pretty bad job at finding stuff, either not displaying things until you get really zoomed in or just straight up missing something that has those key words somewhere in the name or description. A bot that looks through all the addresses and shows a map that truly shows all the locations that satisfy that search, whether the keyword is directly in the name or hidden somewhere Google apparently doesn't check that well like a description or review, could be really useful.


r/ProgrammingPrompts • • Jun 15 '19

"Smart Fridge" application idea

8 Upvotes

Hi there!

As you probably saw this is my very first post on Reddit :)

But let's back to the main topic here which is my idea for an application - "Smart Fridge" (this is only idea for a name). So, everything here is only an idea, but I really would like to get a feedback from you guys - what you think about this idea, etc.

----------------------------------------------------------------------------------------------------------------------------------------------------

For who?

Application is dedicated for all people who have a fridge at home.

Problem to solve?

This situation very often happens - you are in a shop but you cannot remember if you still have a milk (or some other product) in your fridge.

Why this application would be useful?

Application for user would be available via smartfon/web (firstly web application and android app later in the future). Application would show all scanned products which are available in your fridge in real time. So when you would be in a shop you can just open application/web and see what you have in a fridge available.

How would it work?

I thought about a Raspberry Pi + some mini barcode scanner module. This computer would be installed inside the fridge. When you will be put a new product into a fridge you will have to scan the barcode of this product before put into. When barcode is scanned the Raspberry Pi would communicate with the API that product with this barcode has been put into a fridge and The API would do the necessary logic. The same thing would happen if "user" is going to get some product from the fridge, he would has to scan the barcode again (maybe some switch somewhere to inform that product is getting from the fridge and not put into - this is a problem to discuss).

Pros?

  • Product that are in a fridge are available online

  • For sure this would be a cheaper solution instead of buying some fridge with cameras inside (very expensive now)

  • This solution would be available for every fridge at home (just need some space to install Raspberry PI inside)

Cons?

  • Of course the biggest disadvantage seems to be requirement to scan barcode before put/get product into/from the fridge.

  • Raspberry PI inside the fridge will not propably looks good

----------------------------------------------------------------------------------------------------------------------------------------------------

What do you think guys about this idea? I would be very grateful for you opinion and feedback :)


r/ProgrammingPrompts • • Jul 28 '16

Very Easy: Create a Fischerrandom piece order generator.

8 Upvotes

Fischerrandom is chess with all the back rank pieces all jumbled and scrambled and crazy like. The only three rules are that the king has to be between the rooks, the bishops must be on opposite colored squares, and the two sides have to be exactly symmetrically the same! Make the output something like "RBNNKRQB" indicating the white back rank. You dont need the black because it is just a mirror of white on the other side of the board. If you wanted to get real fancy you could associate each value with a picture of the corresponding piece and output a fancy piece array. *edit added rule about opposite colored bishops


r/ProgrammingPrompts • • Mar 08 '14

MOD: removal of link submissions

8 Upvotes

I have removed link submissions because I was looking forward to this subreddit focusing on conversationally creating and comparing projects and I feel that links to already created lists of projects may take away from this. However, I am aware that it is still possible to link to these pre-made lists by way of an in-text link. Please share your opinions on this decision! Thanks!


r/ProgrammingPrompts • • Dec 28 '18

Actor search

7 Upvotes

Hi reddit. So I have a programming question that I need help with. I'm writing an application in Javascript where I have to come up with a list of actors that starred in movies with both Keanu Reeves and Nicolas Cage but not necessarily at the same time but I'm not exactly sure where to start?


r/ProgrammingPrompts • • Jul 26 '17

How to go about making a twitter post extension for longer twitter posts.

7 Upvotes

Not sure if I'm living in cuckoo land here or if this is actually a viable project that could take off. I was wondering what people would think of an app extension that, when you hover over the link with your cursor, would open the link as a window next to the cursor. This way, you could hover over a link on twitter, and read a longer-than-144-character post on twitter right next to the cursor without leaving the site at all. Thus, people can make longer twitter posts. Think bit.ly but specifically for making longer twitter messages.

How could it be done? I was considering making something like this as a small project in Javascript and upload it as a Chrome app.


r/ProgrammingPrompts • • Dec 28 '16

[Medium-Hard]Which Steam Games do you and your friend share?

7 Upvotes

Any language is acceptable.


r/ProgrammingPrompts • • Dec 24 '14

Merry Christmas to all who Celebrate!

7 Upvotes

r/ProgrammingPrompts • • Mar 11 '14

Password Generator!

7 Upvotes

Create a program that reads/writes a text file in which are stored passwords for different accounts. I envision the passwords being formed by random combinations of words which relate to your life in some way (this way, even though the password is random, it is still memorable). This would probably require a resizable list of words which could also be saved in the file and be modified through the program's interface.

BONUS!: Encrypt the text file while not in use by the program. I can't imagine why...


r/ProgrammingPrompts • • May 01 '20

How best to implement this?

6 Upvotes

Hi all!

I feel like this is a good prompt but also might help people think outside-the-box for a problem I have!

I'm in the military and we have a scheduling problem at my job that I believe can be solved via a relatively simple tool, but the concept could be difficult to implement and I'm looking for some ideas.

We have difficulty scheduling 100+ people with shifts, training, business trips, etc. Most people tend to use excel for this sort of thing but it's a massive amount of work and just not an ideal solution.

I'm looking to create a visual schedule of all personnel, laid out horizontally, that will block off dates with activities/etc. and allow for the input of new events, changing dates, colors for different type of activities, etc. I'd really like this to be able to create a "draft" schedule and also drag/drop items around on the schedule... i.e. much more dynamic than it is in a static excel sheet.

Here's the problem: being on a military network I can't just (1) run my own web server, (2) I have access to a limited set of tools (Microsoft Access/Excel/etc.), and (3) I don't believe going to a pre-built, paid solution that's hosted by a third-party will be approved.

(I know PHP/CSS/MySQL, Java, and have dabbled in some frameworks like CakePHP.)

Any thoughts?

Appreciate any feedback!


r/ProgrammingPrompts • • Apr 01 '20

optimize this function if you're bored.

6 Upvotes

private float roundTarget(float target) {
if (target > 0) {
if (target <= .5f) {//greater than zero but less than .5
return target = .5f;
}
return target = 1;//greater than .5
} else if (target < 0) {//less than 0
if (target >= -.5f) {//less than 0 but greater than -.5
return target = -.5f;
}
return target = -1;//less than -.5
}
return target = 0;
}