[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]

WRITE A PROGRAM IN YOUR FAVORITE LANGUAGE THAT CONCATENATES TWO

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: 230
Thread images: 36

File: 1484332469273.jpg (32KB, 412x430px) Image search: [Google]
1484332469273.jpg
32KB, 412x430px
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 <- c(1, 2)
>>
def concat(a, b):
import math
return a * 10 ** int(math.ceil(math.log(b) / math.log(10))) + b
>>
File: 1489248925418.png (265KB, 768x480px) Image search: [Google]
1489248925418.png
265KB, 768x480px
let concat = (a,b) => '' + a + b

LOL
>>
File: 1464465684459.jpg (1MB, 5628x3348px) Image search: [Google]
1464465684459.jpg
1MB, 5628x3348px
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 ;;
>>
>>59562047
What's this language?
>>
>>59562064
OCaml
>>
>>59562064
Garbage
>>
File: colour-logo.png (39KB, 2187x601px) Image search: [Google]
colour-logo.png
39KB, 2187x601px
>>59562078
t. front dev web developper
>>
File: 1478043020168.gif (2MB, 336x199px)
1478043020168.gif
2MB, 336x199px
>>59562069
wtf I wanted to learn ocaml now
>>
>>59561661
const numConcat = (x1,x2) => {
return Math.pow(10, Math.ceil(Math.log10(x2)))*x1+x2
}
console.log(numConcat(12,5))


easy
>>
>>59561661


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

return ab;
}


FUCK YOU BIRD
>>
>>59561864
it wont work for b=10^smth
>>
File: 1427663130461.png (86KB, 244x252px) Image search: [Google]
1427663130461.png
86KB, 244x252px
>>59562103
>front dev Web developer
>>
File: 1472073888972.jpg (150KB, 1390x974px)
1472073888972.jpg
150KB, 1390x974px
>>59562047
>somebody paid money for these shutterstock images in glorious HD
>>
>>59562108
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)

>>59562177
front-end, my bad

>>59562213
That poor soul
>>
>>59561661
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
>>
>>59562103
>front
>dev
>web
>developer
are you even fucking trying anymore?
>>
>>59561661
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
>>
File: akari~nn.png (522KB, 519x697px) Image search: [Google]
akari~nn.png
522KB, 519x697px
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;
}
>>
>>59562226
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.
>>
>>59562345
Write your own pow, you litterally have an example here >>59562047
>>
File: maki is cute 56.png (619KB, 661x935px) Image search: [Google]
maki is cute 56.png
619KB, 661x935px
my $concat = 12 . 5;
print $concat, "\n";
>>
File: 1466882747310.gif (137KB, 170x244px) Image search: [Google]
1466882747310.gif
137KB, 170x244px
std::cout << a << b;
>>
>>59562374
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)
>>
>>59562382
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;
}
>>
>>59561661
idk about performance
int_cat = lambda int_1, int_2: int(str(int_1) + str(int_2))
>>
>>59561661

EZ

def concat(a, b):
print(a, b, sep='')
>>
>>59562460
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; }
>>
>>59561661
unsigned int concat(unsigned int a, unsigned int b) {
unsigned int s = b;

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

return a + s;
}
>>
File: maki is cute 714.jpg (291KB, 1700x1200px) Image search: [Google]
maki is cute 714.jpg
291KB, 1700x1200px
>>59562384
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
>>
File: 1407096737995.png (197KB, 593x454px) Image search: [Google]
1407096737995.png
197KB, 593x454px
>>59562388
>>
>>59562501
The built in function is most likely faster. If it's not you should leave the language for the garbage that it is.
>>
File: wt20cdvf66my.jpg (104KB, 750x1334px) Image search: [Google]
wt20cdvf66my.jpg
104KB, 750x1334px
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;
}
>>
>>59562630
> implying you need performance for this shitty exercise
But otherwise I totally agree with (You)
>>
>>59562547
neat
>>
>>59562630
No it's not, it's fucking slow because it works with fucking doubles.
Just use a lookup table.
>>
>>59562682
powi(1,1000000)

what now faggot
>>
>>59562663
thanks. it seems like the least clumsy procedure
>>
>>59562596
love live is a scourge on this board

>>>/jp/
>>>/u/
>>
File: maki is cute 491.jpg (259KB, 724x1024px) Image search: [Google]
maki is cute 491.jpg
259KB, 724x1024px
>>59562723
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.
>>
>>59562746
logarithms don't apply to ints.
>>
>>59562746
> Not writing a entire framework each time you need a so-called "standard function"
Anon please, try at least
>>
File: poglauch.gif (2MB, 240x232px) Image search: [Google]
poglauch.gif
2MB, 240x232px
>>59562737
nice rebuttal
>>
>>59562746
it's not worth the performance hit to calculate a number that can never go past log10(2^64) digits.
>>
File: 1434521932363.jpg (265KB, 1200x868px) Image search: [Google]
1434521932363.jpg
265KB, 1200x868px
>>59562596
>>59562737
>maki is cute 491.jpg
>maki is cute 714.jpg
>714.jpg
>714
warning: waifufaggotry at unsafe levels
>>
File: maki is cute 1120.png (2MB, 1772x1477px) Image search: [Google]
maki is cute 1120.png
2MB, 1772x1477px
>>59562827
maki is nicos waifu not mine
>>
>>59562047
>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
;;
>>
File: 1438110463771.jpg (43KB, 500x371px) Image search: [Google]
1438110463771.jpg
43KB, 500x371px
>>59562848
>1120
Take your fucking reply and go.
>>
>>59562746
>convert int to double
>compute log10
>round down
>compute 10^n
>convert back to int

vs

>multiply int by 10
>compare two ints
>repeat
>>
>>59562696
Now you are retarded
>>
>>59562881
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
>>
>>59562175
Guess it should be 1 + math.floor() then instead of math.ceil().
Thanks!
>>
local a,b = 12,5
local c = a..b
>>
>>59561661
function concat($one, $two) {
$concatted = $one.$two;
return $concatted;
}
>>
>>59561661
proc digicat {a b} { return $a$b }

Integers are strings in Tcl because everything is a string in Tcl.
>>
>>59561661
int concat(int a, int b){
int k;
for(k = 1; k<b;k=k*10);
a=a*k;
return a+b;
}
>>
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;
}
>>
>>59562213
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.
>>
>>59561876
Nigger he said no strings
>>
>>59563519
Nope
>>
>>59563681
>Nope
Sorry, missed the semicolon. You are right
>>
>>59561661
>Control shift C: some code on the web
>Control shift v
>run code
done :^]
>>
>>59561661
pow(x, ceil(log10(y))) + y
>>
>>59563565
You ruined the fun and I bet you program in jython
>>
>>59561661
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
>>
File: IT28-25.jpg (154KB, 800x540px)
IT28-25.jpg
154KB, 800x540px
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());
}

}
>>
>>59563900
C/C++
#include <iostream>
#include <cmath>

using namespace std;

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

int main(){
cout<<concat(12,100)<<endl;
}

>>
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
>>
>>59561661
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));
>>
>>59562332
OP said no strings you absolute pancake.
>>
>>59564178
It's C++ only.
>>
>>59564616
r-rate me senpai !
#include <stdio.h>


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;
}
>>
>>59562475
>>59562481
>>59562547
>>59563518
>no strings

>>59563316
what the fuck
>>
str concatin8(int a, int b){
return a + b;
}

int main(){
std::cout << concatin8(12, 5) << endl << "/g/ BTFO!!!";
}




And that's how you do it OP
>>
>>59564604
Sepples is only required for the I/O, the code that does the actual computation would work in pure C.
>>
>>59564639
no strings you dumb nigger
>>
>>59564638
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
>>
>>59564633
(b / mult >= 1)

You don't need it. Better:
(b > mult)
>>
File: 1424253173_82.jpg (37KB, 600x600px) Image search: [Google]
1424253173_82.jpg
37KB, 600x600px
>>59564666

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

int main(){
std::cout << concatin8(12, 5) << endl << "/g/ BTFO!!!";
}



What about now?
>>
>>59563316
Who even uses the x87 stack these days.
>>
>Use a loop to figure out the length of the second number, eg: >>59561669
>Use logs to figure out the length of the second number, eg: >>59561864
>Copy the numbers into a variable backwards, then reverse the digits in that variable, eg: >>59564526
>>
>>59563518
What is even the purpose of Tcl?

>>59564178
>using namespace std
>>
Here.
from math import log10

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

>>
>>59564638
you should work on your reading comprehension. >>59562547 does not use strings
>>
>>59564881
That's not a ``reading comprehension" issue, I meant to reply to the post above it.
>>
>>59564897
:^)
>>
>>59564735
I could do it in FMA4 but w/e, it'd take more time
>>
 (defun pls-no-stabbenings (a b) (+ (* 10 a) b))
>>
>>59561661
unsigned long concat(unsigned short a, unsigned short b) {
unsigned short c = b;
do {
a *= 10
} while (c /= 10);
return a + b;
}
>>
>>59564993
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;
}
>>
>>59561661
>Integers
>No strings
>Ignores the negative & negative case
Eat that crow
>>
>>59564993
nice. compare to: >>59562547
i dont think you should restrict a and b to shorts; though overflow can obviously occur if they all (input and output) are the same width
>>
>>59561661
f = lambda x, y: int(str(x) + str(y))
>>
def concat(one, two)
multiplier = 10
while multiplier < two
multiplier *= 10
end
(one * multiplier) + two
end

puts concat(44,55)
puts concat(555666,123)


Output:
4455
555666123
>>
from math import log10
l = lambda x: 0 if not x else log10(abs(x))
f = lambda x,y: x*10**int(l(y)+1)+y
>>
I do know a bit of BASIC. Does this count?

1 cls
2 input x$
3 input z$
4 print x$+z$

or do I need to do it mathematically
>>
>>59565471
They said you're not allowed to use strings.
>>
>>59561661
int concat(int a, int b)
{
return a*((int)(pow(10, ceil(log10(b))))) + b;
}

did I do good?
>>
int concat(int a, int b)
{
return (a * pow(10, floor(log10(b) + 1)) + b;
}
>>
>>59562124
>java
>>
>>59561661
(lambda (x y) (parse-integer (concatenate 'string (write-to-string x) (write-to-string y))))
>>
Clojure makes this trivial
(defn concat-ints [int1 int2]
(read-string (str int1 int2)))
>>
>>59561661
(defun concatenate-integers (x y)
(declare (integer x y))
(+ (* 10 x) y))
>>
>>59565805
That won't work
>>
>>59565791
NO STRINGS, ARRAYS OR OTHER BULLSHIT
JUST MATH
>>
ok

10 take integer
20 concatenate it with another integer
30 print the result
>>
>>59565851
(defun concatenate-integers (x y)
(declare (type (integer 1 *) x y))
(+ (* 10 x) y))

:^)
>>
last attempt
int concat(int x, int y){
return x*round(pow(10,floor(log10(y)+1))) + y;
}
>>
>>59561661
=A1&B1
>>
>>59564993
You did it wrong.
unsigned long concat(unsigned short a, unsigned short b) {
unsigned long c = a; unsigned short d = b;
do c *= 10; while (d /= 10);
return c + b;
}
>>
>>59561661
BIRDMIN NO
>>
>>59565940
there was nothing wrong with his procedure
>>
>>59565954
Yes there was. The whole point of the return value being a long and the parameters being shorts was to protect against overflow, but it didn't actually protect against overflow because while the left parameter was being repeatedly multiplied by 10, it was still a short.
>>
int concat(int a, int b)
{
return (a*10)+b;
}
>>
>>59565974
gotcha. you should mention the changes you make because thats a difference that is easy to miss.
>>
>>59565996
KEK
>>
File: amadeus-sigh.webm (996KB, 1280x530px) Image search: [Google]
amadeus-sigh.webm
996KB, 1280x530px
>>59565996
>>
File: god.gif (462KB, 500x250px)
god.gif
462KB, 500x250px
>>59565919
>>
File: dog.gif (462KB, 500x250px) Image search: [Google]
dog.gif
462KB, 500x250px
>>59566146
>>
>>59562047
this code makes my brain hurt
>>
#define concat(a, b) ((a) * pow(10, floor(log10(b)) + 1)  + (b))
>>
File: 1489342872319.jpg (84KB, 700x714px) Image search: [Google]
1489342872319.jpg
84KB, 700x714px
Program tuvi;
Uses crt;
Var
X,j:integer;
i:string;
Begin
X:=2;
j:=5;
i:=X+j;
End.
>>
>>59563471
No converting to string
>>
>>59561661

print(x, y, sep='')


What, can you come up with anything simpler?
>>
>>59566353
Now do it with math
>>
>>59561661
int concat(int, int);

You don't know what the implementation is, therefore you can't say it's wrong
>>
>>59561661
var concat = int1 + '' + int2;
>>
function concat(a, b)
n = math.floor(math.log10(b))+1
a = a*10^n
return a+b
end
>>
>>59566672
now write your own log function
>>
int concat(int a, int b) {
return concat(a, b);
}
/* It returns the correct result when it halts. */
>>
>>59566883
there's no base case, it will never halt

dumb anime poster
>>
File: U7Ghu2s.gif (3MB, 448x291px) Image search: [Google]
U7Ghu2s.gif
3MB, 448x291px
>>59566904
>>
>>59566384
import math
print(x, y, sep='')
>>
File: image.jpg (3KB, 101x57px) Image search: [Google]
image.jpg
3KB, 101x57px
How to concatenate integers in Malbolge
>>
File: 1485152752545.jpg (12KB, 200x272px) Image search: [Google]
1485152752545.jpg
12KB, 200x272px
>>59566962
>>
>>59566230
>b evaluated twice
>>
///  ConcatTwelveAndFive
// Concatenates 12 and 5
// Input:
// A - int, first value, should = 12
// B - int, second value, should = 5
// Output:
// return - int, return value, will = 125
// Note:
// Only works if A = 12 and B = 5
// (Can also work if A = 1 and B = 25)
int ConcatTwelveAndFive(int A, int B)
{
return 125;
}
>>
File: 1439486461794.gif (993KB, 250x250px) Image search: [Google]
1439486461794.gif
993KB, 250x250px
>>59567708
>>
>>59567708
A = 0, B = 125 also works
>>
>not using glorious bash
#!/usr/bin/env bash

function concat {
echo $1$2
}

echo $(concat 12 5)
>>
I wrote it in English:
Given L, R, concatenate L onto R:
Find N by integer-dividing R by 10 as many times as it takes to turn the number into 0 (the number of times is N). Result: 10^N * L + R
>>
Erlang masterrace.
7> list_to_integer(lists:concat([56, 5])).
565

>>
I want to see someone do this using unary/peano arithmetic.
>>
>>59567708

>Not using

assert(a == 12);
assert(b = 5);
>>
File: 1484615584386.jpg (1MB, 3816x3592px) Image search: [Google]
1484615584386.jpg
1MB, 3816x3592px
>>59562213
>he doesn't own the premium HD Harolds
>>
>>59567785
The second assert is completely useless.
Looks like someone is gonna get stabbed.
>>
Everything done by a processor is binary math.
>>
>>59568309
ummm what about quantum computers??
>>
import math

def concat(a,b):
c = a * 10**int(math.log10(b)) + b
return c


havent tried it, but something like this
>>
>>59561661
int a;
int b;
System.out.println(a+b);

not super great but I'm learning
>>
>>59564650
Doesn't compile on C compiler nigger.
>>
File: 16681988.jpg (22KB, 399x225px)
16681988.jpg
22KB, 399x225px
>>59561661
 cat main.d ;and ldc2 main.d;and ./main
import std.stdio;

void main()
{
int a = 12;
int b = 999;
writeln(concat(a, b));
}

int concat(in int x, in int y)
{
int multiplier = 1;
while (!(y/multiplier >= 1 && y/multiplier <= 9))
{
multiplier*=10;
}
return multiplier*10*x+y;
}
12999
>>
>>59562345
saved
>>
File: jurina.jpg (11KB, 291x315px) Image search: [Google]
jurina.jpg
11KB, 291x315px
>>59566962
>>
>>59570162
That's just printing a string
>>
#import iostream
using namespace std;

int main()
{
int n1,n2;
cin >> n1 >> n2;
cout << n1 << n2;
}
>>
>>59563565
well, someone's boss paid money then
>>
No one has done the fastest solution yet: Binary search the largest power of ten to fit in a (using comparisons, i.e if statements), multiply it by a, add b.
That's at most 5 cmp (for 32 bit ints), one mul and an add.
>>
>DO MY HOMEWORK OR THIS BIRD IS GONNA STAB YOU
No.
>>
def d(a, b):
if b < 10:
return a * 10 + b
else:
return d(a * 10 + b % 10, b // 10)
>>
>>59570170
So?
>>
>>59570261
But you'd have to calculate the powers (or squares alternatively) on each step of binary search.
>>
>>59570436
>>59570261
Oh wait, I missed the 'if' part, although messy it would be faster indeed.
>>
>>59561661

>ITT: retarts making things more complicated than it needs to be

using System;

public static void Main() {
Console.Write(12);
Console.Write(5);
}
>>
>>59561661
Int a;
Int b;
Cout<<a<<b;

I am a literature student
>>
>>59570450
that will trash pipelines and jump predictions.
on a platform that provides ln as hardware instruction, calculating log_10(arg2) could be faster. (that's just ln(arg2)/ln(10), exp is in hardware, is ln?)
Also doesn't restrict the size of the numbers.
concat :: Integer -> Integer -> Integer
concat x y =
y + x * (logBase 10 y + 1)
>>
>>59570502
ITT retards doing IO when working on integers.
>>
>>59570502
read OP again
he didn't say to output the two numbers concatenated, he said to concatenate them with "JUST MATH"
you program just outputs two numbers, it doesn't concatenate them, nor does it utilise math
>>
>>59570733
To be honest, the OP is rather bad aswell.
Concatenation ins't a particularily well defined mathematical operator.
And for computers concatenation of numbers would probably be in the binary domain, not decimal.
>>
> no strings
> is actually more performant to do with strings
>>
>>59570804
programming/problem-solving exercises are rarely practical
>>
>>59561661
def concat (a,b)
return "%d%d" % ((a,b))

print(concat(12,5))
>>
>>59570804
The return type is a string right?
>>
Integer.parseInt(Integer.toString(arg1) + Integer.toString(arg2));
>>
>>59570804
if you are given to integers and are supposed to return another integer, converting to and from string will was time.
But I agree with >>59570829
>>
>>59561661

int concat(int a, int b)
{
int result = 0;
int acc = 1;

do {
result += (b % 10)*acc;
acc *= 10;
} while ((b /= 10) > 0);

do {
result += (a % 10)*acc;
acc *= 10;
} while ((a /= 10) > 0);

return result;
}
>>
File: 1410923286809.jpg (477KB, 1280x1666px) Image search: [Google]
1410923286809.jpg
477KB, 1280x1666px
get fukked scrubs
var concat = function(a, b){ return parseInt( (a + "" + b) );}
>>
>>59571079
improvement:

int concat(int a, int b)
{
int result = 0;
int acc = 1;

do {
result += (b % 10)*acc;
acc *= 10;
} while ((b /= 10) > 0);

return a*acc + result;
}
>>
>>59571130
>NO STRINGS, ARRAYS, OR OTHER BULLSHIT
>JUST MATH
>>
>>59562388
/thread
>>
>>59571152
The string is empty though
Checkmate atheists :^)
>>
>>59571182
An empty string is still a string.
>>
File: NoHomers3.jpg (26KB, 400x251px)
NoHomers3.jpg
26KB, 400x251px
>>59571185
It says no stringS.
We can have one.
>>
>>59562388
kek
>>
public class daddy {
public static void main(String[] args){
system.out.println("hello world");
}
}
>>
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define all(a) (a.begin()),(a.end())
#define ZERO(a) meset(a,0,sizeof(a))
#define FOR(x,val,to) for(int x=(val);x<int((to));x++)
#define FORE(x,val,to) for(auto x=(val);x<=(to);x++)
#define FORR(x,arr) for(auto &x: arr)
#define PRINT(arr) copy((arr).begin(), (arr).end(), ostream_iterator<int>(cout, " "))
#define REE(s_) {cout<<s_<<'\n';return 0;} //print s_ and terminate program
#define GETVEC(vec,amount) copy_n(istream_iterator<int>(cin),(n),back_inserter((vec)))
#define GET(arr) for(auto &i: (arr)) cin>>i
#define MEMSET_INF 127 //2139062143 (USE FOR MEMSET) - memset(arr,MEMSET_INF,size)
#define INF 2139062143 //for comparison
#define ULL_INF 18446744073709551614 //for comparison
#define F first
#define S second
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
using namespace std;

int concat(int a, int b){
int bsz=0;
int tmp=b;
while(tmp){
bsz++;
tmp/=10;
}
return b+a*pow(10,bsz);

}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int a = 12;
int b = 5;
cout << concat(12,5);
}
>>
>>59571218
Since a and b are being converted to strings, you have more than one.
>>
>>59571273
I don't even
>>
>>59571278
a and b are being added to the empty string, they remain integers after the operation .
>>
Best language here:

 Program ConCatAB;

VAR
a,b : LongInt;
Result : Int64;

Function NumOfDigits10 (n : LongInt) : LongInt;
Begin
NumOfDigits10 := 1;
While n > 0 do
begin
NumOfDigits10 := NumOfDigits10 * 10;
n := n div 10;
end;
End;

BEGIN

Write('a='); ReadLn(a);
Write('b='); ReadLn(b);

Result := (a * NumOfDigits10(b)) + b;

Write('Concat(',a,',',b,')=',Result);

ReadLn;

END.
>>
>>59567724
>125 = 1250
>>
>>59571404
>1250 = 0125
>>
>>59571502
>0125 = 125

wait, scratch that
>>
>>59561661
[Code]var $d = a . b;
>>
>>59572163
>php
>>
>>59572163
No strings you baka.
>>
>>59561661
console.log(1 + '' + 2);
>>
>>59561661
#!/bin/bash
concat() {
echo "$1$2"
}
export -f concat
>>
>>59571079
>copy digits into the result digit-by-digit
I like.
>>
>>59562388
C++ wins again
>>
>>59571273
You forgot:
>#define BEGIN {
>#define END }
>>

"12"+"4"

>>
>>5956166
//In C
int concat(int a, int b){
int d= log (b);
for (int i=0; i <= d; i++)
a*=10;
return a+b;
}
int log (int c){
for (int i=0; c>9; i++)
c/=10;
return i;
}
>>
Meh
    function concat($left, $right)
{
if (!is_numeric($left) && !is_numeric($right) || ($right < 0))
return -1;

$sgn = 1;
if ($left < 0) {
$sgn = -1;
$left *= -1;
}

$rightFactor = 1;
do {
$rightFactor *= 10;
} while ($rightFactor < $right);
return ($sgn * (($left * $rightFactor) + $right));
}
>>
>>59561661
>>
>>59561661
#include <stdio.h>

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

int abs(int a)
{
if (a < 0) {
return -1 * a;
} else {
return a;
}
}

int main()
{
int a, b, s;
scanf("%d %d", &a, &b);
s = (a * b < 0) ? -1 : 1;
printf("%d\n", s * concat(abs(a), abs(b)));
return 0;
}


I don't get it
>>
import math

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

print(concat(12.5))
>>
def concat(a, b):
if b == 0: c = 10
else: c = 1
while b:
c = 10 * c + b % 10
b = b // 10
while c != 1:
a = 10 * a + c % 10
c = c // 10
return a
>>
>>59561661
>NO STRINGS, ARRAYS, OR OTHER BULLSHIT
so like
def concat(list_)
order = 0
total = 0
for digit in reversend(list_):
order = order + 1
total = total + digit * 10^order
return total

this still uses arrays though
>>
File: 81072056.jpg (157KB, 500x371px) Image search: [Google]
81072056.jpg
157KB, 500x371px
>>59573008
>tfw forgot python
def concat(list_)
order = 0
total = 0
for digit in reversend(list_):
order += 1
total = total + abs(digit) * 10**order
return total


of course if it's two numbers it's even easier
>tfw didn't read the prompt
def concat(first, second)
total = 10*abs(first) + abs(second)
return total

should've just specified positive integers desu, don't know what it means to concatenate negative integers without treating them as strings
>>
>>59561661
import math

def concat(a,b):
b_len = 1+ math.floor(math.log(b,10))
return a*(10**b_len) + b
>>
>>59566718
why don't you ask him to implement addition while he is at it
>>
>>59573242
oh I get it

oops
>>
>>59572348
>NO STRINGS, ARRAYS, OR OTHER BULLSHIT
>JUST MATH
>>
>>59562388
>
printf("%d%d", a,b);
>>
File: 2017-01-02.jpg (2MB, 3000x3000px) Image search: [Google]
2017-01-02.jpg
2MB, 3000x3000px
OK I think I actually solved it without using logs! Which i looked up on wikipedia and still don't understand!
 
$int1 = 120;
$int2 = 510;
$mult = 1;
while ($int2 >= 1) {
if (($int2 - $mult) <= 0) {
print $int1 * $mult + $int2, "\n";
exit;
}
else {$mult = ($mult * 10)}
}
>>
File: Yun 1--article_image.jpg (28KB, 620x400px) Image search: [Google]
Yun 1--article_image.jpg
28KB, 620x400px
>>59566962
>>
>>59561661
concat = lambda a, b: (b * 10**(math.ceil(math.log10(a)))) + a
>>
>>59564935
this only works for single digit numbers anon
>>
>>59573008
10^order in python is actually bitwise xor, you wanted 10**order
Thread posts: 230
Thread images: 36


[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.