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
Tyler Brown
In task 2 does it count or compress? What's the output for "abcba"?
invert (Leaf n) = Leaf n invert (Node a l r) = Node a (invert r) (invert l)
Kayden Hall
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.
Austin Wright
Jesus Christ Did someone hit him with a truck or something?
Kevin Watson
>task 3: >find all the right triangles with perimeter 120 syms x y ezplot(x + y + sqrt(x^2 + y^2) == 120, [0 100])
Aaron Cox
Does he have cancer or is he just aggressively balding?
Parker Wood
basically, choose an H and solve [math]H\sin(\theta) + H\cos(\theta) = 120 - H [/math] for \theta
Jose Thompson
no latex here, /sci/.
Leo Bell
I was just going to post with θ in there but I wasn't sure if Sup Forums filters it.
Robert Rivera
cool it doesn't. good to know.
Ryan Gutierrez
Exactly. And for task 2 just:
count = map (length &&& head) . group . sort
Kayden Davis
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
Easton Gutierrez
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); }
Jeremiah Cruz
>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.
Ryan White
...
Noah Lopez
fuck, my version is bigger count [] = [] count a@(x:xs) = (,) (length $ filter (==x) a) x : count (filter (/=x) a)
Jace Cooper
DELETE THIS
Hunter Miller
also what's up with (&&&) hoogled it and its from Control.Arrow?
Carter Foster
Yeah it's just a fancy way of applying two functions to an argument and returning a tuple with both results.
Christopher Thompson
>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 ;)
Nathaniel Martin
whoops only 90 deg triangles, second condition must be: something likr arcsin(a/c) == arctan(a/b)
Aaron Morris
No
Lincoln Baker
How does an "inverted" tree supposed to look? 2 is trivial with an associative array. 3 is not even a programming question.
Ethan Fisher
Task2: def task2(v): return [(sum(1 for a in v if a == i) for i in set(v)]))
print(repr(task2('1122233333'))
Ryder Nelson
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)
Gavin Brown
>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.
Aiden Thomas
the girl on the left is a friend of mine
Levi Adams
Thanks for sharing
Angel Young
task 2: list.GroupBy(x => x);
Michael Martin
Sigourney Weaver really let herself go.
Anthony King
task 2 is fucking baby task easy peasy took me two minutes
Chase Reyes
>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
Hudson Thompson
What a curly-jew afro and AIDS skinny dude that is
Colton Myers
>[y:ys] also, look at previous solutions in haskell