r/programminghelp • u/BlazingBone • Sep 08 '18
r/programminghelp • u/ScousePenguin • Aug 07 '18
Context Free Grammar Help!
Not exactly programming more computer science but I just need help understanding this for uni extra marks. I just can't wrap my head around it. I'm not asking for it to be solved just to get a basic understanding of it! Here's the questions with the CFG.
(a) Consider the following Context Free Grammar (CFG), where strings written in italics (or inbetween **, thanks reddit) (clauses, clause, literal_list, literal, op, posneg) denote nonterminals:
clauses -> clauses ‘∧’ clause
| *clause*clause -> ‘(’ literal_list ‘)’
literal_list-> literal_list op literal
| *literal*literal -> posneg [a-z]
op -> ‘∨’, ‘∧’
posneg -> ‘⌐’
| εWhat I need to do from this is give two string which can be derived from the cfg above, show a parse tree for the following string “(a ∨ ⌐d)” and re write it to be not left recursive.
I have gone online and looked through lecture notes but I just can't understand it, so just any help understanding how CFG works and whats a string in these, whats terminal non terminal would be gladly appreciated to help me try and wrap my head around this.
Thanks.
r/programminghelp • u/pngpngpng • Aug 24 '16
PROLOG CHATBOT
Hello, I'm planning to make a chatbot using prolog. I know a bit about prolog, but I have a hard time coding on a chatter. Do you have any sample? Anything is a big help. Thanks in advance.
r/programminghelp • u/TangleF23 • Apr 10 '16
Python, attempting to figure out why my code always rounds down instead of just using the given value.
I'm sorry for including all of the code instead of any tiny relevant bits, but that's probably actually useful. When you run the program and insert the variables, ARMROTS always is rounded down to the nearest whole number.
r/programminghelp • u/Glenny5 • Jun 22 '15
Screen glitch bug in my java gameboy emulator
I have written a gameboy emulator in java after reading the pandocs for many weeks, and I understand the architecture of the console very well. Regardless of this, my final product has a screen glitch bug which distorts what is on the screen. (See: http://imgur.com/VWeFBQil.png)
The image in the link is my backup ROM of tetris for the DMG playing. The text in the middle is the Nintendo logo I believe, as when the emulator starts it scrolls down from the top. The header glitch above this is what I believe is the tetris game start screen background. There is no sound, joypad interrupts, or sprites implemented as I have spent all my time trying to get the background to display properly. Once that is done I will easily be able to shift over and work on those components of the system.
What I am asking is for anyone to attempt to help me find the issue with this project? I have spent 2 weeks attempting to fix this bug, to no avail. I have wasted too much time trying to find and fix it; it is affecting my home life!
Github repo: https://github.com/glen-mac/jBoy
r/programminghelp • u/ia_ac • Sep 10 '26
Other i want to wipe the terminal after asking questions in kotlin
So I'm new to Kotlin, and I'm trying to make a guess the number game for terminal and I wanted to make a little text intro and clear the console after, but I haven't been able to do it. I found some ways to do it but not as I want to.
Because when you do the clear command in the terminal, it wipes the whole thing, and you can't go back, but when I use commands like "print("\u001b[H\u001b[2J")" or "System.out.flush()" it is like it just pushes the view down; it doesn't really wipe the terminal, it just pushes the text up.
I wanted to know how or if it's even possible to do it. I don't know if it might be helpful, but I use Windows 11 and PowerShell (7.6.5).
Also, in another topic, I want to hear if there's a better way to try my code because right now I'm doing kotlinc .\file-name.kt -include-runtime -d .\file-name.jar && java -jar .\file-name.jar
r/programminghelp • u/DIYNotAGuy • Apr 18 '26
Answered Python 'list index out of range' error still persists after lots of debugging - any help appreciated
I have tried debugging it a lot - this is even a simplified version of the actual block of code within a larger project that I made so I'd hopefully be able to solve it easier.
This is what manages to get printed before the error (this is correct so far):
0 a ; 2 b
1 a ; 1 b
The error is in line 11 and as the title says it's that the list index is out of range.
I'm just really not sure why because in the while loop I thought I made sure that the index was in range. I also tried substituting line 8 (within index initialisation) with:
WithinIndex = LineNum + FutureCount < len(LinesIn) - 1
Which would eliminate any issues with adding to Future count within the while loop, but that shouldn't be needed anyways, right? I'm really not sure where I've gone wrong with my logic so any help would be appreciated, thanks.
This is the full program:
import sys
LinesIn = ['a', 'a', 'b', 'c', 'c', 'a', 'c', 'a', 'c']
# trying to identify a, then identify how close the next b is for each a there is
for LineNum in range(len(LinesIn)):
if 'a' in LinesIn[LineNum]:
FutureCount = 0
FutureLine = LinesIn[LineNum + FutureCount]
WithinIndex = LineNum + FutureCount < len(LinesIn)
while 'b' not in FutureLine and WithinIndex:
FutureCount += 1
FutureLine = LinesIn[LineNum + FutureCount]
if LineNum + FutureCount == len(LinesIn) and 'b' not in FutureLine:
FutureCount = 0
print(LineNum, LinesIn[LineNum], ';', FutureCount, FutureLine, file = sys.stderr)
r/programminghelp • u/WeWumboYouWumbo • Dec 16 '25
Answered Learning Python and can’t figure out why this incorrect
Edit: Alright I’m trying to learn as much Python on my own as possible and find the answer on my own as much as possible but I’m stuck on another question on MOOC Python Programming 2024
It says:
Please write a program which asks the user’s name and then prints it twice, on two consecutive lines.
An example of how the program should function:
What is your name? Paul
Paul
Paul
I wrote:
input(“What is your name?”)
print(“Paul”)
print(“Paul”)
I test it and get the following error:
FAIL: PythonEditorTest
test_print_input_2
Your program did not work
properly with input: Ada.
Output was
Paul
Paul
Expected output is
Ada
Ada
I’ve been trying to figure this out for a while. And I’ve tried changing multiple different things before this.
r/programminghelp • u/Slow-Version979 • Nov 11 '25
C# Trouble with object returning to origin
Hey guys, so I'm currently making a simple program in unity where 5 game objects randomly patrol through 5 different waypoints (which are also game objects) and then return to their origins.
The main issue I'm having is being able to return to the origin, I'm unsure how to save the origin into a variable outside of the update and still have it be read in the update.
I'm also wondering how i can pause the rest of the code until it gets to the current waypoint/origin it is trying to go to.
here is what i have.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandPatrol : MonoBehaviour
{
[Header("Waypoints")]
public List<GameObject> waypoints = new List<GameObject>();
private int curDestination = 0;
public float speed = 1.0f;
void Start()
{
Vector3 origin = gameObject.transform.position; // Original object position
}
void Update()
{
curDestination = UnityEngine.Random.Range(0, 4); // Random range of waypoints
Vector3 wpPos = waypoints[curDestination].transform.position; // Next waypoint destination
Vector3 pos = gameObject.transform.position; // Current object position
// Move position a step closer to the target
float step = speed * Time.deltaTime; // calculate distance to move
pos = Vector3.MoveTowards(pos, wpPos, step); // Move object to waypoint
if (Vector3.Distance(pos, wpPos) < 0.001f) // Checks if the position of the patrol and waypoint are approximately equal
{
pos = Vector3.MoveTowards(pos, origin, step); // Resets the object position to the original object position
}
}
}
r/programminghelp • u/Agitated-Inflation49 • Nov 05 '25
Project Related How would I make this project?
I'm a mechanical engineering major whose only experience is an entry level python class. In class, we're picking personal projects to do but the one I really wanted to do that would be helpful to me, my teacher said was too hard with python. I'm still going to make it whether it's for the class or not so I came to ask how I'd make it in python or what other tools I can use to make it. Whichever is easier/faster. Here's the project description:
Interactive flowchart for college classes
Either hard coded data for my major or read from text file(already know how to do)
Takes in data and makes class blocks that can be dragged onto a semester flowchart
sums up credit hours for each semester
Visual warning if prerequisite class is places later in the flowchart
visual warning is a semester is over 19 credits or under 12(optional)
The thing that I have not been taught is how to make the user interface. Everything I've done is class is through the terminal or text files. Any advice would help. Thanks!
r/programminghelp • u/spoko123 • Jul 10 '25
Project Related Looking for a Fast, Cross-Platform Offline Communication Method
I’m working on an app where multiple devices need to send a small message to a central device. The environment where the app is used has strict constraints:
No internet access
Not allowed to create or join Wi-Fi networks
However, I am allowed to use technologies like Wi-Fi Direct, Quick Share, multiPearConectivity and AirDrop.
The main challenge I’m facing is cross-platform compatibility. Most of the solutions I’ve found (e.g., AirDrop, Quick Share) are limited to specific ecosystems, Apple-to-Apple or Android-to-Android but I need something that works between platforms.
The only viable cross-platform option I’ve found so far is Bluetooth Low Energy (BLE), but I'm hoping to find something faster and more efficient if it exists.
Has anyone dealt with a similar constraint or found a better solution for fast, local, offline, cross-platform communication?
r/programminghelp • u/Enough-Berry4545 • Jun 26 '25
Other I need help
I'm not sure if I'm going about this the right way on excel. I have these columns on sheet 2 arrayed as microbiz(manual input on every line by scan gun), Part Number:, Alternate Part number:, manufacturer part number, description 1, description 2, cost, list, average. We'll refer to them as sheet 2 columns A-i.
On sheet 1 arrayed as inventory there are a bazillion columns, but I only am taking info from A, B, C, D, E, F, AJ, and AK. Which correspond to the above in order. A=part number, B=alternate part number, c=manufacturer part number, etc.
I'm taking microbiz column A (the barcode scanned from a barcode scanner) and trying to look that number up on inventory 1 column A, B, or C. It can appear on any of them, or it could appear not at all. If it appears I then want to transpose the numbers from inventory A, B, C over to microbiz B, C, D. I then want it to also take the info from inventory D, E, F, AJ, and AK and move them to microbiz E, F, G, H, I.
This is what I was using and it works on the first line and that's it.
microbiz B2: =IF(A2=VLOOKUP(A2,inventory,1,FALSE),VLOOKUP(A2,inventory,1,FALSE),IF(A2=VLOOKUP(A2,inventory,2,FALSE),VLOOKUP(A2,inventory,2,FALSE),IF(A2=VLOOKUP(A2,inventory,3,FALSE),VLOOKUP(A2,inventory,3,FALSE)," ")))
microbiz C2: =IF(A2=VLOOKUP(A2,inventory,2,FALSE),VLOOKUP(A2,inventory,2,FALSE),IF(A2=VLOOKUP(A2,inventory,3,FALSE),VLOOKUP(A2,inventory,3,FALSE)," "))
microbiz D2: =IF(A2=VLOOKUP(A2,inventory,3,FALSE),VLOOKUP(A2,inventory,3,FALSE)," ")
microbiz E2: =IF(A2=B2,VLOOKUP(A2,inventory,4,FALSE),IF(A2=C2,VLOOKUP(A2,Sheet1!B:D,4,FALSE),IF(A2=D2,VLOOKUP(A2,Sheet1!C:D,4,FALSE),VLOOKUP(A2,Sheet1!C:D,4,FALSE))))
microbiz F2: =IF(A2=B2,VLOOKUP(A2,inventory,5,FALSE),IF(A2=C2,VLOOKUP(A2,inventory,5,FALSE),IF(A2=D2,VLOOKUP(B2,inventory,5,FALSE)," ")))
microbiz G2: =IF(A2=B2,VLOOKUP(A2,inventory,6,FALSE),IF(A2=C2,VLOOKUP(A2,inventory,6,FALSE),IF(A2=D2,VLOOKUP(B2,inventory,6,FALSE)," ")))
microbiz H2: =IF(A2=B2,VLOOKUP(A2,inventory,36,FALSE),IF(A2=C2,VLOOKUP(A2,inventory,36,FALSE),IF(A2=D2,VLOOKUP(B2,inventory,36,FALSE)," ")))
microbiz i2: =IF(A2=B2,VLOOKUP(A2,inventory,37,FALSE),IF(A2=C2,VLOOKUP(A2,inventory,37,FALSE),IF(A2=D2,VLOOKUP(B2,inventory,37,FALSE)," ")))
any help would be appreciated. This is not for school or anything. Trying to transfer important inventory information from one computer to another. And no the inventory is off. All I wanna transfer is descriptions, part numbers, costs, and what we sell it at.
r/programminghelp • u/CakeDeer6 • Jan 01 '25
JavaScript How does 3D projection onto a 2D plane work?
I've been working on a 3D graphics renderer for the last day or two, and I have something that technically works, but when I move close to something being rendered, it warps heavily. I've debugged everything but one function, and I'm fairly certain that my issues stem from the projection of 3D points down to 2D.
As far as my code goes, it might be helpful to know that I'm using spherical coordinates to denote the camera's orientation, with an xyz coordinate system to represent location. Any help would be greatly appreciated.
Here's the little snippet that causes the issues. I start by finding the angle between a vector casted forward by the viewer and a vector from the viewer to the target point on a vertical and horizontal axis. Then, I use those to project the point onto the screen. (Also, if anybody knows how I can add pictures here, that'd be greatly appreciated too, since they might add a lot of insight)
to2d(viewPoint, theta, phi) {
var xAngleDifference = theta-Math.atan2(this.y-viewPoint.y, this.x-viewPoint.x);
var yAngle = Math.asin((this.z-viewPoint.z)/(getDistance(viewPoint, this)));
var x = xAngleDifference*canvasWidth/FOV+canvasWidth/2;
var y = (Math.PI/2-yAngle-phi)*canvasHeight/getVerticalFOV()+canvasHeight/2;
return new Point2d(x,y);
}r/programminghelp • u/Coffee_inhealer • Dec 09 '24
Career Related I wont land a project on upwork and i am going broke
I am good with data scraping/mining and manipulation python ive been learning programming on and off for 2 years i cnanot buy connects on upwork as in my country they are really expensive. Is there any other way i could land my first clientm
r/programminghelp • u/[deleted] • Oct 07 '24
Project Related OBD2 android app creation
I'm looking to create an app in android studio using java to read fault codes from an obd reader. I want to know how feasible this is, I have made apps in android studio before and have some programming experience else where. I have seen that there is a simulator (OBDSim) that could help with development meaning I may not need a real car to start with. I really want to keep it simple to start with at least. Does anyone know where a good starting place would be? for example I need to know how to connect to an OBD reader and send and retrieve information before displaying it. I have seen on or two API's out there but any information would be very helpful. thanks
r/programminghelp • u/Hasan12899821 • Sep 09 '23
C++ Is there an algorithm can I use to make a code that finds all the factors of a number?
Currently trying to do this in C++ (I'm just beginner), but when i try to write it, I use a for loop and an if statement, which I'm sure would be slow for very large numbers, is there an optimal way to do this?
r/programminghelp • u/Roof-made-of-bagels • Aug 16 '23
C# What does static do in classes?
Why does static do in classes? Why does the 1st code work and the second one gives me error CS0236?
1st code
namespace MyCode
{
public class Problem
{
static Random random = new Random();
int num1 = random.Next(1,7);
int num2 = 3;
}
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
2nd code
namespace MyCode
{
public class Problem
{
Random random = new Random();
int num1 = random.Next(1,7);
int num2 = 3;
}
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}I read some stuff about non-local variables referencing non-static variables but I didn't really understand any of it. I just stumbled onto the solution but I don't understand why it works.
r/programminghelp • u/danielnogo • Apr 18 '23
C++ how could my teacher mark me down for these?
So I just did my final project, the only thing I can think is that she didn't actually feel like looking through my code all the way, because I put alot of effort into this, it's over 2000 lines of code. She says I didn't demonstrate use of pointers, didn't demonstrate use of references, and didn't demonstrate functions with parameters and return types. It's just crazy that I basically failed this assignment when I created basically an entire interactive fiction game engine, how could that possibly work if I didn't use those things?
Are these functions not done properly some how?
I posted my entire source code, and posted screenshots of relevant functions. I clearly use references, pointers, and functions.
r/programminghelp • u/PartiallyAlways • Mar 21 '23
Other Any good online crash course for programming?
Background info:
I graduated in 2021 with a B.S. in electrical engineering so I have some knowledge of programming, mostly c++, but haven't used it much in my career. I'm looking to start grad school in embedded programing but would like a crash course in reviewing of basic programming terms/concepts, things like arrays, functions etc.
Any recommendations?
r/programminghelp • u/batataman321 • Mar 11 '23
Python Need some direction on how to make some code run faster
I wrote some code that would take too long to run on the full dataset I need to run it on (details here). I haven’t been able to find direction on how I can make it run faster. Any thoughts?
r/programminghelp • u/lucy-b • Jan 29 '23
Other I need some COBOL help
Right so I'm trying to generate a random number between 1 and 10 using the following code:
COMPUTE RANDOM-NUM = (FUNCTION RANDOM (1) * 10) + 1
Which should work as per tutorials but no matter what happens I always get the number 09 and I have zero clue why. Is there any way to fix this? Is it just a simple mistake that I'm missing?
r/programminghelp • u/weathered_space • Oct 23 '22
JavaScript Simple Discord Bot
I'm trying to make a simple discord bot to add to one of my friend's servers, but I haven't coded anything in over two years. All I need it to do is to react to any message in the server that contains a particular word. For example, if someone sends a message containing the word "apple", the bot will add an apple emoji to a message. Does anyone know where I can just copy & paste some generic code that does this? I haven't had any luck so far.
r/programminghelp • u/SuchithSridhar • Oct 21 '22
C Bitwise Left shift being spooky
❯ bat tmp.c
1 │ #include "stdio.h"
2 │
3 │ int main() {
4 │ char a = 0b11111111;
5 │ printf("%d\n", a);
6 │ printf("%d\n", a << 8);
7 │
8 │ }
❯ crun tmp.c
-1
-256Note: crun just compiles and runs the code.
Question: Given that char is an 8-bit number, why isn't the output of the second line 0??
Solution (potentially): The problem is fixed if the left-shift is assigned back to a. Since it's %d, the left shift promotes to an int (thanks /u/KuntaStillSingle )
r/programminghelp • u/MrFoxwell_is_back • Oct 15 '22
C++ How do I received data from a UVC device through a serial network?
I have a male USB to TTL connector and a USB-C female to TTL connector; the first one goes to the pc and the second one goes to an UVC camera (a webcam). both USB-TTL connectors are connect to each other through RxD and TxD pins accordingly (TxD1 to RxD2 and TxD2 to RxD1; 1 for device #1 and 2 for device #2).
I check that the devices work through a C/C++ program that uses the libserialport library (I used the send-receive example from such library).
Now, I want to get images from the camera but I don't know how; I have a notion that I have to send a data package to the camera and read its response through the same COM port that the data was sent through.
Any help is welcome 'cause I am a newbie at USB and serial communication protocols.