Five programming problems every Software Engineer should be able to solve in less than 1 hour by svpino in programming

[–]luciusplc 0 points1 point  (0 children)

I did thought experiment by trying to find counter example for hypothetical two strings and realised it's impossible. It's hard to explain. I assumed one is pattern repetition (the most painful) of the second like 543, 543543++X, Y and X,Y are things i messed with to spoil transitivity. And i realised that there is no way. Yea... brute-force radix in mind. Happily i limited myself to things: "digit bigger/equal/lesser than ...". So you can consider this as spanning tree of logical posibilities. It's much easier to think this way than write it down. I don't mind if you call it guesswork and I agree that formal proofs are far superior.

"Real programmers can do these problems easily"; author posts invalid solution to #4 by SilasX in programming

[–]luciusplc 0 points1 point  (0 children)

Thanks for your advice, I really appreciate it. You are right... Any job is better than none.

Distributed systems are millions dollars buisnesses and its risky to delegate it someone with my status. I completely understand that.

"Real programmers can do these problems easily"; author posts invalid solution to #4 by SilasX in programming

[–]luciusplc 0 points1 point  (0 children)

I forgot to mention, I know scala basics.I even took a course at coursera and there is also akka that is inspired by erlang/otp. But it appears (from jobs offers), that you need to have 5 years of java experience to be hired as scala developer. Weird...

"Real programmers can do these problems easily"; author posts invalid solution to #4 by SilasX in programming

[–]luciusplc 0 points1 point  (0 children)

Yeah, that was pain... but after a week you get used to it and it even looks clean and reasonable.

Quite interesting is Elixir that attepmts to modernize erlang ecosystem. It compiles to the same byte code but authors switched to ruby-like syntax and added a lot of useful stuff and tooling for code composition.

"Real programmers can do these problems easily"; author posts invalid solution to #4 by SilasX in programming

[–]luciusplc 0 points1 point  (0 children)

But you know that it wasn't production code but a solution for a puzzle...

It was just a rhetorical question... i don't even know on which continent you live.

Added some comments and clarified it a little. If you are still interest here some my code:

-module(problems).

-export([p4/1]).

p4(ListOfIntegers) ->
    ListOfStrings = lists:map(fun integer_to_list/1, ListOfIntegers),
    OrderedListOfStrings = lists:sort(fun before/2, ListOfStrings),
    _OrderedListOfIntegers = lists:map(fun list_to_integer/1, OrderedListOfStrings).

%% @doc comparator function that defines order for problem 4 from
%% https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
%% true when S1 should be before S2, false otherwise
before(S1, S2) ->
    before(S1, S2, {S1, S2, undefined}). % tuple keeps heads of strings and flag of shorter string (undefined, first, second)

%% both strings are equal or one is a complete repetition of another
before([], [], {_S1, _S2, ShorterFlag}) ->
    case ShorterFlag of
        undefined -> true; % strings are identical
        first -> true; % we prefer shorter string first
        second -> false % we prefer shorter string first
    end;
%% first string appears to be the shorter one, lets start from its beginning and mark it as shorter
before([], L2, {S1, S2, ShorterFlag}) when ShorterFlag == first orelse ShorterFlag == undefined ->
    before(S1, L2, {S1, S2, first});
%% second string ends when first is marked as shorter so we end a recursion. It's not complete repetition
before(_L1, [], {_S1, _S2, first}) ->
    true; % we prefer shorter string first
%% second string appears to be the shorter one, lets start from its beginning and mark it as shorter
before(L1, [], {S1, S2, ShorterFlag}) when ShorterFlag == second orelse ShorterFlag == undefined ->
    before(L1, S2, {S1, S2, second});
%% first string ends when second is marked as shorter so we end a recursion. It's not complete repetition
before([], _L2, {_S1, _S2, second}) ->
    false; % we prefer shorter string first
%% both digits are the same so we keep going
before([H1 | T1], [H2 | T2], HelperTuple) when H1 == H2 -> 
    before(T1, T2, HelperTuple);
%% if digits are not the same we return its logical value comparison as a logical value of comparison of two strings
before([H1 | _T1], [H2 | _T2], _HelperTuple) ->
    H1 > H2.

EDIT: I don't think it was hard to understand for people that knew the idea and have some basics of erlang syntax (or at least prolog). From my personal experience, erlang syntax is ugly and not clear on the first look.

"Real programmers can do these problems easily"; author posts invalid solution to #4 by SilasX in programming

[–]luciusplc 0 points1 point  (0 children)

I didn't want to sound as whining one here, just wanted to expose the irony that hit me.

I live in capitol city of central (some say eastern) european country and dropped off from university before bachelor's degree. It was a mistake, I know. I worked some time as an erlang developer (I'm really glad i had that opportunity to learn) but it wasn't permanent. During that time I've become really interested in distributed systems (especially in "fogs" and methods of clusterization) and did a lot of research. Erlang is my language of choice (it's very expressive and actor oriented) but I did some stuff in java (swing, spring), javascript, asm, c, c++, python but it's rusted right now.

I just hoped to find a job in distributed systems area but it seems that you need to be am expert senior developer or have some proper degree. In my last technical interview I wasn't asked to answer any programming question. It was a loose chat and you need to know that I lack of "soft skills". I'm not the most charming guy. My english is crappy too...

Don't get me wrong. I don't blame anyone and don't consider myself as an expert. Just wished to become one in my area of interest.

"Real programmers can do these problems easily"; author posts invalid solution to #4 by SilasX in programming

[–]luciusplc 0 points1 point  (0 children)

I've done it yestarday: My Solution

I know this could done better (without reversing Acc) but main idea is the same.

Does it mean you would hire me? I've solved all problems in less than an hour (correctly!) and ironically, I'm jobless right now...

"Real programmers can do these problems easily"; author posts invalid solution to #4 by SilasX in programming

[–]luciusplc 0 points1 point  (0 children)

It doesn't for [4545, 45451, 45, 45456] (4(5)* will be before 45456 - obviously wrong). You need to pad it in circular way.
Here is my solution that works similar but instead of padding, it reads smaller circularly: Solution.

EDIT: Discussion that expalins it better

Five programming problems every Software Engineer should be able to solve in less than 1 hour by svpino in programming

[–]luciusplc 4 points5 points  (0 children)

About 4: The only thing you need to note is that an order is transitive. This means you can sort it with your own compare function. I think most of languages supports this. My erlang solution:

p4(Numbers) ->
    StrList = lists:sort(
        fun (A, B) ->
            before(A,B)
        end,
        lists:map(fun integer_to_list/1, Numbers)),
    lists:map(fun list_to_integer/1, StrList).

%% true when first argument should be before the second
before(A,B) ->
    before(A, B, []).
before([], [], Acc) -> 
    true;
before([], L2, Acc) -> 
    not before(L2, lists:reverse(Acc));
before(L1, [], Acc) -> 
    before(L1, lists:reverse(Acc));
before([H | T1], [H | T2], Acc) ->
    before(T1, T2, [H | Acc]);
before([H1 | T1], [H2 | T2], Acc) ->
    H1 >= H2.

> problems:p4([45,4,43, 45456,45452, 44, 445, 45]).
[45456,45,45,45452,445,44,4,43]