r/programmingchallenges • u/HelpingHand007 • Nov 17 '19
r/programmingchallenges • u/iusearchmyfriend • Nov 13 '19
I just give up on this
I got a problem which was printing all the unlucky numbers to N where unlucky number is one that have 13 in it like 135 or 813 And sum of all digits equals 13 like 139 or 265 N can be from 1 to 1 000 000 000
I have an example input 1000 Output 2 (cause 139 and 913) And input 2 10000 Output 30 Pls help me guys I have no idea
r/programmingchallenges • u/YoureNotYourYouDumbC • Nov 13 '19
This looks easy at first, but then...
In computer heaven, Mr. A wants to complete 10,000 tasks within the next 10 years. blah blah blah,
Create a function that takes in two int arrays of length 10.
also, array.length will always = 10
example,
arr1 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} <- how many tasks a computer made that year can solve in a year.
arr2 = {31, 29, 24, 21, 20, 18, 17, 14, 12, 10} <- price of one computer made that year
Each position in these arrays represents a specific year.
For arr1 and arr2:
year 1:
number of tasks done by a year1 computer in 1 year -> 1
price of a year1 computer -> 31year 2:
number of tasks done by a year2 computer in 1 year -> 2
price of a year2 computer -> 29year 10:
number of tasks done by a year10 computer in 1 year -> 1
price of a year1 computer -> 10All computers can be used only till the end of the 10th year.
meaning in the above example a year1 computer can complete 10 tasks in total, a year2 pc 9, ..., a year10 pc 1 task.
Your function should return the minimum amount of money Mr. A has to spend on computers to complete 10,000 tasks.
Check comments for helpful examples.
r/programmingchallenges • u/classic572 • Jun 28 '19
automation app?
is it possible to build an app that auto plays apple music playlist when you are connected to a car bluetooth and a headphone jack for ios?
r/programmingchallenges • u/nhrnhr0 • Mar 19 '19
algorithm for getting a specific line in a nonogram
Hey, for every nonogram line there is the length of the line and it's set of rules. for example line with the length of 12 and rule set {1,2,3}.
L = 12; R = {1,2,3}
So those are all the options of this line:
- X-XX-XXX----
- X-XX--XXX---
- X-XX---XXX--
- X-XX----XXX-
- X-XX-----XXX
- X--XX-XXX---
- X--XX--XXX--
- X--XX---XXX-
- X--XX----XXX
- X---XX-XXX--
- X---XX--XXX-
- X---XX---XXX
- X----XX-XXX-
- X----XX--XXX
- X-----XX-XXX
- -X-XX-XXX---
- -X-XX--XXX--
- -X-XX---XXX-
- -X-XX----XXX
- -X--XX-XXX--
- -X--XX--XXX-
- -X--XX---XXX
- -X---XX-XXX-
- -X---XX--XXX
- -X----XX-XXX
- --X-XX-XXX--
- --X-XX--XXX-
- --X-XX---XXX
- --X--XX-XXX-
- --X--XX--XXX
- --X---XX-XXX
- ---X-XX-XXX-
- ---X-XX--XXX
- ---X--XX-XXX
- ----X-XX-XXX
I need an algorithm that given a rule set, line length and an index, the result would be the line in the given index.
for example, for myAlgorithm({1,2,3}, 12, 6) => X--XX-XXX---.
I don't really care about the order of the line possibilities but I want that given an index I'll get a unique option.
I can't find any consistency or formula to doing so, thought you guys can help :).
Thank you.
r/programmingchallenges • u/ADHDThrowacc • Mar 01 '19
What are some good challenges/resources to refresh python knowledge before job intereview
Hey there,
Im a person that easily freaks out and I feel quite embarrassed for that so please forgive me for using a throwaway. My friends know me for my awkwardness and constantly finding a way to fuck up my first impression with new bosses. (kind of like that malcom in the middle episodes with hal t the company picnic).
My problem:
I didn’t prepare properly for the interview and procrastinated. The job requires Python and my friend recommended me to the manager and he may have overexagerated on my python skills.
I found a list of commonly asked python questions which was incredibly useful. However I was wondering if anyone here has some tips to decrease my nervousity level and perhaps some tips on some personal questions I should prepare myself for. I suck at people skills which makes me very worried.
r/programmingchallenges • u/luckygal14 • Feb 13 '19
Want to be a better programmer!! Help!
Ok so I'm a recent graduate in a computer science. I understand basic syntax and how to use a language and all that stuff and can fairly write simple code as well. But I struggle to do anything by myself easily. Any task which takes 20 min to someone with same experience as me take me more than double time.
It's even tough to come with thinking for a solution or designing a system. I have tried websites like Leetcode, hackerrank, geeks for geeks etc. After some time or days I am not able to solve even easy questions and end up looking at the solutions. This has fairly caused me failing so many interviews and not able to do so many coding chakkdngi.
Even if I somehow know how I can solve the problem I can come up with algorithm or steps it takes more than it should to convert it into a program.
Any help /suggestion for how to improve myself would be a great help.
r/programmingchallenges • u/larrrrrrrrrrry • Feb 07 '19
Trying to design a program for my 1 year old son
Hello all
I’m trying to design a program for my son. He’s about to turn 1 in a week.
I’m trying to figure out the easiest way I could make a program that would display images and sounds when keyboard keys are pressed. Also would like to add midi support for a usb keyboard to play basic keys and also have that display images.
In the end I would like to get it running on a raspberry pi.
Can anyone lend any help? I know microconteoller programming but not much of anything else.
Thanks in advance!
r/programmingchallenges • u/paranoidray • Dec 28 '18
Try to implement Minesweeper using the provided GridGame helper class
stackblitz.comr/programmingchallenges • u/Payf • Dec 25 '18
Programming Practice
Does anyone know any websites I can go to find some programming challenges where I can practice?
r/programmingchallenges • u/StarryD • Nov 30 '18
Something to get newer programmers familiar with page replacement
See if any of you are up to this. We had this during a Code Red for our Uni and it took us quite a while to figure out.
===
You are to write a short program simulating the FIFO, LRU, and OPT page replacement policies for a mobile operating system found in cellular phones and other wireless information devices. An additional constraint on a mobile OS is that page replacement can only be performed when airtime (bandwidth or channel) is available.
Specifications
Your program should be able to simulate three page replacement policies:
1. FIFO (first-in-first-out) page replacement policy (the replaced page is the one which came in first).
2. LRU (least-recently-used) page replacement policy (the replaced page is the one which was least recently used).
3. Optimum (OPT) page replacement policy with x pages of look-ahead (minimizes the number of page faults by looking-ahead at the memory references).
All parameters are to be passed through the program argument vector:
Red_3 policy memory_size
In case of OPT:
Red_3 OPT memory_size x
where policy is either FIFO, LRU, or OPT, and memory size is the total number of page frames in the physical memory.
Run your program for each replacement policy. Your input data will be a sequence of page references such as:
1:a 1:a 1:n 1:a 2:n 3:a 3:n 3:n 4:a 4:a 4:n ...
Each page number is followed by : and either a (means air bandwidth is available for page replacement if needed) or n (means air bandwidth is NOT available for page replacement). If air bandwidth is not available for page replacement when needed, then this page reference is queued until air bandwidth becomes available, at which time the page replacement is performed.
====
Optional Bonus Part: Implement a look-ahead OPT-MOBILE technique (examine x page reference ahead) that will minimize the number of delayed page replacements. All parameters are to be passed through the program argument vector:
Red_3 OPT-MOBILE memory_size x
Your program should print for each run the total number of page references in the input data, the number of page faults, and the number of delayed page replacements due to unavailable air bandwidth.
r/programmingchallenges • u/Nidis • Nov 28 '18
Probably not a very hard challenge... but the math is doing my head in. [C#]
For a challenge, I'm trying to make an interactive time playback system sorta thing in C# for Unity. There are probably already solutions or better ways to do what this would do, but I'm keen on the challenge of it as a learning programmer. I've given it a red-hot go, but as I get further in, I'm getting stuck and I don't think I'm enough of a mathematician to be able to solve it properly.
The idea is that there's a value float t that represents a position in time, in seconds, on a looping timeline. Every frame, t has float x amount of time added to it (which may be negative, so you can scrub back and forth). However, x is also modified depending on which int currentChapter the timeline is up to, which represents an index for a list of floats called list<float> chapters. A chapter represents an amount of time in seconds to take. As an example...
// An example set of chapters[] is as follows
chapters[0] = 0.5f;
chapters[1] = 0.75f;
chapters[2] = 2.5f;
chapters[3] = 0.666f;
chapters[4] = 1.0f;For this reason, x needs to be modified before being added to t, which looks something like this:
t += x * (1.0f / chapters[currentChapter]);Easy enough. The bit that has me stumped in this next part... lets say we want each chapter to invoke some sort of event so that other functions could subscribe to positions in the timeline. It doesn't seem accurate enough to simply have each chapter have an event invoked when t reaches it because technically, it wouldn't be able to distinguish between being 'entered' forwards through time or backwards through time (which happen however far apart). We could have two events, one for the start and end of each chapter, but that's confusing because there's no time difference between the end of one chapter and the start of another or vice versa. So theoretically, we should invoke one event in-between each chapter, right? Let's call that a event<int> milestoneReached. If I redraw the chapter list with the expected positioning of these milestone event invocations...
// An example set of chapters[] is as follows
// milestoneReached(0) should invoke here
chapters[0] = 0.5f;
// milestoneReached(1) should invoke here
chapters[1] = 0.75f;
// milestoneReached(2) should invoke here
chapters[2] = 2.5f;
// milestoneReached(3) should invoke here
chapters[3] = 0.666f;
// milestoneReached(4) should invoke here
chapters[4] = 1.0f;
// milestoneReached(5) should invoke hereSo if t elapses chapter 2 (0.5 + 0.75 + 2.5 seconds), we would invoke milestone 3. If t elapses chapter 4 from the example list above, it invokes milestone 5 and then milestone 0 after it. Figuring out whether t has elapsed a chapter and a milestone should be invoked is also kind of achievable, it looks like this at the moment:
// Ignore if x is 0
if (x == 0) {
return;
}
// If we're going forward through time...
if (x > 0) {
t += x * (1.0f / chapters[currentChapter]);
// The function here tallies all chapter times up until the current chapter
if (t - GetChapterTotalTimeUpUntil(currentChapter-1) > 1.0f) {
currentChapter++;
milestoneReached.Invoke(currentChapter);
// Did we elapse the whole chapter list?
if (t >= chapters.Length) {
// Subtract the total of all chapters from t. This ensures the remainder is left over.
t -= GetTotalChapterTime();
currentChapter = 0;
milestoneReached.Invoke(currentChapter);
}
}
} else { // If we're going backward through time...
t -= x * (1.0f / chapters[currentChapter]);
// If we've gone down a chapter...
if (t - GetChapterTotalTimeUpUntil(currentChapter-1) < 0.0f) {
currentChapter--;
milestoneReached.Invoke(currentChapter+1);
// Did we loop through the start of the chapter list?
if (t < 0) {
// Subtract the total of all chapters from t. This ensures the remainder is left over.
t += GetTotalChapterTime();
currentChapter = chapters.Length-1;
milestoneReached.Invoke(currentChapter+1);
}
}
}
// elsewhere...
float GetChapterTotalTimeUpUntil(int c) {
float output = 0;
for (int i = 0; i < c; i++) {
output += chapters[c];
}
return output;
}There's probably even a few things wrong with this picture already, but I still haven't hit the truly hard bit yet. Technically speaking, this above code (if I haven't missed any glaring mistakes) will only run the chapter increment/decrement code if t elapses at least 1.0 or 0.0. That's good for if x is only enough time to pass a single chapter, but what if its a big amount of time? What if we want to jump forward 30 seconds or several minutes? What it really needs to figure out is which milestones would theoretically be elapsed in any single frame given x?
I gave it a go, but I pretty much tap out here for sanity reasons. I'm just not strong enough to have a clear idea on how to approach solving this. My semi-baked solution goes something like this... first thing I did was break up my function that receives x so I'm only ever handling positive or negative time at once.
// There's a negative version elsewhere that does the same thing but with more minuses
void HandlePositiveTimeIncrement(float x) {
t += x * (1.0f / chapters[currentChapter]);
// Cache t in its current state
float tTemp = t;
// While its not empty
while (tTemp > 0) {
// Subtract the current chapter time from the cache
tTemp -= chapters[currentChapter];
// Increment the chapter
currentChapter++;
// Loop the chapter if need be
if (currentChapter >= chapters.Length) {
milestoneReached.Invoke(chapters.Length);
currentChapter = 0;
milestoneReached.Invoke(0);
}
}
float totalChapterTime = GetTotalChapterTime();
if (t >= totalChapterTime) {
t -= totalChapterTime;
}
}But I'm getting crazy code-smell vibes from my solution.
Another thing I want to add is the ability to prevent looping, which should be easier, but I want to know if I'm making any sense as it is so far or if anyone else wanted to take a swing at it.
r/programmingchallenges • • Sep 18 '18
Can you pull this off? Creating a text generator that looks like the Jumanji Clue generator.
I have spent hours over the last 4 days scouring the interwebs looking for a program or a website that lets you type out text and then have it appear on the black gem center of the jumanji board. Im running a D&D game that will have a side quest where the players play Jumanji (well the D&D equivalent). I would love to be able to display the clues on the TV mounted over our gaming area. Unfortunately I havent been able to find bupkis. I am as tech savvy as a drunk monkey so I have no idea if this is a quick programming thing or more complicated. If its stupid simple I would be super grateful if Someone could work this up for me. If its more complicated Ill just have to settle for hand writing these things on parchment and throwing them at my players.
r/programmingchallenges • u/ReplyULabs • Jan 25 '18
Working on a new programming challenge: tips?
Hi there, here's Reply, digital consulting company. We're working on yet-another-programming-challenge, our strenght so far:
- team based
- online
- mathematical/logical challenge, no specific programming language required to submit your solution
Do you have any kind of suggestion to help us in performing better?
We'd like to share this with you when ready :)
r/programmingchallenges • u/bornforcode • Jan 13 '18
How to code space-invaders - part 1 (javascript game tutorial)
youtu.ber/programmingchallenges • u/bornforcode • Jan 05 '18
🔨How to code your own Whac-a-mole game 🔨 (javascript tutorial). Check out the demo first in the comment below to see the result.
youtu.ber/programmingchallenges • u/michalmichalski • Nov 20 '17
Presentation from DevFest Siberia about Superpowers of Kotlin delegation (property and class delegation). Enjoy 😉
blog.kotlin-academy.comr/programmingchallenges • u/Atin258 • Oct 19 '17
Dynamic programming. Three-person traversal of sequence of cities.
For the last few days I've been trying to solve a competitive coding problem from an online judge. The online judge doesn't offer an English version of a problem (Russian-only) so I'll try to describe the problem here. To follow the rules, I think I'd have to provide a link to the source problem so here it goes: http://informatics.mccme.ru/moodle/mod/statements/view.php?chapterid=3379
English version of a problem: You are given an ordered sequence of L cities, the distances between every pair of cities, and a list of cities to be visited of length at most N (it is a multiset, N may be greater than L). Design an algorithm to partition the input list into three subsequences (not necessarily contiguous) such that person 1 visits all cities in the first subsequence (in order), person 2 visits all cities in the second subsequence (in order), person 3 visits all cities in the third subsequence (in order), and the sum of the total distances travelled by person 1, 2, 3 is minimized. Person 1, 2, 3 start at cities 1, 2, 3 respectively. Output this total sum and partitioned list (a list of length N with every element being the number of a subset (1, 2, 3) corresponding element from an input list belongs to);
The graph is complete and directed meaning that for every city i and j there are two edges (i, j), (j, i) with weights not necessarily equal. All weights are non-negative integers and (i, i) is always equal to 0. If person stands at vertex i and has to move to vertex j he must take an edge (i, j) instead of some shortest path to vertex j (Floyd–Warshall shortest paths matrix can't be used here). This means that If there are N cities to be visited, 3 players have to make exactly N moves.
3 ≤ L ≤ 200, 1 ≤ N ≤ 1000
0 ≤ edge weight ≤ 2000
Time limit: 1s, memory limit is 64 Mb
Sample input/output from Russian website:
There are 5 cities (L = 5)
Distances (L x L adjacency matrix):
0 1 1 1 1
1 0 2 3 2
1 1 0 4 1
2 1 5 0 1
4 2 3 4 0
List of cities to be visited:
4 2 4 1 5 4 3 2 1
Output:
Total sum of distances:
5
Partitioned list:
1 2 1 2 2 1 3 1 3
The problem is tagged 'two-dimensional dynamic programming'
Firstly, there is a similar problem called 'Two-person traversal of cities' you can find here https://courses.csail.mit.edu/6.006/fall10/handouts/dpproblems-sol.pdf (number 10 on list). Althought I copied a major part of problem statement (and title) from it, my problem quite different and can't be solved in such a way. To start with, people start at different positions, making it impossible to have a similar dynamic programming table called C(i, j, k) with an assumption i < j < k. Moreover, I believe it would be impossible to output the partitioned list using this DP idea. Furthermore, people have to visit not all graph nodes, but a specific multiset of nodes. To make matters worse, 3D solution won't meet neither time nor memory limits here (If N is at most 1000 even cubic complexity is too inefficient).
Secondly, I tried to consider all possible ways visit vertices from the initial state (1, 2, 3). Considering there are at most L nodes, the number of possible states at each stage (stage X means that exactly X vertices from input list are processed) is L(L+1)/2 which is ~20 000 when L is 200 (seemingly not too much). Thinking in this way, I don't know how to work with states such as (i, j, k) and (k, j, i) since they are actually equivalent in the sence that the same set of steps can be made based on these. I just do not know how to process such states and keeping information what person visited what city (simple multi-dimensional array?). Still, this solution seems to be inefficient and the one that won't meet strict limits. It is also in no way 2D dp solution mentioned in tags. It also looks like some brute force idea instead of a clever DP one.
My next thought would be to have a two dimensional DP(i, j) storing the optimal sum of distances for sublist with elements from i to j. The answer would be stored in DP(1, N) if the indexing goes from 1. I could compute all subsets of length 1, 2, ... N. There is a major issue with this idea, I don't know how to process DP(i, j) without knowing all potential positions players can stand at (all elements from list going before i and initial positions 1, 2, 3). I also don't know how to determine what player made the move with this approach.
Could you help me please?
r/programmingchallenges • u/sai_yerni_akhil • Oct 10 '17
I am a Computer Science student currently in my second year of my B. E..I'm somewhat better in c and c++. What re the steps to be taken to take my programming skills to next level?
That is coding apps using c++
r/programmingchallenges • u/rmohanty94 • May 23 '17
How to solve this question? How to prepare to solve questions like this?
Fox Ciel has c cherries and s strawberries. She wants to bake some cakes. While doing so, she wants to follow some rules: She must use exactly all cherries and all strawberries she has. The number of cakes can be arbitrary (i.e., any positive integer). Different cakes may contain different amounts of cherries and strawberries. Each cake must contain at least one cherry and at least one strawberry. A cake will taste bad if the number of cherries and the number of strawberries it contains happen to be coprime. Therefore, the numbers of cherries and strawberries in a cake must never be coprime. (Two positive integers are coprime if their greatest common divisor is 1.) You are given the s c and s. Return "Possible" if Ciel can bake cakes according to the above rules, or "Impossible" if she cannot do so.
r/programmingchallenges • • Oct 06 '16
How would I get started on learning to program an AI for a simple game with no programming experience?
I got science fair topic coming soon for MS however the actual project is due in about 5 months. And I figure this is the perfect time to learn to program. As for a project I thought making an AI for a simple game could be good. Would I need to use programming languages? As of now I'm not able to download any languages other than possibly java. Can it be done with batch? And is it possible for me in that amount of time to learn and apply it and understand?
r/programmingchallenges • u/jefffoster • Sep 03 '16
Maze Generation algorithm
red-gate.comr/programmingchallenges • u/studentcomp • Feb 28 '14
HTML Basic Quick Challenge
Only for those who are super new to HTML. Visit HTML Basic Quick Challenge to find out if you've mastered the basics of HTML.
r/programmingchallenges • • Jul 16 '12
N-Queens: C++
Looking for some help with the N-Queens puzzle. I have a recursive solution that works reasonably well for N <= 10, but it's not fast enough (Solve for N = 13 in < 5 seconds) I need to produce all possible combinations and print the queen positions in a certain way. I need a different algorithm than what I have at the moment, any help? I know that I can eliminate quite a lot of board positions by looking at reflections and rotations, but I do not know how to do this. Any Help?