[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
Prove you're not a pajeet
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: 251
Thread images: 23
File: hvEnMpK.png (80 KB, 694x732) Image search: [Google]
hvEnMpK.png
80 KB, 694x732
Well?
>>
i don't know how to program, but maybe I can afford a DNA test
>>
var sum = (a, b) => a + b;
var avg = arr => arr.reduce((a, b) => a + b) / arr.length
>>
>>55121653
Shit, I first thought I'd use a function for reduce, but then remembered it has to be a lambda. UPD:

var avg = arr => arr.reduce((a, b) => a + b) / arr.length
>>
>>55121623
C#

var averageOfList = this.ListOfNumbers.Average(n => n);

Why is this such a problem?

If it's a list of more complex objects it's like:

var averageOfList = this.ListOfNumbers.Average(n => n.ValueYouWantToAverage);

Are you 12?
>>
def avg(arr):
return reduce(arr, lambda a, b: a+b) / len(arr)
>>
File: 1435352635578.jpg (244 KB, 1846x1212) Image search: [Google]
1435352635578.jpg
244 KB, 1846x1212
>>55121623
But I am.
>>
>>55121623
>find the average of a list of numbers
But can you average two ints in C?
>>
poo => loo
>>
python 3

from functools import reduce

avg = reduce( (lambda x,y:x+y) , l )/len(l)
>>
>>55121623
I don't know
>>
// Go
f := func(list []int) int {
sum := 0
for i := range list {
sum += i
}
return sum / len(list)
}

fmt.Println(f([]int{1,2,7392,72615,62,9}))
>>
>>55121975
Hello, Pajeet

>>55121997
Hello to you, too, another Pajeet
>>
I don't have to code, I have money
>>
>>55121623
What's a lambda expression? I've been programming for 5+ years now and the only lambda I know is the C++ one.
>>
File: 1462313441325.png (1 MB, 910x823) Image search: [Google]
1462313441325.png
1 MB, 910x823
what is pajeet? and what's wrong for being one?
>>
>>55122135
>what is pajeet
slang for indian or south asian

>what's wrong for being one
all the negative stereotypes
dirty
poo in loo
cheap
bad at software
>>
File: 1464920836961.jpg (20 KB, 275x307) Image search: [Google]
1464920836961.jpg
20 KB, 275x307
>>55122143
oh shit. i guess im not welcome here.
>>
Can't you just do something like this?


avg :: [Int] -> Int
avg list = (foldl + 0 list) / (size list)

>>
>>55121623
// javascript
let ƛ = (array) => array.reduce((x,y)=>x+y)/array.length
ƛ([1,2,3,4,5]) // 3
>>
>>55121623
//php
$lambda = function($array) { return array_sum($array)/count($array); }
$lambda([1,2,3,4,5]); // 3
>>
>>55122175
You are not welcome anywhere. Even negros have more acceptance
>>
>>55121623
>2016
>not being pajeet master race
>>
>>55121623
//go
package main

import "fmt"

func main() {
ƛ := func(numbers []float64) float64 {
sum := 0.0
for _, num := range numbers {
sum += num
}
return sum / float64(len(numbers))
}
fmt.Println(ƛ([]float64{1, 2, 3, 4, 5}))
}
>>
>>55121975
l not in scope. You FAIL.
>>
>>55121623
# python
l = lambda li: sum(li)/len(li)
print l([1,2,3,4,5])
# 3
>>
>>55121623
dear kind mr stackoverflow can you please teach me how expression of lambda do list of numbers to average? i am very eager of learnings thank you kindly kind sir. kind regards dr. p. kapoor
>>
>>55122184
That's full of errors. Stick to Go or Javascript.
>>
Singly linked list, single pass.
#! /usr/bin/env guile
!#

(use-modules (srfi srfi-1))

(define (avg lst)
(apply / (fold (lambda (x prev)
(list (+ (car prev) x) (+ (cadr prev) 1)))
'(0 0)
lst)))
>>
>>55122321
>Javascript
>Implying I've ever touched that language

Mate stop assuming assumptions it's not cool. I haven't written in Haskell in forever.
>>
File: 1382340664025.png (50 KB, 1316x1152) Image search: [Google]
1382340664025.png
50 KB, 1316x1152
//Java
// it looks like shit
// t. junior java dev
public Double getAvg(List<Integer> intList){
return intList.stream().mapToInt(Integer::intValue).average().getAsDouble();
}


to test:
@Test
public void testIntAvg(){
ArrayList<Integer> intList = new ArrayList<>();
intList.add(0);
intList.add(1);
intList.add(2);
intList.add(3);
intList.add(10);

Assert.assertEquals(new Double(2), testClass.getAvg(intList));
}
>>
>>55121653
JavaScript is kiddie shit and doesn't count. Literally anyone can do JS.
>>
>>55121623
>tfw don't know what lambdas are
Can someone tell a c wizard what a lambda is in a sentence?
>>
>>55123044
Anonymous functions(which you can treat like variables)
>>
File: 1462546368518.jpg (433 KB, 900x900) Image search: [Google]
1462546368518.jpg
433 KB, 900x900
Sup guys, I'm new to shell scripting.
Anyone got a bash/sh solution please?
>>
>>55123056
Why would anyone want this?
>>
>>55123076
Callbacks, visitor pattern, you name it.
>>
File: DSC00357.jpg (1 MB, 2592x1944) Image search: [Google]
DSC00357.jpg
1 MB, 2592x1944
>>
File: ss+(2016-06-17+at+03.50.31).png (5 KB, 438x82) Image search: [Google]
ss+(2016-06-17+at+03.50.31).png
5 KB, 438x82
>>55123076
>>55123176
They are pretty great when you need to call a one-liner.
>>
File: ob4zoX.jpg (2 MB, 3936x5248) Image search: [Google]
ob4zoX.jpg
2 MB, 3936x5248
>>55123188
>>
>>55121623
>use a lambda expression
Why the fuck would i do that?
>>
>>55121623
I don't want to do your homework, madarchod.
>>
>>55121847
#include<math.h>
>>
>>55121623
No. I don't fizzbuzz unless Im being compensated at University Professor rates this aint welfare codecamp kiddies.
>>
>>55123436
Bullshit. A true C bytefucker would do pointer magic, like placing the ints near each other, than casting the first pointer to a pointer to longint, then moving bits to the right in the value of that pointer.
>>
>>55121623

tfw I can't lambda
>>
glorious ruby mustard race
 arr.inject(0) { |a, b| a += b} / arr.size.to_f 
>>
>>55121623
data TTree = Leaf Int | Plusbranch TTree TTree | MinusBranch TTree TTree | MulBranch TTree TTree | DivBranch TTree TTree

evalT :: TTree -> Int
evalT (Leaf x) = x
evalT (Plusbranch x y) = eval x + eval y
evalT (MinusBranch x y) = eval x - eval y
evalT (MulBranch x y) = eval x * eval y
evalT (DivBranch x y)
| evalT y == 0 = error "Division by 0
| otherwise = evalT x 'div' evalT y


This made realize the value of functional programming the first time when i saw someone at my university doing this in java with like 200 lines of code and a monster of a architecture structure.
>>
someone outsource this to india
>>
>tfw when your pajeet homeroom teacher was the only person in your boring town in the middle of nowhere that wasn't mentally challenged. Pajeets are cool you guys.
>>
>>55123483
What's this? A Lisp interpreter version 0.0.1?
>>
>>55123058
>life is strange
I like you.

on topic:
I only programmed for about a week in total in my life. I'm weak.
>>
>>55123507
I honestly can't tell the difference between an Indian and a gypsy. They look the same to me. And I fucking hate gypsies, they're scum, they're worse than niggers.
t. eastern european
>>
>>55123483
>lisp users are this delusional

>>55123479
this can be shortened
 arr.reduce(:+) / arr.size.to_f 
>>
>>55123058
>using bash for math
>>
>lisp users are this delusional
Well it looks like an execution tree parser to me.
>>
>>55123058
There is no solution in bash because bash doesn't have lambda.
>>
Postgresql is better than mysql.
>>
>>55121681
Where are your imports?
>>
>>55123535
>Lisp
Its Haskell dumbass
>>
R

mean(list)
>>
>>55121623
//C
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("gomenasai dev-san, I can't do this lambda shit\n");
exit(EXIT_FAILURE);
}
>>
>>55122950
>intList.stream().mapToInt(Integer::intValue).average().getAsDouble();

wow
>>
lambda x:sum(x)/len(x)
>>
  auto getAverage = [](const std::vector<int>& nums) {
int sum = 0;
for (int num : nums)
sum += num;
return static_cast<double>(sum) / nums.size();
};
std::cout << getAverage({1, 2, 3}) << std::endl;
>>
>>55122134

What is a lambda expression at all? I've been programming nearly 20years and this thread is first I've chosen to care about it
>>
>>55123076

Anonymous functions have the same effect as ye olde inline macros but are handled by the compiler rather than a preprocessor. To that extent they represent a more elegant solution than inline macros
>>
>>55121623
(/ (foldl + list) (length list))

can i just take a picture of my toilet instead?
>>
>>55121623

(declaim (ftype (function (symbol) boolean) pajeetp))

(defun pajeetp (symbol)
(get 'not-pajeet 'symbol))

(setf (get 'self 'not-pajeet) t)
>>
>>55124049

int numbers[] = {1, 3, 8, 4, 3, 9, 3, 1, 7, 8, 9};

cout << [&numbers]() -> double {
int total;

for (int& i : numbers)
total += i;

return (double)total / (sizeof(numbers) / sizeof(numbers[0]));

}() << endl;


Why use static_cast?
>>
>>55121623
I know how to poo in loo.
>>
>>55121623
> Python
f = lambda x : sum(x)/len(x)

# or

def sum(spam):
foo = 0
for i in range(0, len(spam)):
foo += spam[i]
return foo

f = lambda egg : sum(egg)/len(egg)
>>
>>55124804
f = lambda x : sum(x)/len(x)

# or

def sum(spam):
foo = 0
for i in range(0, len(spam)):
foo += spam[i]
return foo

f = lambda egg : sum(egg)/len(egg)
>>
>>55122216
/thread
>>
>>55123455
You don't even need math.h to add and divide
>>
>>55121623
I have a job in info sec.
Done
>>
>>55121623
[](list<int> l) -> int {
int average = 0;
for (auto &e : l)
average += e;
return e/l.size();
}
>>
File: 1298967325529.png (597 KB, 754x638) Image search: [Google]
1298967325529.png
597 KB, 754x638
>desperately trying to project to a group of anonymous people they're smarter than a perceived stereotype
>the question is actually so simple, they may prove they are not the stereotype, but do prove feel threatened by it because it is not far off their own abilities

you're embarrassing yourself, /g/
>>
File: 20160617_194552.jpg (759 KB, 2560x1440) Image search: [Google]
20160617_194552.jpg
759 KB, 2560x1440
>>55121623
This is pic of me
>>
>>55124631
Because C++ programmers are a lot like Catholics: anything good or helpful must come with lots of suffering
>>
>>55125167
Integer division, brah
>>
File: bort.jpg (14 KB, 320x246) Image search: [Google]
bort.jpg
14 KB, 320x246
>>55121623
What does lambda do/mean? I would have to make a loop with total += array[i] then divide by the length.
>>
>>55121623
I can read and speak in 6 diferent languages.
I understand another 2 in spoken form.
And I'm Mediterranean white.

I'm also using a tripcode that makes me a faggot.
>>
>>55125575
Read the thread or use Google
>>
>>55125620
I'm googling but I don't understand the explanations.
>>
>>55125656
They're just anonymous functions
>>
>>55125678
So it's just a way for OOP languages to get around the constraints of OOP while telling themselves they are still using OOP?
>>
>>55125656
There ain't no shame in that. Seriously, not even memeing here. I also don't understand why defecating somewhere else other than a toilet elicits so much repulsion from everyone here.
>>
File: 1348604665273.jpg (482 KB, 500x800) Image search: [Google]
1348604665273.jpg
482 KB, 500x800
>>55121623
>>
>>55125706
No? It's primarily a functional concept that was useful enough that other languages adopted it
>>
>>55125706

Are you retarded?
>>
(fn [l] (/ (reduce + l) (count l)))
>>
>>55122175

fuck off
>>
>>55125706
Greetings pajeet!
>>
>>55121623
fun main(args: Array<String>) {
println(MyMath.sum(listOf(-10, -15, 30, 1, 3, 4, 5)))
println(MyMath.sumLambda(listOf(-10, -15, 30, 1, 3, 4, 5)))
}

object MyMath {
fun sum(numbers: List<Int>): Int = numbers.sum();
fun sumLambda(numbers: List<Int>): Int = numbers.reduce { a, b -> a + b }
}
>>
>>55121645
You actually made me lol. Wp anon.
>>
import lambda
lamba (muh_array)
>>
In Prolog:
average(List, Avg) :- average(List, Sum, 0, Size, 0), Size =\= 0, Avg is Sum / Size.

average([L|List], Sum, AcuSum, Size, AcuSize) :- AcuSumNew is L + AcuSum, AcuSizeNew is AcuSize + 1, average(List, Sum, AcuSumNew, Size, AcuSizeNew).

average([], Sum, Sum, Size, Size).
>>
(* This is OCaml *)
open Core.Std

let average = function
| [] -> 0.0
| _ as lst ->
let sum = List.fold ~init:0 ~f:(+) lst
in float(sum) /. float(List.length(lst))

let () =
assert (average [] = 0.0);
assert (average [1] = 1.0);
assert (average [1;2;3;4] = 2.5)

let () =
printf "Ok\n"
>>
>>55121623
>prove you're not a pajeet

I was asked to find the average of a list of numbers.

I deposited $0.05 into a foreign account, got the code, then resold it to a U.S. corporation for $500.
>>
average = lambda x: sum(x)/len(x)

python wins again
>>
>>55125706
>constraints of OOP

Is this a young fag thing? Or the result of people only being exposed to early Java?

I've never worked in an OOP language that didn't let you have collections of functions which were not attached to any given class. Nor was I ever told "hurr durr you always have to use a class."

"Constraints" my ass.
>>
>>55128963
average([])
>>
>>55128963
>run code
>20 minutes later
>"python wins again"
>c was finished in 20ms
>>
File: smug anime girl 413.jpg (10 KB, 237x212) Image search: [Google]
smug anime girl 413.jpg
10 KB, 237x212
>>55129001
average = lambda x: sum(x)/len(x) if len(x) > 0 else 0
>>
>>55124100
>muh years of experience

Grandpa, you shouldn't have stopped learning all those years ago.

You're junior-level until you catch up.
>>
>>55122275
You just proved you're a pajeet.

reduce(lambda x, y: x + y, mylist) / len(mylist)
>>
>>55129041
that's not really the point of lambda. See >>55129110
>>
>>55128791
>using core
lmfao
>>
>>55129057
>muh hipster terminology for ancient techniques > years of experience

All /g/ can do is discuss lambdas and FizzBuzz.

If /g/ ever tried designing a real application it would be a cluster fuck of spaghetti code and security holes.
>>
>>55121623
=SUM(A:A)

Excel Master Race
>>
>>55129144
>average
nice job pajeet.
>>
>>55129168
touche
>>
>>55121847
If they're sorted then

a + ((b-a)>>1)

will avoid overflows
>>
File: 1465632588781.jpg (51 KB, 398x582) Image search: [Google]
1465632588781.jpg
51 KB, 398x582
>>55129022
>c finished after python
>>
>>55129137
but... lambda are kind of important with map/reduce and hadoop being a thing.
>>
>>55129229
>needing to sort numbers to find a average
thanks pajeet. you can go home now.
>>
ITT: people giving lambda expressions identifiers and calling them directly.
If you don't have a higher order function, you probably don't need to use lambda.
>>
>>55129265
>not noticing ms=milliseconds
gtfo pajeet
>>
>>55129315
they look cool tho
is that not enough reason
>>
>>55123058
#! /bin/sh

TOTAL=0
COUNT=0

while read ANS; do
if [ -n $(echo "ANS" | grep '.' | grep '^[0-9]*.?[0-9]*$') ]; then
TOTAL=$(( $TOTAL + $ANS ))
COUNT=$(( $COUNT + 1 ))
fi
done

if [ "$COUNT" != 0 ]; then
echo $(( $TOTAL / $COUNT ))
else
exit 1
fi


In Bourne Shell because fuck bash.
Also not feeling like jumping through hoops to shove lambdas into Bourne again (nor into BourneAgain).
>>
>>55129298
You're the moron who writes

pivot = (left + right) / 2

in a quicksort, aren't you?
>>
WHERE THE FUCK IS HASKELL?
>>
>>55129776
(\x -> (sum x) `div` (length x)) [1,2,3,4,5]
>>
>>55123483
>'div'
Syntax error on 'div'
Perhaps you intended to use TemplateHaskell
In the Template Haskell quotation 'div'
>>
>>55129670
Not him, but what's wrong with that?
>>
File: index.jpg (9 KB, 254x198) Image search: [Google]
index.jpg
9 KB, 254x198
>>55129776

Where it belongs.
>>
>>55129322
>>not noticing ms=milliseconds
>gtfo pajeet

Why would Pajeet recognize ms? He has never had code run that fast.
>>
>>55130455
You shouldn't even write quicksort or any algorithm for that matter, because they've already been written and optimized, so you only use them.
>>
>>55130455
literally nothing, but if the list is already sorted I think it makes it a lot slower
>>
>>55130844
It's right here: >>55130096

I don't see any other one-liners like this.
>>
>>55129670
>finding averages
>needs to sort the numbers
again, thanks pajeet. you can go home now.
>>
File: toilet-worship.jpg (179 KB, 750x868) Image search: [Google]
toilet-worship.jpg
179 KB, 750x868
[CODE]
SELECT 'I AM NOT PAJEET MY FRIEND' FROM DUAL;
[/CODE]
>>
>>55124100
Closures. Lambda is a math-wankery term.
>>
>>55123508
pretty sure it's haskell
>>
>>55129041
>body of if BEFORE the if and the condition

HOW THE *FUCK* CAN PYTHONFAGS DEFEND THIS
>>
>>55131174
Good for one-liners. Ruby has the same feature.
>>
>>55122956
Oh I didn't realise that's how this worked
>in any language
>any language except JS
fucking moron
>>
I've been programming for a while, but I have no fucking clue how lambda expressions work.
>>
>>55131036
closures and lambdas aren't synonymous. lambda == anonymous function, anonymous function doesn't have to be a closure.
>>
For starters I poop in a toilet
>>
>>55122294

so much this, but im alright with their questions, what is fucking annoying is their dumbass answers. so hard to refrain from yelling ""racist"" remarks when browsing stackoverflow at work
>>
>>55122950
>public Double getAvg(List<Integer> intList){
> return intList.stream().mapToInt(Integer::intValue).average().getAsDouble();
> }

India: the Java function.
>>
>>55129137
And anime
>>
>>55122216
Remember negros fuck their moms and sisters and daughters in Africa, aids is more common than the common cold there.
>>
>>55121623
>use lambda
But you're the pajeet, anon!
>>
>>55122950
public static double avg(Collection<? extends Number> in) {
return in.stream().map(Number::doubleValue).reduce(0.0, (a,b)->a+b) / in.size();
}
>>
def fold(lst, f, base):
i = 0
while i<len(lst):
base = f(base, lst[i])
i+=1
return base
a = [1,2,3,4,5,6]
print fold(a, lambda x, y: x+float(y), 0)/len(a)
#or
reduce(lambda x, y: x+float(y), [1,2,3,4,5,6])/6


yes you can use reduce also
>>
My last name is Christensen and I live in Denmark.
>>
File: 1412631739036.png (114 KB, 694x670) Image search: [Google]
1412631739036.png
114 KB, 694x670
>tfw you've seen ACTUAL code written by a "PROFESSIONAL" that looks EXACTLY like this.
>>
>>55121975
does python 3 allow you to do that?
is it not functools.reduce()?
>>
>>55132677
>holy shit
literally just need mod
>>
>>55132693
from X import Y

imports one function (Y) from a module (X). Python 2 also has this kind of import syntax.
>>
>>55121623
(a => a.reduce((p, v, i, a) => i == a.length - 1 ? (p + v) / a.length : p + v))([1,2,3,4])
>>
>>55121670
well done
>>55132913
my less elegant version that I wrote before seeing yours
>>
Lambdas are so fucking cool. I literally cannot overstate how cool lambdas are. They're like the second coming of Christ. They're perfect for a cutting-edge hacker like me, who likes breaking things to see how they tick.
My favorite part is how much you can cram into one line. A statement that used to be spread over two lines can now be written in one. HOW M*TH*R FR*GG*N' COOL IS THAT?
>>
>>55133284
>python programmers
>>
>>55121623
(\xs -> sum xs / sum [1 | x <- xs]) [1..10]
5.5
>>
>>55134122
>
sum [ 1 | x <- xs]

>
[1,1,1,1,1...]

oh god why
>>
>>55130096
>div
>>
>>55134148
so i can get the length, fag
retardedly, the official length returns an int, and u can't divide a float by an int,
>>
# R
x <- c(1,2,3,4,5)
avg(x)
>>
>>55122209
winrar
>>
The correct answer is that only a fucking PAJEET WOULD USE A LAMBDA FOR SUCH A SIMPLE FUCKING TASK.

THERE ARE BUILTIN FUNCTIONS IN ALMOST EVERY LANG THAT DO THIS AND IF NOT THEN YOU JUST IMPLEMENT A SIMPLE FUCKING REDUCE OR LOOP AS THE FIRST FEW POSTS SHOW.. tHIS IS THE DUMBEST FUCKING NIGGER PAJEET POST I'VE EVER FUCKING SEEN.
>>
add all the numbers and divide by the number of numbers, or count the most used number.
>>
average = lambda { |*nums| nums.reduce(:+) / Rational(nums.length) }
>>
i dont know this nerd ass shit im just here for mouse reviews
>>
average=lambda n:sum(n)/len(n)
>>
>>55134611
that's fine, but posting worthless comments in threads you don't know anything about is kind of counter-productive. if you have some disorder that compels you to give everyone your input even if you have none to give, then you should see a doctor, buddy
>>
>>55134626
do not speak to me please pajeet t
>>
>>55134634
fully white. you're just one of those entitled retards who thinks his failure is the result of pajeets who miraculously control things behind the scenes, aren't you?

not everything is a conspiracy; you're just a fucking loser.
>>
average =: +/ % #
>>
#include <MsgBoxConstants.au3>

Local $numArray[] = [ 8, 9, 0, 1, 1, 1, 9 ]
$rows = UBound($numArray)
$sum = Null
For $num In $numArray
$sum += $num
Next
$result = $sum/ $num
MsgBox($MB_SYSTEMMODAL, "", $result)
>>
lambda x: sum(x) / len(x)


^:)
>>
>>55121623
int average(int n, int *arr)
{
float avg = 0.0f;
int i;
for (i = 0; i < n; i++)
avg += (float) arr[i] / n;
return (int) avg;
}


Can I have job now?
>>
>>55134947
lol no
>>
>>55121623

SumOp sumOp = (list, listSize, sum )->( return listSize >= 0 ? (list, listSize - 1, sum + list[listSize - 1]) : sum );

>>
>>55134980
fine, here's a real lambda function.
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var avg = (function(arr) { var avg = 0.0; for (var i = 0; i < arr.length; i++) avg += arr[i] / arr.length; return avg; })(numbers);
>>
>>55134650
>projecting
>>
depth dup 1- 0 do -rot + swap loop / .
>>

VAR number = 0;

if{

number => 0;

)

THEN

{

find.average.number

)



This is my own custom language btw. It's highly sophisticated.
>>
File: tbh fam.jpg (38 KB, 572x765) Image search: [Google]
tbh fam.jpg
38 KB, 572x765
>>55123339
>>
>>55132744
i know that but if you from x import y do you not have to say x.y()?
>>
[Code]
fun average (lst:real list) = avg LST 0 0;

fun avg [] 0 _ = 0
| avg [] (sum:real) (len:real) = sum div real
| avg ((h::t):real list) (sum:real) (len:real) = avg t (sum + h) (len +1);
[/code]
>>
>>55135793
Fucking auto correct!
[Code] should be all lower case and LST should be lower case too.
>>
>>55135822
>Programming on an iphone.
lmao
>>
>>55132329
so? indians are worse.
>>
I don't know how to program and I have a wonderful toilet and a bidet in my house
>>
>>55121623
that's that half life shit nigga
>>
>>55132329
Remember whites fuck their moms and sisters and daughters in America.
>>
typedef double (*LAMBDA_EX) (double, double);

extern double reduce(double list[], int len, LAMBDA_EX lambda)
{
double result = list[0];
int i;

for (i = 1; i < len; i++) {
result = lambda(result, list[i]);
}

return result;
}

static double _lambda_add(double a, double b)
{
return a + b;
}

extern double average(double list[], int len)
{
return reduce(list, len, _lambda_add) / len;
}
>>
File: 1466152921662.jpg (23 KB, 536x536) Image search: [Google]
1466152921662.jpg
23 KB, 536x536
>>55122950
> Arrays.asList(0,1,2,3,4)
Fucking retard
>>
wrote it on branfuck, however it works only with 2 numbers

++>++++++++<
[<+>-]
<[[->+<][->>+<<]]
>>
>>55137681
Could you use optimize it with movfuscator please? https://github.com/xoreaxeaxeax/movfuscator
>>
Java
integerList.stream().mapToInt(x->x).average();
>>
let kek lst = lst |> List.reduce (+) |> (/) <| lst.Length

dotting can be cool sometimes
>>
File: 1455269280629.jpg (31 KB, 546x242) Image search: [Google]
1455269280629.jpg
31 KB, 546x242
>>
>>55138286
>ELM
Why hello there, sir. I like you.
>>
>>55138328
well it's not ELM, it's F#
>>
>>55138337
Well then I don't like you anymore, sir.
>>
>>55138360
(you)
>>
meme tier
let lmao = List.fold (fun (s,l) x -> (s+x,l+1.0)) (0.0,0.0) >> (fun (s,l) -> s/l)
>>
>>55122143
>bad at software
>>
>>55121623
why use a lambda, why not make a named function so its reusable?
>>
>>55138534
What if you only need it once?
>>
>>55138550
you may use it in the future, and refactoring an anonymous function so you can use it later seems like more work than accepting the trivial hit to your namespace and memory footprint that keeping a function in memory would represent.
>>
>>55121623
I am a C programmer. I do not consider anonymous functions to be valid engienering practice.
>>
>>55138570
>factoring an anonymous function so you can use it later seems like more work
ctrl + x, let nameForLambda = ctrl + v
>>
I tried really hard to dick around with map and filter to get a sensible result out of an empty list but my functional-fu is not good enough.

avg = lambda list: reduce(lambda x,y: x + y, list, 0) / reduce(lambda x,y: x + 1.0, list, 0)
>>
val avg = {
array ->
var sum : Float = 0
for (i in array)
sum+=i
sum/array.length
}
>>
>>55138665
you're and idiot

>>55138583
also you
>>
>>55139099
thanks for the (you). Here is yours
>>
>>55132677
>huge C# project
>function that looks exactly like this (identifier names changed, obviously)
void Killme(object arg_a, object arg_b) {
if(Event != null) {
int out_a = -1, out_b = -1;
if (arg_a is TypeA) out_a = ((TypeA)arg_a).What.Ever;
if (arg_b is TypeA) out_b = ((TypeA)arg_b).What.Ever;
if (arg_a is TypeB) out_a = ((TypeB)arg_a).What.Ever;
if (arg_b is TypeB) out_b = ((TypeB)arg_b).What.Ever;
if (arg_a is TypeC) out_a = ((TypeC)arg_a).What.Ever;
if (arg_b is TypeC) out_b = ((TypeC)arg_b).What.Ever;
Event(out_a, out_b);
}
}

And this is a project that is used every day in an actual company.
I'm not working on it anymore, thank god. It was a nightmare.
>>
>>55121623
lambda l: sum(l)/Len(l)
>>
>>55134151
Why are you getting flustered?
>>
>>55131174
You know c has the ternary operator as well, right?

flip = (x == 0) ? backflip(): frontflip()
>>
>>55139760
;
>>
I'm a slav. We're the new improved pajeets for the new era.
>>
code]
//scala

nums.reduce((a, i) => a + i/nums.length)


[/code].
>>
fuck off poojet
>>
Anybody who traversed the list more than once is retarded.
average = uncurry (/) . foldl' (\(s, l) x -> (s+x, l+1)) (0,0)
>>
>>55141278
That's absolutely beautiful.

10/10

Haskell wins.

Thread over.
>>
>>55130455
...because then it's just a mergesort?
>>
>>55121623
I went to a university where there are actually classes and professors, where you have to take tests and do projects, as opposed to just ordering a diploma in the mail.

Also, when I say that I know how to program, I mean on a real computer, and not just by writing statements on a chalkboard.

Oh yes, I also use a flush toilet and toilet paper.
>>
>>55142739
The only languages I am proficient in at the moment is PHP and Bash.

Come at me ameritards.
>>
>>55141278
Technically this traverses the list twice as well. It just does them at the same time. When you traverse the list you are still doing two checks for each element.

Retard.
>>
#(/ (reduce + %) (count %))
>>
All these solutions using the length of the array make me sad. What about infinite sequences?

(fn
[seq]
(loop [c 0
acc 0
s seq]
(if (nil? (first s))
(/ acc c)
(recur (inc c)
(+ acc (first s))
(rest s)))))
>>
>>55138038
>mapToInt(x->x)
what the fuck? why?
>>
File: kattefyr.jpg (42 KB, 604x453) Image search: [Google]
kattefyr.jpg
42 KB, 604x453
>>55143700
You're an idiot. There is so much wrong with that post.

1. You're incapable of formatting code on 4chan.
2. Your solution doesn't handle infinite sequences at all. It eagerly attempts to process all elements, meaning it will never terminate, and not produce any intermediate results. It's not solving what you're implying it solves.
3. You've failed to realize you're just reducing. Instead you're using the brutish loop construct like a newcomer to functional programming.
4. You're not using constructs like if-let et al, further suggesting you don't know anything about the specific language you're using.
5. You're mocking other people for something you clearly don't understand.

If you want that to work, you'll have to return a lazy sequence of cumulative averages. One implementation could be the following:

(defn cumulative-average
[coll]
(->> coll
(reductions
(fn [[cum-avg i] n]
[(-> (dec i)
(/ i)
(* cum-avg)
(+ (/ n i)))
(inc i)])
[0 1])
(rest)
(map first)))


That allows you to work with infinite lazy sequences:

(take 10 (cumulative-average (iterate #(+ 10 %) 10)))


and get a running cumulative average like so:

(10 15 20 25 30 35 40 45 50 55)


Now stop being shit on the internet.
>>
QA engineer
>>
File: 1466285549973.jpg (74 KB, 1024x512) Image search: [Google]
1466285549973.jpg
74 KB, 1024x512
>>55139232
Actually I can relate having been forced to write code like that.

So, we have 2 weeks in a Sprint to deliver too much shit because the product owner is involved in what is taken into the sprint for some reason.

Either we split the work and all code is different when merged together, or one guy splits the PBI and it ends up with such switch statements that will eventually have to be implemented, but then again the PO does not reserve time to:
a) follow-up on old PBIs
b) refactor old code
Either way the code is unmainainable

So basically you're fucked if you have a manager in an IT company.
>>
What the fuck is a lambda?
>>
>>55146567
anonymous function
>>
>>55146689
What's it hiding?
>>
>>55146752
Its sexuality.
https://en.wikipedia.org/wiki/LGBT_symbols#Lambda
>>
>>55132251
can you show the non pooland version?
>>
>>55146752
>implying anonymity means having something to hide

sometimes it makes more sense to not have a name
>>
>>55141278
wew lad (FSharpPlus)
let hask = uncurry (/) << List.fold (fun (s,l) x -> (s+x, l+1.0)) (0.0, 0.0)
>>
>>55146879

some tips:

dont use the data type as variable name or include it in the variable name, its retarded. use a hint of what it represents instead.

use various steps with comprehensive variable names and even comments instead of a long method chain like that.

get used to do things this way and you'll fix bugs a hell of a lot faster, not to mention if someone else has to work with your code.
>>
>>55142903
No I just do it once.
>>
using system.linq;

public decimal OP_a_shit(IEnumerable<decimal> myList)
{
return myList.Average();
}
>>
>>55122950
>return intList.stream().mapToInt(Integer::intValue).average().getAsDouble();

thkx 4 the kek
>>
>>55122143
Doesn't really apply to Indian Americans though desu
>>
>>55141278
Looks like I was the retard after all. I should have put bang patterns there:
average = uncurry (/) . foldl' (\(!s, !l) x -> (s+x, l+1)) (0,0)

(compile with -XBangPatterns)

Also, if the list happens to be integers and you want a rational result, this performs better when compiled with -O2:
average = \xs -> sum xs % genericLength xs
>>
(* F# *)
let avg list = List.fold (fun a b -> a + b) 0 list / (List.length list)


There's obviously a shorter way to do this but OP said there needs to be a lambda.
>>
Cá bhfuil an leithreas?
>>
>>55121623
>in any language
>use a lambda
but what if I use shit languages?
>>
>>55149951
kek
>>
What is a lambda expression?

Why not just the Average method in Visual C#?
average = arrList.Average();

Programming is easy. You guys are dumb.
Thread replies: 251
Thread images: 23

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.