• Breaking News

    Wednesday, April 4, 2018

    Are some people just not cut for programming? I've been progressing very slowly learn programming

    Are some people just not cut for programming? I've been progressing very slowly learn programming


    Are some people just not cut for programming? I've been progressing very slowly

    Posted: 03 Apr 2018 03:36 AM PDT

    I've been programming for about 6 months now (in python) and while I've certainly learned a lot, I still struggle with basic concepts like classes/functions/objects, don't know anything about using regex, generators, etc., and even though I've looked into those topics before, I just forget about them the next day. I feel like I sometimes spend hours on 10 lines of code that someone else could figure out in a couple of minutes, and it's infuriating. and even for the same functions I did 100 times already, I still have to look them up. and for some reason I have a lot of trouble reading/understanding programming docs when learning a new api -I can't comprehend how everything 'fits' together and have problems thinking structurally. I'm really only good at getting an idea of how stuff works by looking at other people's similar code and trying random things until it works.

    I think it may be due to my lack of math ability (I'm bad at even algebra 1) so I'm not sure if I should study math first and then try programming or just give up since it's something I've never been good at/seem to be progressing very slowly. I do plan to start a computer science degree by the end of this year, but I've been doubting my abilities/capacity to handle it, and I'm not sure if I should look for a different career area.

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

    Completely lost while finding resources to learn Android development for Java programmers; need advice

    Posted: 03 Apr 2018 04:24 PM PDT

    So, I've been trying to learn Android development for the past few weeks. I know core Java, so after researching for some time I found a free Udacity course - Developing Android Apps by Google, which in theory was targeted at people like me. I started watching it and got through quite a bit of the course. At first, everything made sense from a Java perspective - I understood what everything was for in theory. However, the course is way too chaotic. Everything is arranged randomly, explanations of concepts like RecyclerView are given in 30 seconds (not joking), then a guy quickly codes for 2-3 minutes without explaining anything and then I'm supposed to do it all by myself with minimal advice. Sorry if this sounds like a rant, I just really don't know what to do.

    Is this really the best that internet can offer? Android is running on +2b devices right now, so I thought that there will be something else, but so far all I can find are 5-year-old Reddit posts, 4000-page books and this course.

    Do you know any good resources that actually can help me with all this? Or am I just a bad developer for not understand that course?

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

    I've reached a cool point in my programming journey

    Posted: 03 Apr 2018 06:20 PM PDT

    I've begun to notice more and more than I am thinking of the world in terms of code. When I use other applications or software and I complete an action, expanding a list, calculating something, having some information returned to me. I begin immediately to think about how that was implemented on the back end like "Oh, they looped through an array and made some modifications there to return my travel plans" etc. Cool stuff.

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

    Python Properties - Am I Using or Abusing?

    Posted: 03 Apr 2018 10:04 PM PDT

    I have a question about using Python properties, and I've written a few code examples below to explain. If you have time I've also included a video which explains the problem in the context of my more complicated program including why I think it's important.

    Divider1

    Here is a basic class Divider1 which can divide two numbers:

    class Divider1: def __init__(self, numerator=0, denominator=1): self.numerator = numerator self.denominator = denominator def get_result(self): return self.numerator / self.denominator 

    Here I use the Divider1 properly:

    >>> d = Divider1(5, 10) >>> d.get_result() 0.5 

    Here the Divider1 has been used incorrectly:

    >>> d = Divider1(5, 'hi') >>> d.get_result() TypeError: unsupported operand type(s) for /: 'int' and 'str' >>> d = Divider1(5, 0) >>> d.get_result() ZeroDivisionError: division by zero 

    Ideally, the error message would tell me where the mistake was made. The mistake is not that I attempted a division by zero, it's that I passed the wrong arguments into the constructor! In a more complicated example, a class could feasibly remain in an invalid state for a long time. Debugging this could become tricky!

    Divider2

    Here is a new Divider, Divider2, which addresses the issue:

    class Divider2: def __init__(self, numerator=0.0, denominator=1.0): try: numerator = float(numerator) denominator = float(denominator) except ValueError: raise ValueError("Numerator and denominator must be numeric!") if denominator == 0: raise ValueError("Denominator must be non-zero!") self.numerator = numerator self.denominator = denominator def get_result(self): return self.numerator / self.denominator 

    Solved!

    >>> d = Divider2(5, 'hi') ValueError: Numerator and denominator must be numeric! >>> d = Divider2(5, 0) ValueError: Denominator must be non-zero! 

    But it can still be abused:

    >>> d = Divider2(5, 10) >>> d.numerator = 'hi' >>> d.get_result() TypeError: unsupported operand type(s) for /: 'str' and 'float' >>> d = Divider(5, 10) >>> d.denominator = 0 >>> d.get_result() ZeroDivisionError: float division by zero 

    For my program, it's important to me that it can't be abused easily, because I want my module to be able to be self-contained. Issues in my use of the module should be obvious from the outside, not the inside. This should make it easier to debug.

    Divider3

    Here is a new Divider, Divider3, which solves the issue:

    class Divider3: def __init__(self, numerator=0.0, denominator=1.0): self.numerator = numerator self.denominator = denominator def get_result(self): return self.numerator / self.denominator @property def numerator(self): return self._numerator @numerator.setter def numerator(self, value): try: value = float(value) except ValueError: raise ValueError("Numerator must be numeric!") self._numerator = value @property def denominator(self): return self._denominator @denominator.setter def denominator(self, value): try: value = float(value) except ValueError: raise ValueError("Denominator must be numeric!") if value == 0: raise ValueError("Denominator must be non-zero!") self._denominator = value 

    Solved!

    >>> d = Divider3(5, 10) >>> d.numerator = 'hi' ValueError: Numerator must be numeric! >>> d = Divider3(5, 10) >>> d.denominator = 0 ValueError: Denominator must be non-zero! 

    Now Divider3 cannot be put into an invalid state (unless the private variables are changed)! Great!

    Questions

    I had to write a lot of code here to solve this simple issue. This is probably overkill for such a simple class like my Divider, but for something more complicated, could this be a good idea? Is this degree of safety completely excessive for Python full-stop? If so, then when are Python properties useful, if ever?

    Again, if you have time, here's my video which explains the problem in the context of my more complicated class.

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

    Took 4 MERN Stack/React&Redux Courses on Udemy, my experience and opinion

    Posted: 03 Apr 2018 09:58 PM PDT

    Hello everyone,

    I just wanted to share with you all my experience with these courses on Udemy and what you should be expecting in regards to these courses if you plan to take them. Just letting you know that this is my personal opinion so others may say otherwise.

    Here are the courses I've taken in this order:

    Modern React with Redux - Stephen Grider

    Node with React: Fullstack Web Development - Stephen Grider

    The Complete React Web Developer Course (with Redux) - Andrew Mead

    Full stack Universal React with Redux, Node js and MongoDB - Marco Tomasello

    Background

    A little background of myself, Computer Science Major, graduating May 2018. Fluent in Java and Python. Have some experience with web development, frontend and backend (personally like backend over frontend). I mainly used Python for server-side programming.

    Why I wanted to learn

    I wanted to see what was all the hype about with React and Node.js so I decided to take these courses. It's also a hot and desirable skill to know these days so I wanted to add it to my resume.

    My progress and how I finished these courses

    I started working on these courses from January 2018 - April 2018. I had winter break and nothing to do so that's why I was able to complete so much. Plus, had a friend who was interested in learning as well so we did 3 courses together, the last one I did on my own.

    Modern React with Redux - Stephen Grider:

    When I first took this course, I honestly thought React and Redux were super confusing to learn and complex. Also I never touched JavaScript before so I didn't really understand what I was looking at and how React.js and Redux worked together.

    Stephen is a great instructor, however, he sort of drones off a lot and doesn't get straight to the point so I got confused for quite a while but thankfully I took notes and I had a basic understanding of how React.js and Redux work which I thought was a great start because it's not like any other front-end framework I've ever dealt with.

    He basically makes you code around 3-4 small web application projects just so you could grasp the basic of the concept.

    Did I truly understand React.js/Redux in this course?

    Nope

    Node with React: Fullstack Web Development - Stephen Grider

    This course helps you build a Full-Stack web application using MongoDB, Express.js, React.js, and Node.js. After you finish the project, he helps you deploy it on Heroku.

    You use Passport for OAuth, Sendgrid, and Stripe APIs to build this application which was really cool. However... I didn't understand how Node.js and Express.js worked cause it was completely different from Python Flask. I thought it was weird how the middleware function were in a separate file but it made sense after some research and playing around with the code. I'm not fluent in JavaScript either so I guess that's what hinder my progression but this course did help me understand JavaScript ES6 more.

    Overall, it was a cool project that we built, but dealing with so many different APIs while also learning MERN was kinda overwhelming.

    And sadly, it did not solidify my understanding of React&Redux and MERN Stack...well, not yet

    The Complete React Web Developer Course (with Redux) - Andrew Mead

    Andrew's course are mainly for people who don't have any experience in programming. So if you do have some experience, I suggest you skip a few sections. If you don't, this course will certainly help you.

    Since I have experience with programming, I personally thought this course was way too slow for me and each video was really long which I didn't like.

    You build two projects using React, Redux, and Firebase. They're mainly CRUD (Create, Read, Update, Delete) projects which was great because I thought Stephen kind of lacked implementing those. This is more React/Redux focused and Andrew explains React/Redux in more detail. It may be a long course but in my opinion, it was worth it because I understood React/Redux much better after he showed various demonstrations on how these two work together. But after going through this course, I wanted to learn how MERN Stack worked. Firebase is not used very often in industry (or I don't think so…).

    Did this course helped me solidify my understanding of React/Redux?

    Yes! But now I wanted to learn how MERN works

    Full stack Universal React with Redux, Node.js and MongoDB - Marco Tomasello

    Out of all these courses, I thought this was the best course I've taken thus far. Why? Because he goes straight to the point and each lecture is less than 5-10 mins so it's easy to go through. Marco doesn't drone off or talk a lot like Stephen and Andrew. He explains difficult concepts such as Redux really well and how functions such as mapStateToProps and mapDispatchToProps work. His diagrams made more sense and they were easy to comprehend as well. He helps you build a small book shop application that has CRUD operations as well. Keep in mind, you have to have some experience of React/Redux before taking this course, otherwise it's difficult to grasp for someone who's never coded before. But if you have coding experience and you're curious about React/Redux & MERN Stack, I'd take this course first. I had a friend who took Stephen Grider's course and Andrew's course to learn React/Redux but she didn't understand it. I recommend this course to her and she understood it immediately.

    Okay…now would I say this course helped me understand React/Redux and MERN Stack?

    YES! Finally...like 4 courses later lol

    Summary

    Stephen's teaching style is really good, it's relatable to what you should be coding in real-world applications. You may or may not pick up React/Redux or MERN really well in his course because the concept is difficult to grasp in the beginning because React/Redux is not like any other frameworks you've seen. It's basically a model you have to follow and you need to understand it before you code it. Otherwise, it doesn't make sense. Stephen's MERN course had good practices and the API's we implemented were really cool, but I thought it was overwhelming because I felt like we were focusing on the wrong areas and not grasping the basic understanding of how MERN works.

    Andrew's teaching style is good, but only for people who are new to programming. If you're not new to programming, I think you'd find his lectures too long and he does break down the concepts but honestly it made me want to sleep sometimes or give up because he would take too long to explain it when he could've explained it in a few minutes.

    Marco's teaching style is a bit more fast-paced but he breaks down the concept well and explains it less than 5-10 minutes which is great because I realize React/Redux concepts are not that difficult, but it's intimidating in the beginning because most of the time, you're trying to figure out how everything is connected and how the React/Redux model works. However, I don't recommend this course if you're new to programming because he expects you have some knowledge of React/Redux and programming experience prior to the course. I was able to understand MERN Stack and React/Redux better because I guess when everything starts to make sense, it excites me because I'm finally making great progress and I figured out how to implement a lot of the features on my own.

    Even though I have a solid understanding of React/Redux and MERN Stack, there's still a lot to learn but I'm happy of how much I've learned and all these courses in the end were worth it.

    EDIT:

    Added more details, fixed grammar, and fixed formatting

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

    Can we get a sticky explaining that literally everyone thinks they're not cut out for programming at some point and remove posts asking about it?

    Posted: 03 Apr 2018 06:51 PM PDT

    I get it, we've all been there and needed reassurance at one time or another but this sub is supposed to be about learning to program, not soothing the same existential crisis every 10 hours.

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

    College student. Learn programming with external soruces (eg lynda) or stick to uni courses

    Posted: 03 Apr 2018 10:14 PM PDT

    I got to UCLA and i wanted to learn programming. The problem is that i am biochemistry and i cant take normal CS classes (since i am not an engineer). While i could take other routes to reach those (asking for exceptions or minoring in bioinformatics) i was wondering if i should instead take courses like lynda. While i will definitely learn, will it affect my curriculum of having taken CS from ucla vs say Lynda? thanks!

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

    Python w/Django or PHP for a virtual pet site?

    Posted: 03 Apr 2018 09:26 PM PDT

    Hello!

    I really would like to attempt to create my own virtual pet site. Right now I only know python, html, css, and a little bit of javascript. I am going to learn mySQL next.

    I know that python cannot be implemented into html without the use of a framework like django. I haven't messed too much with django, so I was wondering if the combination of python and django would work to create a pet site? Or would I be better off just learning PHP and using that for this project?

    Thank you!

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

    Need a review on my attempt at MVVM pattern (Xamarin, C#, XAML)

    Posted: 03 Apr 2018 11:43 PM PDT

    I would like some feedback on whether my code follows MVVM principles well.

    Please see my post on the Code Review Stack Exchange: Login modal with MVVM pattern

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

    Effective Java in Kotlin, item 2: Consider a builder when faced with many constructor parameters

    Posted: 03 Apr 2018 11:40 PM PDT

    How to go from first year compsci student to employable?

    Posted: 03 Apr 2018 02:52 PM PDT

    Hey guys, cool sub. I lurk a lot but don't post here much, being a learner and all.

    As the title states, I'm at the end of my first year as a computer science student currently headed towards an associates (or a possible transfer to a 4 year program).

    Like many others, I wanted to learn to code for a long time before i really got started. but the process of actually getting started mystified me so much.

    Eventually I decided to go back to school and see if a more structured environment would help me learn, and it definitely did.

    So far I've learned html/css and basic JavaScript, along with some basic Php and C++.

    I'm proud of my progress so far, but I feel like I'm still a long ways away from having the kind of skills that would make me employable as a programmer.

    So I guess the point of this is:

    What steps can I take to build on my knowledge in a way that will help me find a job?

    What did you programmers out there do to make your resume stand out?

    What kind of projects should I be doing on my own to have something nice to talk about on a resume?

    I see a lot of people talk about building apps that do random, mundane and otherwise useless tasks as a means of learning, but this doesn't seem like the way to go for me.

    Should I build a website? There are so many toolkits out there for non-programmers to make nice websites that it seems like a pointless endeavor..maybe a highly scripted and decked out site that did something special with JavaScript canvas or something?

    Should I build a functional app? That seems like it might be too far outside my skillset at this point... maybe I could learn as I go though? I don't see why not! Picking up something like C# or a mobile development platform could be a lot of fun..

    Should I try to contribute to some kind of project looking for volunteer programmers, and try my best to learn as I go? Maybe some fan game that needs help or a database site looking for scripters?

    These all seem like they could be great or potentially terrible approaches for me, as an up and comer. And we all know time is the most valuable resource we have!

    So any insight you real programmers might have for me is greatly appreciated!

    Thanks for reading.

    Edit grammar

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

    Learning vs Memorization

    Posted: 03 Apr 2018 11:28 PM PDT

    How do you guys "learn" computer science?

    Coming from the medical field, all I've ever had to do is memorize and memorize, which I am incredibly good at. However, in a field like computer science, where you actually have to understand what you're learning and apply it, memorization isn't really helpful. Sure I can remember what I read and I seem to understand it while I'm reading it, but when I'm asking to think about them critically later or to explain something, I'm at a loss. I no longer am able to explain what I learned/read or I simply regurgitate what I read without fully understanding it.

    How do you guys go about learning information that isn't simply just memorizing the book or tutorial or video, etc?

    Thanks.

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

    [JS] What's wrong with this code?

    Posted: 03 Apr 2018 11:19 PM PDT

    So, first of all, I'm working on a Discord bot that, whenever a user types !emotes <twitch username>, it will return the emotes from that Twitch user, if any.

    This code was working perfectly fine last night, but now it doesn't want to seem to work. I passed off the code to a couple of buddies to test it, and it works perfectly fine for them, which I don't understand.

    Here's the current code I'm using (excluding tokens etc):

    https://hastebin.com/viviqejaza.js

    Here's the error that I keep getting: https://i.imgur.com/CgTUktu.png

    Also, on line 25, I'm trying to log the data, but that isn't returning anything either... Any ideas? Internet? Out of date NPM package? I'm losing my shit here, honestly.

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

    We are creating a site that helps people (like you!) learn to code. We'd love your feedback!

    Posted: 03 Apr 2018 09:15 AM PDT

    TL;DR Check out this interactive tutorial and let us know what you think https://tttiny.com/@corey/rainbow-snake-tutorial/source?autoplay

    Getting started with coding is hard! We think people should be able to tinker with code without needing to install a bunch of confusing developer tools. So we've made a site that lets you build cool JavaScript creations in the browser.

    This is an interactive tutorial we created https://tttiny.com/@corey/rainbow-snake-tutorial/source?autoplay and we would love to get feedback on what you think of it! If you found it helpful let us know what other types of tutorials you would like to see.

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

    Can someone help me with this C code assignment?

    Posted: 03 Apr 2018 11:09 PM PDT

    I do not understand how to do this assignment for the life of me. any help would be appreciated. Thanks! Assignment

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

    What's the best way to learn web development online for free?

    Posted: 03 Apr 2018 01:19 PM PDT

    I tried to learn web dev a few years ago but struggled to stick with it.

    I wanna try to get back into learning it as my first programming experience and i'm wondering what website or tutorials are the best that are available.

    submitted by /u/rdf-
    [link] [comments]

    Seg Fault is partially resolved upon adding an endl?

    Posted: 03 Apr 2018 07:14 PM PDT

    bool Relation::isJoinable(Tuple t1, Tuple t2, vector<string> s1, vector<string> s2) { cout << "is joinable "<< s1.size() << endl; for (int i = 0; i < s1.size(); i++) { cout <<"EXCUSE ME"; for (int j = 0;j < s2.size(); j++) { cout << j << " "; if (s1[i]==s2[j]&&t1[i]!=t2[j]) { cout << "can't add because " << s1[i] << "=" << t1[i] << " " << t2[j] << endl; return false; } } cout << endl; } return true; } 

    This code is giving me a seg fault, but it outputs "is Joinable 3" before the seg fault. However, if I remove the endl, it seg faults before that whole line of output (it doesn't say "Is joinable").

    I've looked this up and it seems many of the solutions end in noticing some uninitialized variable. I've poured over this code and still can't find the issue. What am I not understanding about this use of endl?

    EDIT: It seg faults even earlier if I take the endl off of the line that outputs "first".

    for(set<Tuple>::iterator it1 = tuples.begin(); it1 !=tuples.end(); it1++) { int i = 0; cout << "first" << endl; for(set<Tuple>::iterator it2 = (r2.getTuples()).begin(); it2 !=(r2.getTuples()).end(); it2++) { cout << i+1 << " *"; bool canJoin = isJoinable(*it1, *it2, s1, s2); if(canJoin) { cout << "I am adding a tuple!" << endl; } } } 

    EDIT 2: It does the same thing if I place a cout statement above the previous one without using an endl

    cout << "Hello"<< endl; int i = 0; cout << "first"; 

    If I take out the endl, it seg faults and doesn't even display "Hello"

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

    Worthwhile certifications for someone NOT picking up the tab?

    Posted: 03 Apr 2018 10:57 PM PDT

    So my employer wants to keep me around and has offered to pay for any online courses or certificates that would further my programming education (and of course make me more useful to the company). My initial research suggests that the consensus here is that certifications are pretty much worthless. However, since I wouldn't be the one picking up the tab, I'm wondering if there are any that would be worthwhile or would make me more employable in the future, such as an AWS certification.

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

    css clip-path invalid property value

    Posted: 03 Apr 2018 10:09 PM PDT

    The css property clip-path is in this class:

    .header { /* 95% viewport height */ height: 95vh; /* url() @param path imports an image*/ /* setting multiple images, with the gradient on top. Look up the params of linear-gradient, goes from first color to second color left to right, by changing opacity of the image on top you can see the second image*/ background-image: linear-gradient( to right bottom, #7ed56fc7, #28b485bb), url('../img/hero.jpg'); /* sets the background to the size of the viewport size of the element */ background-size: cover; /* Ensures that the image is always at the top of the container */ background-position: top; position: relative; /* top left, top right, bottom right, bottom left coordinates in the format <x> <y> for each corner*/ clip-path: polygon(0 0, 100 0, 100% 75vh, 0 100%); } 

    and clip-path isn't being loaded as chrome inspect says that it has invalid property value? Ideas?

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

    Not a fan of HTML and CSS yet liking jQuery and CS50

    Posted: 03 Apr 2018 09:44 PM PDT

    Hi all. I am currently working thru freeCodeCamp and CS50. I'm very early in both but I think I'm already getting a feel for what I like and don't.

    I could not care less about making something look pretty. I get high off making everything work and want to blow my brains out while reading Stack Overflow looking for the right bootstrap class to make the project look prettier and meet the requirements.

    In CS50 I love learning about the how's and why's of it all. I love math. It's my passion.

    Any comments or recommendations. I'm not sure what I'm looking for. I just need input. I don't have friends.

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

    SQLITE3 help

    Posted: 03 Apr 2018 09:38 PM PDT

    I want to get the first name from a "player" table, so basically a player.name = "Bruno Mars". How can I make it only check for the first name and not the whole name. I want it to look if the first name begins with a B.

    Right now I have:

    SELECT name from player where player.name Like ('%b%');

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

    Making a really awesome GUI

    Posted: 03 Apr 2018 05:43 PM PDT

    The story is really brief:

    -> I'm using C (but can change, if it's worth the time)

    -> I will make a GUI app for libraries

    The db part is basically solved, because i am using SQLite, no trouble. Simply done.

    The trouble is in the GUI part. I want it to be:

    1- Multiplataform - at least Debian (with all those desktop envs) and Windows

    2- Not to make a lot of overhead. Not JavaFX with its absurd memory usage (~800MB for a table and some popup windows). I want something simple

    3- Absurdely flexible (at compile time) GUI. I want all the buttons/etc to be like I want them: modern, flat.

    At this point, i looked at this and almost said "F*k it. I'll just make my own UI from scratch!" (scratch means OpenGL/GLFW in this case), pretty sure Sublime does this too.

    I want to hear a better programmer say what i have to hear. I am worried with acessibility and screen size ( but i am pretty sure i will just use 800x600). I mean, if i use GLFW, is it possible to use the Virtual Keyboard form windows? Or any issue like that that i can't even think?

    Oh, and you can't say "it's crazy to make an UI from scratch" without giving a really valid argument.

    Thank you all.

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

    How to Decrease the Compilation on My Program

    Posted: 03 Apr 2018 09:25 PM PDT

    This is C++. Forgot to Mention in the title

    Description of My Program This program will be about building a hash table. You will read words, separated by whitespace, from a given file into your program. As you read the words, you should insert each word into a hash table. The word itself is the key value, and each entry in the hash table also needs to store a list of the line numbers where the word appears. When inserting a word that already appears in the hash table, simply add the current line number to the list for the word. You will also count the number of collisions that occur while inserting words into the hash table. Every probe to a cell that contains a word other than the one being inserted or searched should count as an additional collision, so that inserting a word may have multiple collisions. Probes to empty cells or cells already containing the word do not count as collisions.Once you have read all of the words,you should output the total number of words read, the number of distinct words, and the total number of collisions that occurred in the hash table. Finally, you will read words from the query file and report the line numbers where the word occurs, and the number of collisions while searching for the word in the table.

    Problem: Now my problem is that the very long time to compile because of trying to find the unique words that are in the file (which contains 1095695 words). How would i solve this?

    ./project3 big.txt hashq2.txt 91111 qp // command line stuff. big.txt is the txt file that I'm getting the strings from. hashq2.txt is the query file, 91111 is how big the hash table will be, and qp is quadratic probing

    The code:

    include <iostream>

    include <fstream>

    include <string>

    include <cstring>

    include <vector>

    using namespace std;

    typedef struct node { int line; string strin; node next; nodeprev; } node;

    class line { public: node * lineList(int countLine, int countWord, node ptr, string strin) { node *newNode = new node; newNode->strin = strin; newNode->line = countLine; newNode->next = NULL; if (countWord == 0) { head = ptr; } tail = newNode; if (ptr == NULL) { return newNode; } ptr->next = tail; tail->prev = ptr; return tail; } private: node head; node* tail; };

    int main(int argc, char **argv) { node *getLine = NULL; node *getLine2 = NULL; line Line; ifstream inFS; inFS.open(argv[1]); if (!inFS.is_open()) { cout << "Error: File did not open." << endl; return -1; }

    char letters; string strin; int countLines = 1; int countWords = 0; int size = 91111; // this is the how big the hash table will be int uniqueWords = 0; string words[size] = "1qwerfdsw234rdsw234"; // this string is used to check for a unique words later on while (inFS.get(letters)) { if (letters == '\n') { // checks if there is new line countLines++; } if (!isspace(letters)) { strin.push_back((letters)); } else if (strin != "") { if (countWords == 0) { getLine = Line.lineList(countLines, countWords, getLine, strin); getLine2 = getLine; } else { getLine2 = Line.lineList(countLines, countWords, getLine2, strin); } for(int i = 0; i < size; i++){This is where the problem is since it takes forever to find uniquewords if (countWords == 0) { words[i] = strin; break; } if (strin == words[i]) { break; } else if (words[i] == "1qwerfdsw234rdsw234" || i == size - 1) { words[i] = strin; uniqueWords++; break; } } strin.clear(); countWords++; } } inFS.close(); cout << "The number of words found in the file was " << countWords << endl; cout << "The number of unique words found in the file was " << uniqueWords << endl; 

    Expected Output:

    The number of words found in the file was 1095695

    The number of unique words found in the file was 81397

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

    Computer Science Textbook Reading

    Posted: 03 Apr 2018 09:19 PM PDT

    How long does it typically take for you to read about 20 pages of a computer science textbook and understand the content? Do you take notes while you read? What is your system?

    I currently read and take notes as I go through the book but this is taking way too damn long. My retention is good with this system but I lose a huge amount of time. It takes me like an hour/1.5 hrs per 15-20 pages.

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

    Given an unsigned integer, it's easy to swap every even and odd bit. Can this be generalized to swapping every even and odd n bits?

    Posted: 03 Apr 2018 05:18 PM PDT

    In the case where n = 1, if we have an unsigned 32bit integer i, the swapped integer would be

    ((i & 0xaaaaaaaa) >> 1) | ((i & 0x55555555) << 1)

    When n = 2

    ((i & 0xcccccccc) >> 2) | ((i & 0x33333333) << 2)

    and so on.

    What about if n is an arbitrary number? ...and, let's say that i is an arbitrary 128bit integer rather than a 32bit integer so we have 7 cases rather than 5?

    I suspect there is a way to generalize the process for a given n, and it would be nice to have that so that I don't necessarily have to hardcode each individual case whenever it comes up (for example, implementing certain Cryptographic Hash Functions--e.g. JH).

    Edit: I have one example of a way to do it, but it seems a little clunky for my tastes.

    uint32_t mask = 0; submask = (2n) - 1; for (uint32_t index = 0; index < 32; index += 2n) { mask |= submask; submask <<= 2n; } 

    This would generate 0x55555555 for n = 1 and 0x33333333 for n = 2. I don't like that it requires a loop with a variable number of iterations, however, if I were stuck with this as my best generation option, I might just hardcode all the cases I were to work with.

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

    No comments:

    Post a Comment