r/ProgrammingPrompts • • Jun 08 '21

Build a reddit search system

16 Upvotes

Build a simpler version of reddit search system that will take a query as input and return the matching post results.

Some instructions and examples are given below to get started (You can use any language you want. Instructions use javascript style just for representation)

// 1. Create some dummy data similar to reddit text posts
post1 = { title: 'Build a reddit search system', description: "Build a simpler version of reddit.....", id: 1 }

// 2. Store all the data in one data structures e.g. array
postArray = [post1, post2, ....]

// 3. Index postArray data for fast search (any changes you want to make for quick and better search. Google about "search indexing" or watch the video I shared.
function indexData(postArray){...}

// 4. Create search function that will print the returning posts
function search(query){...}

// 5. Bonus: highlight the matching lines

You can learn about key terms used in search systems using this video on how google search works. I will also build it and share my work at the end of this week.


r/ProgrammingPrompts • • Nov 15 '20

An Educational Game: Tribe

16 Upvotes

The Gameboard. We have Africa divided into assorted zones along with three possible start points.

So the game is for 2-3 players.

Each player gets a language development card deck.

Game play: each player rolls 1d6. This is the number of starting cards you can draw from your language development deck.

The name of your tribe is made from this initial alphabet.

Your first game piece is on the start point.

What happens during a turn?

step 1: Turn Option

A. Move an existing piece to an adjacent location.

or

B. Attack a rival on an adjacent location. This is a massacre and you take the location from your rival.

Or

C. Spawn a new piece from your start location-only if you have an existing piece on start location. The new piece is moved into an empty adjacent location.

Or

D. develop language. Roll 1d6. Draw new alphabet cards from your language deck equal in number.

Step 2: Check language Development. If you can spell a word from your drawn alphabet- words like farming, pyramid, canoe, boat, then your tribe has developed these. If you can spell canoe and have secured a location next to madagascar, you can move a game piece to the island next turn. If you can spell boat you can sail from any coastal location to madagascar next turn.

As your tribe occupies the map, in conflict with your opponent(s) the game continues until you gain all 26 letters of the alphabet before your rival, or wipe out your rival.

Its just a little educational game I created for public domain as an outflow of my linguistic archaeology research. So feel free to turn it into a billion dollar online franchise.

Game board

Cards A-M

Cards N-Z


r/ProgrammingPrompts • • Aug 11 '19

Please spread the word around.

16 Upvotes

I created the sub r/GoProjectIdeas/ today specifically for golang enthusiasts who cannot find an idea for a project to work on or need others to contribute to their existing go projects. Hoping to see many contributors.


r/ProgrammingPrompts • • Mar 07 '17

[Easy-Medium] Front-end & Networking challenge

15 Upvotes

I wrote a fun coding challenge recently: http://dev.getethos.com.

There's a few different steps but see if you can get to the end. Understanding of web is needed for part 1, and understanding of networking is needed for part 2.

Please don't spoil!


r/ProgrammingPrompts • • Sep 26 '15

[Easy/Medium] Tic-Tac-Toe

15 Upvotes

Write a program that will allow two players to play Tic-Tac-Toe.

The program should accomplish the following:

  • Allow the player to choose their symbol between X and O

  • Allow the player to choose who goes first

  • Display an empty board once the game starts

  • Display the board after each move, updated with that move

  • Display the board and end the game when the win condition is met, or there is a draw

The program must also ensure that:

  • Players cannot overwrite each other's moves

Deciding how the player will input their move is up to the programmer.

Additionally, write an algorithm for an AI to use in single-player mode.

Along with the abovementioned points, the AI should ideally:

  • Identify its best play, and

  • Block the player if they are going to win

Bonus challenge: Create a similar program for 3D Tic-Tac-Toe. This is played on three 3x3 grids, one on top of the other. Players win by forming squares that line up vertically, horizontally or diagonally, on a single grid or evenly across all grids. For example, Grid 1 [0,0], Grid 2 [0,1], Grid 3 [0,2] forms a horizontal line down the grids, and is therefore a win. The game must identify this win condition.

The program should ideally represent this visually, on console or otherwise. If creating an AI, it should ideally follow the points above as well.


r/ProgrammingPrompts • • Mar 18 '15

[Easy]Mathematical Simulation - Breaking a Stick to form a Triangle

15 Upvotes

Another Monte Carlo simulation.

A stick of a given length is twice broken at random places along it's length.

Calculate the probability that a triangle can be formed with the pieces.


Definition:

It is possible to form a triangle if none of the pieces are larger than half the length of the stick.


Assignment:

Create a program in a language of your choice that:

  • Asks the user for the length of the stick

  • Asks the user how many tries should be carried out

  • Simulate the breaking of the stick (each try has a new stick of length)

  • Count the successful tries

  • Print the probability as a percentage

Hint: The expected result should be around 23%

Have fun!


r/ProgrammingPrompts • • Mar 05 '15

The Game of 21 aka Subtraction Game (or Nim)

15 Upvotes

The game of 21 is one of the oldest and simplest games known to mankind.

There are 21 tokens (matchsticks, pebbles, or any other small objects) on the table.

Each player can take 1, 2, or 3 tokens each move.

The player who has to take the last token loses (alternatively wins).

You should create the program for a game of 21 in a language of your choice according to the following specifications:

  • The game should be playable with either 2 players or against the computer

  • The program should handle the counting, win/lose evaluation and check that the players only make valid moves

  • The minimum computer player should take 1 to 3 pieces randomly

  • The program should alternate the starting player on each round

  • Overall winner should be who won best of 5 rounds (customizable)

  • There is no need for a real graphical interface, simple console will suffice, but a GUI is a nice optional touch.


Challenge:

  • Program a computer player that never loses. (It's definitely possible to win a game of 21 as either the first player or as the following player.)


Variants:

  • Make the initial quantity of tokens and the maximum number of tokens that can be taken per turn changeable.


Another, famous variant of 21 is known as "Nim" (or "Marienbad" from the movie "Last Year at Marienbad" from the year 1961)

  • In this variant, the tokens are arranged in 3 heaps of 3, 4, and 5 tokens.

  • Players may take any number of tokens from a single heap.

  • The player who has to take the last token wins (or loses - depending on the variant).

  • Again, the number of heaps and the numbers of tokens per heap can be made adjustable

This variant is also fully solved and can be played in such a way that any perfect player can always win.


r/ProgrammingPrompts • • Sep 02 '14

4 is the Magic Number

15 Upvotes

Before writing any code, you need to figure out the premise of the game!

ex 1.
eleven is six
six is three
three is five
five is four
4 is the magic number

ex 2.
one is three
three is five
five is four
4 is the magic number

When you've figured out the rules of the game, simulate it.
(You can also have your friends scratch their heads over this during car rides)

hint: I used a recursive function and a dictionary (as in python)


r/ProgrammingPrompts • • May 26 '14

Wa-Tor - Population Dynamics Simulation

15 Upvotes

WA-TOR##

Alexander K. Dewdney and David Wiseman developed a simple population dynamics simulation that was published in the December 1984 issue of Scientific American.

The introduction to Wa-Tor by Alexander K. Dewdney:####

Somewhere, in a dimension that can only be called recreational at a distance limited only by one's programming prowess, the planet Wa-Tor swims among the stars. It is shaped like a torus, or dougnut, and is entirely covered with water.

The two dominant denizens of Wa-Tor are sharks and fish, so called because these are the terrestrial creatures they mist closely resemble. The sharks of Wa-Tor eat the fish and the fish of Wa-Tor seem always to be in plentiful supply.

Wa-Tor is a time-discrete simulation. Each step is a "tick" in time. The program should calculate the next step and display it after the calculation is completed.

For simplicity, the planet is shaped like a torus, or doughnut. Basically, it can be simulated by a two-dimensional matrix (or array) where the top and bottom ends, and also the left and right ends wrap around (Hint: modulo operation).

References####

The simulation needs a few parameters to initialize the original population:#####
  • Initial number of fish in the ocean

  • Initial number of sharks in the ocean

  • Age at which fish breed (Once a fish breeds, the age of the breeding fish and of the offspring are set to 0)

  • Age at which sharks breed (same rule as for fish)

  • Time after which a shark that hasn't found food dies of starvation

There are a few rules for the fish and sharks:#####
  • At the beginning, the sharks and fish are randomly distributed across the grid.

  • The initial age of each shark and fish is randomly chosen between 0 and breeding age.

  • There can be only one animal (fish or shark) in single grid cell after each tick (during a tick it is possible that a shark and a fish are in the same cell because the shark eats the fish. After the tick, only the shark will be left in the cell)

  • Both, fish and sharks, move only in the cardinal directions (North, South, West, and East)

  • Fish swim in random directions at each tick

  • Sharks hunt - if there are fish in the surrounding cells sharks will pick a cell with a fish and eat it. If there are no fish surrounding the shark, the shark will move like a fish in a random direction.

  • If an animal reaches the breeding age, the animal first moves according to the movement rules, then a new animal of the same type is spawned in the cell from which the old animal moved, and the age of both, the parent and the offspring is reset to 0.

  • If a shark does not find any food before it reaches the starvation age, it dies and disappears from the grid. If it finds food, the starvation timer is reset to 0.

Expected Output at the End of each Tick####

  • Number of fish and difference between previous and current population

  • Number of sharks and difference between previous and current population

  • A simple graphical representation of the ocean (in the original program, a blank (space) was used for an empty grid position, a period (.) was used for a fish, and a zero (0) was used for a shark.

Additional Info####

  • There should be a way to select whether to manually advance the generations, or to automatically advance the generations (up to a certain limit) with a display interval (user configurable).

  • In the original program, the ocean was 32 cells wide and 14 cells high. For modern computers this setting is too small, so the ocean should be 80 cells wide and 40 cells high (or user configurable).

Optional Extensions####

  • Allow for diagonal movement for both, fish and sharks

  • Make fish more intelligent: let them sense sharks (with a configurable probability) in a configurable distance (up to 3 cells) and if the sense sharks, let them take evasive action

  • Let sharks detect fish in a configurable range (up to 3 cells)


r/ProgrammingPrompts • • May 23 '14

Create a text adventure with simulation

15 Upvotes

Interactive text-based stories, where the magic happens in the head - not new. But I haven't seen one with a simulated world in the background yet.

This idea is for beginners and pros alike - just pick your level of complexity.


Example: "You are in a kitchen. You see a stove, a fridge, a ceiling lamp, a switch, and a sink. There is an open door to the north, a closed window to the west."

The objects in the room have properties, the room itself has an environmental situation (e.g. air pressure, smells, temperature), the player also has properties (e.g. when the light is low or the player is blind-folded, the data retrieved via the eyes is limited/removed, so the text is changed accordingly, all by procedure instead of manually typed!).

On every game turn, simulate(); is called on all existing objects in the game world. So, when you return to room X, the fruits in the bowl on the table might have become a little less fresh.


Some ideas:

  • The game could either be turn-based, like the classic ones, or it could be in real-time in 1-second-steps, and as soon as the player starts typing, the game is paused until the input line is empty again. Alternatively, the whole input could happen via dropdown-menus: The moment a menu is opened, the game is paused. I attempted this a little, works very well - there was an "exits" menu, a "you" menu, and an "objects" menu.

  • Simple "sound rendering": Sounds could be muffled or too silent to identify. One sound could be "drowned out" by another one, so that you e.g. have to turn off a washing machine to be able to hear/identify the person imprisoned behind the secret wall. One way to do this, for example, could be to describe the sounds a bit to the machine. http://en.wikipedia.org/wiki/Audio_frequency is an interesting resource for this. Based on it, one could describe with a boolean or double the significancy and volume of 4 or 5 frequency sections of the sound in question. This would allow to calculate how much a sound might be overridden by another one, to determine if it should be described to the player clearly, in a very coarse way that could be interpreted freely, or if the sound isn't described at all.

  • Simple "light rendering" - or should I call it "em radiation rendering"? http://en.wikipedia.org/wiki/Electromagnetic_spectrum Nuclear terrorism, here we come! (Hi FBI.)

  • Player and other beings could have rather complex and simulated stats, e.g. body temperature, hunger, weight, height, stance (Can you see the police car outside through the window while being bound on the floor?)

  • Talking about police: NPCs could gather information (with some Garbage Collection to prevent data overkill), so if you drive your van to the city park and abduct someone, the police might be able to browse the tree of available options/objects to pick up an informational trace and ultimately get to you. I know, totally insane, but I believe it's not impossible. On the other hand, during your next game, you might play a cop yourself! An open self-experience system?

  • Once you have a working system with rooms and some objects, start writing a world generator so that you have fun exploring your simulation while you're writing it. Tests will probably be pretty inspiring for the overall project.


Suggestions:

  • After a few attempts, I have figured out that the object model should use soft links, meaning that the objects should refer to each other via an ID number (e.g. 64 bit long), because ultimately you will face the beast that saving/loading is, and loading while related objects don't exist yet is a pain. Better just use soft links and look everything up in a manager class that also does the loading/saving.

  • Every object (hence the master class from which all object classes inherit) should have an inventory. You could add flags and checks for/against the player/simulation using it, but it's good if it exists. E.g. put an object into your mouth. Or define buildings by "house contains floors which contain apartments which contain rooms" etc.

  • Additionally, each object might have a variable list (in Java, it would probably be a HashMap<String, Object>), because that's again much easier to save/load than creating extra variables in each object and then having to deal with those.

  • If you want to make a toilet (or whatever other kind of world object), my attempts have shown that it's best to create a separate class for every kind of object instead of trying to build the omni-object.

  • Go crazy! E.g. in my realtime-attempt (Java) where input happened via dropdown menu, I made a toilet where you can lift/lower the lid and the seat (each pushing each other), you can flush, and you can abort the flushing which means that the next flush works right away but is shorter (the tank refills in realtime, the rest is logical - See the beauty of simulation versus just writing the story?). It's easy and fun to write world-objects like these, and they are easy to extend: Say, the toilet does not refill if the incoming water pipe is turned off. Of course you still have a free flush. Alternatively, you might be imprisoned and might need water. Hard choices have to be made, especially if you also simulate bowel movements.

  • Again, go crazy: It's a text adventure system! Well, you can't just make up anything, because you have to give it some reality via simulation, but otherwise: Sky's the limit! Processing time is not an issue. Why shouldn't a turn take a few seconds? Do all the things you wished were in your favorite 3D action adventure game, but they didn't put it in because of development constraints, marketing, or simply because everything at once can't be done on today's PCs. But I double-dare you: DON'T fuck up the FoV!


r/ProgrammingPrompts • • Jan 07 '15

[EASY][Beginner] UAGS (Universal Acronym Generating System)

14 Upvotes

This is an extremely simple prompt, just for fun.

It is suitable for beginners as it only uses basic input/output and string manipulation.

UAGS (Universal Acronym Generating System)

Acronyms are currently all the hype in all forms of communication.

Your task is to program an Acronym Generator.

  • The user inputs a few words for which the Acronym should be generated

  • The computer takes the first letter for each word

  • The first letter of each word is then capitalized

  • All first letters are then joined together to form the Acronym

  • The Acronym should then be printed

  • Ask the user if they need another acronym generated

Have fun coding!


r/ProgrammingPrompts • • Dec 01 '14

[Easy][Dice Game] House Numbers

14 Upvotes

This time it's going to be a quick and simple prompt.

The aim of the game is to roll the highest house number.

To achieve this goal, each player rolls a single six-sided die three times. After each roll the player decides where to put the roll result. The roll result can be placed in either the hundreds, the tens, or the ones position. Each position can only be filled once and changing one's mind is not possible.

Rules:

  • The game is played with a single six-sided die

  • Each player rolls 3 times

  • After each roll the player has to decide where to put the roll result.

    • There are three positions where the roll result can be placed: ones, tens, and hundreds.

    • Each position can only be filled once

  • After the three rolls, the final house number is written down.

  • The highest result wins the round.

  • If there is a draw, all players with the same result score.

The highest possible house number is 666 and the lowest possible is 111.

Task:

Write a program to simulate the game of house numbers

  • Allow any number of human players to play

  • Allow any number of rounds to be played

  • The computer should do the dice rolling

  • The users should decide where to place the die after each roll

  • The computer should declare the round winner after each round

  • The computer should track score of the round winnings and of the roll results of each round for each player

  • The computer should declare an overall winner by round wins and a score winner by highest total score

Variants:

  • Lowest house number wins the round, lowest overall score is the score winner

  • Alternating rounds: First round plays high house number, second round plays low house number, next one high, and so on.

Special (not in the original rules):

+A single roll result may be flipped. I.e.: If the player rolls a "1" during a high house number round, they may flip the die to change the roll result to a "6". The opposite die sides are: 1-6, 2-5, 3-4.

Extended option:

  • Allow for computer players with varying strategies

Have fun coding!


r/ProgrammingPrompts • • Mar 31 '14

Martyr2'S Mega Project Ideas List! - 125 Project Ideas

14 Upvotes

r/ProgrammingPrompts • • Mar 09 '14

Virtual Dungeons and Dragons Dice

14 Upvotes

I challenge y'all to make a set of virtual DnD dice of which you can decided how many sides the dice have. This one should be really simple though there's plenty of room for branching off and being as thorough as you'd like (ASCII art title, keep track of each player's rolls and keep track of them by name etc.).


r/ProgrammingPrompts • • Nov 17 '14

[Easy to Difficult] Connect Four

13 Upvotes

Introduction

Connect Four is a well-known strategy game originally published in 1974 by Milton Bradley/Hasbro.

The aim of the game is to get 4 chips of a single color in a straight line (horizontal, vertical, diagonal). The opponent tries to achieve the same while blocking the other's attempts.

The game board is vertical with 7 columns and 6 rows:

0123456
5
4
3
2
1
0

Players take alternating turns dropping their chips in one of the columns (0...6). The chips fall down the column until either the bottom (row 0) or another chip stops them.

The winner is the first player to get four of his chips in a straight line (vertical, horizontal, or diagonal).

Base Task - Easy

  • Create a program that allows 2 users to play a game of Connect Four.

  • In it's simplest form, each player enters a number from 0 to 6 to drop a chip in the respective column.

  • The computer evaluates the board, checks and declares a winner.

  • For the base task, no computer player is required.

Optional Tasks - Varying Difficulties

  • Code computer players with varying strategies.

    • Random strategy: Computer drops in random slots

    • Defensive strategy: Computer tries to break player's chains

    • Agressive strategy: Computer tries to win

    • AI - MinMax pattern: Computer plays intelligent with the minmax pattern (theoretically Computer plays a "perfect player" - plenty resources on the web.

  • Save and Resume functions

  • Win/lose statistics

  • Different Board sizes (rows, columns) with different winning conditions. Minimum size is classic Connect four, minimum winning condition is four in a row.


r/ProgrammingPrompts • • Feb 03 '26

No AI Prompts

12 Upvotes

This subreddit is not for Prompt Engineering, Vibe Coding, AI Prompting.

This is a place for little programming challenges or simple project ideas.


r/ProgrammingPrompts • • Apr 27 '20

We arelooking for help in creating a corona tracking app

12 Upvotes

Hey everyone!

Under the hackathon of the german Bundesregierung we crated a BLE Tracking app.

We wanted to do this open source and as a community driven project, but until now this was not really succesfull. Iam a first grad student and dont have the time nor the knowledge to realize this alone.

https://github.com/MoritzGan/TrackCovidClusterAndroid

Iam know looking for People that maybe want to join forces and create a really open source and privacy preserving tracking App.

If you are interested and know android dev/ java/kotlin/ swift or ionic/ angular please pm me :)

Everyone is welcome!


r/ProgrammingPrompts • • Mar 29 '16

[Easy] Make a simple password generator

12 Upvotes

Make a password generator that generates a random password of desired length specified by user input.

For example:

Enter desired password length>> 7

hY@rSdA


r/ProgrammingPrompts • • Jul 16 '15

[Easy] Currency converter

12 Upvotes

Convert currency using command line arguments

Argument format should be currency amount newcurrency

E.g.

Convert USD 100 GBP

Should convert 100 dollars into pounds and print the result

Must include a minimum of 3 different currencies

Bonus points: add another argument which takes a filename and saves the result in a text file of that name


r/ProgrammingPrompts • • Mar 18 '15

[Easy]Mathematical simulation: Shooting PI

12 Upvotes

In honor of the PI Day of the century (but a bit late), I want to present an unorthodox, but mathematically correct version of estimating PI.

PI is the most commonly known constant. It is the ratio between the circumference and the radius of a circle.

PI is also an irrational number. It has (theoretically) infinite digits.


Let's get shooting.

Imagine a square with a constant length. Inside this square a quarter of a circle is drawn with the center of the circle at the bottom left corner and the radius equal to the length of the square.

See this Wikimedia image

The mathematical definition of a circle is:

A circle is the set of all points in a plane that are at a given distance (r) from a given point, the centre.

Using the above we can create our approximation:

  • We fire a number of shots on the rectangle. (Assume that all shots hit the rectangle, no misses).

  • Each shot has a random x and a random y coordinate in the range 0 to length inclusive.

  • Calculate the distance from the bottom left corner (x = 0, y = 0) by using the Pythagorean theorem: d = square root of (x^2 + y^2)

  • Check if the calculated distance d is less than or equal to the length of the square.

    • If the distance is less or equal (the shot is inside the quarter-circle), increment a counter.

  • Once all shots are fired, the ratio of hits to total shots equals to PI/4

  • Output the approximation by printing (hits/total shots) * 4.

This approximation uses a mathematical model called Monte Carlo Method.

The program should:

  • Ask for the length of the square

  • Ask for the number of shots to fire

  • Perform the calculation as outlined above

  • Output the result

  • Ask if another simulation should be run. If so, start from the beginning.

All programming languages are allowed.

Have fun shooting


Challenges

  • Display the results graphically, as in this image (same as linked above).

  • Allow the user to run a series of tests with varying lengths and numbers of shots.


r/ProgrammingPrompts • • Jan 11 '15

[Game Component] - Card Game Components

12 Upvotes

This will probably be my last prompt for a couple of weeks as my job requires me to travel and I don't know if I will have an open internet (or any internet at all) at my travel destination/job site.


This time it's again about re-usable game components.

Part 1: Playing Card

Create a single playing card for card games.

  • Standard Playing card:
    Each playing card has a

    • Suit (Hearts, Clubs, Diamonds, Spades)

    • Name (2,3,4,5,6,7,8,9,Jack,Queen,King,Ace)

    • Numeric Value (number cards have their numeric value equal to their name, Jack, Queen, King have each a value of 10, Aces can be either 10 or 1 depending on the setting of acesHigh)

    • acesHigh value that determines if the Aces count as 1 (acesHigh = false) or as 10 (acesHigh = true)

    • sequential value (from 0 to 12 where the "2" card has sequential value 0 and the Ace has sequential value 12)

    • optional a graphical representation of the card

    • optional a Unicode representation of the card in the form <suite symbol><card name> (the unicode values for the suits are: Spade: U+2660 (hex), Heart: U+2665 (hex), Diamond: U+2666 (hex), and Club: U+2663 (hex), the values can also be found at Wikipedia - Playing Cards in Unicode

    • textual representation in the form "<name> of <suite>" (e.g. "2 of Hearts", "Ace of Spades")

  • optional Joker:

    • By default, the Joker has no suit and no value. It only gets the suit and value assigned when the card is played.

  • Custom Playing card:
    Custom Playing cards can have:

    • a Color (as text) - similar to suite

    • a Name

    • a numeric value

    • a sequential value

    • optional a graphical representation of the card

    • textual representation in the form "<name> of <suite>" (e.g. "2 of Hearts", "Ace of Spades")


Part 2: Deck (general Storage for a number of cards)

Create a deck (discard pile, player hand) of playing cards for card games

  • A deck can hold an arbitrary number of Cards (either Standard cards, or Custom cards).

  • The deck should provide methods for adding to and removing cards from the top of the deck.

  • The deck should provide a method for shuffeling

  • The deck should provide medhods for direct card access (based on index) - adding and removing

  • The deck should provide a method to randomly pull any card from the deck


Optional - Part 3: Shoe (storage for a number of decks)

In Casino games, like Blackjack, usually multiple decks of cards are used.

The Shoe should be able:

  • To hold any number of identical decks

  • To remove the to card of the shoe

  • To shuffle the whole shoe


If anybody has further ideas, please comment and I'll add them.

Happy coding!


r/ProgrammingPrompts • • Mar 08 '14

Decimal to Roman numeral

12 Upvotes

A program that will output a roman numeral from a decimal.


r/ProgrammingPrompts • • Mar 08 '14

Reverse Checkers AI

12 Upvotes

The rules of reverse checkers are:

if a player can make a jump, he must make that jump. If there is a double jump, he must make the double jump.

Try and create the game. Now try adding an AI to play the game. If you're not familiar with building AI's, this would be a great chance for you to get some experience, but it'll take some reading. The go to solution algorithm is the minimax algorithm, which looks at your best moves and your opponents best moves. http://en.wikipedia.org/wiki/Minimax

To increase efficiency implement alpha beta pruning. http://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning

Have fun. It was a fun project for me.


r/ProgrammingPrompts • • Aug 07 '19

Fizz Buzz Challenge. Except you can only use 1 line of code.

11 Upvotes

Here is my submission using the R programming language

code:

replace(replace(replace(1:100,grepl(0,1:100%%3),"FIZZ"),grepl(0,1:100%%5),"BUZZ"),grepl(0,1:100%%3)&grepl(0,1:100%%5),"FIZZBUZZ")

output:

 [1] "1"        "2"        "FIZZ"     "4"        "BUZZ"     "FIZZ"     "7"        "8"        "FIZZ"     "BUZZ"     "11"      
 [12] "FIZZ"     "13"       "14"       "FIZZBUZZ" "16"       "17"       "FIZZ"     "19"       "BUZZ"     "FIZZ"     "22"      
 [23] "23"       "FIZZ"     "BUZZ"     "26"       "FIZZ"     "28"       "29"       "FIZZBUZZ" "31"       "32"       "FIZZ"    
 [34] "34"       "BUZZ"     "FIZZ"     "37"       "38"       "FIZZ"     "BUZZ"     "41"       "FIZZ"     "43"       "44"      
 [45] "FIZZBUZZ" "46"       "47"       "FIZZ"     "49"       "BUZZ"     "FIZZ"     "52"       "53"       "FIZZ"     "BUZZ"    
 [56] "56"       "FIZZ"     "58"       "59"       "FIZZBUZZ" "61"       "62"       "FIZZ"     "64"       "BUZZ"     "FIZZ"    
 [67] "67"       "68"       "FIZZ"     "BUZZ"     "71"       "FIZZ"     "73"       "74"       "FIZZBUZZ" "76"       "77"      
 [78] "FIZZ"     "79"       "BUZZ"     "FIZZ"     "82"       "83"       "FIZZ"     "BUZZ"     "86"       "FIZZ"     "88"      
 [89] "89"       "FIZZBUZZ" "91"       "92"       "FIZZ"     "94"       "BUZZ"     "FIZZ"     "97"       "98"       "FIZZ"    
[100] "BUZZ"