r/programminghelp • • Aug 05 '20

Python Recursion and syntax help in Letter Combination problem

3 Upvotes

Hi, I'm trying to understand this working program that solves the Letter Combinations of a Phone Number problem. I get how the answer is achieved, but there are syntax and recursion elements throwing me off. I have a few questions, please excuse me if they're too many.

  1. How does prev = self.letterCombinations(digits[:-1]) work? I'm assuming it's recursively calling self.letterCombinations and, when I used a print statement, prev is doing the combining already. What I don't understand is, in a second iteration, how is it combining letters if it hasn't encountered return [s + c for s in prev for c in additional] yet? I'm not clear on how the recursion is functioning for longer inputs (example: "232").

  2. Why does prev = self.letterCombinations(digits[:-1]) stop at -1 and is not instead [:]?

  3. What's the deal with additional = mapping[digits[-1]]? I don't get why it's added separately.

Program(Python 3):

class Solution:
    # @param {string} digits
    # @return {string[]}
    def letterCombinations(self, digits):
        mapping = {'2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', 
                   '6': 'mno', '7': 'pqrs', '8': 'tuv', '9': 'wxyz'}
        if len(digits) == 0:
            return []
        if len(digits) == 1:
            return list(mapping[digits[0]])
        prev = self.letterCombinations(digits[:-1])
        additional = mapping[digits[-1]]
        return [s + c for s in prev for c in additional]

r/programminghelp • • Jun 28 '20

HTML/CSS [Javascript] Function returns wrong value

3 Upvotes
includesAllNodes(list) {
    let listNodes = []
    list.forEach(thing => {
        listNodes.push(thing.node)
    })
  
    this.nodes.forEach(item => {
        if (!listNodes.includes(item)){
            console.log('noy')
            return false;
        } 
    })
    return true
}

For some reason this function will log 'noy', but return true. I'm completely at a loss as to what to do.


r/programminghelp • • Jun 27 '20

Python How do I see if an IP address is using a VPN or Proxy?

3 Upvotes

My code:

import socket

hostname = socket.gethostname()
IPaddr = socket.gethostbyname(hostname)

print(IPaddr)

This just prints the IPv4 address. I want this program to also be able to know if the IP address is using a VPN or proxy.


r/programminghelp • • Jun 22 '20

Python low level dns request in python using socket

3 Upvotes

My goal is to make a connection to a dns server in python send a query and receive an ip given a host name as part of the query. I know that the specification is online however it is difficult to read.


r/programminghelp • • May 19 '20

ASM Can anyone help me make this code in TASM assembly language?

3 Upvotes

Sample output:

Enter first number: 9

Enter the operator ( + - * / ): *

Enter second number: 2

Answer: 11

Enter first number: 3

Enter the operator ( + - * / ): ?

Wrong operator!

Enter first number: A

Wrong input!


r/programminghelp • • May 03 '20

Answered I need some help with python lol

3 Upvotes

i have 2 questions i am still trying to figure out the whole python thing but my first question is that I need to write a line of Python code to iterate over and print the values in a list called my_list on a separate line. How would i go about doing that?

and my second question is that I trying to make a python function that takes an string argument.  This function must ask the user for a input until it gets a number from 50 to 100 and when it does, return that number to the caller of the function. How would i go about doing that?


r/programminghelp • • Apr 18 '20

Python creating a new array using conditions on another array

3 Upvotes

Hey, hope you and your loved ones are safe from the pandemic!!

I would just like some help in how to go about creating a function in which I have a list of lists (called groceries) and a list of conditions. The function is meant to print out a new list that meets those conditions.

I thought about using a for loop inside a for loop but for some reason the result is always the groceries lists all merged into one massive list. Below is my pseudocode and should i not be putting a for loop inside another for loop? (ik this is a fairly simple problem but i really suck a coding lol)

def promotions(groceries, conditions):
promototions_lst=[]
for food in groceries:
for condition in conditions:
if condition[1]:
selection_lst += phone
else:
return False
print (promotions_lst)


r/programminghelp • • Feb 27 '20

Trying to input values into column in R, but it’s putting the desired value in for every cell.

3 Upvotes

I have a baseball game results dataset from 2019. I’m trying to input the teams that played winning percentage into a new variables called VisPer(visiting team winning percentage) and HmPer(home team winning percentage). I used this line of code:

If(VsTm == “COL”) {VsPer = .472}

I expected this to input .472 into VsPer only for the rows where VsTeam(Visiting team) is equal to COL; however, it inputted .472 into VsPer for every single row in the data frame. Can anyone help?


r/programminghelp • • Feb 17 '20

C# C# XML Serialization help

3 Upvotes

I'm using XML Serialization to read XML into classes in C#. But there's this one particular error:

Every time I use CloneObjectSerializable() on an instance it gives me this error:

Type 'System.Xml.XmlNode' in Assembly 'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable

Even though I marked every class with

[System.SerializableAttribute()]

with the correct

XMLRoot()

too. Basically the mapping with the structure of the XML is correct, if I switch to debug mode all the data that the classes have after reading XML are correct too, yet I just can't seem to clone an object generated by XML. What is going on ? I feel like I'm losing my mind :(


r/programminghelp • • Feb 04 '20

Answered Read files line-by-line

3 Upvotes

I'm making a punnet-square generator and I need to read 2 files containing parent data line-by-line to see the first two characters of each line. I think I can go off from there by myself.


r/programminghelp • • Feb 02 '20

Other Is there any known documentation on how to program in the infamously hard to understand malboge language?

3 Upvotes

Not practical in any sense but it would be something to brag about saying you know one of the hardest to understand languages.


r/programminghelp • • Jan 15 '20

JavaScript Does js work with ios?

3 Upvotes

I started JavaScript as one of my new year resolution. I’m familiar with a few other program languages like python, html and css. But I recently dive into app and game development with js but I’m not sure if js works on ios


r/programminghelp • • Dec 10 '19

Someone explain why round off error in java happens please, I seriously don’t understand why I can not just do double == double and carry on with my day

3 Upvotes

r/programminghelp • • Nov 27 '19

Visual Basic help

3 Upvotes

Essentially, a guy at work developed this program in VB and has quit, so now it's mine. I have basic programming knowledge from C++ classes in college, that's pretty much it

I need to know why the highlighted/breakpoint If statement is not true. How can I find out what .OPByteValue1/2/3 are? If I can tell what VB is seeing, I might be able to go from there

https://i.imgur.com/lZs9Ke7.png


r/programminghelp • • Nov 24 '19

Find largest character by ASCII value in a string and insert it at the end recursively

3 Upvotes

Hey,

one part of my homework assignment is this exercise which I haven't been able to figure out to do.

So basically I have to find the largest character in a String (ASCII value) and then insert it at the end.

The catch is that I have to implement this recursively and I have to work with the predefined method parameters so I can't change anything here.

"String shiftLargestChar(String text)"

Example:

"taabkeuhm" -> "aabkeuhmt"

Any help is appreciated!


r/programminghelp • • Oct 26 '19

Answered Making a function for 'and' operator using ONLY 'or' and 'not' operators in Python

3 Upvotes

I can't seem to wrap my head around doing this. I am not sure how to check if both terms are True without messing up the return statement since the 'or' operator will always return True if one of the terms is True. There was a hint provided saying to take a look at the truth table of not (a and b) which looks fairly similar to an 'or' truth table other than the part (False, False) and (True, True) being different. I tried recreating it with ors and nots, but it just won't print out what I need.


r/programminghelp • • Sep 06 '19

How does one go about creating a specialized non-cryptographic hash?

3 Upvotes

This question actually derives from a very specific problem I am currently tasked with solving. Essentially, I need to hash incoming values that are generated by a mathematical function into a hash table.

The function is g(x) = 4x + c, along the domain x ∈ [0, ~500], with the constant {c | 60000 ≤ c ≤ 4000000000, mod(c, 4) = 0}. I will not ever know the value of c.

How would one go about creating a uniformly distributed hash function for this input set?


r/programminghelp • • Aug 12 '19

Could someone please explain?

3 Upvotes

I’m aware this may not be the perfect sub to post this question but I’m not sure where else to ask so please have a little patience :). I’ve come across someone whose job title is a “quant developer/programmer”. I’ve looked online to no actual avail. Could someone please explain this? And how one could get into this type of field? Thanks. I’m quite clueless to all this 😅


r/programminghelp • • Jun 07 '19

Why do I have an infinite loop this .asm file?

3 Upvotes

I am attempting to learn Intel x64 Assembly and I have written a program that should print "Hello, World!" 10 times. However, when I assemble and run the program, it prints an infinite loop. Any help is greatly appreciated.

Here is the code I have written:

            global _start

            section .data
msg: db "Hello, World!", 0xa
len: equ $ - msg

        section .text
_start:
        mov rcx, 1        ; Set the counter to 1. 
        jmp _print        ; Jump to the _print function.

        mov rax, 0x3c     ; exit(
        mov rdi, 0        ; 0
        syscall           ; );

_print:
        mov rax, 1        ; write(
        mov rdi, 1        ; STDOUT_FILENO,
        mov rsi, msg      ; msg,
        mov rdx, len      ; sizeof(msg),
        syscall           ; );

        inc rcx           ; rcx++
        cmp rcx, 10       ; if (rcx <= 10)
        jle _print        ;     _print

        ret               ; return

Also, any references to beginner x64 Intel Assembly material is quite welcome.


r/programminghelp • • May 21 '19

Trying to Create Form Template in VB.net

3 Upvotes

Hello all, I'm trying to create a basic incident management application in VB.net and I'm a little stuck.

The plan is to have one main interface, and anytime I click on a "New Incident" button, it opens a new window, and creates a file to start writing to.

My problem lies within trying to create a new window every time I click on New Incident, without having to create a shitload of new forms in VB.net. I assume there's some way to create a template form to use but I can't for the life of me figure it out.

If anyone can point me in the right direction I would greatly appreciate it


r/programminghelp • • Apr 04 '19

Help passing new values to objects.

3 Upvotes

I want to be able to change the parameters of some objects that represent different animations at will. My current method accomplishes what I want but involves comparing strings, which I imagine is really slow. Is there a way to accomplish this same thing without needing to compare strings or better yet, just set the first value in the struct to the actual variable I would like to change?

Step 1: Set up struct to pass animation variables to object.

https://pastebin.com/YKPGfw7Z

Step 2: Put together array of new values and send to object.

https://pastebin.com/eEHHRMzU

Step 3: Update object values based on array of new values. An empty string signifies the end of the new value list.

https://pastebin.com/WDDBjhxy


r/programminghelp • • Mar 28 '19

How do I add the option for a user to delete data from a list?

Post image
3 Upvotes

r/programminghelp • • Feb 23 '19

Need help with this Mimo C++ Practice Question

3 Upvotes

Hi everyone,

I am a newbie currently using Mimo to learn some basic C++ in my free time. At the end of the section about classes, it asked me this question. I am stumped and at this point don't even know if it can be solved because I feel like I did every combination. I also think there is a typo in the code it has given me (I believe one of the "}"' must have a ";" at the end). Can anyone help me? Thanks!


r/programminghelp • • Feb 06 '19

New at programming, learning C. Is k&rs book the best to start with?

3 Upvotes

So im wanting to learn low level programming (kernel and OS), and C is something o decided to learn as a first step. I have a original copy of the ANSI edition of k&r the c programming language. Is this a good starting point for a book? Ive done t first 2 examples and its quite interesting.