This is a thred for fizzbuzz niggers who think they can use logic

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

In task 2 does it count or compress? What's the output for "abcba"?

count

output = [(2,'a'), (2,'b'), (1','c')]

forgot to say
notice the order

public static Map distinct2Count(Collection col) {
return col.stream()
.distinct()
.collect(
Collectors.toMap(m->m, m->Collections.frequency(col, m)));
}

Is that moot?

all of those are harder than fizzbuzz

post some output
also, what lang?

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.

Looks like Java 8 lambda expression

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

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;
}

whoops meant to reply to OP

why are you calling distinct()[/col]?

Yeah this is after he went to work for Google

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.

Jesus Christ
Did someone hit him with a truck or something?

>task 3:
>find all the right triangles with perimeter 120
syms x y
ezplot(x + y + sqrt(x^2 + y^2) == 120, [0 100])

Does he have cancer or is he just aggressively balding?

basically, choose an H and solve [math]H\sin(\theta) + H\cos(\theta) = 120 - H [/math] for \theta

no latex here, /sci/.

I was just going to post with θ in there but I wasn't sure if Sup Forums filters it.

cool it doesn't. good to know.

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

Inverting the tree meaning swapping left to right, because if so then it's just this?

template
void invertTree(T &node)
{
std::swap(node.left, node.right);
if (node.left != NULL)
invertTree(node.left);
if (node.right != NULL)
invertTree(node.right);
}

>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.

...

fuck, my version is bigger
count [] = []
count a@(x:xs) = (,) (length $ filter (==x) a) x : count (filter (/=x) a)

DELETE THIS

also
what's up with (&&&)
hoogled it and its from Control.Arrow?

Yeah it's just a fancy way of applying two functions to an argument and returning a tuple with both results.

>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 ;)

whoops only 90 deg triangles, second condition must be:
something likr arcsin(a/c) == arctan(a/b)

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)

>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

Thanks for sharing

task 2:
list.GroupBy(x => x);

Sigourney Weaver really let herself go.

task 2 is fucking baby task easy peasy
took me two minutes

>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 task 3:
>find all the right triangles with perimeter 120
not today

What a curly-jew afro and AIDS skinny dude that is

>[y:ys]
also, look at previous solutions in haskell

>not today
[ (a,b,c) | a

forgot to put predicate a^2 + b^2 == c^2