WRITE A PROGRAM IN YOUR FAVORITE LANGUAGE THAT CONCATENATES TWO INTEGERS OR THIS BIRD IS GONNA STAB YOU

WRITE A PROGRAM IN YOUR FAVORITE LANGUAGE THAT CONCATENATES TWO INTEGERS OR THIS BIRD IS GONNA STAB YOU

FOR EXAMPLE, concat( 12, 5 ) -> 125

NO STRINGS, ARRAYS, OR OTHER BULLSHIT
JUST MATH

def digitcount(number):
d = 0

if number == 0:
return 1

number = abs(number)

while number >= 1:
number /= 10
d += 1

return d

def join(a,b):
return a * pow(10,digitcount(b)) + b

print(join(12,5))

CAW CAW

pls_don't_stab

def concat(a, b):
import math
return a * 10 ** int(math.ceil(math.log(b) / math.log(10))) + b

let concat = (a,b) => '' + a + b

LOL

let rec pow n = function
| 0 -> 1
| p -> n * pow n (p-1) ;;

let concat a b =
let digitcount num =
let count = ref 0 in
let num_ref = ref num in
while !num_ref >= 1 do
count := !count + 1 ;
num_ref := !num_ref / 10
done ;
!count in

let spell num =
for i = digitcount num - 1 downto 0 do
let digit = (num / pow 10 i) mod 10 in
print_int digit
done

in begin
spell a ;
spell b
end ;;

What's this language?

OCaml

Garbage

t. front dev web developper

wtf I wanted to learn ocaml now

const numConcat = (x1,x2) => {
return Math.pow(10, Math.ceil(Math.log10(x2)))*x1+x2
}
console.log(numConcat(12,5))


easy

public String concat(int a, int b){
StringBuilder ab = new StringBuilder();
ab.add(a);
ab.add(b);

return ab;
}


FUCK YOU BIRD

it wont work for b=10^smth

>front dev Web developer

>somebody paid money for these shutterstock images in glorious HD

It has been written by the French researcher Xavier Leroy and is the functional language taught in the majority of universities in France. You will have a lot of doc in French but I'm not sure there are a lot of actually good and complete doc in English. Try with F# (which is another ML dialect written by Microsoft)

front-end, my bad

That poor soul

program test;

uses math;

Function concat (a,b:integer):double;
Var
C:integer;
begin
If a>=10 then C:=a div 10 else c:=1;
concat:=a*power(10,c)+b;
End;

begin

writeln (concat(12,5):2:0);
end.

>le ebin functional programming xD

>front
>dev
>web
>developer
are you even fucking trying anymore?

Use log to find out how many times you have to multiply the first argument by 10, add the second argument.

Here's mine in JavaScript:
"" + a + b

I got stuck because I forgot pow() takes real numbers and not integers.

int concat(int a, int b)
{
a *= pow(10, (int) log10(b) + 1);
return a + b;
}

My university had me learn Haskell. It was an easy switch from Haskell to F#.

Every now and then I'll write a SQL Server CLR in F# to mess with my DBA.

Write your own pow, you litterally have an example here

my $concat = 12 . 5;
print $concat, "\n";

std::cout

Yup Haskell is goat too. There's some program solving tool (or whatever it's called in English) written over it called Isabelle/HOL if you want to try some fun shit (and if you don't mind the ugliest syntax in the world)

Why would I write my own pow?
I'd only end up with trash like
int powi(int a, int b)
{
int base = a;
while (b--)
a *= base;
return a / 10;
}

idk about performance
int_cat = lambda int_1, int_2: int(str(int_1) + str(int_2))

EZ

def concat(a, b):
print(a, b, sep='')

You just ended up with a working function. Now use it instead of bitching.

log and pow functions rely on platform specific calls and are extremely wasteful compared to simple string concatenation.

nobody is this strapped for memory

(define (concat x y)
(define (digits n)
(+ (if (= 0 (remainder y 10)) 1 0) (inexact->exact (ceiling (log10 y)))))
(+ y (* x (expt 10 (digits y)))))

(display (concat 12 5))

function concat(a, b) { return "" + a + b; }

unsigned int concat(unsigned int a, unsigned int b) {
unsigned int s = b;

do {
b /= 10;
a *= 10;
} while (b);

return a + s;
}

wait wait
my $int1 = 12;
my $int2 = 5;
my $mult = 10 ** length($int2);
print $int1*$mult+$int2, "\n";

i failed precalculus so i dont know what logs do

...

The built in function is most likely faster. If it's not you should leave the language for the garbage that it is.

int concat(int a, int b) {
if (b < 0)
b = -b;
int x = 10;
while (b >= x)
x *= 10;
return a>=0 ? a*x + b : a*x - b;
}

> implying you need performance for this shitty exercise
But otherwise I totally agree with (You)

neat

No it's not, it's fucking slow because it works with fucking doubles.
Just use a lookup table.

powi(1,1000000)

what now faggot

thanks. it seems like the least clumsy procedure

love live is a scourge on this board

your posts are a scourge on this board moron

The number of people in this thread who don't know about logarithms is too damn high.

logarithms don't apply to ints.

> Not writing a entire framework each time you need a so-called "standard function"
user please, try at least

nice rebuttal

it's not worth the performance hit to calculate a number that can never go past log10(2^64) digits.

>maki is cute 491.jpg
>maki is cute 714.jpg
>714.jpg
>714
warning: waifufaggotry at unsafe levels

maki is nicos waifu not mine

>while do
>ref
>for
>;
Why even do it in OCaml?

let concat_int a b =
let rec rem n acc =
if n < 10 then acc
else rem (n/10) (10*acc)
in
a * (rem b 10) + b
;;

>1120
Take your fucking reply and go.

>convert int to double
>compute log10
>round down
>compute 10^n
>convert back to int

vs

>multiply int by 10
>compare two ints
>repeat

Now you are retarded

This isn't very impressive when you know that gallery-dl exists.

intConcat PROTO C, intA:DWORD, intB:DWORD, intOut:PTR DWORD

.code
intConcat PROC C uses eax edi, intA:DWORD, intB:DWORD, intOut:PTR DWORD
LOCAL intDigNum:DWORD
mov intDigNum, 1
mov edi, intOut

mov eax,intB
test eax,eax
jz FLOATSKIP

FINIT
FLDLG2
FILD intB
FY12X
FLD1
FADD
FIST intDigNum

FLOATSKIP:

mov eax, intA
mul intDigNum
add eax, intB
mov DWORD PTR [edi], eax
ret
intConcat ENDP


onnaphone so can't check if it compiles or not, should work tho

Guess it should be 1 + math.floor() then instead of math.ceil().
Thanks!

local a,b = 12,5
local c = a..b

function concat($one, $two) {
$concatted = $one.$two;
return $concatted;
}

proc digicat {a b} { return $a$b }
Integers are strings in Tcl because everything is a string in Tcl.

int concat(int a, int b){
int k;
for(k = 1; k

int cat(int a, int b) {
int max;
for(max=1; b / i >= 10; max = max*10);
for(int i = max; i > 0; i = i / 10) {
a = a * 10 + (b/i)
b = b - (b/i)*i
}
return a;
}

wrong.

someone on /hr/ had stated his company has some account that allows them to dl a shitload of these images a day for some contract rate. he then uploaded said images.

Nigger he said no strings

Nope

>Nope
Sorry, missed the semicolon. You are right

>Control shift C: some code on the web
>Control shift v
>run code
done :^]

pow(x, ceil(log10(y))) + y

You ruined the fun and I bet you program in jython

based python

import math

def concat(a,b):
return a*10**int(math.ceil(math.log(b,10)))+b

print(concat(12,5))

>all these meme languages
kek

public class ConcatInt {

public static void main(String[] args) {
int num0 = 58;
int num1 = 8;
StringBuilder sb = new StringBuilder();

sb.append(num0);
sb.append(num1);

System.out.println("Fuck you OP\n" + sb.toString());
}

}

C/C++
#include
#include

using namespace std;

int concat(int a, int b){
return a*pow(10, ceil(log10(b+1))) +b;
}

int main(){
cout

The 3rd possibility.
def concat(a,b):
acc1, acc2, l = 0, 0, 0
if b == 0: l += 1
while b:
acc1 = 10 * acc1 + b % 10
b = b // 10
l += 1
while a:
acc1 = 10 * acc1 + a % 10
a = a // 10
l += 1
while l:
acc2 = 10 * acc2 + acc1 % 10
acc1 = acc1 // 10
l -= 1
return acc2

function concatenateIntegers(n, m, base) {
var x;
if(Number.isInteger(n) === false) {
throw "n is not an integer.";
} else if(Number.isInteger(m) === false) {
throw "m is not an integer.";
} else if(n < 0) {
throw "n is not non-negative.";
} else if (m < 0) {
throw "m is not non-negative.";
}
function digitCount(n, base) {
var n2 = n;
var digits = 1;
while(n2 >= base) {
digits++;
n2 = Math.floor(n2 / base);
}
return digits;
}
function baseShift(n, base, places) {
var n2 = n;
for(var i = 0; i < places; i++) {
n2 = n2 * base;
}
return n2;
}
return baseShift(n, base, digitCount(m, base)) + m;
}

print("Please enter a non-negative decimal integer:");
var x = readline();
print("Please enter another non-negative decimal integer:");
var y = readline();
x = Number.parseInt(x);
y = Number.parseInt(y);

console.log(concatenateIntegers(x, y, 10));

OP said no strings you absolute pancake.

It's C++ only.

r-rate me senpai !
#include


int concat(int a, int b) {
int mult=1;
while (b / mult >= 1) {
mult*=10;
}
return a*mult+b;
}

int main() {
int x = 132, y = 58392;

printf("Numbers to concat :\n");
printf("x : %d\n", x);
printf("y : %d\n", y);
printf("Concat is : %d\n", concat(x, y));

return 0;
}

>no strings

what the fuck

str concatin8(int a, int b){
return a + b;
}

int main(){
std::cout

Sepples is only required for the I/O, the code that does the actual computation would work in pure C.

no strings you dumb nigger

yeah I messed it up a bit I realized
intConcat PROTO C, intA:DWORD, intB:DWORD, intOut:PTR DWORD

.code
intConcat PROC C uses eax edi, intA:DWORD, intB:DWORD, intOut:PTR DWORD
LOCAL intDigNum:DWORD
mov intDigNum, 10
mov edi, intOut

mov eax,intB
test eax,eax
jz FLOATSKIP

FINIT
FLDLG2
FILD intB
FYL2X
FLD1
FADD
mov intDigNum, 10
FILD intDigNum
FYL2X
FIST intDigNum
FILD intDigNum
FSUB
F2XM1
FLD1
FADD
FILD intDigNum
FXCH
FSCALE
FIST intDigNum

FLOATSKIP:

mov eax, intA
mul intDigNum

add eax, intB
mov DWORD PTR [edi], eax
ret
intConcat ENDP

(b / mult >= 1)

You don't need it. Better:
(b > mult)

str concatin8(int a, int b){
return a + b;
}

int main(){
std::cout

Who even uses the x87 stack these days.

>Use a loop to figure out the length of the second number, eg:
>Use logs to figure out the length of the second number, eg:
>Copy the numbers into a variable backwards, then reverse the digits in that variable, eg:

What is even the purpose of Tcl?

>using namespace std

Here.
from math import log10

def digitconcat(a, b):
d = int(log10(b)) + 1
return a * 10**d + b

you should work on your reading comprehension. does not use strings

That's not a ``reading comprehension" issue, I meant to reply to the post above it.

:^)

I could do it in FMA4 but w/e, it'd take more time

(defun pls-no-stabbenings (a b) (+ (* 10 a) b))

unsigned long concat(unsigned short a, unsigned short b) {
unsigned short c = b;
do {
a *= 10
} while (c /= 10);
return a + b;
}

SHIT I FORGOT THE SEMICOLON
unsigned long concat(unsigned short a, unsigned short b) {
unsigned short c = b;
do { a *= 10; } while (c /= 10);
return a + b;
}