Implement any of following (or all if you're pro) in your favorite language

implement any of following (or all if you're pro) in your favorite language

tree data structure which can have as many child trees as one possibly wants
and a function to invert such a tree

fibonacci with linear time complexity
(either nth fibonacci or a list of all fibs, your choice)

averaging of a list of numbers
(hard mode, list is traversed only once
e. g. no summing the list (one traversal) and then dividing by its length (another traversal))

code in language X wins if its
>efficient
>short
>& has hot/pretty syntax

third one is more of a plus

pic unrelated

We aren't going to do you're homework for you.

>can't do it
just as expected
>>>/desktop thread/

if it was homework, I'd say
>please do all three in specific language X
you nigger faggot

just google any of it

LOL
Is one of those titty mouse pads?

Python has the 3rd one in a one liner, but I'm on my phone

Also, can't you just use list.length or some equivalent instead of two traversals?

nobody says lol anymore
kys

Answer my question you fucking faggot.

>posting homework

>list.length
It invokes a function that traveses the list, so even tho you can't see it, it counts as one

>averaging a list is homework
stop

From what I see about murican cs courses on this site, it could very much be homework desu

just admit it, you guys can't implement shit

lol

>It invokes a function that traveses the list, so even tho you can't see it, it counts as one
no, length is usually a parameter that is in memory for most lists

lol, whyd that guy delete his average implementation?

I don't know about other langs, but in python list objects are implemented as simple c arrays, so to get the length you must iterate at least once

I wish I was more like Neil. What a great picture, the man knows what he wants then goes and gets it. He has this memory forever now while I post on Serbian Sudoku boards.

Truly an inspiration to us all.

couldn't you just count as you transverse the list once? so like one for loop with a sum and a count.

fibonacci with linear time average complexity would store the numbers.

ayy lmaoing @ u

Why exactly?

You're never gonna make it, Rajeesh. len() is O(1) for lists in CPython.

Then when you initialize the list it automatically counts its own elements and stores it in a parameter. Please explain how the fuck would it "know" its own size without counting it first.

I am sorry for your brain damage. Your average function doesn't initialize anything. Also, any initialization of a list would have to traverse itself to copy values (even if it's all zeroes) to it unless you wanted it uninitialized.

Why don't you read the actual implementation and try to educate yourself instead? It's not that hard and I believe a pooinloo could come up with it given some time thinking.

since gtards aren't smart enough, I'll provide some of my own

>tree
data Tree = Leaf a | Node a [Tree a]

invert (Leaf a) = Leaf a
invert (Node a trees) = Node a (map invert $ reverse trees)

>linear fibonacci

fibs = 0 : 1 : zipWith (+) fibs (tail fibs)


>list average
{-# LANGUAGE BangPatterns #-}
import Data. List

average xs = (s / b) where (s, b) = sumlen xs

sumlen :: [Float] -> (Float, Float)
sumlen = foldl' f (0,0) where f (!s,!l) x = (s+x, l+1)

He didn't say the oneliner would be a hardmode solution

>not data Tree a = Node a [Tree a]

respect with using functional programming

I can't find a reason to apply functional programming so I don't retain anything anytime I learn some

Well, here is my attempt at the third problem. Still learning, pls no bully

#include
#include

using namespace std;

void main()
{
float numberTotal = 0;
float listLength = 0;
vector numbers;

for (int nIndex = 0; nIndex < 10; nIndex++)
{
numbers.push_back(nIndex +1);
}

for (int nIndex = 0; nIndex < 10; nIndex++)
{
numberTotal += numbers[nIndex];
listLength++;
}

cout

Damn id love to get snoop dog to sign something like that.

I don't know c++, but there's two loops
so I think you're traversing twice

touche
you can do a two liner Quicksort ?

everyone says lol you sad faggot

maybe in reddit, but I wouldn't know
thats where you come from right?

you can probably combine those two loops into one

#include
#include
using namespace std;

int main()
{
float numberTotal = 0;
float listLength = 0;
vector numbers;

for (int i = 0; i < 10; ++i) {
numbers.push_back(i);
numberTotal += numbers[i];
++listLength;
}

cout