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
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 ;;
>>59562047
What's this language?
>>59562064
OCaml
>>59562064
Garbage
>>59562078
t. front dev web developper
>>59562069
wtf I wanted to learn ocaml now
>>59561661const 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
>>59562103
>front dev Web developer
>>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
>>59561661program 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
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
my $concat = 12 . 5;
print $concat, "\n";
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 likeint powi(int a, int b)
{
int base = a;
while (b--)
a *= base;
return a / 10;
}
>>59561661
idk about performanceint_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; }
>>59561661unsigned int concat(unsigned int a, unsigned int b) {
unsigned int s = b;
do {
b /= 10;
a *= 10;
} while (b);
return a + s;
}
>>59562384
wait waitmy $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
>>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.
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/
>>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
>>59562737
nice rebuttal
>>59562746
it's not worth the performance hit to calculate a number that can never go past log10(2^64) digits.
>>59562596
>>59562737
>maki is cute 491.jpg
>maki is cute 714.jpg
>714.jpg
>714
warning: waifufaggotry at unsafe levels
>>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
;;
>>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;
}
>>59561661proc 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 pythonimport 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());
}
}
>>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
>>59561661function 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 realizedintConcat 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)
>>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))
>>59561661unsigned 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 SEMICOLONunsigned 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.
>>59561661int 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
ok10 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 attemptint 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
>>59565996
>>59565919
>>59562047
this code makes my brain hurt
#define concat(a, b) ((a) * pow(10, floor(log10(b)) + 1) + (b))
Program tuvi;
Uses crt;
Var
X,j:integer;
i:string;
Begin
X:=2;
j:=5;
i:=X+j;
End.
>>59563471
No converting to string
>>59561661print(x, y, sep='')
What, can you come up with anything simpler?
>>59566353
Now do it with math
>>59561661int 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
>>59566904
>>59566384import math
print(x, y, sep='')
How to concatenate integers in Malbolge
>>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;
}
>>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 usingassert(a == 12);
assert(b = 5);
>>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.
>>59561661cat 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
>>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 beusing 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
>>59561661def 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
>>59561661int 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;
}
get fukked scrubsvar 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.
>>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;
}
Mehfunction 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#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 likedef 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
>>59573008
>tfw forgot pythondef 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 promptdef 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
>>59561661import 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);
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)}
}
>>59566962
>>59561661concat = 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