Snowtsuku Posted April 10, 2015 Posted April 10, 2015 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 : > Quote
Eclipsed Posted April 10, 2015 Posted April 10, 2015 In case ppl too lazy to check link, problem is Print 100 to 1 Assume all headers and function declarations made already ie. just focus on implementation You must start with (cannot write anything before the following): for(int i = 0; ...) Quote
Guest Posted April 10, 2015 Posted April 10, 2015 Java for(int i=0;i<100;i++) { system.out.println(100-i); } Or did I miss something? Total time : 10 sec Quote
Flutterz Posted April 10, 2015 Posted April 10, 2015 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."); Quote
Snowtsuku Posted April 10, 2015 Author Posted April 10, 2015 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. Quote
Kimossab Posted April 10, 2015 Posted April 10, 2015 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. Quote
Tenkuru Posted April 11, 2015 Posted April 11, 2015 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 for (int i = 0; i < 100; ++i) { cout << 100 - i << ' '; } Quote
Permagate Posted April 11, 2015 Posted April 11, 2015 Well, to be fair, it is easy to fail spectacularly when people are under pressure. Also, Smart Person's Mirage exists. I'm personally a fan of MEAN stack, though I'm using Ruby on Rails for my job. Quote
Snowtsuku Posted April 11, 2015 Author Posted April 11, 2015 Well, to be fair, it is easy to fail spectacularly when people are under pressure. Also, Smart Person's Mirage exists. I'm personally a fan of MEAN stack, though I'm using Ruby on Rails for my job. I want to learn Ruby for the lulz. Any recommendation for references? Quote
Permagate Posted April 11, 2015 Posted April 11, 2015 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 Quote
Snowtsuku Posted April 11, 2015 Author Posted April 11, 2015 I'm fine with the language. I don't do much web dev. I'm more of a hardware programmer than a software programmer anyway. Quote
Chronopolis Posted April 14, 2015 Posted April 14, 2015 for(int i = 0; i<100; i++){ std::cout << i - 100 << std::endl; } Mm just took 30 seconds to think about. Quote
zoom909 Posted April 15, 2015 Posted April 15, 2015 for(int i = 0; i<100; i++){ std::cout << i - 100 << std::endl; } Mm just took 30 seconds to think about. Doesn't matter how fast you are if you get it wrong. Also, C++ is so ugly...look at that "print" statement... Quote
Kelebek1 Posted April 21, 2015 Posted April 21, 2015 #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. Quote
Snowtsuku Posted April 21, 2015 Author Posted April 21, 2015 asm is too hard for casuals like me I used asm for some robotics stuff. Not really my forte though. Quote
Kimossab Posted April 21, 2015 Posted April 21, 2015 I've just studied asm for x86 processors, we just studied the basics of basics though and I hated it... Quote
Kelebek1 Posted April 21, 2015 Posted April 21, 2015 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. Quote
Kimossab Posted April 21, 2015 Posted April 21, 2015 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... Quote
Kelebek1 Posted April 21, 2015 Posted April 21, 2015 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. Quote
Kimossab Posted April 21, 2015 Posted April 21, 2015 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 Quote
kamiwakai Posted April 30, 2015 Posted April 30, 2015 Its a matter of purpose. I hate ASM for making GUI, but I love ASM when programming for NES. Besides, my all time favorite is Javascript, the most flexible and creative language in the world. Permagate 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.