[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

http://www.shiftedup.com/2015/05/07 /five-programming-proble

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 47
Thread images: 4

File: 1475983284896.jpg (50KB, 600x600px) Image search: [Google]
1475983284896.jpg
50KB, 600x600px
http://www.shiftedup.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour

>Write a program that outputs all possibilities to put + or - or nothing between the numbers 1, 2, ..., 9 (in this order) such that the result is always 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.

Well /g/?
>>
>>60557572
no fuckin clue good thing im not a "software engineer"
>>
>>60557572
simple
just fucking google it
why you would do anything but google it is beyond me
you get paid to get shit done, not jerk yourself off
>>
File: 1491619022917.jpg (44KB, 282x341px) Image search: [Google]
1491619022917.jpg
44KB, 282x341px
>>60557627
>Alright anon, we need to develop an application that will let our clients manage and track their trucks when they're on the road as well as balance and distribute their inventories between locations.
>No problem boss! I'll just google it!
What did I go to school for
>>
>>60557643
Oh are we done solving masturbatory problems?
>>
>>60557661
Funnily enough, the author of this article addresses people like you directly.

>If you bother to read this blog at all (or any other blog about software development), you are probably good enough to solve these and 5 more problems within the hour. The people that think are above all these "nonsense" are usually the ones that can't code crap.
>>
>>60557691
whelp, you caught me, I'm not a programmer
>>
>>60557704
I know you're not, you sound more of a starbucks barista kind of guy
>>
>>60557716
no, I work at a grocery store
>>
>>60557720
I was close.
>>
>>60557729
I think baristas get paid more
>>
>>60557739
Depends. I know some people who work at a grocery store who make $13-15, and most starbucks places pool tips.
>>
>>60557747
nah, I make $9.50
>>
>>60557572
Its hard. All i can think of to cut down on the possibilities is ignore all arrays of numbers where number of uneven numbers is not divisible by two, so ignoring uneven results.
>>
>If you bother to read this blog at all (or any other blog about software development), you are probably good enough to solve these and 5 more problems within the hour. The people that think are above all these "nonsense" are usually the ones that can't code crap.

This is his asnwer for question 4:

import java.util.Arrays;
import java.util.Comparator;

public class Main {

private static Integer[] VALUES = { 5, 2, 1, 9, 50, 56 };

public static void main(String[] args) {
Arrays.sort(VALUES, new Comparator() {

@Override
public int compare(Integer lhs, Integer rhs) {
String v1 = lhs.toString();
String v2 = rhs.toString();

return (v1 + v2).compareTo(v2 + v1) * -1;
}
});

String result = "";
for (Integer integer : VALUES) {
result += integer.toString();
}

System.out.println(result);
}
}


And people wonder why java is such a slow piece of shit.
>>
literally fuck this
if i get asked something like this then i am walking the fuck out

you will never ever code in a vacuum like that so what the fucks the point?
>>
>>60557859
What exactly is wrong with that? It's a simple solution to a timed exercise.
>>
>>60557572
Would knowing how to solve such a problem really help me in industry?
>>
>>60557572
I did this one a while ago. Can be easily solved with a recursive function.
>>
>>60557883
Converting to string defeats the purpose of it being a challenge and is slow.
>>
>>60557572
yeah, question 5 is probably the only one I can't do in less than five minutes, and my answer probably wouldn't be particularly nice or good (would probably brute-force it, with a handful of sanity checks for speed)
too lazy to actually do it right now, it's almost 2am

the rest of the problems are fizzbuzz-tier, and if it takes you thirty minutes to do any of them, you should look for a different profession
>1 is literally "do you know how loops work, like at all" (result+=list[ii] in a loop)
>2 is basically "do you know how lists work, like at all" (resultlist.push_back(list1[ii]);resultlist.push_back(list2[ii]) in a loop)
>3 is just "I've told you exactly how this works, put it into actual code" and anyone can implement a fibonacci anyway (if 0 or 1, return 0/1 respectively, if greater, call self with previous two indicies)
>4 can be done lazily by just putting all of the numbers into one big string and then sorting the characters -- there's likely better ways, but that's the zero mental effort answer
>>
this number 5 question was made only to get audience from the readers
>>
File: 1279842955903.png (136KB, 225x350px) Image search: [Google]
1279842955903.png
136KB, 225x350px
>>60557572
>>60557691
is not this the nignog who's own solution to problem 4 or 5 was wrong?
>>
i don't understand...
can't you write 99+1-1+1-1... ad infinitum? how can i possibly write all of the possibilities?
>>
>>60557572
Use the power of the fucking Prolog! With backtracking you should complete this in few minutes, 15 at max.
>>
>>60558566
this
>>
>>60558566
No, you have given a set of numbers and their order. So you cannot add numbers, you only can change +/-.
>>
>>60557962
>>4 can be done lazily by just putting all of the numbers into one big string and then sorting the characters -- there's likely better ways, but that's the zero mental effort answer
retard
>>
This is how you should do an academic exercise without going the retard way. However, should have manual sort which i didnt use since im retarded:

https://pastebin.com/E7CyYW0T
>>
1+2+3-4+5+6+78+9
1+2+34-5+67-8+9
1+23-4+5+6+78-9
1+23-4+56+7+8+9
12+3+4+5-6-7+89
12+3-4+5+67+8+9
12-3-4+5-6+7+89
123+4-5+67-89
123+45-67+8-9
123-4-5-6-7+8-9
123-45-67+89
>>
>>60558668
hmmm
first thing that comes to mind is running through all string possibities, then for each possibility evaluate the expression, and print if it's equal to 100.
but that sounds like the worst way to do this.
what else...
>>
why my fib program dont work

#include <stdio.h>

int main() {

unsigned long long int i, j, k;
int c = 0;

i = 0;
j = 1;
k = 0;

while (c++ < 100) {
k = i + j;
i = j;
j = k;
printf ("fib(%d) = %llu\n", c, k);
}

return 0;

}
>>
>>60557962
>4 can be done lazily by just putting all of the numbers into one big string and then sorting the characters -- there's likely better ways, but that's the zero mental effort answer
You have misunderstood the question. Don't call back.
>>
>>60558948
need thiccer int's
>>
>>60558864
All of them?
>>
>>60558991
I think so, if the numbers have to be ordered
>>
>>60557572
Just brute force it, there are only 8 positions with 3 options each.
>>
>>60559010
I just arrive at my work. I will check that.
>>
>>60558948
you actually can not solve this problem with most implementations of C primitives.
>>
>>60558948
The problem defines the first two numbers of the sequence to be 0 and 1. Yours are 1 and 2. Hardcode in the first two prints, and initialize c to 2.
>>
>>60558912
>>60559027

if it's any consolation, the solution posted on that site is that supposedly retarded brute force method.
>>
>>60559133
To be fair, I'm not sure it's really a "mathematical" problem that can be solved any other way.
>>
>>60557572

That's literally just 6500 or so iterations, you really should be able to do this even through brute forcing
>>
File: Fibonacci.jpg (175KB, 1778x779px) Image search: [Google]
Fibonacci.jpg
175KB, 1778x779px
>>60557962
>>
let with_digits f d1 ds =
let rec loop accu = function
| [] -> f accu []
| d2 :: ds ->
f accu (d2 :: ds);
loop (10 * accu + d2) ds in
loop d1 ds
;;

let rec loop stotal total = function
| [] ->
if total = 100 then
begin
Printf.printf "%s = %d" stotal total;
print_newline ()
end
else
()
| d :: ds ->
let f num ds =
loop (Printf.sprintf "%s + %d" stotal num) (total + num) ds;
loop (Printf.sprintf "%s - %d" stotal num) (total - num) ds in
with_digits f d ds
;;

let main () =
try
let f num ds = loop (string_of_int num) num ds in
with_digits f 1 [ 2; 3; 4; 5; 6; 7; 8; 9; ];
0
with
| x ->
Printf.eprintf "error: %s" (Printexc.to_string x);
prerr_newline ();
1
;;

let () = exit (main ());;
>>
>>60559678
What is that abomination of a language.
>>
>>60559720
It's the best language, ever.
Thread posts: 47
Thread images: 4


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.