/r/programmingchallenges

Photograph via snooOG
  • Project Euler is a good site that comes highly recommended by the community here.

  • For quick, daily challenges, check out /r/dailyprogrammer

  • Got a link to a good programming challenge? Got a programming challenge you've written yourself? Post it here!

  • This subreddit is for programming challenges. Got a link to a good tutorial? You should try posting it in r/learnprogramming instead.

  • Unless it's an integral part of the challenge, please try to stay language-agnostic. It helps reduce the "help me with my programming chores" vibe. This subreddit is not a place to post your programming homework!

  • If a post does not appear, message the moderators so we can rescue it from the spam filter.

  • Got a suggestion for r/programmingchallenges? Let me know.


In the meantime, you can try trolling your compiler:

  //author: krum
  template<int x>
  struct Test
  {
     static void foo()
     {
        Test<x+1>::foo();
     }
  };


  int main()
  {
     Test<0>::foo();
  }

/r/programmingchallenges

12,064 Subscribers

0

Help needed with Reflection Problem. Urgent, please help 馃槶馃槶

anyone please help me with this馃槶 馃槶

i am giving an exam for a job, and i have been trying to solve it , but i cant do it. Today is the deadline for the submitting the exam. I tried with chatgpt and other ai tools many times, still its is giving wrong and i searched in the internet i couldn't find the solution, people were just posting the same question in the internet and none of them were answered.

Please help,i really want to get this job.

here is the question:

https://preview.redd.it/v6v0v0rieymd1.png?width=551&format=png&auto=webp&s=5274cdda174fbfeccd6a6f2c75c9c424ee9c4925

As shown in the diagram, a laser light originates vertically from point 'A' and must reach point 'T'.
There are two rotating mirrors that adjust their angles based on a given relationship with theta.
Assume that the mirrors are infinite in length. The rotation point of the first mirror is directly above A.
The values for x and t are provided in the input file. You need to write a code to determine the theta values聽that will allow the light to reach point T after reflecting off the second mirror.

(C/python)

https://preview.redd.it/i1ixyhgpeymd1.png?width=751&format=png&auto=webp&s=efff84f592510caae13b88351070858a5465b960

Sample Test Result:

Input

2

2

Expected Output

54.91

4 Comments
2024/09/05
08:41 UTC

2

Collection of challenges to practice Go

Hey everyone, I'd like to share with you a project I am maintaining for the past few years where I post challenges to solve in Go. It includes DSA but also other types of problems.

The idea is to strive for the post performant solution and submit it through a Pull Request. Each challenge includes a test and a benchmark.

Feel free to go and solve some or add a new challenge.

https://github.com/plutov/practice-go

0 Comments
2024/07/11
20:42 UTC

4

Encrypting program.

https://preview.redd.it/nzl0vny7ehad1.png?width=919&format=png&auto=webp&s=a432f80b8c292577463034198f0bb22a751cdfb9

I made a little program that encrypts and decrypts messages, how do you like it?

If someone is interested in or just have too much time you can try encrypt this:
415832ylr97porp32tx97t32siht3297dih32ot32t97grof32tsuj327332ro32noitpyr99n9732ym3297kor9832uoy32sne97m32teht32siht32gnide97r3297re32uoy32f73

0 Comments
2024/07/04
10:50 UTC

9

Help with a collective sum

Hi! I'm currently struggling with a program in C++ I'm writing. My professor is having us write a program that does two things: 1. ask a user for a positive number, and a negative one to end the program and 2. the sum of all the numbers that were input by the user. I have the first part, but I don't get how to have the program add up all of the positive integers? The number of inputs could be anything, so assigning variable names and using those would probably take way too long and make the code mucky. I've already Googled the issue and didn't find anything specific to what I'm doing. Thanks in advance!

2 Comments
2020/02/20
01:53 UTC

11

Is there any book which contains all the questions to practice from beginning to hard level?

3 Comments
2020/02/19
10:16 UTC

4

Help with a simple java challenge

Hello all,my instructor gave me this Java challenge to solve. I have a problem understanding both the problem and what the code must do, especially what is the input, I hope you guys can give me advice and help. The challenge uses java, but its fine if you guys can explain it with other codes.

The problem

Imagine a family: father, mother, daughter, 3.5 years old, and an infant (baby, 8 months). The family lives at a home with 5 rooms and in each room, there are 5 boxes. After the father comes back from the work, all the family members do not have any energy whatsoever, except the baby who sucks the energies out of mom and dad by cuddling them!

After the dinner, the father has 100 energy points, the daughter has 100 energy points, the mother has still no energy, but she can walk from room to room.

Now, the daughter loves to pay hide and seek with her father. At 18:00 they start playing hide and seek with following rules:

路 The family come to room 1 and father starts counting down

路 The daughter can go any room and hide in one of the boxes in any room

路 The mother takes baby and she goes to a random room

路 The father searches every box from room 1 and if he cannot find the daughter he goes to other consecutive rooms and continues searching the daughter

路 Searching a box takes 1 (one) energy point from the father and lasts a minute, except following case:

路 If the mother goes any room number with smaller than or equal to that of daughter鈥檚 room number (say, mother goes to room 2, the daughter goes either room 2,3, etc), the mother hands the baby to the father during his search. This time after the dad starts holding the baby, he loses 2 energy points for every box search after he has taken the baby.

路 Then, when the father finds the daughter he come backs to room 1 and leaves the baby there and immediately mom picks the baby and she goes another random room in the second round of game.

路 If the daughter sees that father holds the baby for 3 times, the daughter starts crying and game over

路 If the father has less than 0 (zero) energy, this also causes of game over

The challenge is to implement this little hide and seek game.

You have to calculate how many minutes this game takes

You have to calculate father鈥檚 energy in the end

Programming Tips:

Write a Person Class with attributes name, which will be replaced with father, mother, etc., energy, room number

Write related get set functions, crying, yelling, hiding functions

Write Hide and Seek Game Class: To simulate the game in the main

Example Output:

Game started at 18:00

Mother at room 5

Daughter at room 1

Daughter is hiding in the box 4

Mother at room 1

Daughter at room 5

Daughter is hiding in the box 1

Mother gave the infant to Father

Mother at room 2

Daughter at room 3

Daughter is hiding in the box 3

Mother gave the infant to Father

Mother at room 1

Daughter at room 2

Daughter is hiding in the box 2

Mother gave the infant to Father

Daughter starts crying please stop the game

Father's left energy is 4

Father and Daughter played 45 minute(s) hide and seek

2 Comments
2020/02/17
08:13 UTC

4

a convoluted problem

I go to a school and I'm the only tech competent person in it, anyway the school has a small stationery shop for each grade. the school cannot justify refusing stationery to students if they need it for the day so it works on a system of IOUs. I have to write a program that will work on laptops with python 3.6 and no access to command line, admin or internet downloads. The program must log the date people start a debt, pay back an amount of money and also must add up debts if they take out more than one debt. HELP ME FOR THE SAKE OF JESUS MARY AND JOSEPH I HAVE NO COMMAND LINE

3 Comments
2020/02/10
21:14 UTC

2

Solve this 16 turn 2 player complete information game

This is perhaps a bit bigger challenge than usual, but bear with me.

The game in question is my creation. It is a game where each player tries to build the longest possible snake. Video rules + example game (3:17) are here: https://youtu.be/NY7ib0mR_ow.

Rulebook and other resources here: https://drive.google.com/open?id=1OufzCUiRhyPFdfWQSEt3PYjHNETfIqRq

The question is simple: who wins with optimal play from both players?


Some insight I have so far:

  • Possible move can be redefined as a move that
    • touches your snake or doesn't touch the enemy snake
    • doesn't create a triangle or Y shape of the same color
  • In early game, there are about 1000 turn possibilites, because there are 7 pieces to choose from, a piece can have up to 12 orientations (6 rotations and 2 reflections) and there are 91 spaces on the board
    • Whole game tree has roughly about 10^25 branches
    • This makes traditional algorithms such as minimax very ineffective
  • There was an idea of evaluating position by considering maximum potential lengths of players' longest snakes, but I haven't been able to find an effective algorithm for that which would effectively solve all edge cases
  • Making the first move not to center but to space adjacent to center allows red player to reach the edge of the board with a single piece. This may be the reason making the first turn to the center may not be the optimal move
  • I recommend using this resource for working with hexagonal grids. Particularly chapter on rotation.

Which algorithm would you choose? Do you think some machine learning is feasible? What is effective for searching such a broad game tree?

0 Comments
2020/02/04
02:23 UTC

7

Jumping On The Clouds HackerRank Solution

0 Comments
2020/02/02
18:40 UTC

1

Backbone Architecture for Simulation Platform

Hi guys,

I'm investigating making the simulation environment that we use in our robotics company more modular and distributable for cluster (or multicore) execution. Basically I'm trying to come up with a solid backbone that multiple programs/simulators can send their info to and this info will be passed on to the relevant modules. You can think of this as an alternative to ROS but with some additional requirements due to the cosimulation nature and speed.

- 3d graphics engines like Unity/Unreal will be interfacing to the backbone by sending 3d world information.
- Since we envision to have different simulators/programs running at the same time and communicating, need to come up with a standardized messaging protocol like protobufs.
- We dont have real time requirements, but actually, we should be able to run things faster than real time.
- We would like to be able to distribute different processes in this system to multiple cores on the same PC or on a cluster.
- The message interface should be easy to maintain due to it's frequently changing structure.
- The status of the list of programs and the information that they produce should be easy to monitor in a centralized way.

So far I have investigated ROS, ROS2, DDS and microservices. I would be glad to hear your experiences with such systems and their suitability for this architecture, and of course the alternatives please.
I'm not a CS guy by nature, but due to our need in the team, I would like to take up this challenge.

THanks in advance

1 Comment
2020/02/02
17:34 UTC

1

#JavaScriptJanuary 2020 - Entire Playlist

1 Comment
2020/01/31
14:19 UTC

9

How do developers annotate design and implementation choices?

As software engineering research teams at the University of Sannio (Italy) and Eindhoven University of Technology (The Netherlands) we are interested in investigating the protocol used by developers while they have to annotate implementation and design choices during their normal development activities. More specifically, we are looking at whether, where and what kind of annotations developers usually use trying to be focused more on those annotations mainly aimed at highlighting that the code is not in the right shape (e.g., comments for annotating delayed or intended work activities such as TODO, FIXME, hack, workaround, etc). In the latter case, we are looking at what is the content of the above annotations, as well as how they usually behave while evolving the code that has been previously annotated.

Filling out the survey will take about 5 minutes. Click the link below to fill out the survey:

https://forms.gle/NZYsQr2vUFmH9DQY8

1 Comment
2020/01/31
11:44 UTC

2

VS 2019 community on chromebook

How can i install visual studio 2019 community on chromebook.

3 Comments
2020/01/31
01:09 UTC

0

Website design help

I am looking for help to design a website where I can send the link to a customer they fill in the required boxes and hit apply and it will send all the info to me or load onto google calendar. Is this possible?

5 Comments
2020/01/29
20:39 UTC

1

JavaScript Promises In 90 Seconds #JavaScriptJanuary

1 Comment
2020/01/26
15:39 UTC

2

Need help with RegEx 101 quiz

Check if a string contains the word

word

in it (case insensitive). If you have no idea, I guess you could try

/word/

I honestly have no idea how to attempt this

1 Comment
2020/01/23
18:34 UTC

0

A job in programming

I am not so great in communication skills. How big of a part does communication play in a programming job? I know I should work on this.

2 Comments
2020/01/23
10:40 UTC

1

Open Source Search Engine

I'm want to make an all in one website (for fun) and I want to add a search engine to it such as google, anyone know an open source search engine I could use. For certain reasons I can't have it open a new tab (so no Google custom search) but anyone no an easy to use/setup search engine to add to websites.

3 Comments
2020/01/23
03:08 UTC

5

Motion UI - User Interface Animation (2020)

2 Comments
2020/01/21
21:14 UTC

4

How to create a simple random 3D terrain in python?

4 Comments
2020/01/18
16:37 UTC

1

Common Child HackerRank Solution

0 Comments
2020/01/18
15:44 UTC

7

JavaScript Array Mutator Methods #JavaScriptJanuary

1 Comment
2020/01/17
14:06 UTC

2

How could you programmatically generate a list of the most "interesting" words in the English Language? What would your conditions for 'interestingness' be?

3 Comments
2020/01/15
05:35 UTC

9

JavaScript Array Map Method In 90 Seconds #JavaScriptJanuary

4 Comments
2020/01/14
15:10 UTC

7

Learn Git with us using the multiplayer git challenge game

Hi guys, I have created a git game where people can compete against each other using the git knowledge. I am beta testing the proof of concept so if you would like to try and play, create the account here and use the link to join challenge and let's see who is better ;).

https://www.bettercoder.io/a/test-runs/job-interview-questions/challenge/link/2780c04d-3ee3-49de-b329-380392d1b0d3

The sign up works only from the menu, I'm working on fixing the flow...

0 Comments
2020/01/13
00:18 UTC

7

Array Manipulation Hackerrank Solution | Difference Array | Range Update...

1 Comment
2020/01/12
15:54 UTC

Back To Top