/dpt/ - Daily Programming Thread

Hwat are you working on, Sup Forums?

Previous:

Other urls found in this thread:

en.wikipedia.org/wiki/Arbitrary-precision_arithmetic#Applications
twitter.com/NSFWRedditGif

Can /dpt/ multiply two numbers without *?

Friendly reminder that C doesn't have strings.

Friendly reminder that C doesn't have dictionaries.

>he doesn't understand that everything is just value in memory it's the semantic meaning that we give to that block of memory that makes it a string

Yes, I had to do it in JS recently.

import operator
operator.mul(a, b)

int FStar_add(int *****a, int *****b) {return *****a + *****b;}

int main(int argc, char **argv)
{
if(argc != 3) return EXIT_FAILURE;
int a = atoi(argv[1]), b = atoi(argv[2]);
int *ap = &a; int *bp = &b;
int **app = ≈ int **bpp = &bp;
int ***appp = &app; int ***bppp = &bpp;
int ****apppp = &appp; int ****bpppp = &bppp;
printf("\t%d\t+\t%d\t=\t%d\n", a, b, FStar_add(&apppp, &bpppp));
return EXIT_SUCCESS;
}

>tfw can't install any decent ruby GUI libraries because winblows and forced to use shoes now
FUCK

x / (1/y)

>multiply two numbers without *?
I can multiply two numbers without using builtin number primitives.
(define (inc n) (lambda (f z) (n f (f z))))
(define (add a b) (lambda (f z) (a f (b f z))))
(define (mul a b) (lambda (f z) (a (lambda (s) (b f s)) z)))

(define (succ n) (cons n n))

(define (_0 f z) z)
(define _1 (inc _0))
(define _2 (inc _1))
(define _3 (inc _2))

((mul _2 _3) succ '())

r8 my sum

int getSum(int a, int b) {

while (b != 0)
{
int c = a & b;

a = a ^ b;
b = c

int multiplication (int a, int b) {
int result = 0;
for (int i = 0; i < 32; ++i) {
if ( (b >> i & 1) == 0) continue;
result += (a

function multiply(a:int, b:int):int
{
for(var i:int = 1; i

what language?

shoes is not so bad, what are you trying to build?

Woops, screwed up alot there
function multiply(a:int, b:int):int
{
var a_p:int = a;
for(var i:int = 1; i < b; i++) a += a_p
return a;
}

trace(3*10 + " = " + multiply(3, 10));


Also, language is ActionScript

Looks like typescript

from math import log, e

def multiply(a, b):
e**(log(a)+log(b))

Why tho?

install gentoo

(seriously though, just throw memebuntu or something on your system as a dualboot or in a VM, makes your life a lot easier.)

>e**
>without using **
What a failure.

He said without using *, not without using **.

* and ** are different operators.
If you only care about the literal character then you could just do:
a.__mul__(b)

>without using *
>not **
>tfw the string "**" apparently doesn't contain the character '*'

>average of two ints is hard
double two_ints_average( int a, int b)
{
double average;

return average = (a + b) / 2.0;
}

You are basically moving to problem.
The OP wanted a multiplication method that didn't involve multiplication.
So if you rely on exponents or division, you must implement those as well.

subtest {
lives-ok {
8A * 2Ω == 16V;
}
}

>non-generic
trash

Didn't you die in the last thread?

Agreed. Having to use loopholes to be able to contribute anything is just sad.

fucking dumbass.
double fun(int a, int b){
return (a + b) / 2.0;
}

is much neater if you insist on doing it like that.

>The OP wanted a multiplication method that didn't involve multiplication.
No you fucking retard, because that's impossible.
Protip: repeated summing qualifies as multiplication.
He wanted you to do it without using the builtin multiplication operator.

Now do it without overflowing.

literally double fun(int a, int b) return (a + b) / 2.0;

Retard
template
double average(T a, T b) {
return (a + b) / 2.0;
}

fun ref average(x: I32, y: I32): F32 ? =>
if a == b
a
else
a+b/2.0

>Now do it without overflowing.
#define int uint32_t

typedef struct {
double num, denom;
}Fract;

Fract div(double x, double y) {
return (Fract){x, y};
}

Fract avg(int x, int y) {
return div((double)x + y, 2);
}

Get fucked, retarded animal.

In python to multiply a and b

result = 0
for i in range(b):
result += a
return result

>his language doesn't support bignums

It's just the inverse of the log
You could just use a pre-filled table with the computed values, which would be closer to the slide rule multiplication it's supposed to be.

absolutely gross
auto average(T)(T a, T b) return (a + b) / 2.0;

>Redefining int
>typedef struct
Now do it in a way that doesn't make everyone projectile vomit

>moving the goalpost
Are you enjoying your anal ravaging, baby boy?

take your verbose shit and leave

First = gets.to_f
Second = gets.to_f
puts First+Second/2

>Divide by zero
>Defining int as a uint
user...

>First+Second/2
>2
lol

C++ can do that too
auto average(auto a, auto b) {return (a + b) / 2.0;}

Although I have absolutely no idea why you would want to put the function body on the same line as the signature.

>>divide by zero
Are you suffering from some kind of hallucination, tard? Does 2 look like 0 to you?

>>Defining int as a uint
That's a typo. It should be int32_t. Nevertheless, it's not technically wrong. Get fucked.

if you know you only need one line, there's no reason not to.

I-is that lisp ?

it works.

How does that overflow and what does it overflow.
Pls tell, noob here.

So how is this better than the O(32) solution first posted?

>Are you suffering from some kind of hallucination, tard? Does 2 look like 0 to you?
No but your fractions allow it you mong.

It's disgusting.
auto average(auto a, auto b) {
return (a + b) / 2.0;
}

is superior style.

>Are you suffering from some kind of hallucination, tard? Does 2 look like 0 to you?
After seeing shit like redefining int and typedef'ing structs, I wouldn't be surprised if someone lost their mind and starting hallucinating.

en.wikipedia.org/wiki/Arbitrary-precision_arithmetic#Applications

const average = (a, b) => (a + b) / 2;
average (4, 5); // => 4.5

>O(32)
You mean O(1)

>capitalized variable names
>First+Second/2
stop embarrassing ruby-tan
first, second = gets.to_f, gets.to_f
p (first+second) / 2.0

>your fractions allow it
Completely irrelevant. It's obviously the bare minimum amount of code required to solve a specific problem with this approach, not intended to be a full implementation of fractions. Why are you people so mentally retarded?

nice

>mentally retarded
Ad hominem to cover up your shitty code?
Your implementation is bad and you should feel bad

I just find slide rules neat.

>That bulge

int iavg(int a, int b) {
return a < 0 != b < 0 ? (a + b) / 2 : a / 2 + b / 2 + a % 2 + b % 2;
}

kys yourselves

>lying so blatantly
The post explains why your objection is retarded. No ad homs involved. You're simply too subhuman to understand the difference between arguing that someone is wrong because they are a subhuman degenerate, and explaining why someone is wrong, and then noting that they are a subhuman degenerate. Kill your family and yourself.

>4.5
>not 9/2

>int
You've missed the point

int multiply(int a, int b)
{
int ii;
int result = 0;
for(ii = 0; ii < b; ii++)
{
result += a;
}
return result;
}

God I hate C

>>lying so blatantly
Whomst've'ed've'd are you quoting user?
Is your autistic rage clouding your judgement?

It's a good thing it's not 1989 anymore then.

>ii
Why tho

>doubling down on lies
Don't forget to kill your family first.

Still really common in my industry (telecoms)

You're still not quoting anything I've said

Its really entertaining to see how butthurt you are over being wrong tho, so please keep at it

best solutions so far

>I-is that lisp ?
That's scheme. If you think it looks bad, try doing it in C++ or Rust. (Hasklel and friends can do it more elegantly, though)

Did a little bit of work on my sel4 microkernel based POSIX OS.

>not understanding how greentext works
You have to go back, tard.

seems you're running out of arguments my autistic friend

>char data type takes 2bytes of memory

>POSIX
Disgusting. But good job on actually doing something useful, most of us can learn a thing or two about doing useful stuff.

>2
nani

>useful

>most of us can learn a thing or two about doing useful stuff
>implying that anyone here is capable of doing anything useful

user, we write fizzbuzz's and argue over int averaging

The ship has sailed

>arguments
Against what, tard? Your shitting and drooling all over this thread? You're here to help me burn some time, not to have your drool and shit become the subject of debate.

Then why do you keep replying autismo?
Concede that the implementation was bad, or ignore this completely. Those are your options

>being this retarded for no reason

9 / 2 == 4.5, but if that's what you want

const average = (a, b) => (a + b) + " / 2";
average (4, 5); => '9 / 2'

doesn't work with negative numbers.

>Concede that the implementation was bad
Maybe when you stop shitting and drooling all over the thread, and are able to back up your claims.

UTF-16 encoding

>hardcoded denominator
absolutely disgusting

absolutely gross

Thanks! And I'm not really thinking of creating a completely new operating system, just what I need to replace Linux.
You just tell yourself that so you dont feel as bad about being unable to do anything.

>return average = (a + b) / 2.0;

>back up your claims.
Really? have you been launching your shitty arguments into thin air without reading my replies at all?

I said your implementation was bad because it allows division by 0. You argued that it was hastily put togheter as a bare minimum to run the example.

That dosent make it a good implementation though.

from cmath import log, e

def multiply(a, b):
return (e**(log(a)+log(b))).real

>it allows division by 0
Completely irrelevant, tard, because that was completely besides the point of the snippet.

>That dosent make it a good implementation though.
So you're complaining that it's not a good implementation of something no one was trying to implement? Are you subhuman or just pretending?

If you keep evading the point to give yourself more reason to throw insults in a "debate" you apparently didnt want in the first place, then by all means keep wasting your time AuTiSmO

>If you keep evading the point
Your retarded point has been addressed. You just can't recover from it, so you opt instead to pretend that it didn't happen for a second time now. Your last post is just a longer version of your first attempt to lie that I was using an ad hominem. Don't forget to kill your family, tard.

I can physically feel your autism