Jump to content

Programmer's Corner


Snowtsuku

Recommended Posts

There an article I want to share but a thread for it might be too much so might as well create a mega thread. Anyone can post here, especially those who wants to learn. Feel free to share your preferred language as well.

 

As for the article Link.

 

Feel free to solve it as well. I think it's hard due to the interview pressure but let's see : >

Link to comment
Share on other sites

Yeah... if I were an employer I probably wouldn't hire a programmer who takes more that a minute or two to solve that. (If it's done on paper then I wouldn't care about syntax errors because ain't nobody got time fo' dat)

If you want to be cheeky you can do:

 

for (int i = 0; i < 0, i++);

system.out.println("100 99 98 97 ... etc.");

Link to comment
Share on other sites

Yeah... if I were an employer I probably wouldn't hire a programmer who takes more that a minute or two to solve that. (If it's done on paper then I wouldn't care about syntax errors because ain't nobody got time fo' dat)

If you want to be cheeky you can do:

 

for (int i = 0; i < 0, i++);

system.out.println("100 99 98 97 ... etc.");

This solution reminds me of an answer in the leap year problem. Basically what he did was to parse the 29th of Feb, and check for an exception.

 

 

 

PHP

 

<?php

 

for ($i = 100; $i <=0; $i--) {

 echo $i.' ';

}

 

?>

 

time spend around 45 sec

 

derp 100 to 1 my fault, feeling so bad now...

 

<? php

 

for ($i = 100; $i > 0; $i--) {
 echo $i.' ';
}
 
?>

 

The loop should start from 0.

Link to comment
Share on other sites

for(int i=0; i<100; i++)
     printf("[%d]",100-i);

 

If I understood right what I have to do is print something like : "[100][99][98]...[1]" right? "print 100 to 1" is too confusing to me... I mean the way it's writen "print 100 to 1" it took me a while to think it was to write from 100 to 1 -.- I'm really slow sometimes... wouldn't it be easier like "print all numbers from 100 to 1"?

 

Anyway my prefered language is C. My most hated languages are Java (android at least), SQL and Assembly.

Link to comment
Share on other sites

Though I understand that the pressure of an interview might cause your mind to blank out at times, it really shouldn't take more than a minute or two to solve such a simple problem, much less 10 minutes  :vinty: 
 

for (int i = 0; i < 100; ++i) {
    cout << 100 - i << ' ';
}
Link to comment
Share on other sites

I want to learn Ruby for the lulz. Any recommendation for references?

 

Well, that depends if you just want to learn Ruby (the language), or take things further to Rails (the web framework). TryRuby is decent enough to introduce Ruby. If you want to learn Rails, Michael Hartl book is pretty much recommended everywhere you ask. It is a very heavy book however, since it will teach a lot of web development practices (git, unit testing, security, heroku, etc2) rather than just Rails itself.

 

If you just want to code for fun, I recommend to just learn Ruby and use Sinatra, a simpler web framework compared with Rails  :wafuu:

Link to comment
Share on other sites

#include <stdio.h>

int main() {
    for (int i = 0; i<100; i++) {
        char valueToPrint[5] = {};
        int div1 = 0xa;
        __asm {
                mov eax,0x64
                sub eax, i
                lea ecx,valueToPrint
                cmp eax,0x64
                jb $+0xd
                mov bl,2
                jmp $+0x17
                cmp eax,0xa
                jb $+0xd
                mov bl,1
                jmp $+7
                mov bl,0
                mov[ecx+ebx+1], 0xa
            get_char:
                xor edx,edx
                div [div1]
                or dl,0x30
                mov [ecx+ebx],dl
                dec bl
                test ax,ax
                jnz get_char
            print:
                push ecx
                call printf
                pop ecx
        };
    }
}

I'd never used asm within Visual Studio before, nor using Virtual Studio for anything to begin with. Seems easier on Linux where you can just send a 0x80 syscall write. Ah well, I can't believe I actually did it (as simple as this is). Does require the include before the required start though.

Link to comment
Share on other sites

Why? It's great. I find it easier to figure out what a program's doing by looking at the compiled code rather than the source, although mainly because I know nothing about C#/C++ or other high-level stuff.

 

I've always been used to high level language they seem easier for me to understand than asm. Too many stuff for just 1 simple thing, too much address stuff...

Link to comment
Share on other sites

I've always been used to high level language they seem easier for me to understand than asm. Too many stuff for just 1 simple thing, too much address stuff...

 

And high level languages are a tonne of variable definitions and pointless conversions and type errors for no reason whatsoever. ASM is just bytes, you can interpret them however you want, but it's at least all uniform and simple. To try and split a string in C++ you have to make a huge mess of crap with a tonne of weird function calls and convoluted code, in ASM you can just do exact what you want directly and easily.

Link to comment
Share on other sites

And high level languages are a tonne of variable definitions and pointless conversions and type errors for no reason whatsoever. ASM is just bytes, you can interpret them however you want, but it's at least all uniform and simple. To try and split a string in C++ you have to make a huge mess of crap with a tonne of weird function calls and convoluted code, in ASM you can just do exact what you want directly and easily.

 

Tastes are tastes. We can't all like the same or else this world would be even more fucked up xD

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...