[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

QUICK! APPEND AND PRINT THE ARRAYS {1, 2, 3, 4} AND {5, 6, 7,

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 133
Thread images: 9

File: programming birb.jpg (20KB, 342x360px) Image search: [Google]
programming birb.jpg
20KB, 342x360px
QUICK!

APPEND AND PRINT THE ARRAYS {1, 2, 3, 4} AND {5, 6, 7, 8}

OR THIS BIRD WILL STAB YOU!!!
>>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main() {
const int first[4] = {1,2,3,4};
const int last[4] = {5,6,7,8};
int all[8];
memcpy(all, first, 4 * sizeof(int));
memcpy(all+4, last, 4 * sizeof(int));
printf("[");
for (int i = 0; i < 7; i++) printf("%d, ", all[i]);
printf("%d]\n", all[7]);
}
>>
ar1, ar2 = [1,2,3,4], [5,6,7,8]
print(ar1 + ar2)
>>
File: 1473638962111.jpg (429KB, 1600x1066px) Image search: [Google]
1473638962111.jpg
429KB, 1600x1066px
>>58188444
puts [1, 2, 3, 4] + [5, 6, 7, 8]
>>
>>58188445
>>58188464
C BTFO
>>
System.debug( JSON.serialize( new List<List<Integer>>{ List<Integer>{1,2,3,4}, List<Integer>{5,6,7,8}}));
>>
Console.Log([1,2,3,4].concat([5,6,7,8]));
>>
>>58188444
> perl -E "my @arr = (1, 2, 3, 4); my @arr2 = (5, 6, 7, 8); say @arr, @arr2"
12345678
>>
>>58188444
print $ [1..4] ++ [5..8]
>>
public class OpIsAFaggot {

public static void main(String[] args) {

int[] int1 = new int[]{1,2,3,4};
int[] int2 = new int[]{5,6,7,8};

int[] result = IntStream.concat(Arrays.stream(int1), Arrays.stream(int2)).toArray();

System.out.println(Arrays.toString(result));

}
}
>>
>>58188504
>Console.Log
>>
Precompute and hardcode the result
>>
>>58188444
(displayln (append '(1 2 3 4) '(5 6 7 8)))
>>
x = [1, 2, 3, 4]
y = [5, 6, 7, 8]
x.extend(y)
print(x)
>>
var aOne = [1, 2, 3, 4], aTwo = [5, 6, 7, 8];
var aFinal = aOne.concat(aTwo);
for (var i = 0; i < aFinal.length; i++) {
console.log(aFinal[i]);
}
>>
>ARRAYS
but those are tuples
>>
>>58188444
{1, 2, 3, 4, 5, 6, 7, 8}
>>
>>58188659
you're a tuple
>>
>>58188666
This. Wtf are you fags doing?
>>
>>58188444
int[] a3 = new int[a1.length + a2.length];
System.arraycopy(a1, 0, a3, 0, a1.length);
System.arraycopy(a2, 0, a3, a1.length, a2.length);
System.out.print(a3);
>>
>>58188689
solving the problem, unlike >>58188666
>>
>>58188473
Abstraction is a crutch.
>>
(format t "%s~%" (append '(1 2 3 4) '(5 6 7 8)))
>>
>>58188444
(display (append '(1 2 3 4) '(5 6 7 8)))
>>
File: sweating man.jpg (20KB, 300x300px) Image search: [Google]
sweating man.jpg
20KB, 300x300px
>>58188444
<?php print_r( array_merge( Array(1,2,3,4), Array(5,6,7,8) ) ) ?>
>>
>>58188444
public class Birdo{
public static void main(String[] args){
System.out.print("{");
for(int i = 1; i < 9; i++){
if(i == 8){
System.out.print(i);
break;
}
System.out.print(i+",");
}
System.out.print("}");
}
}
>>
>>58188444
WolframLanguage
Print[Union[List[1, 2, 3, 4], List[5, 6, 7, 8]]];
>>
[|5; 6; 7; 8|] |> Array.append [|1; 2; 3; 4|] |> printfn "%A" 
>>
>>58188534
remains to be beaten
>>
#include <stdio.h>

void main(){


int arr[4] = {1,2,3,4};
int arr2[4] = {5,6,7,8};
int arr3[8];

int i,j;

for(i=0;i<8;i++){

if(i < 4)
{

arr3[i] = arr[i];
}
else
{
arr3[i] = arr2[i%4];
}

}

for(j=0;j<8;j++){

printf("%d",arr3[j]);
}
}
>>
>>58188444
That's plain objects what you've wrote.
Object.assign({1, 2, 3, 4}, {5, 6, 7, 8});
Thanks god for javascript.
>>
Hold on bird, its just compiling
>>
>>58189085
KYS immediately
>>
>>58188464
>>58188472

The point of those threads is to pick a wierd exotic language (which you would like to learn) and try it with that language.
>>
>>58188962

p *(1..4), *(5..8)
>>
>>58188445
> int main
> no return
Cuck
>>
>>58189814
language?
>>
>>58189841

Ruby
>>
>>58190070
That seems incredibly straight forward.
>>
Object.assign([1,2,3,4],[5,6,7,8],{log:function(){console.log(this)}}.log()
>>
a = [1,2,3,4]
b = [5,6,7,8]
c = []
[c.append(i) for i in a], [c.append(j) for j in b]
>>
BIRDMIN NO
>>
>>58189836
>In case a return value is not defined by the programmer, an implicit return 0; at the end of the main() function is inserted by the compiler
>>
(setf x (make-array '(4)
:initial-contents '((1) (2) (3) (4)))
)
(setf y (make-array '(4)
:initial-contents '((5) (6) (7) (8)))
)
(write x)
(write y)

lisp is autism.
>>
File: kermit3.jpg (142KB, 518x501px) Image search: [Google]
kermit3.jpg
142KB, 518x501px
>>58188444
+++[>++++++++++<-]++++++++[>.+<-]
>>
echo "{1, 2, 3, 4, 5, 6, 7, 8}" | lpr
>>
>quick do completely useless task only code monkeys will have to do
How about no?
>>
>>58188444
app([], Rest, Rest).
app([H1|T1], List2, [H1|Rest]) :- app(T1, List2, Rest).

app([1, 2, 3, 4], [5, 6, 7, 8], X).

Without using the builtin append() predicate.
>>
>>58190572
nobody wants you here.
>>58190596
oops forgot to print.
write(X).
>>
>>58190622
>nobody wants you here
Yes. I come here to gloat.
This is all pointless crap. Nobody has to deal with strings in this manner anymore. Really if you're in a language that makes string handling convenient then why aren't you making it so you practically never have to deal with them at all? You clearly didn't care about the cost of running your application.

People being interested in stupid shit like this genuinely bothers me.
>>
File: tfw g is too dumb.png (279KB, 898x790px) Image search: [Google]
tfw g is too dumb.png
279KB, 898x790px
>>58190639
>Yes. I come here to gloat.
That much was obvious dude. Cause you're soooooooooooooo much better than everyone else here.
>>
>>58190666
I'm primarily just suggesting you spend your time more productively.
This is like being amazed that multiplication is just repeated addition when you're 50.
>>
cd array 1-8
ctrl-p
enter


wew that was close
>>
>>58190679
>I'm primarily just suggesting you spend your time more productively.
says the fuckwit shitposting on a /g/ thread.
>>
>>58190690
Posting 'solutions' in this thread suggests a lot about you professionally.
Posting on /g/ says very little.
>>
>>58188534
linked lists are not arrays
>>
>>58190702
>suggests a lot about you professionally.
>professionally.
dude wtf I'm on 4chan this isn't a job interview lmao.
>>
>>58190704
print ([1..4] ++ [5..8] :: Vector Int)


happy now?
>>
>>58190702
You're beyond autistic if you get triggered by people having fun with their profession/hobby.
>>
File: 1482428101697.png (13KB, 588x409px) Image search: [Google]
1482428101697.png
13KB, 588x409px
x=(1 2 3 4)
y=(5 6 7 8)
z=($x $y)


Bonus points to anyone who can identify the language.
>>
fn main() {
let mut x = vec![1, 2, 3, 4];
x.extend_from_slice(&[5, 6, 7, 8]);
println!("{:?}", x);
}
>>
>>58190948
zsh
>>
>>58190343
Fuck off with that shit, that's like saying the compiler will auto assign a variable the value of int if no value is stated.
Yes its valid code, but its terrible practise.
>>
>>58190982
Maybe it's syntactically valid zsh, but not what I had in mind.
>>
>>58190992
I think its fine.
Programs that don't care about the status return don't have to bother writing anything. People were still leaving it out in the implicit int days anyway, and it gives you no reason to use the pointlessly non-portable "void main".
>>
>>58188444
console.log([1,2,3,4].concat([5,6,7,8]));
>>
>>58188444

print (append '(1 2 3 4) '(5 6 7 8))
>>
>>58190992
>but its terrible practise

sounds like you're being autistic. If you're not using return values for anything why bother.
>>
>>58190639
because I spend all day writing C++ and JS mainly using shitty libraries and internal code that other people wrote, and sometimes I just wanna implement some shitty highschool level task.
>>
>>58190343
>>58191110
Not everyone uses C90 anon. in C++ and in C99 and newer, no implicit return statement.
>>
#include <iostream>

template<int...>
struct list
{
};

template<typename, typename>
struct concat;

template<int... X, int... Y>
struct concat<list<X...>, list<Y...>>
{
using result = list<X..., Y...>;
};

template<int... X>
void print(list<X...>)
{
(int[]){ (std::cout << X << std::endl, 0)... };
}

int main(void)
{
print(typename concat<list<1, 2, 3, 4>, list<5, 6, 7, 8>>::result());
}
>>
 Haskell:
[1..4]++[5..8]
>>
>>58188722
abstraction makes it possible for someone to actually accomplish tasks without being a fucking wizard

I mean, manually fucking allocating and deallocating memory? Importing three libraries to add two sets and print the result? Low level is great for understanding and terrible for learning how to actually get shit done.
>>
>>58191703
Finally someone
>>
>>58191792
The struggle makes you stronger, like doing puzzles for your brain or lifting weights for your muscles. High-level languages are training wheels; they keep you weak and soft. The onus is not on the language to be more safe and user-friendly, but on the programmer to git gud.
>>
>>58188445
C99. Works with arrays of arbitrary sizes.
#include <stdio.h>
#define count(x) sizeof(x)/sizeof(int)

int main(void)
{
const int foo[] = {1, 2, 3, 4};
const int bar[] = {5, 6, 7, 8};
int baz[count(foo)+count(bar)];

for(int i = 0; i < count(baz); i++)
{
baz[i] = (i < count(foo))?foo[i]:bar[i-count(foo)];
printf("%d ", baz[i]);
}

return 0;
}
>>
>>58188444
program BirdStab;

var
arr1: array[0..3] of integer = (1, 2, 3, 4);
arr2: array[0..3] of integer = (4, 5, 6, 7);
arr: array of integer;
i: integer;

begin
SetLength(arr, Length(arr1) + Length(arr2));
Move(arr1, arr[0], SizeOf(arr1));
Move(arr2, arr[Length(arr1)], SizeOf(arr2));

for i := 0 to Length(arr1) + Length(arr2) - 1 do
Write(arr[i], ' ');
WriteLn;
end.

>>
>>58192984
Nigga is this a fucking joke you posted it like 3 times you fagget if it's wrong it's wrong you leave it like that you piece of shit
>>
>>58193011
my autism kicked in because SetLength and Move were capitalized but write and writeln were all lowercase
>>
File: Monkey sees, monkey screams.jpg (18KB, 500x371px) Image search: [Google]
Monkey sees, monkey screams.jpg
18KB, 500x371px
>>58188444
#include <stdio.h>

main(){
int arr[4] = {1,2,3,4};
int ays[4] = {5,6,7,8};
int arrays[8];
int i;
for(i=0; i<4; i++) arrays[i] = arr[i];
for( ; i<8; i++) arrays[i] = ays[i-4];
for(i=0; i<8; i++) printf("%d ", arrays[i]);
}
>>
>>58188444
$step = array("Post on /g/", "Kill yourself", "???", "profit!");

$step_num = 0;

foreach ($step as &$step_name) {
$step_num++;
echo 'Step ' . $step_num . ': ', . $step_name;
}
>>
>>58193088

["Post on /g/", "Kill yourself", "???", "profit!"]
.each.with_index { |step,i| puts "Step #{i+1}: #{step}" }
>>
>>58188444
let first = [1, 2, 3, 4];
let last = [5, 6, 7, 8];
[].push.apply(first, last);
console.log(first);
>>
>>58188444
[1,2,3,4] ++ [5,6,7,8]


> Haskell FTW
>>
>>58190449
You confused decimal 30 and hex 0x30, and you needed 31 (49) to start counting at one. And counting from 1 to 8 isn't appending two arrays.
>>
>>58194373

[1,2,3,4] + [5,6,7,8]


>Ruby ftw
>>
{1,2,3,4,5,6,7,8}
>>
>>58188444
print([1,2,3,4]+[5,6,7,8])
>>
horzcat([1 2 3 4],[5 6 7 8])
>>
(print (append (list 1 2 3 4) (list 5 6 7 8)))
>>
>>58188444
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
NSArray *first = @[@1,@2,@3,@4];
NSArray *second = @[@5,@6,@7,@8];

NSArray *all = [first arrayByAddingObjectsFromArray:second];

for(NSNumber *i in all){
NSLog(@"%@",i);
}
}
return 0;
}
>>
>>58194658
puke.jpg
>>
package main

import "fmt"

func main() {
arr1 := []int{1, 2, 3}
arr2 := []int{4, 5, 6}
fmt.Printf("%v\n", append(arr1, arr2...))
}
>>
>>58189781
I think the point was clearly laid out in the OP. If I don't want to get stabbed by a bird, why would I pick a language with which I'm unfamiliar?
>>
>>58188725
Beatiful and totally straight forward. Classy language. Can you name it, lad?
>>
>>58188444
using System;
using System.Collections.Generic;

namespace NoStabPls
{
public static class Program
{
static void Main()
{
int[] array1 = new int[] { 1, 2, 3, 4 };
int[] array2 = new int[] { 5, 6, 7, 8 };
List<int> list = new List<int>(array1);
list.AddRange(array2);
foreach (int n in list) Console.WriteLine(n.ToString());
}
}
}
>>
function NoStab()
local donald = { 1, 2, 3, 4 }
local trump = { 5, 6, 7, 8 }
for i, v in pairs(trump) do
table.insert(donald, v)
end
for i, v in pairs(donald) do
print(v)
end
end
>>
>>58191647
I like your ways.
>>
In ES6

console.log(...[...[1,2,3,4],...[5,6,7,8]])
>>
>programming on my fucking phone
local arr1, arr2 = {1, 2, 3, 4}, {5, 6, 7, 8}

local both = arr1
for _, v in pairs(arr2) do
table.insert(both, v)
end
for _, v in pairs(both) do
io.write(tostring(v) .. "\n")
end

Not gonna bother testing it because I'm on my phone but it should work
>>
>>58197192
o shit a Lua friend
>>
let first = [1,2,3,4]
let second = [5,6,7,8]

for element in first+second {
print(element)
}
>>
>>58188725
>>58196831

samefag
>>
File: Picture3-1-759x500.jpg (42KB, 759x500px) Image search: [Google]
Picture3-1-759x500.jpg
42KB, 759x500px
>>58188444
print([1,2,3,4]+[5,6,7,8])


What do I win
>>
>>58188941
What language is this?
>>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace arrappend
{
class Program
{
static void Main(string[] args)
{
new int[] { 1, 2, 3, 4 }.Concat(new int[] { 5, 6, 7, 8 }).ToList().ForEach(WriteLine);
}
}
}

>>58197806
Looks like F#.
>>
>>58197752
YOUR LYF
>>
>>58188444
CHECKED
Simple Buffer overflow in C:
#include <stdio.h>
int main(){
int first[4] = {5,6,7,8};
int second[4] = {1,2,3,4};
for (int i=0;i<8;i++){
printf("%i",second[i]);
}
first;
return 0;
}
>>
>>58197908
http://ideone.com/yQ18LO
>inb4 works on my machine
>>
>>58197939
I uploaded the binary for you.
Please execute as root, thanks
>>
>>58197939
>>58197986
forgot link
http://www.file-upload.net/download-12200138/a.out.html
>>
>>58198006
This program cannot be run in DOS mode.
>>
>>58188444
puts("1 2 3 4 5 6 7 8");
>>
IO.inspect [1, 2, 3, 4] ++ [5, 6, 7, 8]
>>
QUICK!

APPEND AND PRINT THE ARRAYS {1, 2, 3, 4} AND {5, 6, 7, 8}

OR THIS BIRD WILL STAB YOU!!!{1, 2, 3, 4}{5, 6, 7, 8}
>>
print range(1,5) + range(5,9)
>>
 
#! /usr/bin/python3
arr1 = [1,2,3,4]
for i in (5,6,7,8):
arr1.append(i)

print(arr1)
>>
haskell:

print $ [1..4] ++ [5..8]
>>
#include <iostream>
#include <vector>

using namespace std;

vector<int> concatInts(vector<int> a, vector<int> b) {
vector<int> retVect = a;
for (int x = 0; x < b.size(); x++) {
retVect.push_back(b[x]);
}
return retVect;
}

template <typename T>
void printVect(vector<T> pvect) {
cout << '[';
for (int x = 0; x < pvect.size(); x++) {
cout << pvect[x];
if (x != pvect.size()-1) cout << ',';
}
cout << ']';
}

int main(int argc, char* argv[]) {
vector<int> a = {1,2,3,4};
vector<int> b = {5,6,7,8};
vector<int> c = concatInts(a,b);
printVect<int>(c);
}


Very concise amirite?
>>
>>58200342
#include <iostream>
#include <vector>

int main(int argc, char *argv[])
{
std::vector<int> v1 = { 1, 2, 3, 4 }, v2 = { 5, 6, 7, 8 };
v1.insert(v1.end(), v2.begin(), v2.end());
std::cout << "{ ";
for (auto it = v1.begin(); it != v1.end(); it++) {
std::cout << *it;
if (it != v1.end() - 1) {
std::cout << ", ";
}
}
std::cout << " }\n";
return 0;
}
>>
>>58200342
>>58200873
#include <algorithm>
#include <vector>
#include <iostream>

int main ()
{
std::vector<int> v1{1,2,3,4};
std::vector<int> v2{5,6,7,8};
std::move(std::begin(v2), std::end(v2), std::back_inserter(v1));
for (int i : v1)
std::cout << i << ' ';
std::cout << std::endl;
}
>>
File: 1432660606150.jpg (33KB, 500x375px) Image search: [Google]
1432660606150.jpg
33KB, 500x375px
>>58191647
>(void)
>>
#!/usr/bin/env lc
OHAI
I HAS A RRAY1 ITZ "1,2,3,4,"
I HAS A RRAY2 ITZ "5,6,7,8"
VISIBLE "I HAZ NO RRAYZ :("
VISIBLE "I HAZ A YARN THO"
VISIBLE SMOOSH RRAY1 RRAY2
KTHXBAI
>>
let a = [1,2,3,4],
b = [5,6,7,8],
c = a.concat(b);
console.log(c);
>>
>>58198269
>inspext
>>
>>58188589
(like (i, you))
>>
>>58201958
IO.puts wouldn't print it out properly.
>>
https://hastebin.com/bazomefepo.sm

Too big to post here.
>>
>>58188464
fun fact, this is valid in both ruby and python!
>>
>>58188444
for num in range(1,9)
print num,
>>
>>58202001
>https://hastebin.com/bazomefepo.sm
What language is this? I can't say I've seen formatting like that before
>>
>>58202055
Befunge, autogenerated by BefunGen.

Source here:
program example : display[0, 0]
begin
main_program();
quit;
end

void main_program()
var
int[4] a := {1, 2, 3, 4};
int[4] b := {5, 6, 7, 8};
int[8] c;
begin
c = concat(a, b);
print_list(c);
end

int[8] concat(int[4] a, int[4] b)
var
int[8] temp;
int i;
begin
for (i=0; i < 4; i++) do
temp[i] = a[i];
end
for (i=0; i < 4; i++) do
temp[i+4] = b[i];
end

return temp;
end

void print_list(int[8] a)
var
int i;
begin
for (i=0; i<7; i++) do
outf a[i], ", ";
end
out a[7];
end
end
>>
>>58191703
You didn't print.
Thread posts: 133
Thread images: 9


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.