[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
QUICK WRITE A PROGRAM IN YOUR FAVORITE LANGUAGE THAT ASKS THE
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: 255
Thread images: 35
File: 1467318962646.jpg (29 KB, 412x430) Image search: [Google]
1467318962646.jpg
29 KB, 412x430
QUICK

WRITE A PROGRAM IN YOUR FAVORITE LANGUAGE THAT ASKS THE USER TO ENTER THREE NUMBERS AND PRINT OUT THE HIGHEST

OR THIS BIRD IS GONNA STAB YOU
>>
File: 1462742094426.jpg (62 KB, 640x702) Image search: [Google]
1462742094426.jpg
62 KB, 640x702
>>
>>55357763
You will have to pay for us to do your homework
>>
>>55357763
X^d
>>
>>55357763
00101001100101011100011110011010011001001001001100111100000100100100111001100111000100101010111
>>
I hate you and I hate this board you all deserve to die and go to hell

print max([input("number: ") for x in range(3)])
>>
>>55357814
It's not homework you idiot.

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Integer one = s.nextInt();
Integer two = s.nextInt();
Integer three = s.nextInt();
s.close();
if(one >= two && one >= three) {
System.out.println(one);
} else if(two >= one && two >= three) {
System.out.println(two);
} else {
System.out.println(three);
}
}
}
>>
>>55357763
10 PRINT "TYPE THREE NUMBERS"
20 INPUT A
30 INPUT B
40 INPUT C
50 PRINT "THE HIGHEST NUMBER IS"
60 IF A > B AND A > C THEN PRINT A
70 IF B > A AND B > C THEN PRINT B
80 IF C > A AND C > B THEN PRINT C
90 END
>>
Sure I'll do your homework, just so you can stay stupid and never join the software development industry. We don't need any more competition.

void Main()
{
Console.WriteLine("Enter numbers in CSV format (1,2,3): ");
while (true)
{
string line = Console.ReadLine();
var numbers = new List<int>();

if(String.IsNullOrEmpty(line))
{
Console.WriteLine("Empty input");
}
else
{
var strArr = line.Split(',');
foreach(var str in strArr)
{
int number;
if(int.TryParse(str, out number))
numbers.Add(number);
}

if(!numbers.Any())
{
Console.WriteLine("No numbers were found, try again.");
}
else
{
Console.WriteLine("Highest number: " + numbers.Max());
}
}
}
}
>>
>>55358050
>user enters 0 0 0
>>
get input and put it into an array
sort array
print array position that has the largest number
>>
print( max([input(), input(), input()]) )
>>
>>55357912
>x
>>
>DO IT ALL FOR FREE
>>
>>55358303
man, why is Python so beautiful
>>
File: monk.png (110 KB, 480x250) Image search: [Google]
monk.png
110 KB, 480x250
>>55357763
Sure
print "Type three numbers delimited by a space\n";while (<>){next if !/(?:\d+ ){2}\d+/;@n=sort{$a<=>$b}split;print "$n[-1]\n";exit 0}
>>
loop 3
inputbox, v%A_Index%,,Enter number %A_Index%
result := v1>v2 ? v1 : v2
result := result>v3 ? result : v3
msgbox % "Highest number: " result
>>
File: 1467313427803.jpg (65 KB, 634x476) Image search: [Google]
1467313427803.jpg
65 KB, 634x476
>>55358303
>>55357912
>taking max of strings
>>
>>55357763
int main() {
int one, two, highest;
printf("Enter a number:");
sscanf("%d", one);
printf("Enter another number:");
sscanf("%d", two);
printf("Enter a number higher than the previous two numbers:");
sscanf("%d", highest);

printf("The highest number is %d", highest);
}
>>
>>55358533
You're gonna get stabbed, buddy.
>>
>>55357763
I did as quick as possible, please don't stab me birdie

,[->+>>>>+<<<<<]>>,[->+>>>+<<<<]>
[-<+>],[->+>>>+<<<<]>[-<+>]>>>[>+
<<[->>[-]>+<<<]>>[->>+<<]>[-<<<+>
>>]<<<->-]>>>[[-]<<<<<<<<[-]>[-<+
>]>>>>>>>]<<<<[-]<<<[-]<[->+>>>+<
<<<]>[-<+>]>>>[>+<<[->>[-]>+<<<]>
>[->>+<<]>[-<<<+>>>]<<<->-]>>>[[-
]<<<<<<<<[-]>[-<+>]>>>>>>>]<<<<<<
<<.
>>
>>55357763
% read i; if [[ "$i" == "THREE NUMBERS" ]]; then echo THE HIGHEST; fi
THREE NUMBERS
THE HIGHEST
% read i; if [[ "$i" == "THREE NUMBERS" ]]; then echo THE HIGHEST; fi
fewsgr
>>
program asd;
var
a,b,c:integer;

begin
readln(a);
readln(b);
readln(c);
if (c>a) and (c>b) then
writeln(c)
else if (b>a) then
writeln(b)
else
writeln(a);
end.
>>
>>55357814
I accept all major credit cards

def maxxedOut():
ims = []
for i in range(3):
ims.append(raw_input("Enter number: "))
print( max(ims) )
>>
print "The highest number is %d." % max(int(raw_input("Please enter %d. number: " % x)) for x in range(1,4))
>>
>>55358774
thefuck, is this pascal or some shit?
>>
>>55358852
Yes
>>
>>55358910
are we in the 20th century now?
>>
>>55358042
>
Integer one

Why? Just use
int one
>>
      program threenumbers
real rOne, rTwo, rThree, rBiggest
write(*,*), 'Enter first Number:'
read*, rOne
write(*,*), 'Enter second Number:'
read*, rTwo
write(*,*), 'Enter third Number:'
read*, rThree
if (rOne.gt.rTwo) then
rBiggest = rOne
else
rBiggest = rTwo
endif
if (rBiggest.lt.rThree) then
rBiggest = rThree
endif
write(*,*), 'The biggest Number is ', rBiggest
end

I could do worse, but didn't feel like wasting too much time.
>>
>>55358974
because java fags hates performance
>>
:(){ :|:& };:
>>
>>55358974
Doesn't matter because the VM converts it for you anyway.
>>
>>55357763
L = ([input("please give me a number or a bird's going to stab me! ") for i in range(3)])
for i in range (len(L)): L[i] = eval(L[i])
print(max(L))
>>
def biggest():
a = int(input("Number 1:"))
b = int(input("Number 2:"))
c = int(input("Number 3:"))
print(max(a,b,c))

>>
>>55359026
I believe it does take time to change between a primitive type and a wrapper class. Doesn't really matter here, though.
>>
>>55358931
Unfortunately, no.
>>
>>55358303
>>55357912
these two won't work because of what >>55358482 said

>>55359049
this one doesn't look as pretty but works
>>
>>55359061
The change is made at compile time.
>>
>>55359110
I believe java does not do compile time optimizations.
>>
>>55357763
it was fun, could a cutthroat bird give us more excersises?
>>
if __name__ == '__main__':
inserted = 1
nums = []
raw_input('Insert 3 numbers, I\'ll print out the highest.\n')

while inserted < 3:
nums.append(raw_input('Insert %s more\n' % (3 - inserted)))
inserted = inserted + 1
print 'Max number is : ', max(nums)
>>
>>55357763
x = input();
y = input();
z = input();
print(max(x,y,z));
>>
File: 003-super-angry-richardstep-1a.jpg (32 KB, 305x227) Image search: [Google]
003-super-angry-richardstep-1a.jpg
32 KB, 305x227
>>55359205
>using max() on strings
>>
>>55359228
>entering strings when asked for numbers
>>
>>55359228
If it's python2 then input() evaluates the input, so you would actually get an int if someone inputs an integer.

Still retarded tho
>>
>>55359049
wow, half of /g/ claims to love Python but I was the only one who could actually write something that works despite taking one semester of Python at the beginning of uni and haven't used it ever since

so the "/g/ can't code" meme is true
>>
>>55357763
>quick, make my homework
>>
>>55359276
What are you talking about?
My code works fine.
>>
>>55359270
oh, I didn't know that

it wouldn't work in python3 though
>>
>>55359260
You should assume that everybody who uses your program is dumb.
>>
>>55359293
yeah, sorry, I assumed you're using python3
>>
>>55359313
then they should prepared for the software crashing and learn from their mistakes.
>>
>not writing it in MATLAB
>>
print(max([int(input('Enter a number> ')) for x in range(0, 3)]))


python3
>>
That's a shitty challenge but I'll take the bait. I haven't written any meaningful code in a couple of weeks anyway. I'll finish my torrent parsing library soon™.

use strict;
use warnings;
use feature "say";
use Scalar::Util qw/looks_like_number/;

# I don't know how to call perl's max function (if there is one) and OP doesn't say whether I can reference online material, so I'll assume no.
# here's my shitty implementation
sub maxNum($) {
my @nums = @{shift};
my $num

for (@nums) {
die unless looks_like_number $_;
$num = $_ if $_ > $num
}

return $num;
}

print "Enter three numbers, separated by commas: ";
my $in = <>;
chomp $in;

my @nums = split(",", $in);
say maxNum \@nums;


I'm new to programming and I haven't tested this. Please be gentle.
>>
>>55359331
Why? It uses print as a statement and raw_input,
why would it be python3?
>>
>>55359307
did that in py3 and it worked, what are you on about?
>>
List.([read_int (); read_int (); read_int ()]
|> sort_uniq compare
|> rev
|> hd)
>>
>>55357763
<code>println(sort({faggot(),faggot(),faggot()},OP))</code>
>>
>>55359049
>for i in range (len(L)): L[i] = eval(L[i])
if the bird doesn't stab you I will
>>
>>55359448
checked it on https://repl.it/languages/python3 and it doesn't work correctly
the fact it does SOMETHING doesn't mean it works


>>55359431
idk m8, I just automatically assume people use python3 because why would anyone want to use python2? But yeah, I forgot there's not raw_input() anymore. As I said, I hasn't used python for some time.
>>
#include <iostream>


int main()
{
using namespace std;
int num1, num2, num3;

cin >> num1 >> num2 >> num3;
if (num1 > num2 && num1 > num3)
cout << num1 << endl;
if (num2 > num1 && num2 > num3)
cout << num2 << endl;
if (num3 > num1 && num3 > num2)
cout << num3 << endl;
return 0;
}


#rekt
>>
>>55357763
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int[] intArray = new int[3];
int i = 0;
while(int i < 3){
intArray[i] = s.nextInt();
i++;
}
s.close();
Arrays.sort(intArray, Collections.reverseOrder());
System.out.println(myIntArray[0]);
}
}
>>
1..3
|> Stream.map(fn(_) ->
{x, _} = Integer.parse(IO.gets("Enter number: "))
x
end)
|> Enum.max()
|> IO.puts()
>>
>>55358176
if ($a == 0){
echo "zero is not a number";
die();
}
if ($b == 0){
echo "zero is not a number";
die();
}
if ($c == 0){
echo "zero is not a number";
die();
}
>>
>all these if else loops
>not a single use of ternary

Panjeets out
>>
>>55359703
>Using map for side effects
>>
>>55357763
Why do other languages overcomplicate things?

(print (max (read) (read) (read)))
>>
>>55359260
Input() always returns strings, retard
>>
>>55359837
Yep. Map is useful for loads of things.
>>
I did it, /g/!

import tensorflow as tf
import numpy as np
import random

x = tf.placeholder(tf.float32, [None, 3])
y = tf.placeholder(tf.float32, [None, 3])

def weight_variable(shape):
return tf.Variable(tf.truncated_normal(shape, stddev=0.1))

def bias_variable(shape):
return tf.Variable(tf.constant(0.1, shape=shape))

W = weight_variable([3, 100])
b = bias_variable([100])

W2 = weight_variable([100, 200])
b2 = bias_variable([200])

W3 = weight_variable([200, 400])
b3 = bias_variable([400])

W4 = weight_variable([400, 3])
b4 = bias_variable([3])

L = tf.nn.relu(tf.matmul(x, W) + b)
L2 = tf.nn.relu(tf.matmul(L, W2) + b2)
L3 = tf.nn.relu(tf.matmul(L2, W3) + b3)
L4 = tf.nn.relu(tf.matmul(L3, W4) + b4)

res = tf.nn.softmax(L4)

cross_entropy = tf.reduce_mean(-tf.reduce_sum(y * tf.log(res), reduction_indices=[1]))
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)

prediction = tf.argmax(res,1)
correct_prediction = tf.equal(prediction, tf.argmax(y,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

sess = tf.Session()
with sess.as_default():
sess.run(tf.initialize_all_variables())

for step in range(300):
batch_x=[[random.randint(0, 100) for j in range(3)] for i in range(100)]
batch_y=[[int(j==np.argmax(batch_x[i])) for j in range(3)] for i in range(100)]

sess.run(train_step, feed_dict={x: batch_x, y: batch_y})

if step%25==0:
acc=sess.run(accuracy, feed_dict={x: batch_x, y: batch_y})
print "step "+str(step)+" acc "+str(acc)

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))

p=prediction.eval(feed_dict={x: [[num1,num2,num3]]})

print("The largest number is",[num1,num2,num3][p[0]],"(at position",p[0],")")
>>
>>55359958
I keked
>>
>>55359958
And it works! It works!

andrey@Shanghai:~/nn3max$ python nn3max.py
step 0 acc 0.3
step 25 acc 0.91
step 50 acc 0.99
step 75 acc 0.99
step 100 acc 0.99
step 125 acc 0.99
step 150 acc 0.99
step 175 acc 1.0
step 200 acc 1.0
step 225 acc 1.0
step 250 acc 1.0
step 275 acc 1.0
Enter first number: 45
Enter second number: 99
Enter third number: 81
The largest number is 99 (at position 1)
andrey@Shanghai:~/nn3max$
>>
>>55358482
print(max([int(input()),int(input()),int(input())])
>>
File: 1465223028235.png (345 KB, 718x620) Image search: [Google]
1465223028235.png
345 KB, 718x620
>>55359958
I don't know if lazy or genius.

Hey Neural Network figure this out for me... I'm too lazy.
>>
>>55359139

really faggot?
>>
>>55359958
nice one dude i saw that tensorflow fizzbuzz on reddit too
>>
File: 1457084167495.jpg (16 KB, 154x199) Image search: [Google]
1457084167495.jpg
16 KB, 154x199
>>55359008

> head -n 3 | sort -nr | head -n 1
>>
>>55360083
Well, I haven't. I write it from scratch just now.
>>
female here, i'll do it in C

#include<stdio.h>

int main() ...

shit, I forggot females doesn't know how to code, sorry guys.
>>
>>55359008
don't do this it creates mustard gas
>>
>>55358482
I can't test at the moment but I think it works in python 2.
Even though python 2 is retarded and you should still use int(raw_input()) if that's your target language
>>
>>55359944
Using map for side effects considered harmful
>>
>>55360095
whatever you say :^)
>>
num = {}

for i = 1,3 do
num[i] = tonumber(io.read())

end


table.sort(num)

for i, v in ipairs(num) do
print(v)
end


like i fucking know
>>
>>55359421
It's a shame for Perl code, see >>55358414 for a correct one.
>>
>>55359979
>>55359958
I train the model on numbers ranging from 0 to 100.
When I train it on numbers in range 0-1000, it does not learn anything. Sits as 33% accuracy.
But!
But it works on arbitrarily large numbers!
I'm not sure how to explain this.

Enter first number: 44444
Enter second number: 55555555
Enter third number: 777
The largest number is 55555555 (at position 2)
[[ 0. 1. 0.]]
Enter first number: 333333
Enter second number: 567
Enter third number: 8955
The largest number is 333333 (at position 1)
[[ 1. 0. 0.]]
>>
>>55360198
No it's not. What I've written is perfectly clean and proper. Map works well with nondeterministic functions. It's no more or less harmful than reading user input in any context.
>>
 double maxInRange(double first, double second, double three)
{
if (first > second)
if (first > three)
return first;
else
return three;
else if (second > three)
return second;
else
return three;
}

OR
 std::max(one, two, three); 
>>
    .file    "big.c"
.section .rodata
.LC0:
.string "%d"
.LC1:
.string "x is the largest"
.LC2:
.string "y is the largest"
.LC3:
.string "z is the largest"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %rdi, -40(%rbp)
movq %rsi, -48(%rbp)
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
leaq -20(%rbp), %rax
movq %rax, %rsi
movl $.LC0, %edi
movl $0, %eax
call __isoc99_scanf
leaq -16(%rbp), %rax
movq %rax, %rsi
movl $.LC0, %edi
movl $0, %eax
call __isoc99_scanf
leaq -12(%rbp), %rax
movq %rax, %rsi
movl $.LC0, %edi
movl $0, %eax
call __isoc99_scanf
movl -20(%rbp), %edx
movl -16(%rbp), %eax
cmpl %eax, %edx
jle .L2
movl -20(%rbp), %edx
movl -12(%rbp), %eax
cmpl %eax, %edx
jle .L2
movl $.LC1, %edi
movl $0, %eax
call printf
jmp .L3
.L2:
movl -16(%rbp), %edx
movl -20(%rbp), %eax
cmpl %eax, %edx
jle .L4
movl -16(%rbp), %edx
movl -12(%rbp), %eax
cmpl %eax, %edx
jle .L4
movl $.LC2, %edi
movl $0, %eax
call printf
jmp .L3
.L4:
movl -12(%rbp), %edx
movl -16(%rbp), %eax
cmpl %eax, %edx
jle .L3
movl -12(%rbp), %edx
movl -20(%rbp), %eax
cmpl %eax, %edx
jle .L3
movl $.LC3, %edi
movl $0, %eax
call printf
.L3:
movl $0, %eax
movq -8(%rbp), %rcx
xorq %fs:40, %rcx
je .L6
call __stack_chk_fail
.L6:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
>>
File: 0036 - Gy5UAxw.jpg (947 KB, 2000x2000) Image search: [Google]
0036 - Gy5UAxw.jpg
947 KB, 2000x2000
>>55360316
>this guy
>>
>>55360313
I was more or less joking, maybe it's idiomatic in C#, but I have never worked in a place where that would be considered a good practice.
>>
>>55360364
nevermind, that's Elixir, but my point still stands
>>
File: 1466895168959.jpg (16 KB, 500x308) Image search: [Google]
1466895168959.jpg
16 KB, 500x308
>>55360316
>>
>>55357763
WOW!
>>
My god, Java is PIG DISGUSTING
>>
>>55360316
I can do that too

    .data
.globl _camlFoo__data_begin
_camlFoo__data_begin:
.text
.globl _camlFoo__code_begin
_camlFoo__code_begin:
nop
.data
.quad 768
.globl _camlFoo
_camlFoo:
.data
.quad 4087
_camlFoo__1:
.quad _caml_curry2
.quad 5
.quad _camlFoo__fun_1010
.text
.align 4
.globl _camlFoo__fun_1010
_camlFoo__fun_1010:
.cfi_startproc
subq $8, %rsp
.cfi_adjust_cfa_offset 8
.L100:
movq %rax, %rdi
movq %rbx, %rsi
leaq _caml_compare(%rip), %rax
call _caml_c_call
.L101:
leaq _caml_young_ptr(%rip), %r11
movq (%r11), %r15
addq $8, %rsp
.cfi_adjust_cfa_offset -8
ret
.cfi_adjust_cfa_offset 8
.cfi_endproc
.text
.align 4
.globl _camlFoo__entry
_camlFoo__entry:
.cfi_startproc
subq $24, %rsp
.cfi_adjust_cfa_offset 24
.L103:
movq $1, %rax
call _camlPervasives__read_int_1309
.L104:
movq %rax, %rbx
call _caml_alloc2
.L105:
leaq 8(%r15), %rax
movq %rax, 0(%rsp)
movq $2048, -8(%rax)
movq %rbx, (%rax)
movq $1, 8(%rax)
movq $1, %rax
call _camlPervasives__read_int_1309
.L106:
movq %rax, %rbx
call _caml_alloc2
.L107:
leaq 8(%r15), %rax
movq %rax, 8(%rsp)
movq $2048, -8(%rax)
movq %rbx, (%rax)
movq 0(%rsp), %rbx
movq %rbx, 8(%rax)
movq $1, %rax
call _camlPervasives__read_int_1309
.L108:
movq %rax, %rdi
call _caml_alloc2
.L109:
leaq 8(%r15), %rbx
movq $2048, -8(%rbx)
movq %rdi, (%rbx)
movq 8(%rsp), %rax
movq %rax, 8(%rbx)
leaq _camlFoo__1(%rip), %rax
call _camlList__sort_uniq_1299
.L110:
movq $1, %rbx
call _camlList__rev_append_1029
.L111:
cmpq $1, %rax
jne .L102
leaq _camlList__1(%rip), %rax
call _camlPervasives__failwith_1005

...
>>
int a;
std::cout << "for exit print \"\\n\"" << std::endl;
std::cin >> a;
int result = 0;
while (std::cin >> a)
{
if (result < a)
result = a;
}
std::cout << "Your number is " << result;
>>
function getBig(one, two, three) {
return Math.max.apply( Math, [one, two, three] )
}

ez
>>
>>55360564

doesn't work for negatives. faggot.
>>
>>55360619
no problem for me
    int a;
std::cout << "for exit print \"\\n\"" << std::endl;
std::cin >> a;
int b = a;
int result = b;
while (std::cin >> a)
{
if (result < a)
result = a;
}
std::cout << "Your number is " << result;
return 0;
>>
>>55360619
that's what you get for not precisely defining the input set, fuccboi
>>
C:
#include <stdio.h>

int main (int argc, char* argv[]) {
int temp, max;

printf("Enter number 1: ");
scanf("%d", &max);

printf("Enter number 2: ");
scanf("%d", &temp);
if (temp > max)
max = temp;

printf("Enter number 3: ");
scanf("%d", &temp);
if (temp > max)
max = temp;

printf("The largest number is %d.\n", max);
return 0;
}


Python
print("The largest number is "  + str(max([int(input("Enter number " + str(num) + ": ")) for num in range(1,4)])) + ".")
>>
>>55358533
>user enters number less than previous two anyway
>>
>>55360364
>>55360396
It's almost always cleaner and more declarative to map things rather than manually loop through and mutate lists. And manually looping through and mutating things isn't exactly something you can do in Elixir. The only other way to do this in Elixir would be to manually use recursion, but why do that when that's just a more awkward and manual way of doing what you can do by mapping streams / lists?

Here's another way which maps stdin directly rather than using IO.gets
IO.stream(:stdio, :line)
|> Stream.take(3)
|> Stream.map(&(elem(Integer.parse(&1), 0)))
|> Enum.max()
|> IO.puts()
>>
File: js.png (10 KB, 1052x1052) Image search: [Google]
js.png
10 KB, 1052x1052
>>55357763
const Reader = require('readline-sync')
const numbers = new Array()
for (let i = 0; i < 3; i++) numbers.push(parseInt(Reader.question('Please enter a number')))
numbers.sort()
console.log('Javascript's expressiveness wins again. The number is ' + numbers[2] + '.')
>>
>>55360803
const Reader = require('readline-sync')
const numbers = new Array()
for (let i = 0; i < 3; i++) numbers.push(parseInt(Reader.question('Please enter a number')))
numbers.sort()
console.log('Javascript\'s expressiveness wins again. The number is ' + numbers[2] + '.')


Forgot to escape the quote
>>
#!/usr/bin/env ruby
input = []
3.times
input << STDIN.gets.to_i
end

puts a.max
>>
>>55360699
oh, I absolutely agree, I'm actually sad that Erlang doesn't offer this kind of flexibility.

I like that example better that your previous once
>>
>>55357763
using System;
using System.Linq;
public class Test
{
public static void Main()
{
Console.WriteLine(Console.ReadLine().Split().Select(Double.Parse).OrderBy(i=>i).Last());
}
}
>>
>>55357763
scala most concise:
List(readLine(),readLine(),readLine()).sorted.last
>>
#include <iostream>
#include <limits>

int main(){
int faggot = std::numeric_limits<int>::min();

for (int fuckyou = 0; fuckyou < 3; ++fuckyou){
int nigger = 0;
std::cin >> nigger;

if(nigger > faggot){
faggot = nigger;
}

}

std::cout << faggot;

return 0;
}
>>
>>55357763
Console.WriteLine("Enter numbers separated by a comma.");
Console.WriteLine(Math.Max(Console.ReadLine().Split(',').Distinct()));
>>
>>55361017
>>55360996
>max of strings
>>
>>55360803
>>55360867
or using Math.max()
const question = require('readline-sync').question
console.log(Math.max(question('First number?'), question('Second number?'), question('Third number?')))

Thank god for type coercion.
>>
>>55361030
derp
Console.WriteLine(Math.Max(Console.ReadLine().Split(',').Select(int.Parse).Distinct()));
>>
>>55361030
It orders correctly even with string data. Try it.
>>
>>55361055
http://ideone.com/TdAFXf
>>
>>55361051
I don't see any Math.Max overload that accepts IEnumerable.
>>
>>55361166

Fair point. though anyone who isn't using a bigInt or the equivalent is also failing on that measure.
>>
something like this is probably best

#include <iostream>
#include <string>

int main()
{
std::string c;
std::cin >> c;
int max_num = stoi(c);
for (int i = 0; i < 2; ++i) {
std::cin >> c;
int n = stoi(c);
max_num = std::max(n, max_num);
}
std::cout << max_num << std::endl;
}



it can handle negative numbers, but it still doesn't handle words


pls no stab
>>
>>55361199
>though anyone who isn't using a bigInt or the equivalent is also failing on that measure.
Wrong. Just parse your strings to any number type and it will work. Lexicographic order differs from natural number order.
>>
>>55361188
Ah yes

Console.WriteLine(Console.ReadLine().Split(',').Select(int.Parse).Distinct().Max());
>>
3.times.map{ readline.to_i }.max

meh k
>>
>>55361206
>11 SLOC
>not even prompting the user
Get on my level biatch >>55361038
>>
>>55361417
Is this scala?
>>
>>55361443
>3.times
Ruby
>>
>>55361428
yes, but can you enter the three numbers on one line?
>>
>>55361501
The first line is just an import statement, so yes :^)
>>
max(int(input()) for i in range(0, 3))
>>
fn = require('ask-first-number');
sn = require('ask-second-number');
tn = require('ask-third-number');
m = require('maximum-of-two-numbers');
console.log(m(m(fn.ask(), sn.ask()), tn.ask()));
[/console]
>>
>>55358533
>user enters 600, 700, and then 420
you fail.
>>
File: sussman shig.jpg (71 KB, 500x375) Image search: [Google]
sussman shig.jpg
71 KB, 500x375
(max (read) (read) (read))
>>
File: 1466725042127.jpg (32 KB, 557x612) Image search: [Google]
1466725042127.jpg
32 KB, 557x612
>>55361617
>>
>>55361624
or
(reduce #'max (loop for i from 1 to 3 collect (read)))
>>
>>55361611
Except those aren't real packages like in mine.
>>
>>55361624
what is sussman doing these days?
>>
File: 1467401502762.gif (4 MB, 400x376) Image search: [Google]
1467401502762.gif
4 MB, 400x376
>>55359814
Lol holy fuck
>>
>>55361652
(defmacro cancer (n)
(cons 'max (make-list n :initial-element '(read))))
(cancer 3)
>>
>>55358974
>Integer
>nextInt
>Int
Because fuck consistency
>>
>>55358482
Dont know shit in python 2.x input() yields an integer dumass
>>
File: tmp_26454-INBvStO1081516644.png (312 KB, 506x662) Image search: [Google]
tmp_26454-INBvStO1081516644.png
312 KB, 506x662
Someone needs to do asm asaptbhfam
>>
>>55362037
see >>55360561
>>55360316
>>
also who's dick do I have to suck to find an invite to blackcats ?
>>
>>55362004
Go ahead and see what input() returns when I type in "[x for x in iter(lambda: 1,2)]"
>>
>>55362063
Both of those weren't written by humans.

>>55360316 is the output of `gcc -S` for a C program, and >>55360561 is the equivalent for OCaml or something like that.
>>
I need to ensure that multiple machines hold identical linked list.
Should I just hash the list contents and compare them?
>>
>>55357763
Here you go.
print("Give me 3 numbers.")
input()
input()
input()
print("Which of them is THE HIGHEST?")
print(input())
>>
>>55357763
max(int(raw_input("enter a number ")), max(int(raw_input("enter a number ")), int(raw_input("enter a number ")))
>>
>>55357763
#/bin/bash
declare -a NUM

NUMAMOUNT=3

for ((i=1;i <= $NUMAMOUNT; i++))
do
read -p "Enter number $i: " NUM[$i]
done

HIGHESTNUMBER=${NUM[1]}
for ((i=2;i <= $NUMAMOUNT; i++))
do
if [[ ${NUM[$i]} -gt HIGHESTNUMBER ]]
then
HIGHESTNUMBER=${NUM[$i]}
fi
done

echo $HIGHESTNUMBER
>>
>>55362222

bretty gud
>>
>>55362177
Mkay, I improved it a little.
print("Give me 3 numbers")
try:
print("the answer is:")
print(max([int(input()),int(input()),int(input())]))
except ValueError as e:
print("you are a moron and don't know what number is.")
>>
>>55357763
babys first program.
>.< soooo embarrassing!!
>>
>>55362249
You can't just use a library function that fucking returns the highest number for you. That's the whole assignment.
>>
>>55362249
Actually, also shit.
print("Give me 3 numbers")
try:
print("the answer is:")
print(max([int(input()) for i in range(3)]))
except ValueError as e:
print("you are a moron and don't know what number is.")
>>
>>55362277
It's a builtin in Python.
>>
File: frogtor.png (11 KB, 369x243) Image search: [Google]
frogtor.png
11 KB, 369x243
main :: IO ()
main = print =<< maximum <$> ((\x y z -> x++y++z) <$> getD <*> getD <*> getD)
where
getD = pure . read <$> getLine :: IO [Double]
>>
>>55362241
Is it though? I'm a beginner who's very slowly moving from shell scripting to C. Other than the fact that you can change the amount of numbers to compare, I don't really know if my attempt has any quality to it.
>>
>>55357763
        static void Main(string[] args)
{
var inputs = new List<int>();
var numEntries = 3;

while(numEntries-- > 0)
{
Console.Write($"Enter a number: ");
var input = Console.ReadLine();
var inputToNum = 0;
if (int.TryParse(input, out inputToNum))
inputs.Add(inputToNum);
else
{
Console.WriteLine($"The value '{input}' is not a valid number.");
numEntries++;
}
}
Console.WriteLine($"The biggest number you entered was {inputs.Max()}");
Console.ReadLine();
}
>>
>>55362298
damn c++ is so ugly.
>>
>>55362309
nigga I hope u trollin
>>
>>55362309
It is C#
>>
>>55362287
I wouldn't care to answer *that*, really...
>>
#include <iostream>

int main() {

std::cout << "enter 3 numbers, faggot" << std::endl;
int a, b, c, d;
std::cin >> a >> b >> c;
if (a > b) {
if (a > c)
d = a;
else
d = c;
}
else if (b > c)
d = b;
else
d = c;
std::cout << d << " is the highest, bitch" << std::endl;
}
>>
>>55362332
>>55360315
>>
Thank you oh Universe for being benevolent to me and not making me to write c/cpp/c#/java and especially basic.
>>
File: 1323635452001.png (6 KB, 344x326) Image search: [Google]
1323635452001.png
6 KB, 344x326
>Using built-in constructs/library functions to get a highest number
>Using a "list sorter" for other purposes than moving the elements in an array around
>Putting more than one of the logical steps to determine the highest number in the same line
>Putting the input prompt and the calculations in the same line
>Putting the output and the input prompt in the same line

I feel sick.
>>
>>55362332
>>55362358
improved version for robot-testing
#include <iostream>
#include <algorithm>

int main() {
int a, b, c;
std::cin >> a >> b >> c;
std::cout << max(a, b, c) << std::endl;
}
>>
>>55357763
was thinking of doing it with logic gates but I'm too lazy
>>
>>55362416
sorry, its
std::max();
>>
>>55362390
A fucking armed bird is threatening to kill me if I don't this!
Of course, I'm using any shortcut available.
>>
#include <iostream>

int main()
{
int n[3];
std::cout << "Numbers: ";
std::cin >> n[0] >> n[1] >> n[2];

if(n[0]>n[1] && n[0]>n[2]) std::cout << n[0];
else if(n[1]>n[0] && n[1]>n[2]) std::cout << n[1];
else std::cout << n[2];
}



▲ ▲
>>
>>55362448
Yeah but I think the bird wants to test that you're able to do it on your own. What people are doing here is pretty much just proving that they can ask for user input 3 times in a row.
>>
>>55362467
It appears to me that only speed is of the essence here.
>>
>>55362467
I wouldn't be so pessimistic. It rather proves that people are just not dumb enough to invent another bicycle instead of using max()
>>
>>55358614
Neato
>>
File: max.png (2 MB, 842x644) Image search: [Google]
max.png
2 MB, 842x644
PLC version
>>
>>55362390
You can't expect the right answer to the wrong question.
>>
>>55359530
>why would anyone want to use python2?

are you new to python?
>>
>>55362543
It's not about whether the answer is right, it's about whether your code is legible and you're able to pull off a very simple algorithm without having your hand held by momma library.
>>
>>55362607
Point me to where OP said that.
I'll wait.
>>
File: vb.png (42 KB, 1010x758) Image search: [Google]
vb.png
42 KB, 1010x758
>>
>>55362618
OP didn't. I commented on people's shit code on my own initiative. It's shit.
>>
>>55362693
It's shit because it doesn't reinvent the wheel for absolutely no reason?
>>
>>55362607
Okay, specially for those who hate using built-in features more complex than a loop.
max = None
for i in range(3):
val = input()
max = (not max or max < val) and val or max
But it's just unreadable, sick, slow and retarded in every way.
>>
File: a.png (760 B, 24x78) Image search: [Google]
a.png
760 B, 24x78
>>55362669
you better not be hacking my IP with your visual basic gooey to get access to my command prompt through my telephone
>>
>>55362746
>(not max or max < val)
You should assign the first value to max and then compare it to the remainder of the values. That "not max or" adds extra cpu cycles to every iteration.
>>
print(max(input(), input(), input()))


Python master-race.
>>
>>55362795
>implying amimanus ever forgives and/or forget
WAIT FOR OUR HAPPENING
>>
>>55362884
Compilers should punish anyone trying to get user input and output it to stdout in the same line of code by deleting their home folder
>>
>>55357763
I'm not a programmer but here's my algorithm:

public autistic void main (memespeak[], java_is_garbage_but_faster_than_python){

//Obtain inputs
int number_of_inputs = 3;
float[] inputs = new float[number_of_inputs];

for (int i = 0, i<=number_of_inputs, i++){
input.add(float(??("Enter your number: "+i+"/"+number_of_inputs))); //whatever the fuck they use for user prompt and adding floats to an array
}

//Post result
system.out.println("Thanks, your maximum input was: "+max(inputs)); //or whatever the fuck they use for getting the max value in an array
}


lel I forgot everything.
>>
>>55358303
acknowledged
>>
one = int(input("enter the first number")
two = int(input("enter the second number")
three = int(input("enter the third number")
if one > two and one > three:
print(one)
if two > one and two > three:
print(two)
if three > two and three > one:
print(three)

maybe no my favorite but the easiest
>>
>>55361772
nextInt returns an int, not an Integer.
>>
>>55363070
lol
CSgraduate.png
>>
>>55358614
Is this an actual language?
>>
File: the coolest.png (760 KB, 1920x1080) Image search: [Google]
the coolest.png
760 KB, 1920x1080
>>55357763
>>
>>55363111
of course
>>
>>55358042
>>55357763

u wot

import java.util.Scanner;

public class oopIsAFaggot {
public static void main(String[] args) {
System.out.println("Enter 3 numbaz for I cap yo ass cuzz");
Scanner s = new Scanner(System.in);
Integer one = s.nextInt(), two = s.nextInt(), three = s.nextInt();
s.close();
System.out.println(one >= two && one >= three ? one : two >= one && two >= three ? two : three);
>>
var x = prompt("Input 1st value");
var y = prompt("Input 2nd value");
var z = prompt("Input 3rd value");

Math.max(x, y, z);
>>
>>55357912
>>55358482
Fixed
print(max([int(input('number: ')) for n in range(3)]))
>>
>>55358614
Brainfuck? Amazing.
Would you mind add some comments to it?
>>
>>55357763
puts "Print highest number homework\n   Type numbers (space separated):"
a = gets.split.map(&:to_i)
print "Highest is: #{a.max}\n"
>>
var x1 = prompt(), x2 = prompt(), x3 = prompt();
alert(Math.max(x1,x2,x3));
>>
Kisamaa
>>
def number_input():
try:
return int(input("Enter a number: "))
except ValueError:
print("Try again fucking retard.")
return number_input()

print(max(number_input() for _ in range(3)))
>>
>>55364079
it has comments already!! now that's brainfuck !!
>>
>>55362467
>Yeah but I think the bird wants to test that you're able to do it on your own.

Projecting, much? Since when have you become an expert on killer birds?
>>
>>55359958
This is quite short considering everything it does under the hood. These new machine learning libraries are neat.
>>
# Call with Rscript file.R n1 n2 n3
options(stringsAsFactors=FALSE)
args <- commandArgs(trailingOnly = TRUE)
args <- suppressWarnings(as.numeric(args,na.rm=TRUE))is.na

if (! length(args) == 3) {
stop("You did not provide exactly three arguments.")
} else if (any(is.na(args))) {
stop("You provided a non-numeric argument.")
}

print("The maximum value is ",max(args),".",sep="")
>>
>>55358042
>It's not homework you idiot.
just keep saying that, people here will do your homework for you.

i passed a whole class by just getting /g/ to do my homework for me, nerds lol
>>
I'd solve it in TIS-100, but I'm camping and I don't have it on here.
>>
>>55364801
woop, that extra is.na on line four shouldn't be there
>>
>>55364890
>camping
>on 4chan
I'd beat you if I was your dad
>>
>>55360658
These are the only languages you need. Maybe throw in some LISP too.
>>
>>55363165

>programming monster

Top kek
>>
kek I believe this was one of the exercises in one of my Assembly exams
>>
>>55357763
#include <iostream>

int main() {
int numbers[3];
int max = 0;

for (int i = 0; i < 3; i++) {
std::cout << "Enter a number: ";
std::cin >> numbers[i];
}

for (int i = 0; i < 3; i++) {
if (numbers[i] > max) {
max = numbers[i];
}
}

std::cout << std::endl << "The max number is " << max << std::endl;

return 0;
}
>>
>>55365208
-3 -6 -2

ans: 0

HMMMM IT REALLY MAKES YOU THINK
>>
>>55365208
>>55365245
The skills of this generation of programmers are cancer
>>
>>55365245
Ok, is this better?

#include <iostream>

int main() {
int numbers[3];
int max;

for (int i = 0; i < 3; i++) {
std::cout << "Enter a number: ";
std::cin >> numbers[i];
}

max = numbers[0];

for (int i = 0; i < 3; i++) {
if (numbers[i] > max) {
max = numbers[i];
}
}

std::cout << std::endl << "The max number is " << max;

return 0;
}
>>
>>55365407
>>
>>
>>55360228
>>55361541
>using the smiley with a carat nose
>>
>>55357763
replicateM 3 readLine >>= print . maximum


took me about 3 seconds. untested
>>
>>55365621
is Hasklel worth learning for some audio programming and DSP??
>>
>>55365621
damn, I knew I was missing something.

replicateM 3 (readLn :: IO Integer) >>= print . maximum


actually tested this time
>>
>>55365640
netwire is pretty fun for DSP

https://github.com/ocharles/netwire-classics/blob/master/asteroids/Sounds.hs
>>
>>55365679
but I mean like, can Haskell do some low level stuff like messing with ALSA, calling C functions and system calls?
>>
>>55365716
Haskell has a pretty strong C FFI, one of the best out there for being such a high level language
>>
>>55365716
>>55365729
https://hackage.haskell.org/package/alsa-pcm

you mean like this?
>>
>>55365756
I'm more concerned about how that actually wraps the alsa api
>>
const int main[] = {
-443987883, 440, 113408, -1922629632,
4149, 899584, 84869120, 15544,
266023168, 1818576901, 1461743468, 1684828783,
-1017312735
};

64bit linux
>>
>>55365778
>I'm more concerned about how that actually wraps the alsa api
https://hackage.haskell.org/package/alsa-pcm-0.6.0.4/docs/src/Sound-ALSA-PCM-Core-Handle.html#open

Also check out these for some more high-level DSP/audio stuff
https://hackage.haskell.org/package/synthesizer
https://hackage.haskell.org/package/haskore
>>
File: scratch1.png (28 KB, 305x492) Image search: [Google]
scratch1.png
28 KB, 305x492
ez
>>
File: kqOAoqg.png (615 KB, 665x661) Image search: [Google]
kqOAoqg.png
615 KB, 665x661
>>55357763

I wanted to be obscure so I used qbasic, and it doesn't have a fucking max function. what the hell, bill gates. what were you thinking.

CLS
DIM values(3) as INTEGER
INPUT "Enter 1st integer", values(1)
INPUT "Enter 2nd integer", values(1)
INPUT "Enter 3rd integer", values(1)
max = values(1)
FOR x = 2 TO 3
IF values(x) > max THEN max = values(x)
NEXT x
PRINT "Max value is:"
PRINT max


Jesus it's so much easier in a modern language like R.

values <- rep(0, 3)
n1 <- readline(prompt="Enter 1st integer: ")
n2 <- readline(prompt="Enter 2nd integer: ")
n3 <- readline(prompt="Enter 3rd integer: ")
print(paste("Max value: ", max(values), sep=""))
>>
here's mine
scanf sucks for user input, but oh well

[/code]
#include <stdio.h>
int max(int a, int b) {
if (a > b) return a;
return b;
}
int main() {
int a,b,c;
printf("type three numbers separated by spaces: ");
scanf("%d%d%d",&a,&b,&c);
printf("the biggest is: %d\n",max(a, max(b,c)));
}
[/code]
>>
>>55365988
that image is cancer
>>
File: oops.gif (1023 KB, 366x350) Image search: [Google]
oops.gif
1023 KB, 366x350
>>55366246
whoops
#include <stdio.h>
int max(int a, int b) {
if (a > b) return a;
return b;
}
int main() {
int a,b,c;
printf("type three numbers separated by spaces: ");
scanf("%d%d%d",&a,&b,&c);
printf("the biggest is: %d\n",max(a, max(b,c)));
}


not like it matters that much
>>
>>55357763
AAAA
package main

import (
"fmt"
"math"
)

func main() {
fmt.Println("ENTER THREE NUMBERS:")
nums := []float64{}
for len(nums) != 3 {
var num float64
_, err := fmt.Scanf("%f", &num)
if err != nil {
fmt.Println("ERROR", err)
} else {
nums = append(nums, num)
fmt.Println("OK")
}
}
fmt.Println("HIGHEST:", math.Max(math.Max(nums[0], nums[1]), nums[2]))
}
>>
Hello user, please give me three numbers and I'll give you back the highest number.
>>
>>55365988

im babby at R (not a coder, political "scientist") but check mine

fun1 <- function(x, y, z) {
a <- max(x, y, z)
print(a)
}
>>
>>55357763
Wolfram Language (a shit proprietary language)

CloudDeploy[
FormFunction[{{"num1", "Enter Number 1:"} -> "Number", {"num2", "Enter Number 2"} -> "Number",{"num3", "Enter Number 3"} -> "Number"},
Row[{"Maximum: ",Max[{#num1, #num2,#num3}]}]&,"PNG"]]


Result: https://www.open.wolframcloud.com/objects/b62c464b-be15-434e-aff7-a074e09e94ba
>>
>>55366465
you don't get bonus points for deploying your “maximum app” on the “cloud”. Not even if you make a docker container for it
>>
>>55366465
>>55366648

cant see it anyway, dont have "permission"
>>
>>55366648
That's why it is a shit language. I just did it, because I was already working with it
>>55366748
Didn't notice it:
Go there: https://develop.open.wolframcloud.com/app/
Create a new notebook -> Copy-Paste -> shift enter -> copy link in browser
Should work
>>
File: 1436913873073.png (375 KB, 600x443) Image search: [Google]
1436913873073.png
375 KB, 600x443
>>55366431

> max(x,y,z)

this is REALLY nit-picky, but you're using outdated syntax here. it's still supported, but you should be passing only one argument to max() as a vector, not as 3 separate scalar arguments. so
max(x(1,2,3))

is better practice than
max(1,2,3)
.
same is true with sum(). The ability do do what you did is a leftover from S.

>>55365988
I actually fucked up my code because I decided too late that I was going to pre-allocate my array (always good practice) and forgot to finish doing so.

values <- rep(0, 3)
values [1] <- readline(prompt="Enter 1st integer: ")
values [2] <- readline(prompt="Enter 2nd integer: ")
values [3] <- readline(prompt="Enter 3rd integer: ")
print(paste("Max value: ", max(values), sep=""))


A more user-friendly way to do this is to ask the user for a string of 3 integers, separated by spaces.

val_str <- readline(prompt="Enter numbers, separated by commas (,) : ")
vals <- as.numeric(strsplit(val, split=','))
print(paste("max value: ", max(vals), sep=""))
>>
>>55360899
puts 3.times.collect { gets }.max
>>
>>55366977
>x(1,2,3)

that x should be a c. fucking qwerty.
>>
>>55367015
yea just noticed that playing with it myself, thanks!
>>
pro supgents
read, "enter 3 comma-separated numbers", niggers
print, max(niggers)
end
>>
>>55357763

if(first())
{
runOnChat(1)

print("Enter 3 numbers separated by spaces into chat")
}

if(chatClk(owner()))
{
Nums = owner():lastSaid():explode(" ")
A = Nums[1, string]:toNumber()
B = Nums[2, string]:toNumber()
C = Nums[3, string]:toNumber()

if(A > B & A > C) { print(A) }
elseif(B > A & B > C) { print(B) }
elseif(C > A & C > B) { print(C) }
}
>>
>>55357763
#include <stdio.h>
int main(){

}


Kill me Mr. bird, plox.
>>
>>55358533
thank you for making me kek really hard
'cause I know there are people out there who would unironically write a program like this one
>>
>>55358774
oh Pascal haven't seen it in years are there people out there who are acctually still using it ?
Thread replies: 255
Thread images: 35

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.