Results 1 to 15 of 15
  1. #1
    Sam's Avatar
    Join Date
    Oct 2015
    Gender
    female
    Posts
    1,188
    Reputation
    313
    Thanks
    639
    My Mood
    Psychedelic

    How the heck do people get so good at coding?

    I've learnt a few languages and I wouldn't say I'm even that good at them. I know the basic layout of code, how to write in code. But how do people understand it so well they can do things like this?

    Code:
    function string sexynumber(N) {
        local Str = N:toString()
        local OldStr = Str
        while (1) {
            Str = Str:replaceRE("^(-?%d+)(%d%d%d)", "%1,%2")
            if (Str == OldStr) {
                break
            }
            OldStr = Str
        }
        return Str
    }
    Basically just converts and input number to have commas every 3 numbers. Please break it down because my head is clearly too small.
    Does it just come with advanced learning or is there an easier way to understand it?
    Should I be looking at other peoples codes?

  2. #2
    MikeRohsoft's Avatar
    Join Date
    May 2013
    Gender
    male
    Location
    Los Santos
    Posts
    796
    Reputation
    593
    Thanks
    26,333
    this seems a mix between JavaScript and i dnno what. What language is it?! or the solution must be? C++?
    i dont get why it must be done with an regex replace?

  3. #3
    nicoti's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    63
    Reputation
    10
    Thanks
    6
    My Mood
    Amazed
    IT's a main game dude, try be easier and u understand all)

  4. #4
    MikeRohsoft's Avatar
    Join Date
    May 2013
    Gender
    male
    Location
    Los Santos
    Posts
    796
    Reputation
    593
    Thanks
    26,333
    in JavaScript i would just do this:
    Code:
    function sexynumber(num) {
        const strNumber = num.toString();
        const strLength = strNumber.length - 1;
        const out = [];
        for (let c = -1, i = strLength; i >= 0; i--) {
    	if (isNaN(strNumber.charAt(i))) {
    		continue;
    	}
            if (++c < 3) {
                out.push(strNumber.charAt(i));
                continue;
            } 
            c = 0;
    	out.push(',');
            out.push(strNumber.charAt(i));
        }
        return out.reverse().join('');
    }
    
    console.log(sexynumber(100000000000));
    the concept would work in other languages too

  5. #5
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,321
    My Mood
    Cheeky
    Str:replaceRE("^(-?%d+)(%d%d%d)", "%1,%2")

    is a regular expression replacement, lets break it down

    ^ means start of the string
    (-?%d+) is a capture group. -? means that a minus sign is optional. %d means a digit and the plus sign means 1 or more of the previous match, in this case a digit.
    (%d%d%d) is another capture group. it basically captures when there are 3 digits in a row.

    This regex replace will therefor only match if it can find a string of 4 or more digits, optionally prefixed by a -.

    Example: 1234567890
    The (-?%d+) group captures 1234567 and stores it in %1 and (%d%d%d) captures 890 and stores it in %2. The string is replaced by %1,%2 so this becomes 1234567,890
    it compares 1234567,890 to 1234567890 and notices its not the same, so it repeats the regex replacement

    (-?%d+) now captures 1234 and (%d%d%d) now captures 567, so 1234567,890 this is replaced by 1234,567,890
    it compares 1234,567,890 to 1234567,890 and notices its not the same, so it repeats the regex replacement

    (-?%d+) now captures 1 and (%d%d%d) now captures 234, so 1234,567,890 this is replaced by 1,234,567,890
    it compares 1,234,567,890 to 1234,567,890 and notices its not the same, so it repeats the regex replacement

    (-?%d+) now captures 1, but there are no 3 digits left for (%d%d%d) to capture, so the replace does nothing.
    it compares 1,234,567,890 to 1,234,567,890 and notices its the same, so it's done replacing.

    You can practice regex patterns on sites like regexr[dot]com
    This follows a slightly different format though, as i'm not sure what regex flavor your example is.

    If you use regexr[dot]com enable the multiline flag and use this as expression : ^(-?\d+)(\d\d\d)
    In the text field add
    Code:
    1234567890
    1234567,890
    1234,567,890
    1,234,567,890
    Go to the replace tab in the bottom right and enter $1,$2

    Then you'll see this example.

    It also has an explanation for the regex pattern.
    Last edited by Hell_Demon; 09-05-2018 at 06:40 AM.
    Ah we-a blaze the fyah, make it bun dem!

  6. The Following User Says Thank You to Hell_Demon For This Useful Post:

    fidle89 (09-10-2018)

  7. #6
    Lizzypoopoo's Avatar
    Join Date
    Sep 2018
    Gender
    female
    Posts
    101
    Reputation
    -11
    Thanks
    18
    they just practice and practice just like anything in else in life. some people go to college to learn. people will pay for in depth online courses with live help.

  8. #7
    junh123's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    5
    Reputation
    10
    Thanks
    0
    My Mood
    Amazed
    I'd actually oppose, this seems like bad code and that's why you can't understand it. Good code will be understandable to a beginner coder.
    If the one programming that code would add comments, change the names of the variables/functions to mean something you will understand better.
    (Mostly the comments part. Add comments!)

  9. #8
    huvekuk's Avatar
    Join Date
    Sep 2018
    Gender
    male
    Posts
    11
    Reputation
    10
    Thanks
    0
    I dont think its that hard. I lived with it for 3 weeks as a beginner and could do many things without help. But yeah coding could be made easier.

  10. #9
    fidle89's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    England
    Posts
    185
    Reputation
    9
    Thanks
    13
    My Mood
    Sleepy
    Quote Originally Posted by HeyImGay View Post
    I've learnt a few languages and I wouldn't say I'm even that good at them. I know the basic layout of code, how to write in code. But how do people understand it so well they can do things like this?

    Code:
    function string sexynumber(N) {
        local Str = N:toString()
        local OldStr = Str
        while (1) {
            Str = Str:replaceRE("^(-?%d+)(%d%d%d)", "%1,%2")
            if (Str == OldStr) {
                break
            }
            OldStr = Str
        }
        return Str
    }
    Basically just converts and input number to have commas every 3 numbers. Please break it down because my head is clearly too small.
    Does it just come with advanced learning or is there an easier way to understand it?
    Should I be looking at other peoples codes?
    I dunno, this looks a mess to me. I understand what it's saying but it could be a lot cleaner. I think one of the easiest languages that could do this for you would be PHP, or VB. Then again, jQuery is a godsend for cleaning up code.

    By reading your post I get the impression you don't know a great deal which is fine, a lot of developers here are full-time developers and have it embedded into their heads 24/7. Coding isn't an art, in the sense that anyone can do it given enough time and learning. A lot of languages do more or less the same thing, except it's read different by both the computer and the human behind the screen. Take a look at some examples on Stack Overflow as that's a good website for everything. I know Codecademy was good for starters but I'm not sure what's it like nowadays.

    Edit: One thing I was taught a long time ago was Psuedocode. It's a sequence that's written in standard English (or your chosen language) that is styled as code, making it easier for everyone to read. I'll suggest next time you create something, do it in psuedocode first so you can understand exactly what's happening. With this you can use selection and iteration statements as well and it'll be a hundred times easier to understand. After that, it's just a case of finding the language you want to try creating it in.
    Last edited by fidle89; 09-10-2018 at 02:12 AM.

  11. #10
    free123games's Avatar
    Join Date
    Sep 2018
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    0
    Coding requires understanding of logic

  12. #11
    Dave84311's Avatar
    Join Date
    Dec 2005
    Gender
    male
    Location
    The Wild Wild West
    Posts
    35,808
    Reputation
    5782
    Thanks
    41,316
    My Mood
    Devilish
    Keep doing it nigga, with experience you gain familiarity and knowledge.





    THE EYE OF AN ADMINISTRATOR IS UPON YOU. ANY WRONG YOU DO IM GONNA SEE, WHEN YOU'RE ON MPGH, LOOK BEHIND YOU, 'CAUSE THATS WHERE IM GONNA BE


    "First they ignore you. Then they laugh at you. Then they fight you. Then you lose.” - Dave84311

    HAVING VIRTUAL DETOX

  13. The Following User Says Thank You to Dave84311 For This Useful Post:

    Sam (09-29-2018)

  14. #12
    McLovinTon's Avatar
    Join Date
    Nov 2017
    Gender
    female
    Posts
    305
    Reputation
    36
    Thanks
    22
    My Mood
    Breezy
    not that it matters but if you learn enough code you can hack the pentagon. If you need a VPN i'd recommend NordVPN

  15. #13
    Sam's Avatar
    Join Date
    Oct 2015
    Gender
    female
    Posts
    1,188
    Reputation
    313
    Thanks
    639
    My Mood
    Psychedelic
    Quote Originally Posted by McLovinTon View Post
    not that it matters but if you learn enough code you can hack the pentagon. If you need a VPN i'd recommend NordVPN
    Doubt nordvpn will stop me getting caught by US Government

  16. #14
    McLovinTon's Avatar
    Join Date
    Nov 2017
    Gender
    female
    Posts
    305
    Reputation
    36
    Thanks
    22
    My Mood
    Breezy
    Nah





    Possibly xD

  17. #15
    JFlawkz's Avatar
    Join Date
    Jan 2013
    Gender
    male
    Posts
    13
    Reputation
    10
    Thanks
    3
    I'm in no means "an expert coder" or advanced in any sort but honestly anything i've learned is from basic common sense in understanding aswell as learning from friends, friends are like the best thing for this because you guys could review eachothers code and explanations to eachother on what does what, what goes where and why, I learned quite the few things from friends and its actually so fun to do, honestly round up a few friends that tend to code aswell and it really does help if you guys are coding the same language aswell as projects that are similar so you could see who took what path and how and why, whats more efficient etc.

Similar Threads

  1. How the hell did i get 500 exp?
    By ZombieTea in forum Combat Arms Discussions
    Replies: 22
    Last Post: 05-03-2011, 06:47 PM
  2. Need to learn how the heck to take an ad out of a hack
    By Reaper8281 in forum Combat Arms Help
    Replies: 4
    Last Post: 03-26-2010, 11:46 PM
  3. how the f do i get musik on an lg
    By Hyak in forum General
    Replies: 7
    Last Post: 06-27-2009, 08:34 PM
  4. HOW THE HECK DO YOU BYPASS HACKSHIELD!??
    By THE_NOOB_HACKER in forum Combat Arms Hacks & Cheats
    Replies: 4
    Last Post: 03-18-2009, 04:55 PM
  5. [HELP] How the hell do i get combat arms to work again?
    By true1playa in forum Combat Arms Hacks & Cheats
    Replies: 2
    Last Post: 08-08-2008, 09:57 AM