[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
this is a thred for fizzbuzz niggers who think they can use logic
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 49
Thread images: 3
File: bill zuckerberg.jpg (206 KB, 480x640) Image search: [Google]
bill zuckerberg.jpg
206 KB, 480x640
this is a thred for fizzbuzz niggers who think they can use logic
fizzbuzz won't work, because you've memorized the solution, you arne't using ur brain anymore
new challenge

post how much time it took u to solve (no lying)

task 1:
invert a binary tree (hard google question)

task 2:
make a function f such that
f([1,1,1,2,2,3,3,3,3,3]) = [(3,1), (2,2), (5,3)]
f("aabcddejj") = [(2,'a'), (1,'b'), (1,'c'), (2,'d'), (1,'e'), (2,'j')]

task 3:
find all the right triangles with perimeter 120
>>
>>54972150
In task 2 does it count or compress? What's the output for "abcba"?
>>
>>54972193
count

output = [(2,'a'), (2,'b'), (1','c')]
>>
>>54972203
forgot to say
notice the order
>>
public static <T> Map<T, Integer> distinct2Count(Collection<T> col) {
return col.stream()
.distinct()
.collect(
Collectors.toMap(m->m, m->Collections.frequency(col, m)));
}
>>
>>54972150
Is that moot?
>>
>>54972150
all of those are harder than fizzbuzz
>>
>>54972257
post some output
also, what lang?
>>
>>54972203
Wouldn't you just step along the char input and either make a new array field if the char hasn't been seen before or increment the value?

You could probably regex it as well but that gets a bit more complicated if you want to handle things other than just letters and numbers.

I will never understand the binary tree question.
>>
>>54972311
Looks like Java 8 lambda expression
>>
>>54972321
I see what you're trying to do,
but there's a simpler way to do it.
and yes, it should support all types imaginable

f([Dog, Cat, Dog]) = [(2,Dog), (1, Cat)]

inverting meaning flipping about the center of the tree
just google it
>>
>>54972403
void invertbitree(node* n){
node* temp = n->left;
n->left = n->right;
n->right = temp;
if (n->left != nullptr)
invertnitree(n->left);
if (n->right != nullptr)
invertbitree(n->right);
return;
}
>>
>>54972475
whoops meant to reply to OP
>>
>>54972257
why are you calling
distinct()[/col]?
>>
>>54972270
Yeah this is after he went to work for Google
>>
>>54972475
fuck C is hard to read
why can't it just be

invert (Leaf n) = Leaf n
invert (Node a l r) = Node a (invert r) (invert l)
>>
function invert (Tree T): Tree {
if (isLeaf(T)) return T;
else return makeTree(T.val, T.r, T.l);
}

function countFreq (List L): List {
HashMap H = makeHash();
for e in L {
if (not H.hasKey(e)) H.add(e, 1);
else H.update(e, H.get(e) + 1);
}
List out = makeList();
for k, v in H {
out.append(makeTuple(k, v));
}
}


There are infinite right triangles with perimeter 120 so I'd rather not find all of them.
>>
>>54972592
Jesus Christ
Did someone hit him with a truck or something?
>>
File: Untitled.png (20 KB, 562x506) Image search: [Google]
Untitled.png
20 KB, 562x506
>>54972150
>task 3:
>find all the right triangles with perimeter 120
syms x y
ezplot(x + y + sqrt(x^2 + y^2) == 120, [0 100])
>>
>>54973156
Does he have cancer or is he just aggressively balding?
>>
>>54973053
basically, choose an H and solve [math]H\sin(\theta) + H\cos(\theta) = 120 - H [/math] for \theta
>>
>>54973192
no latex here, /sci/.
>>
>>54973205
I was just going to post with θ in there but I wasn't sure if 4chan filters it.
>>
>>54973216
cool it doesn't. good to know.
>>
>>54972610
Exactly. And for task 2 just:

count = map (length &&& head) . group . sort
>>
You should be able to solve this
Suppose we want to print a sequence of n words each with ln length
There is a limit M of characters per line. Each word has to be succeeded by a whitespace, no splitting allowed
Write a program that prints the message while minimizing the amount of whitespace in the end of each line
>>
>>54972150
Inverting the tree meaning swapping left to right, because if so then it's just this?

template <typename T>
void invertTree(T &node)
{
std::swap(node.left, node.right);
if (node.left != NULL)
invertTree(node.left);
if (node.right != NULL)
invertTree(node.right);
}
>>
>>54972150
>find all the right triangles with perimeter 120
If s_x and s_y are the sides at the right angle, then the perimeter is s_x + s_y + sqrt( s_x^2 + s_y^2 ). then it's very easy to solve for one of the two variables, let's solve for s_y:

s_y = 120 ( 60 - s_x ) / ( 120 - s_x ). As all sides need to be > 0, you need to choose s_x from (0, 60). Those are all right triangles with perimeter 120.
>>
File: 1448217243832.jpg (104 KB, 480x640) Image search: [Google]
1448217243832.jpg
104 KB, 480x640
>>54972270
>>54972592
>>54973156
>>
>>54973324
fuck, my version is bigger
count []       = []
count a@(x:xs) = (,) (length $ filter (==x) a) x : count (filter (/=x) a)
>>
>>54973694
DELETE THIS
>>
>>54973324
also
what's up with (&&&)
hoogled it and its from Control.Arrow?
>>
>>54974028
Yeah it's just a fancy way of applying two functions to an argument and returning a tuple with both results.
>>
>>54972150
>task 3:
>find all the right triangles with perimeter 120

task 1:
traverse to end, swap values
traverse to end-(1+i), swap values
i++
rinse and repeat

task 2:
create resolution dict
for each element in input:
if element in resolution dict increment value
else create key = element with value 1
return dict_to_list()

task 3:
for values from the real space? infinite
for ints:
In [3]: n = 0

In [4]: for a in xrange(1, 121):
...: for b in xrange(1, 121):
...: for c in xrange(1, 121):
...: if a + b + c == 120 and a**2 + b**2 == c**2:
...: n += 1
...: print a, b, c
...:
20 48 52
24 45 51
30 40 50
40 30 50
45 24 51
48 20 52

In [5]: n
Out[5]: 6

no optimized but why? if fastes implementation counts it is below 1 min ;)
>>
>>54977126

whoops only 90 deg triangles, second condition must be:
something likr arcsin(a/c) == arctan(a/b)
>>
>>54972270
No
>>
How does an "inverted" tree supposed to look? 2 is trivial with an associative array. 3 is not even a programming question.
>>
Task2:
def task2(v):
return [(sum(1 for a in v if a == i) for i in set(v)]))

print(repr(task2('1122233333'))
>>
Are these really what you consider hard?

>1
Swap sides and invert them recursively

>2
dictionary
insert every new element in the correct place

>3
given a
b = (sqrt(481 - 4a - 4a^2) - 1)/2
c = 120 - (a + b)
>>
>>54977826
>Are these really what you consider hard?
Last one is completely wrong, so I guess it's too hard for you. Really no idea what you even tried to do there, honestly.
>>
the girl on the left is a friend of mine
>>
>>54978661
Thanks for sharing
>>
>>54972150
task 2:
list.GroupBy(x => x);
>>
>>54973694
Sigourney Weaver really let herself go.
>>
>>54972150
task 2 is fucking baby task easy peasy
took me two minutes
>>
>>54972150
>task 1:
>invert a binary tree (hard google question)
What does inverting a binary tree even mean?
Question is too vague.

>task 2:
>make a function f such that
>f([1,1,1,2,2,3,3,3,3,3]) = [(3,1), (2,2), (5,3)]
>f("aabcddejj") = [(2,'a'), (1,'b'), (1,'c'), (2,'d'), (1,'e'), (2,'j')]

count :: a [a] -> Int
count x [] = 0
count x [y:ys]
| x == y = 1 + count x ys
| otherwise = count x ys

f :: [a] -> [a]
f [] = []
f [x:xs] = [(count x xs, x)] ++ f [y \\ y <- xs | y <> x]

>task 3:
>find all the right triangles with perimeter 120
not today
>>
>>54973694
What a curly-jew afro and AIDS skinny dude that is
>>
>>54979470
>[y:ys]
also, look at previous solutions in haskell

>not today
[ (a,b,c) | a <- [1..120], b <- [1..120], c <- [1..120], a + b + c == 120]


>>54979277
>easy peasy
right, is that why u didn't post the solution
>>
>>54981593
forgot to put predicate
 a^2 + b^2 == c^2
Thread replies: 49
Thread images: 3

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.