Software Development and Programming Careers (Official Discussion Thread)

Joined
Apr 3, 2014
Messages
71,910
Reputation
17,063
Daps
305,930
Breh that’s just programming. It’s always gong to be frustrating. I said this before on here , I follow a lot of famous programmers on Twitter , every once in a while they’ll post something like

“ I spent 6 hrs chasing down this bug, come to find out it was due to one line of code”

Im talking about millionaires who still code. Everybody comments “ Wow can’t believe you made that mistake”

No matter how great you become at it , you’re going to get frustrated. It’s just your Love/Passion/patience for programming has to exceed the frustration.




Old post from you but this is legit how I feel and how I know this is for me. I spent 7 hrs straight on a Saturday night chasing a bug and trying to figure out why my program wouldn't work. I didn't finish until 4 AM Sunday morning. It was frustrating, it was hard, but I loved it. And I solved it. :wow:
 

null

...
Joined
Nov 12, 2014
Messages
29,185
Reputation
4,881
Daps
46,386
Reppin
UK, DE, GY, DMV
Breh that’s just programming. It’s always gong to be frustrating. I said this before on here , I follow a lot of famous programmers on Twitter , every once in a while they’ll post something like

“ I spent 6 hrs chasing down this bug, come to find out it was due to one line of code”

Im talking about millionaires who still code. Everybody comments “ Wow can’t believe you made that mistake”

No matter how great you become at it , you’re going to get frustrated. It’s just your Love/Passion/patience for programming has to exceed the frustration.

i don't think "frustrated" is the word. and sometimes it comes down to a single character (or less).
 

null

...
Joined
Nov 12, 2014
Messages
29,185
Reputation
4,881
Daps
46,386
Reppin
UK, DE, GY, DMV
I've dabbled in C# but Visual Studio is so slow

"Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux"



*not sure who I ended up all the way back there
 

Rozay Oro

2 Peter 3:9 if you don’t know God
Supporter
Joined
Sep 9, 2013
Messages
41,252
Reputation
5,272
Daps
75,044
"Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux"



*not sure who I ended up all the way back there
I’m peep
 

TheAnointedOne

Superstar
Joined
Jul 30, 2012
Messages
7,784
Reputation
666
Daps
30,669
Alot of you guys, I assume, have done leetcode. So you are all probably familiar with the 'longest common prefix' problem which is supposed to be easy. My over-engineered rust solution is retarded:

Code:
use std::collections::HashMap ;

struct PrefixTable_t {
    table: HashMap<String, u32>,
    max: u32,
}

impl PrefixTable_t {

    fn new() -> Self {
        PrefixTable_t {
            table: HashMap::new(),
            max: 0
        }
    }

    fn add_to_table( &mut self, word:&str ) {

        let mut ret = String::new() ;        

        for itr in word.chars() {            
            
            ret.push( itr ) ;
            
            self.table
                .entry( ret.clone() )
                .and_modify( |x| *x += 1 )
                .or_insert(1) ;
        }

        self.max = match self.table.iter().max_by_key( |x| x.1 ) {
            Some(x) => x.1.to_owned(),
            None => 1,
        }
    }

    fn is_empty( &self ) -> bool {
        self.table.is_empty()
    }

    fn all_ones( &self ) -> bool {
        self.table.iter().all( |x| *x.1 == 1 )        
    }

    fn get_max_count( &self ) -> u32 {
        self.max
    }

    fn longest_common_prefix( &self ) -> String {        

        if self.all_ones() {
            return "".to_string() ;
        }

        let lcp = self.table
            .iter()
            .filter( |x| *x.1 == self.max )
            .map( |x| x.0 )
            .collect::<Vec<_>>() ;

        lcp.iter()
            .max_by_key( |x| x.len() )
            .unwrap()
            .to_string()
    } 
}

impl Solution {
    pub fn longest_common_prefix(strs: Vec<String>) -> String {

        match strs.len() {
            0 => "".to_string(),
            1 => strs[0].to_string(),
            _ => {

                if strs.iter().all( |x| x.is_empty() ) {
                    return "".to_string() ;                
                }

                let mut p = PrefixTable_t::new() ;

                strs
                    .iter()
                    .for_each( |s| p.add_to_table(s) ) ;                
            
                let lcp = p.longest_common_prefix() ;

                match strs.iter().all( |x| x.starts_with( &lcp ) ) {
                    true => lcp,
                    false => "".to_string(),
                }
            }
        }
    }
}
 

Rev Leon Lonnie Love

damned mine eyes, DAMNED mine eyes!!
Joined
Nov 11, 2017
Messages
21,827
Reputation
5,458
Daps
88,757
Alot of you guys, I assume, have done leetcode. So you are all probably familiar with the 'longest common prefix' problem which is supposed to be easy. My over-engineered rust solution is retarded:

Code:
use std::collections::HashMap ;

struct PrefixTable_t {
    table: HashMap<String, u32>,
    max: u32,
}

impl PrefixTable_t {

    fn new() -> Self {
        PrefixTable_t {
            table: HashMap::new(),
            max: 0
        }
    }

    fn add_to_table( &mut self, word:&str ) {

        let mut ret = String::new() ;       

        for itr in word.chars() {           
           
            ret.push( itr ) ;
           
            self.table
                .entry( ret.clone() )
                .and_modify( |x| *x += 1 )
                .or_insert(1) ;
        }

        self.max = match self.table.iter().max_by_key( |x| x.1 ) {
            Some(x) => x.1.to_owned(),
            None => 1,
        }
    }

    fn is_empty( &self ) -> bool {
        self.table.is_empty()
    }

    fn all_ones( &self ) -> bool {
        self.table.iter().all( |x| *x.1 == 1 )       
    }

    fn get_max_count( &self ) -> u32 {
        self.max
    }

    fn longest_common_prefix( &self ) -> String {       

        if self.all_ones() {
            return "".to_string() ;
        }

        let lcp = self.table
            .iter()
            .filter( |x| *x.1 == self.max )
            .map( |x| x.0 )
            .collect::<Vec<_>>() ;

        lcp.iter()
            .max_by_key( |x| x.len() )
            .unwrap()
            .to_string()
    }
}

impl Solution {
    pub fn longest_common_prefix(strs: Vec<String>) -> String {

        match strs.len() {
            0 => "".to_string(),
            1 => strs[0].to_string(),
            _ => {

                if strs.iter().all( |x| x.is_empty() ) {
                    return "".to_string() ;               
                }

                let mut p = PrefixTable_t::new() ;

                strs
                    .iter()
                    .for_each( |s| p.add_to_table(s) ) ;               
           
                let lcp = p.longest_common_prefix() ;

                match strs.iter().all( |x| x.starts_with( &lcp ) ) {
                    true => lcp,
                    false => "".to_string(),
                }
            }
        }
    }
}
That's a LOT of lines :picard:

I dont know how to read rust code but isn't the simplest way to just iterate over all strings at the same time and test for equality of characters from the strings and stop on the first failure, while saving the character for each pass of the equality test. I think the complexity would be the length of the longest string.

I would have to sit down and think about a more efficient solution.
 

TheAnointedOne

Superstar
Joined
Jul 30, 2012
Messages
7,784
Reputation
666
Daps
30,669
That's a LOT of lines :picard:

I dont know how to read rust code but isn't the simplest way to just iterate over all strings at the same time and test for equality of characters from the strings and stop on the first failure, while saving the character for each pass of the equality test. I think the complexity would be the length of the longest string.

I would have to sit down and think about a more efficient solution.

My original solution was to use a matrix of characters and check the columns for equality. But leetcode doesn't allow the use of external libraries.
 

null

...
Joined
Nov 12, 2014
Messages
29,185
Reputation
4,881
Daps
46,386
Reppin
UK, DE, GY, DMV
@TheAnointedOne what's the problem link breh? If I can drag my lazy bones to have a look I will. Maybe I have done it already. your solution looks a bit long.

if it is longest common prefix of an array of strings then sorting it first will really simplify the problem. then you can just check the sorted list pair-wise. sorting is O(log n) so relative to brute-force very inexpensive. if you don't want to move strings around (expensive?) you can sort a bunch of pointers to the strings and use that sorted pointer list for your checking.
 

TheAnointedOne

Superstar
Joined
Jul 30, 2012
Messages
7,784
Reputation
666
Daps
30,669
@TheAnointedOne what's the problem link breh? If I can drag my lazy bones to have a look I will. Maybe I have done it already. your solution looks a bit long.

if it is longest common prefix of an array of strings then sorting it first will really simplify the problem. then you can just check the sorted list pair-wise. sorting is O(log n) so relative to brute-force very inexpensive. if you don't want to move strings around (expensive?) you can sort a bunch of pointers to the strings and use that sorted pointer list for your checking.

 
Top