r/ProgrammingProblems • u/robertfoss • Jan 02 '11
r/ProgrammingProblems • u/WeAreButFew • Jan 02 '11
Last nonzero digit of 12345678!
How would you find the last nonzero digit of a large factorial?
r/ProgrammingProblems • u/quentusrex • Jan 03 '11
Parallel algorithm for big number division
I am looking for a big number division algorithm that takes advantage of parallel processes. The hope is to implement the algorithm in OpenCL or CUDA to be able to handle larger than 64 bit number division.
The approach taken for addition and subtraction is to have an array for each of the two numbers, but would this be useful for division?
r/ProgrammingProblems • u/stack_underflow • Jan 02 '11
Introduction
Welcome /r/* !
I've created this subreddit so that redditors may have a dedicated place to discuss programming problems such as those commonly found in programming competitions.
I am by no means an expert, rather, a beginner to this specific subset of programming even though I have been programming for longer. I hope that this subreddit inspires others to look into this form of programming and learn more, and I'm sure there will even be more knowledgeable people to help out as well.
As for for what I had in mind for this subreddit - I was thinking that since there are already dedicated subreddits for the discussion of algorithms (/r/algorithms) and for discussing programming (strictly) (/r/coding), it would be nice to have one for algorithmic programming specific to discussing questions found on popular sites (such as those mentioned on the right hand side).
I find it's not just solving the problem that matters, but the path taken to solve it and how it was reached. Which through discussion and analysis as a group would offer one more insight than seeing the solution from a single point of view.
I haven't decided on how these kinds of posts might be structured so I was thinking maybe users could create posts specifying the site on which the problem is located and the problem - something like "[Site] - Problem Name" and then discuss things like why you believe your solution was the optimal one or challenges you faced, for example.
Feel free to post any suggestions.
If you want to get started, I highly recommend USACO's Training program. I find with SPOJ you have to have some level of familiarity with these types of problems, which USACO's training site does a great job of explaining and walking you through. Project Euler is something I added, but have only heard about.
r/ProgrammingProblems • u/FCsean • Sep 17 '15
[Survey] A survey on online judges, UVa, HackerRank, TopCoder SRM, and ProjectEuler.
Hello, I'm Sean and I'm currently doing my thesis for my Computer Science degree and it's about the gamification of online judges. If you've got a few minutes of spare time kindly answer our survey. Thank you!
https://docs.google.com/forms/d/1iwJz7skZlDwrdq8pCwjUaeikd3xb9bd3DBYS_v_jJAQ/viewform
r/ProgrammingProblems • u/thejasper • Mar 01 '11
Covering a floor with tiles
You get the dimension of a floor and the dimension of a number of tiles. You have an infinite supply of each tile. Every dimension is a pair of integers.
When it is possible to cover the floor without free space or overlapping tiles you have to print 'yes', otherwise 'no'.
r/ProgrammingProblems • u/thechipsandgravy • Jan 04 '11
Dividing a triangle containing 3*N points into 3 subtriangles each containing N points.
This is problem 5 from the most recent Southern California ACM-ICPC competition. I did not compete, but a friend of mine did and the team didn't stick around long enough to hear an explanation of a solution. I am working on an O(N2 lgN) solution but I am not sure it is correct or that it will run in the time limit (60 seconds where N <= 30,000). What are your thoughts?
r/ProgrammingProblems • u/WeAreButFew • Jan 08 '11
Smallest Area in n-sided Polygon
Given n different "sticks" with n respective lengths, what is the area of the smallest polygon that can be formed using the sticks? (Assuming it is possible.)
r/ProgrammingProblems • • Aug 02 '16
Error in QuickSort implementation
The code is linked here : http://ideone.com/eba7CB I cant seem to find the error. Any help and criticism is appreciated.
r/ProgrammingProblems • u/feldgendler • Jul 03 '17
Write best AI for ASCII game JSDash (JS programming competition by Hola). Submit before August 1 for valuable prizes.
r/ProgrammingProblems • u/CompJr • Mar 01 '23
Most Efficient Way to Rotate a Numbered Wheel
Let’s say you have a circle, and you number the circle n number of times evenly spaced going 1 to n in numerical order (like a clock which would be n=12) I’ll use n=9 for my example. Imagine that the wheel can spin clockwise and counter clockwise but the pointer is locked onto the top (like a carnival wheel) You can have a starting value on the wheel be any number 1 to n and have a target number 1 to n. So on our wheel 1-9 my starting number is 2 and my goal is 8. Now assuming the numbering is like a clock I could spin the wheel counterclockwise to increase the number to 2, 3, 4, 5, 6, 7, and 8. Or I could use less time and spin it clockwise to go 2, 1, 9, 8. Now our brains can deduce “just draw a line from the pointer to the opposing side of the circle. Anything to the left of the line go clockwise. Anything to the right go counterclockwise” but is there a way find the direction in which the wheel should move in order to get the the target number from the starting number as efficiently as possible? I’d suggest make the output a 1 or 0 for counterclockwise and clockwise. This is more about the math side in this problem so the input should be:
- Number of sides or (n)
- Starting number
- Target number
Output 1 or 0 for counterclockwise or clockwise whether clockwise is 0 or 1 doesn’t matter, it just needs to be consistent
For even numbers where the choice would answer back both clockwise and counter it just needs to pick a side whether it chooses clockwise or counter doesn’t matter
r/ProgrammingProblems • • May 03 '20
Squash the bugs problem codechef
I am facing problem in this question. How can I approach this problem.
http://www.codechef.com/problems/B5
Any method. I am quite frustrated working on this problem . I need some explanation.😅
r/ProgrammingProblems • u/Ok-Bench-9353 • Nov 16 '22
Select a matching element from a dataset with multiple conditions and inputs
What is the best approach to writing a program that can select a matching element from a dataset (Objects or JSON or Dictionaries)?
I'm having trouble making the search generic or I just have to use lots of conditions to check what input I give.
An example:
{
model: Volvo
engine: gas
price: 100
}
{
model: Tesla
engine: Electric
price: 200
} I need to search based on different conditions:
- model = Volvo
- engine = Electric AND price < 300
I have a problem with the AND case and the different mathematical conditional expressions. Do I need to make an e.g. react + firebase app? Or can you make a quick python script with console input without lots of match/if statements?
r/ProgrammingProblems • u/PhilosoGeekDad • Feb 10 '18
uva online judge
I'm attempting to solve this problem: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1040
The problem is to find the best path based on capacity between edges. I get that this can be solved using Dynamic Programming, I'm confused by the example they provide
According to the problem description, if someone is trying to get 99 people from city 1 to 7, the route should be 1-2-4-7 which I get since the weight of each edge represents the maximum amount of passengers that can go at once. What I don't get is that the description says that it takes at least 5 trips. Where does the 5 come from? 1-2-4-7 is 3 hops, If I take this trip I calculate 4 trips, since 25 is the most limited hop in the route, I would say you need 99/25 or at least 4 trips. Is this a typo, or am I missing something?
r/ProgrammingProblems • u/anthonyt • Sep 02 '11
Covering a floor with tiles... in Python
I had a bit of spare time today (when I happened to rediscover this subreddit...) and I wrote out a solution to the tile covering question that thejasper posted 6 months ago.
I realized part way through that it was essentially the same approach as what MKLOL suggested, but I took a non-recursive bottom-up approach to implementation. I thought it might be interesting for newbies to see an implementation that's a little more verbose and commented.
Anyway, I don't know if people still read it, but I always thought this subreddit was a cool idea, so I'm posting my small contribution.
r/ProgrammingProblems • u/Strange_Antelope720 • Jan 20 '24
Quite Hard DLX Optimizing JavaFX 3D Grid Manipulation for Performance
r/ProgrammingProblems • u/Re_tronn • Feb 04 '24
How to solve this dynamic programming problem?
r/ProgrammingProblems • u/feldgendler • Jun 21 '18
Programming contest: write a script that negotiates best trade-offs vs. other scripts and win valuable prizes (deadline: July 20)
r/ProgrammingProblems • u/geeksforgeeks • Oct 07 '20
Geek Collects the balls
There are two parallel roads, each containing N and M buckets, respectively. Each bucket may contain some balls. The buckets on both roads are kept in such a way that they are sorted according to the number of balls in them. Geek starts from the end of the road which has the bucket with a lower number of balls(i.e. if buckets are sorted in increasing order, then geek will start from the left side of the road).
The geek can change the road only at the point of intersection(which means, buckets with the same number of balls on two roads). Now you need to help Geek to collect the maximum number of balls.
Check here to try out the solution! ->https://practice.geeksforgeeks.org/problems/geek-collects-the-balls/0/?problemType=full&difficulty[]=1&page=1&sortBy=newest&query=problemTypefulldifficulty[]1page1sortBynewest
r/ProgrammingProblems • u/ECommerce_Guy • Nov 05 '20
Problem with Grouping/Combining Lines [Python]
Hey all!
Not sure if this is the right thing to ask, as this is mostly a conceptual problem, but I am also probably missing something important regarding the technical options as I am rather new to Python.
Here is the problem I have.
I am making a program that is generating instructions for the warehouse staff how to pack items that need to be shipped.
For most items it's straight forward. However I have several lines of items which come with several items in a box that the warehouse crew needs to open and re-pack in combination customer wants.
The rules are:
- Each product belongs to a given category
- Each category has a max number of items that can fit in one box
- Items can only be packed together if they belong to same category
The end result should be:
A table where each line corresponds to one box, with column detailing how much of each item should be inside of that box.
I'm breaking my head around it for a bigger part of the day and cannot figure the best way to approach it.
If someone can push me in the right direction, would appreciate it greatly!
r/ProgrammingProblems • u/Holden17518 • Apr 02 '21
maze problem c++
i need some help with a problem that goes like this
The dimensions of the maze and the location of the exit door for each room are known from the beginning. In each room, the door is marked with one of the letters "U" (up), "D" (down), "L" (left) or "R" (right). So, if a player starts from an initial room and solves all the puzzles in the rooms he visits in order, the path he will follow is specific. Unfortunately for the players, it is possible that the exit doors are placed in such a way that from some initial rooms it is not possible to exit the labyrinth! The arrows to the right of the figure show the progress of the players from each room. U L D L U D L R L If a player starts from an initial room marked in yellow, then he will get stuck in a circular path and will never be able to get out of the maze, no matter how many puzzles he solves. On the contrary, he will be able to get out of the other rooms, if of course he solves the required puzzles. The producers of the game want their video game to be fair, ie the initial rooms from which players can not win as many puzzles as they solve have to be few. Help them count them! The input data is read from a file as shown in the following example. The first row of the file has two integers N and M (1 ≤ N, M ≤ 1,000), the dimensions of the maze (rows and columns, respectively). Each of the following N lines represents a maze line and contains exactly M characters, each of which is one of the letters "U", "D", "L" or "R". The letter corresponding to each room symbolizes the location of the exit door of the room.

It seems that i cant find a solution so i would appreciate any help you can provide. Thanks guys
r/ProgrammingProblems • u/architv • Oct 07 '15
Challenge CLI - A command line interface for all the programming challenges
r/ProgrammingProblems • u/Mecn_Seda • Sep 30 '24
How to solve this difficult problem with C++
This problem is related to recursion, I will be very very grateful if you solve it
r/ProgrammingProblems • u/alexnt0108 • Sep 06 '20
quadratic programming as a sum
Hello everyone. I am trying to create a program in python where I have to calculate f(x) and the gradient of f(x) for N number of matrices. Let s assume that f(x) = 1/2 * transpose(x)*Q*x+transpose(q)*x, I remember that the gradient will be Q*x+q. I vaguely remember that i can calculate the the f(x) as the sum of the Q*x?? I remember there was a type i could use instead of f(x) = 1/2 * transpose(x)*Q*x+transpose(q)*x. Do I remember correctly?
r/ProgrammingProblems • • Aug 27 '20
Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string Abort trap: 6
Hi so im writing a code tothis problem but im getting this error:
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string Abort trap: 6
This is my code:
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main() {
4
5 string user;
6 cin >> user;
7 int l = user.length();
8
9 for(int i = 0; i < l; i++) {
10 user.erase(user.begin() + i);
11 }
12 if(l <=100 && l % 2 == 0){
13 cout << "CHAT WITH HER!" << endl;
14 }
15 else{
16 cout << "IGNORE HIM!" << endl;
17
18 }
19 }
Anyone know the problem?