Programming

python- i need help

Learn Programming - Sun, 10/21/2018 - 02:02

def linersearch (item,key):

index = 0

while (index<len(item)):

if (item[index]==key):

break

index = index+1

if (index<len(item)):

return index

else :

return 0

s1=[10,11,17,7,8]

key=10

found= linersearch(s1,key)

if(found!=-1):

print(key,"found",found)

else:

print( key,"not found")

can someone explain the steps to me ? i memorized which i know is wrong and i want to understand it , why we wrote each line and what it does ?

submitted by /u/uaeluffy
[link] [comments]

[Java Exceptions]

Learn Programming - Sun, 10/21/2018 - 01:40

I'm trying to make modifications to this code, but first, I want to understand it.

From what I learned, you can only have one live exception at a time. Is this true? When f() is called in line 11, we have a live one, so we break away from the try and enter the catch block. Once we run line 14, does the that exception die? So it doesn't make sense to throw e again? I saw an example where somehow an exception wasn't able to be caught, and was rethrown. If such a case happens, how is it handled?

And also, what if in a catch block, you throw a totally new exception. Is it the duty of the next immediate catch block after that offending catch block to give catch that new exception?

submitted by /u/SignificantGarbage
[link] [comments]

Coin Change Problem - minimum coin to make exact change

Learn Programming - Sun, 10/21/2018 - 01:34

I am trying to understand the problem where given a set of denominations (and unlimted coins for those demoninations), find the minimum coin required to make a certain amount.

So in the case of {5, 3, 2} and the target of 9. The answer would be 3 since we can make it from 3+3+3 or 5+2+2.

I watched this youtube video on dynamic programming and how to solve this specific problem - https://www.youtube.com/watch?v=Y0ZqKpToTic.

He uses a table to basically break down the problem into sub problems. I understand how he's able to fill in the table starting with the first row where denomination is 1 (his coin denomination included 1). In his case, you can make any change with 1.

We don't have 1 in our example, instead, we start with 5. I am stump as to how to handle this. When I try to create my table and I ask myself, "how many coins with demonination of 5 make 6?", the answer should be 0, but if I plug 0 into the table, working out the rest of the table with his algo doenst make sense.

Can someone tell me what the ? should be in my table below? (or fill out the table entirely for me so I see what's going on)

https://imgur.com/a/KITmf20

submitted by /u/Guy-Lambo
[link] [comments]

[MIPS] Restoring s register post loop?

Learn Programming - Sun, 10/21/2018 - 01:22

I'm working on an assignment in MIPS that builds a binary tree and traverses it, but I'm stuck on something strange. We can't edit code outside those BEGIN STUDENT CODE BLOCK lines, yet I need to restore $s3 after I use it as a counter for the loop that executes build_tree. All the code that does the wrap up is in add_done though, outside my designated block. Is the answer just to go to a second routine before going to add_done or is there something simpler I can do?

Thanks in advance!

Code Snippet:

# # Name: add_elements # # Description: loops through array of numbers, adding each (in order) # to the tree # # Arguments: a0 the address of the array # a1 the number of elements in the array # a2 the address of the root pointer # Returns: none # .globl add_elements add_elements: addi $sp, $sp, -16 sw $ra, 12($sp) sw $s2, 8($sp) sw $s1, 4($sp) sw $s0, 0($sp) #***** BEGIN STUDENT CODE BLOCK 1 *************************** # # Insert your code to iterate through the array, calling build_tree # for each value in the array. Remember that build_tree requires # two parameters: the address of the variable which contains the # root pointer for the tree, and the number to be inserted. # # Feel free to save extra "S" registers onto the stack if you need # more for your function. # # # If you saved extra "S" reg to stack, make sure you restore them # # $a0 is the address that contains the array of values. # $a1 is the number of elements in that array. # $a2 is the the address of a word which contains the pointer to the trees root sw $s3, 16($sp) # current count MY SOLUTION CODE HERE... #***** END STUDENT CODE BLOCK 1 ***************************** add_done: lw $ra, 12($sp) lw $s2, 8($sp) lw $s1, 4($sp) lw $s0, 0($sp) addi $sp, $sp, 16 jr $ra #***** BEGIN STUDENT CODE BLOCK 2 *************************** # # Put your build_tree subroutine here. # # $a0 is a pointer to a pointer to the root node # $a1 is the new number to insert. build_tree: #***** END STUDENT CODE BLOCK 2 ***************************** submitted by /u/14bux
[link] [comments]

training tesseract OCR

Learn Programming - Sun, 10/21/2018 - 01:20

I'm working on a project that takes data from screen shots while I'm playing a game. I was hoping to use tesseract to read numeric values on the screen but it isn't perfect as the font is a little pixilated.

I'm working in python and on a mac.

Is there a way i can feed tesseract examples with the correct values to train it? it just has to read 0-9, dollar sign and comma sign.

Any other ways round this problem would be welcome too.

submitted by /u/jungle_is_massive
[link] [comments]

[Java] How do I make the program wait for GUI input?

Learn Programming - Sun, 10/21/2018 - 01:19

I know how to make the program wait for command line input. What I'm looking for is something like scanner.nextInt only in gui. Like scanner.nextNumberClicked. Im making a calculator/math workout app.

submitted by /u/BigBootyBear
[link] [comments]

advantages and disadvantages of array-based queues and linked-list-based queues

Learn Programming - Sun, 10/21/2018 - 01:17

like the title says. I can't seem to find any information on this, I tried google but it keeps returning information about regular linked list and arrays. Any idea?

submitted by /u/phantom9001
[link] [comments]

Where can i learn Intermediate to Advance level of Programming?

Learn Programming - Sun, 10/21/2018 - 00:46

Actually it been a long time since I have been programming in C and C++ but at most I have done a small project like management system. I want to learn to program real life applications using modules and other libraries and whatever is done.

So anyone can tell where actually I can learn about advance programming?

Sidenote: I am still a college student and have learned C basics and learning C++ now that will be basic too. As for data structures I know stack,queue and linked list and basic algorithms.

submitted by /u/vegeta001
[link] [comments]

[Scala help] I need a countdown iterator inside a for/yield comprehension.

Learn Programming - Sun, 10/21/2018 - 00:37

I have a list of tuples made up of ( Queue[Int] , Double ) pairs. I need to prepend a countdown onto the Queues in that list. The following code should do that.

import scala.collection.immutable.Queue val db:List[ (Queue[Int] , Double) ] = List( (Queue(34,18),0.12) , (Queue(14,18),0.34) , (Queue(34,28),0.45) , (Queue(44,38),0.56) , (Queue(74,48),0.67) , (Queue(84,58),0.78) ) db var iw:Int = 7 val fatdb = for( el <- db; iw = iw - 1 ) yield{ (iw +: el._1 , el._2 ) } fatdb

The code above does not compile. iw goes out of scope within the for/yield comprehension. There are workarounds involving the use of .zip() While certainly possible, the resulting code would be absolutely nasty and impossible to read. It seems like there should be some straightforward way of doing this.

Your thoughts?

submitted by /u/moschles
[link] [comments]

People and their choice of language

Learn Programming - Sun, 10/21/2018 - 00:34

Have you noticed any pattern on people and their preferred language?

I've recently come to notice this and i'm quite intigued. That is, a python programmer would tend to be more imperative and straight-to-the-point types. Whereas, say a java programmer would be the emotional kind.

I'd just like to know if others have also recognized this pattern. Of course i'm generalizing here and not everyone could be grouped. So don't come at me with that.

Is this anything in the community as how people like their languages with respect to how they are as a person?

submitted by /u/parotta36
[link] [comments]

Is it possible to make a button in one activity that kills any instance of another activity by classname?

Learn Programming - Sun, 10/21/2018 - 00:11

The internet doesn't have any answer beside creating the killable activity within the button activity - I can't do that, the activity to kill must start from mainactivity but this activity should be able to kill it.

submitted by /u/rudolphtheredknows
[link] [comments]

[C++] Confusion about const member functions

Learn Programming - Sat, 10/20/2018 - 23:30

Hey all.

I am creating a header file for a program that draws an arrow, and need to classify certain functions as "const". I have a function called "draw" that calls two other functions "drawHead" and "drawTrunk" to create the arrow, and I would imagine this is a const function (as far as my understanding goes) because it is not directly modifying the object. However, in order to do this I must also classify "drawHead" and "drawTrunk", as well as their constituent functions "drawDots" and "drawStars" as "const" functions. These functions take an integer "arrowSize" and bases their calculations on the number of dots and stars to create the various arrow sizes. Wouldn't these be considered as functions that modify the object? I am generally confused about using "const" and would really appreciate some clarification on this issue. Thank you for your time!

submitted by /u/SaintPuce
[link] [comments]

[ C++ Help] Concerning pointer to an array of pointers

Learn Programming - Sat, 10/20/2018 - 23:11

I'm currently working on an assignment, and I think I have successfully made a linked list of the elements in a periodic table read from a file (amount of elements will vary).

But I'm now trying to create a pointer to an array of pointers to Element (Element **ptr = new Element *[n] is found in main file and is passed into read_table). I'm not sure of how I should do this though. Is what I'm doing correct? Or should it be " ptr[i] -> *head.pElement " ?

Element struct has been created in another file and table will be a prototype in that file.

Code Snippet:

struct Node { Element *pElement; Node *next; }; int table(Element **&ptr) { Node *head = new Node; // starts off the linked list Node *temp = new Node; // temp node to make switch for head node Element e; int counter = 0; // counter to keep track of num of elements // open input file ifstream infile; infile.open(file_path_will_be_placed_here); // loop to read file and create linked list while(infile >> e.atomicNumber) { infile >> e.name; infile >> e.abbreviation; infile >> e.mass; head -> pElement = new Element; // the node's pElement points to a new Element *head -> pElement = e; // sets node's pElement to the read data stored in e *temp -> next = head; // might have to point to &head head = temp; // head points to where temp does temp = new Node; // temp points to new node counter++; // increment counter every time for every element } for(int i = 0; i < counter; i++) { // confused !@!@? ptr[i] -> head.pElement; }

submitted by /u/AriAruff
[link] [comments]

Looking for a Mentor in iOS/Swift

Learn Programming - Sat, 10/20/2018 - 22:50

Hey folks,

I've been dabbling with swift the last couple of months, hopping from course to course on Udemy to Treehouse. I'm currently working through a treehouse iOS path to learn the language.

I'm looking for a mentor or someone to converse with to bounce the concepts I'm learning, to make sure I'm going down the right path and for someone who has advice as I pick up more and more skill. I'm not really surrounded by coders so It's hard to find friends in person to speak with.

My goals of being a coder is to make apps but also to possibly find a developer job once my skills are up to snuff. I'm 31 and I'm currently a trainer on the retail side of a tech company and the coding bug bit me and for the first time in a long time, I see a path beyond what I'm doing.

I know swift has its niche market but for the time being (and based on the advice of others on reddit) I've chosen this language and decided to stick to it for a bit until I really get a good grasp on coding in general, and then branch out to other languages.

If you're interested or have ideas of other places where I can better find a mentor, please share. Any advice is helpful. It's a long road but I'm committed!

Thanks!

submitted by /u/dmdaisey
[link] [comments]

Looking for debugger recommendation under Windows

Learn Programming - Sat, 10/20/2018 - 22:50

My main working language is D, and mago-mi is pretty much in pre-alpha stage (doesn't even support commands it claims, --args is completely broken, best it can currently do is to print out the full trace).

Visual Studio wouldn't be a bad choice, however the only way I can use it for debugging is by attaching it already running processes (and in one case, a bug happens very quickly and I still couldn't track it down without a proper debugger), or if I use it to develop my own programs, however VisualD isn't well maintained and has limited support for the D language compared to VSStudio's code-D, also I can use dub this way easily, so dependency management is easy.

Wanted to give LLDB a try, but I cannot find a precompiled version, nor compile it (documentation is very vague on it plus doesn't like my mingw also being installed), and I don't know if GDB supports non-DWARF symbols. Windbg is even less helpful than mago-mi. x64dbg seems to be more optimized for reverse engineering than general debugging.

submitted by /u/ZILtoid1991
[link] [comments]

How to dynamically add a new heading to body using jQuery.

Learn Programming - Sat, 10/20/2018 - 22:28

I have a title, I want to have 2 titles, so I am trying to add a new element usin jQuery as follows:

$(".TopHeader").after($("h2"));

Where the html looks like:

<h1 class="TopHeader">Title</h1>

However this doesn't work and none of the other methods I have tried work either. Including append, and appendChild.

submitted by /u/camilo16
[link] [comments]

Hi, Guys, I have a question about sound libraries and how to set up a download system in a very efficient way.

Learn Programming - Sat, 10/20/2018 - 22:27

Hi, Guys, I have a question about sound libraries and how to set up a download system in a very efficient way.

My name is Marcel and I travel around the world and record sounds. Many of the sounds I record are published on my website in form of a blog post linked with Bandcamp and other unpublished sounds are stored in one cloud where people can buy the library and have full access to all recordings.

Here is an example

https://freetousesounds.com/aircraft-takeoff-sound-effects-changi-airport-singapore/

People that are interested in these sounds can read the story how I recorded the sounds and then download from Bandcamp but I want to create a new theme and slowly go away from this style and build a platform where people can search sounds just like on Soundsnap or Pro Sound Effects websites.

Here is an example of how Soundsnap does it

https://www.soundsnap.com/tags/walla

Or this example from pro sound effects that is made by a company called audio source

https://download.prosoundeffects.com/#!explorer

I love this look and the way how it's presented. You see the waveform and the length of the sounds. You click on download and that's it.

My website is about 1.5 years old and has already over 20K visitors a month. I do believe that many people who are landing the first time on the page are confused or don't have the time to look around for that long and leave without really finding the sounds.

I have all sounds stored in one cloud but I know it's not possible to do this with the one I have right now but I have a friend who is going to build me a server in his house to store all my recordings.

I really want to set this up but don't know where to start right now.

submitted by /u/FREETOUSESOUNDS
[link] [comments]

Making A Compatibility Layer/Emulator

Learn Programming - Sat, 10/20/2018 - 22:17

I want to create/learn about compatibility layers or emulators. What do I need to know, and what tutorials/resources are available to me? What languages do I need to learn? All I can do is C++. How do I go from coding to practical stuff?

submitted by /u/hualu
[link] [comments]

Pages