• Breaking News

    Thursday, September 3, 2020

    Had my first programming interview, legs still shaking. learn programming

    Had my first programming interview, legs still shaking. learn programming


    Had my first programming interview, legs still shaking.

    Posted: 02 Sep 2020 09:41 AM PDT

    I can't even. The amount of times I said "no, sorry idk what that means?". Still got the job, you can do it guys. Keep grinding.

    Edit: Wow! Thanks a lot for all your comments and the awards!!

    Some FAQs

    I am a male, 17 years old, HS senior. Completely self taught (utube, udemy, edx and a few books and articles). Have been learning for 3 years now.

    I live in a big city so there are a lot of local software houses here.

    This wasn't actually my 'first' interview, have been applying since covid, actively and did get a couple interview offers but I declined.

    Interview was for a junior level backend developer. Php, laravel and sqlite and a little vue.

    Logical assessment was beginner level algorithms from leetcode and stuff. Like binary search, ordering arrays etc. How would u design the Twitter Api. Questions about my previous web dev projects

    Techincal questions were programming related, mainly php. Questions like what features does oop have? Advantages of oop, oop vs functional? Overloading, coupling, boxing unboxing, stuff like that. Facades, frameworks, web scraping, web sockets etc.

    There were questions related to version control, programming paradigms, test driven development and the likes which I completely flunked. Give that stuff a read before you take an interview. Also postman!

    Some people are surprised bh how I got the job on the first try. There could be a lot of reasons but one I think of is I have major imposter syndrome and before applying to a place I would spend days reading docs and scanning through github projects,I think, that might have contributed a bit.

    Again, Thank you everyone!

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

    DataCamp is giving free access to all its courses till September 9th !

    Posted: 02 Sep 2020 04:08 AM PDT

    Just make and account and start learning. I know this is a programming subreddit and DataCamp is primarily for those interested in data science but there are courses on scala, python, SQL and R on there so I though I'd put it here.

    Have been hanging out here for quite a while so decided to put it up. Forgive me for any formatting errors or stuff, this is my first ever post.

    Source:

    https://twitter.com/DataCamp/status/1300765729537626113

    Minor Edit: They provide certificates for any courses you complete.

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

    My first contribution ever to Open source has been merged!

    Posted: 02 Sep 2020 07:12 PM PDT

    Same as the title, I feel so proud of myself because I really didn't think I could do it at first because I thought I wasn't ready and I thought I should just focus on some side projects for my portfolio since that would be more at my level. But I'm glad I did it anyway because I learned so much even though my contribution wasn't some sparking new feature, just a bug. I learned how to read C# code written by other people, how to debug a dll, I quickly learned how to write some unit tests and etc. etc.. the project is also apart of the .net foundation too!

    Anywho I'm happy this has been a major boost in my motivation in learning and moving forward with my projects. To anyone out there wanting to do the same, you can do it don't listen to your anxiety and self-doubt, you cant get better if you don't try.

    p.s sorry for the ramble I literally don't have anyone to talk to about programming that understands what I am referring to.

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

    I'd like to work on your open-source or personal project if you need an intern/apprentice.

    Posted: 03 Sep 2020 12:05 AM PDT

    I'm a 2020 batch CS grad. Due to the pandemic, most of my plans have gone out of the window. I've been home alone for so long that I'm losing my mind. I'd like to work on something with other people. I'd like to learn new programming and CS concepts from you all. I have worked in Python, Java, C++, JS, frontend stuff, design stuff. If you need a partner for your project, please let me know. I can work on the project for 3-4 hours everyday.

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

    Is C++ good for website development?

    Posted: 02 Sep 2020 06:52 PM PDT

    Is C++ good for web development? and what are the pros and cons?

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

    What is the point of structs in C++ when it's almost the same as a class?

    Posted: 02 Sep 2020 11:39 PM PDT

    Is it only for things where you don't have methods ? And as soon as you have a method you should use a class?

    Is it there for legacy reasons?

    I know the only difference is that a strict has all members public hy default. Everything else is the same as a class.

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

    If you want to learn web programming using Python/Django, check out this guide.

    Posted: 02 Sep 2020 05:01 PM PDT

    When I was learning Django, I watched countless youtube videos but I never found a cohesive guide of how to start developing web apps with Django.

    I have written a book to help beginners learn django web development. The first three chapters are free, see link below. If you find it useful after reading the preview, please consider buying my book. Thanks

    Django 3...2...1...Takeoff!: Quick Guide to Learning Django 3 Web Development Free Preview:

    https://drive.google.com/file/d/1uqSzghY1kRIWVFQ4HXV-Befv9-1UHbN6/view

    Entire Book:

    https://www.amazon.com/Django-Takeoff-Quick-Learning-Development-ebook/dp/B08H4W2WLD/ref=tmm_kin_swatch_0?_encoding=UTF8&qid=&sr=

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

    For those who self-taught, exactly what topics should i learn to land a job/internship? Super lost

    Posted: 02 Sep 2020 11:54 AM PDT

    Im a 100% self-taught, beginner in learning Python, and this is my first ever brush with anything computer science-related. I would love to become a jr software developer in the next 1-2 years (preferably back-end but am obviously willing to try anything), but im lost on what to learn. I understand the best way to learn is writing code aka doing projects, but what do i LEARN first to get to that point?

    Right now, im still in the middle of Automate the Boring Stuff. I do practice problems the book has as i learn each topic (practice projects). Some have advised me to learn data structures next. Im lost on what to learn after data structures, and what to learn after that. What topics should I be studying next to at least get my foot in the door for an interview in the future?

    Does anyone have advice on general roadmap of topics to learn that would help me have a solid understanding? Each topic/skill i do, i will be creating mini projects as i learn, but my main issue is, what do i learn? For those who started a job as jr developer or even internship, what are the topics i should learn?

    PS: please don't be afraid to dumb down your answers; im new to this field and would appreciate all the help i can get!!

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

    An introduction to Linux through Windows Subsystem for Linux

    Posted: 02 Sep 2020 01:26 PM PDT

    I'm working as an Undergraduate Learning Assistant and wrote this guide to help out students who were in the same boat I was in when I first took my university's intro to computer science course. It provides an overview of how to get started using Linux, guides you through setting up Windows Subsystem for Linux to run smoothly on Windows 10, and provides a very basic introduction to Linux. Students seemed to dig it, so I figured it'd help some people in here as well. I've never posted here before, so apologies if I'm unknowingly violating subreddit rules.

    Getting Windows Subsystem for Linux running smoothly on Windows 10

    GitHub Pages link

    Introduction and motivation

    tl;dr skip to next section

    So you're thinking of installing a Linux distribution, and are unsure where to start. Or you're an unfortunate soul using Windows 10 in CPSC 201. Either way, this guide is for you. In this section I'll give a very basic intro to some of options you've got at your disposal, and explain why I chose Windows Subsystem for Linux among them. All of these have plenty of documentation online so Google if in doubt.

    • Dual-booting with Windows and a Linux distro
      • Will basically involve partitioning your drive and installing Linux from an external bootable USB through your computer's boot menu. You'll get the full Linux experience.
      • Lots of Linux flavors to choose from. For beginners, Ubuntu and Linux Mint are generally recommended. I have Ubuntu 18.04 LTS, I'd recommend Ubuntu 20.04 LTS since it's newer, but it's all up to you.
      • However, it's a pain to setup and to constantly be switching between operating systems, so up to you. Maybe you wanna make the full jump to Linux, maybe you don't.
      • Life pro tip: if you go this route, disable Window 10's Fast Startup feature as it will get very screwy with a dual-boot.
    • Using a virtual machine (VM) to run Linux
      • Involves downloading a VM, downloading a .iso image file of whatever operating system you'd like, and running on your local machine.
      • Devours RAM and is generally pretty slow, would not recommend.
    • Using bash emulation software, like Putty or Git Bash
      • bash stands for Bourne Again Shell (no, Bourne is not a typo), it's the most commonly used Linux shell these days
      • bash emulators generally don't include a package manager, i.e. you can't download new bash programs, so pretty limited for general usage. BUT you can install a package manager externally, kind of hacky but can work.
    • Using Windows Subsystem for Linux (either WSL 1 or WSL 2)

      • WSL provides a compatibility layer for running Linux natively on Windows 10. It has integration features certain Windows 10 development apps (notably Visual Studio Code) as well.
      • You've got two options, WSL 1 and WSL 2. WSL 2 was recently released and features a real Linux kernel, as opposed to an simulated kernel in WSL. This means WSL 2 offers significant performance advantages, but still lacks some of WSL 1's features.
      • WSL 1 is what I currently use, and thus what I'll be talking about in this guide. I'm not necessarily recommending it, frankly I regret not doing a dual-boot sooner and ditching Windows, but a dual-boot isn't for everyone and takes a lot of time you might not have right now.
      • Getting WSL initially setup is easy, but making it run smoothly requires some effort, and some features (like audio playback or displaying GUIs) require workarounds you can research if interested.

      With that out of the way, let's get started with setting up WSL 1 on your Windows 10 machine.

    Setting up WSL

    So if you've read this far I've convinced you to use WSL. Let's get started with setting it up. The very basics are outlined in Microsoft's guide here, I'll be covering what they talk about and diving into some other stuff.

    1. Installing WSL

    Press the Windows key (henceforth Winkey) and type in PowerShell. Right-click the icon and select run as administrator. Next, paste in this command:

    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart 

    Now you'll want to perform a hard shutdown on your computer. This can become unecessarily complicated because of Window's fast startup feature, but here we go. First try pressing the Winkey, clicking on the power icon, and selecting Shut Down while holding down the shift key. Let go of the shift key and the mouse, and let it shutdown. Great! Now open up Command Prompt and type in

    wsl --help 

    If you get a large text output, WSL has been successfully enabled on your machine. If nothing happens, your computer failed at performing a hard shutdown, in which case you can try the age-old technique of just holding down your computer's power button until the computer turns itself off. Make sure you don't have any unsaved documents open when you do this.

    2. Installing Ubuntu

    Great! Now that you've got WSL installed, let's download a Linux distro. Press the Winkey and type in Microsoft Store. Now use the store's search icon and type in Ubuntu. Ubuntu is a Debian-based Linux distribution, and seems to have the best integration with WSL, so that's what we'll be going for. If you want to be quirky, here are some other options. Once you type in Ubuntu three options should pop up: Ubuntu, Ubuntu 20.04 LTS, and Ubuntu 18.04 LTS.

    ![Windows Store](https://theshepord.github.io/intro-to-WSL/docs/images/winstore.png) Installing plain-old "Ubuntu" will mean the app updates whenever a new major Ubuntu distribution is released. The current version (as of 09/02/2020) is Ubuntu 20.04.1 LTS. The other two are older distributions of Ubuntu. For most use-cases, i.e. unless you're running some software that will break when upgrading, you'll want to pick the regular Ubuntu option. That's what I did.

    Once that's done installing, again hit Winkey and open up Ubuntu. A console window should open up, asking you to wait a minute or two for files to de-compress and be stored on your PC. All future launches should take less than a second. It'll then prompt you to create a username and password. I'd recommend sticking to whatever your Windows username and password is so that you don't have to juggle around two different user/password combinations, but up to you.

    Finally, to upgrade all your packages, type in

    sudo apt-get update 

    And then

    sudo apt-get upgrade 

    apt-get is the Ubuntu package manager, this is what you'll be using to install additional programs on WSL.

    3. Making things nice and crispy: an introduction to UNIX-based filesystems

    tl;dr skip to the next section

    The two above steps are technically all you need for running WSL on your system. However, you may notice that whenever you open up the Ubuntu app your current folder seems to be completely random. If you type in pwd (for Present Working Directory, 'directory' is synonymous with 'folder') inside Ubuntu and hit enter, you'll likely get some output akin to /home/<your_username>. Where is this folder? Is it my home folder? Type in ls (for LiSt) to see what files are in this folder. Probably you won't get any output, because surprise surprise this folder is not your Windows home folder and is in fact empty (okay it's actually not empty, which we'll see in a bit. If you type in ls -a, a for All, you'll see other files but notice they have a period in front of them, which tells bash that they should be hidden by default. Anyways).

    So where is my Windows home folder? Is WSL completely separate from Windows? Nope! This is Windows Subsystem for Linux after all. Notice how, when you typed pwd earlier, the address you got was /home/<your_username>. Notice that forward-slash right before home. That forward-slash indicates the root directory (not to be confused with the /root directory), which is the directory at the top of the directory hierarchy and contains all other directories in your system. So if we type ls /, you'll see what are the top-most directories in your system. Okay, great. They have a bunch of seemingly random names. Except, shocker, they aren't random. I've provided a quick run-down in Appendix A.

    For now, though, we'll focus on /mnt, which stands for mount. This is where your C drive, which contains all your Windows stuff, is mounted. So if you type ls /mnt/c, you'll begin to notice some familiar folders. Type in ls /mnt/c/Users, and voilà, there's your Windows home folder. Remember this filepath, /mnt/c/Users/<your_Windows_home_folder>. When we open up Ubuntu, we don't want it tossing us in this random /home/<your_username> directory, we want our Windows home folder. Let's change that!

    4. Changing your default home folder

    Type in sudo vim /etc/passwd. You'll likely be prompted for your Ubuntu's password. sudo is a command that gives you root privileges in bash (akin to Windows's right-click then selecting 'Run as administrator'). vim is a command-line text-editing tool, kinda like an even crummier Notepad, which is a pain to use at first but bear with me and we can pull through. /etc/passwd is a plaintext file that does not store passwords, as the name would suggest, but rather stores essential user info used every time you open up WSL.

    Anyway, once you've typed that in, your shell should look something like this: ![vim /etc/passwd](https://theshepord.github.io/intro-to-WSL/docs/images/vim-etc-passwd.png)

    Using arrow-keys, find the entry that begins with your Ubuntu username. It should be towards the bottom of the file. In my case, the line looks like

    theshep:x:1000:1000:,,,:/home/pizzatron3000:/bin/bash 

    See that cringy, crummy /home/pizzatron3000? Not only do I regret that username to this day, it's also not where we want our home directory. Let's change that! Press i to initiate vim's -- INSERT -- mode. Use arrow-keys to navigate to that section, and delete /home/<your_username> by holding down backspace. Remember that filepath I asked you to remember? /mnt/c/Users/<your_Windows_home_folder>. Type that in. For me, the line now looks like

    theshep:x:1000:1000:,,,:/mnt/c/Users/lucas:/bin/bash 

    Next, press esc to exit insert mode, then type in the following:

    :wq 

    The : tells vim you're inputting a command, w means write, and q means quit. If you've screwed up any of the above sections, you can also type in :q! to exit vim without saving the file. Just remember to exit insert mode by pressing esc before inputting commands, else you'll instead be writing to the file.

    Great! If you now open up a new terminal and type in pwd, you should be in your Window's home folder! However, things seem to be lacking their usual color...

    5. Importing your configuration files into the new home directory

    Your home folder contains all your Ubuntu and bash configuration files. However, since we just changed the home folder to your Window's home folder, we've lost these configuration files. Let's bring them back! These configuration files are hidden inside /home/<your_Ubuntu_username>, and they all start with a . in front of the filename. So let's copy them over into your new home directory! Type in the following:

    cp -r /home/<your_Ubuntu_username>/* ~ 

    cp stands for CoPy, -r stands for recursive (i.e. descend into directories), the * is a Kleene Star and means "grab everything that's here", and the ~ is a quick way of writing your home directory's filepath (which would be /mnt/c/Users/<your_Windows_username>) without having to type all that in again. Once you've run this, all your configuration files should now be present in your new home directory. Configuration files like .bashrc, .profile, and .bash_profile essentially provides commands that are run whenever you open a new shell. So now, if you open a new shell, everything should be working normally. Amazing. We're done!

    6. Tips & tricks

    Here are two handy commands you can add to your .profile file. Run vim ~/.profile, then, type these in at the top of the .profile file, one per line, using the commands we discussed previously (i to enter insert mode, esc to exit insert mode, :wq to save and quit).

    alias rm='rm -i' makes it so that the rm command will always ask for confirmation when you're deleting a file. rm, for ReMove, is like a Windows delete except literally permanent and you will lose that data for good, so it's nice to have this extra safeguard. You can type rm -f to bypass. Linux can be super powerful, but with great power comes great responsibility. NEVER NEVER NEVER type in rm -rf /, this is saying 'delete literally everything and don't ask for confirmation', your computer will die. You've been warned. Be careful.

    export DISPLAY=:0 if you install XLaunch VcXsrv, this line allows you to open graphical interfaces through Ubuntu. The export sets the environment variable DISPLAY, and the :0 tells Ubuntu that it should use the localhost display.

    Appendix A: overview of top-level UNIX directories

    tl;dr only mess with /mnt, /home, and maybe maybe /usr. Don't touch anything else.

    • bin: binaries, contains Ubuntu binary (aka executable) files that are used in bash. Here you'll find the binaries that execute commands like ls and pwd. Similar to /usr/bin, but bin gets loaded earlier in the booting process so it contains the most important commands.
    • boot: contains information for operating system booting. Empty in WSL, because WSL isn't an operating system.
    • dev: devices, contains information for Ubuntu to communicate with I/O devices. One useful file here is /dev/null, which is basically an information black hole that automatically deletes any data you pass it.
    • etc: no idea why it's called etc, but it contains system-wide configuration files
    • home: equivalent to Window's C:/Users folder, contains home folders for the different users. In an Ubuntu system, under /home/<username> you'd find the Documents folder, Downloads folder, etc.
    • lib: libraries used by the system
    • lib64 64-bit libraries used by the system
    • mnt: mount, where your drives are located
    • opt: third-party applications that don't have any dependencies outside the scope of their own package
    • proc: process information, contains details about your Linux system, kind of like Windows's C:/Windows folder
    • run: directory for programs to store runtime information. Similarly to /bin vs /usr/bin, run has the same function as /var/run, but gets loaded sooner in the boot process.
    • srv: server folder, holds data to be served in protocols like ftp, www, cvs, and others
    • sys: system, used by the Linux kernel to set or obtain information about the host system
    • tmp: temporary, runtime files that are cleared out after every reboot. Kinda like RAM in that way.
    • usr: contains additional UNIX commands, header files for compiling C programs, among other things. Most of everything you install using apt-get ends up here.
    • var: variable, contains variable data such as logs, databases, e-mail etc, but that persist across different boots.

    Appendix B: random resources

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

    Confusion over O(M+N) being more correct than O(2N) for multiple parameters in code

    Posted: 02 Sep 2020 09:55 PM PDT

    I have heard how the correct or tightest upper bound in this code would be O(N+M). My question is why would saying O(N+N) be wrong. I have heard how this would be a loose or false upper bound. If that is the case, how do we know if O(n) is < O(m), or how do we know if O(n) > O(m)? The main reason I keep seeing is that we use O(N + M) over O(2N) is because there is no guarantee if O(N) = O(M). My confusion is how can we not tell that O(N) = O(M) is true? Clearly we have two simple for loop that run linearly, which will allow us to add them in my head and make it O(N + N). Where am I going wrong? Is it because we do not know if the two linear growth rates have any relation? If that is the case in regular math we can add 2x with 3x and make it 2x+5x knowing that both linear growth rates are different.

    public void ex(int n, int m) { int i - 0; int j = 0; while(i < n) { i++: } while(j < m) { j++; } } 
    submitted by /u/Pea_Alive
    [link] [comments]

    I want to fix a bug with a display adapter driver. Where do I start?

    Posted: 02 Sep 2020 09:14 PM PDT

    I have an Acer laptop, which has a strange bug. If I close the lid and reopen it, the screen stays turned off, though the laptop itself is still on and running. No sleep/hibernate or anything like that.

    This only happens when the display adapter driver from Acer's website is installed. If I downgrade the driver to the generic Microsoft one then I no longer have this problem, but I lose the ability to control screen brightness, and probably some graphics performance.

    This is the source of the official driver (the Intel one): https://www.acer.com/ac/en/CA/content/support-product/6305?b=1&pn=NX.G36AA.001

    Is there a way I can fix the bug in the Intel driver from Acer?

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

    Setting up git permissions

    Posted: 03 Sep 2020 12:41 AM PDT

    Hello,

    I have a personal project that's currently housed in a private repo in GitHub. I want to allow other contributors into the repo but I want to keep tight control over what goes in as an admin. Is there a free way on GitHub or other git clients to only allow PRs after it has gone through approval from me?

    I have recently learned that protected branches in GitHub isn't free for private repos.

    Any and all help would be greatly appreciated.

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

    Books Vs Courses

    Posted: 03 Sep 2020 12:38 AM PDT

    Hello everyone :) I'm a complete beginner, just finished Colt Steele's python3 Bootcamp and CS50 and small other coursera courses. I'm feeling I am improving, specially with CS50.

    My question is very simple, when do I have to learn from books + how to learn from a book. For an online course I watch the lectures and solve the problems " which are marked automatically" what about books then? And what I will get from books far than I can take from the online courses?

    Thanks all

    submitted by /u/0ssamaak0
    [link] [comments]

    What project to build for C++ OOP?

    Posted: 03 Sep 2020 12:36 AM PDT

    Hey, I just started out with OOP on C++, but I have experience with other languages. I was wondering what projects I could build that utilize OOP in C++.

    I was also thinking about doing a CRUD App with C++ and some sort of SQL, but I have no idea what GUI or type of SQL i should use.

    Any ideas? Thanks!

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

    Help me how to find out the odd column index in a two dimensional array

    Posted: 03 Sep 2020 12:24 AM PDT

    I need help to copy the elements in the odd column index in another array. Basically, the number of my col and rowws depend on the user so I have a scanner. I can't copy the elements since I don't know what to do to find the odd column index. And can you give me also an idea on how to copy the other elements in another array.

    import java.util.Scanner; import java.util.Random; import java.util.Arrays; class try { public static void main(String[] args) { MP2 array = new MP2(); int A[][] = array.load_A(4); } public int[][] load_A(int n) { Random random = new Random(); Scanner in = new Scanner(System.in); int row, col; System.out.print("Enter the number of rows:"); row = in.nextInt(); System.out.print("Enter number of columns: "); col = in.nextInt(); int A[][] = new int[row][col]; for (int i = 0; i < row; i++) { // do the for in the row according to the column size for (int j = 0; j < col; j++) { // multiple the random by 10 and then cast to in A[i][j] = 1 + random.nextInt(50-1); System.out.print("\t "+(A[i][j])); } // add a new line System.out.println(" "); } return A; } } 
    submitted by /u/blissful_rae
    [link] [comments]

    Cheatsheet

    Posted: 03 Sep 2020 12:04 AM PDT

    Does the industry look down on people who uses cheat sheets? There is no in way hell I can remember everything I learn. I have a binder full of cheatsheet ranging from basic file creation to rocket science (some chemistry crap from high school). I just try to remember the syntax of most languages and refer to my cheatsheet when I'm studying at home. I can't even remember my mom birthday ffs. Do you guys use cheat sheet? What's your favorite? Share please.

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

    Do you have any advice for me? (Freelancing)

    Posted: 03 Sep 2020 12:01 AM PDT

    I'm software Engineer Student. Recently I joined Fiverr trying to earn some extra money since I'm struggling. I published a Web Scraping GIG and I had 2 clients contacting me for projects. Good as beginning right? Problem is I was unable to take any of the projects since I tried to develop solutions and failed !

    First Project : Script that gets 100 Google results for every keyword in an Excel Sheet (3k keywords)

    Second Project : Script that downloads every new Instagram Post/Story for several users and publishes to discord

    I just want to know, are the projects too hard or they are just fine and I need to learn more about Web Scraping before making a GIG or do I need to change the Niche (I have experience with Flask/Django/Bootstrap/React) ??

    PS : I've already made 3 personal scraping projects (Ebay reviews Scraper, Amazon Affiliate links generator, Google results scraper for SEO) using Bs4, Requests & Selenium ..

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

    What are the best youtubers that teach coding for web development like PHP, JavaScript and HTML?

    Posted: 02 Sep 2020 11:58 PM PDT

    Title just looking for youtube recommendations on people that are good at teaching those languages

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

    Extremely hard leetcode problem 675. Cut off Trees for Golf Event

    Posted: 02 Sep 2020 07:59 PM PDT

    Would really appreciate the help in understanding the solution for this problem! I have no idea what's happening, not even familiar with the syntax being used in the first 2 lines. First the problem:

    You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-negative 2D map, in this map:

    1. 0 represents the obstacle can't be reached.
    2. 1 represents the ground can be walked through.
    3. The place with number bigger than 1 represents a tree can be walked through, and this positive number represents the tree's height.

    In one step you can walk in any of the four directions top, bottom, left, and right
    also when standing in a point which is a tree you can decide whether or not to cut off the tree.

    You are asked to cut off all the trees in this forest in the order of tree's height - always cut off the tree with lowest height first. And after cutting, the original place has the tree will become a grass (value 1).

    You will start from the point (0, 0) and you should output the minimum steps you need to walk to cut off all the trees. If you can't cut off all the trees, output -1 in that situation.

    You are guaranteed that no two trees have the same height and there is at least one tree needs to be cut off.

    Example 1:

    Input: [ [1,2,3], [0,0,4], [7,6,5] ] Output: 6 

    Example 2:

    Input: [ [1,2,3], [0,0,0], [7,6,5] ] Output: -1 

    Example 3:

    Input: [ [2,3,4], [0,0,5], [8,7,6] ] Output: 6 Explanation: You started from the point (0,0) and you can cut off the tree in (0,0) directly without walking. 

    Constraints:

    1 <= forest.length <= 50 1 <= forest[i].length <= 50 0 <= forest[i][j] <= 10^9 

    Solution:

    class Solution: def cutOffTree(self, forest): trees = sorted((v, r, c) for r, row in enumerate(forest) for c, v in enumerate(row) if v > 1) sr = sc = ans = 0 for _, tr, tc in trees: d = self.bfs(forest, sr, sc, tr, tc) if d < 0: return -1 ans += d sr, sc = tr, tc return ans def bfs(self, forest, sr, sc, tr, tc): R, C = len(forest), len(forest[0]) queue = collections.deque([(sr, sc, 0)]) seen = {(sr, sc)} while queue: r, c, d = queue.popleft() if r == tr and c == tc: return d for nr, nc in ((r-1, c), (r+1, c), (r, c-1), (r, c+1)): if (0 <= nr < R and 0 <= nc < C and (nr, nc) not in seen and forest[nr][nc]): seen.add((nr, nc)) queue.append((nr, nc, d+1)) return -1 

    Can someone help explain what is happening in the trees = sorted(..) not even familiar with that syntax. Also what is the underscore in for _, tr, tc in trees line? And just a quick summary of what's happening in this code would be really helpful, or any help really. Thanks in advance!

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

    C++ sfml-d-2.dll not found issue

    Posted: 02 Sep 2020 11:28 PM PDT

    I'm sure this is a newbie thing, but I am working on making a basic game in microsoft visual. I am following a tutorial and was directed to download the SFML Files and correctly linked the sfml lib and include in the proper places. I know this because there are no errors when I write the code for the sprite background. I am getting an error when launching the code that the SFML d-2.dll is missing even though I have those in the project file. I am working on a school AWS system and cant get access to the Program files. Is this the issue, or is there another place I can put the DLL2 files that the computer will recognize?

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

    Just graduated with a history degree & I want to pursue a career in programming but I am not sure why

    Posted: 02 Sep 2020 07:27 PM PDT

    Just kind of reading through some posts it seems that people often have a purpose in learning how to code and why they want to and the specific language they want to do. I just guess I feel very discouraged in pursing and learning how to code as I have never been very "technology-oriented" and never really expressed any interest in this before. Whenever I tell someone that I am interested in pursing that type of career they just shrug me off, so I guess I am just wondering if anyone has any stories or life experiences on completing changing directions on career choice and pursing a career in programming?

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

    C - Program Changes Results Between Runs

    Posted: 02 Sep 2020 11:08 PM PDT

    So I'm trying to learn c and I was able to get the code compiled and running. The point of the code is to read a file and only read the lines that doesn't start with #.

    However, after running the program consecutively (in the exact same build), the output is randomly different.

    Sometimes it is as desired:

    a

    But sometimes there is a random @ sign following the first char:

    a@

    After increasing the initial length of the char array, I have found that sometimes it will send a bunch of /s after it:

    a///////////

    What could be causing this?

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

    Im sure this a dumb question but how do properties(C#) and getter/setter methods protect class members when they can be changed through those methods and properties?

    Posted: 02 Sep 2020 04:59 PM PDT

    I'm sure I'm missing the obvious so I apologize in advance but you learn that you should make members of a class private and then use properties or getter/setter methods to access those variables. But how does that make your code more secure? Yes, you can't directly change the values of those private members but you can use the properties or getter/setter methods to change them. So they are still accessible and can still be changed outside of the class. How does this provide protection for those private members?

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

    Anyone else (not yet employed in the career) feel that there are possibly too many people trying to do the same thing?

    Posted: 02 Sep 2020 01:04 PM PDT

    Idk I guess one of those days. I feel like I'm learning something that I personally enjoy about 3 months into C# and i love it and ive come a very long way, but I keep feeling like I'm learning something that I will not be able to actually get hired doing because of the vast numbers of people also doing the same thing. I Specifically avoided learning Python for that reason, all the guides to becoming programmers recommend python and YouTube the views on videos I've seen are 5-6x the views of any other language I've seen past few months. Was thinking maybe C# will be less saturated?

    Maybe I'm depressed about nothing. Lol. Well my question is, is the programming job market over saturated realistically speaking or not really? Anyone know?

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

    No comments:

    Post a Comment