text:
Summing a sub-square of a quarter of an infinite chessboard
Description of the problem
Imagine a quarter of an infinite chessboard, as in a square grid, extending up and right, so that you can see the lower left corner. Place a 0 in there. Now for every other cell in position (x,y), you place the smallest non-negative integer that hasn't showed up in the column x or the row y.
It can be shown that the number in position (x, y) is x ^ y, if the rows and columns are 0-indexed and ^ represents bitwise xor.
Task
Given a position (x, y), return the sum of all elements below that position and to the left of that position, inside the square with vertices (0, 0) and (x, y).
The input
Two non-negative integers in any sensible format. Due to the symmetry of the puzzle, you can assume the input is ordered if it helps you in any way.
Output
The sum of all the elements in the square delimited by (0, 0) and (x, y).
Test cases
5, 46 -> 6501
0, 12 -> 78
25, 46 -> 30671
6, 11 -> 510
4, 23 -> 1380
17, 39 -> 14808
5, 27 -> 2300
32, 39 -> 29580
14, 49 -> 18571
0, 15 -> 120
11, 17 -> 1956
30, 49 -> 41755
8, 9 -> 501
7, 43 -> 7632
13, 33 -> 8022

vaguely related

Interesting, I'm curious if there's a bitwise way to express this without summing everything.

We'll see what you guys come up with :)

The main diagonal is A224923.

Perl 6, 19 bytes
{sum [X+^] 0 X..@_}

Try it online!
The sum of the bitwise xor between all numbers in the range 0 to all inputs.

Python 2, 49 bytes
lambda x,y:sum(k/-~x^k%-~x for k in range(~x*~y))

Try it online!
The usual div-mod trick for iterating over two ranges. Unfortunately, since we want inclusive ranges, we need to raise each input by 1, which we do with -~. Thanks to Bubbler for saving 2 bytes by cancelling the minuses on -~x*-~y.
Python 3 would be a byte longer using //. I tried to use the 3.8 walrus operator to cut down on the -~x repetition, without success.
55 bytes
f=lambda m,n:m|n>0and(m^n)+f(m-1,n)+f(m,n-1)-f(m-1,n-1)

Try it online!
A cute recursion, but unfortunately longer. This doesn't use anything particular about XOR -- this same method can be used to add up any two-variable function over a rectangle. The base case m|n>0 terminates with zero when either m or n becomes negative, or (harmlessly) when both are zero.
This will time out on larger test cases due to the huge degree of recursive branching.
52 bytes
f=lambda m,n,b=1:m|n>0and(m^n)+f(m,n-1)*b+f(m-1,n,0)

Try it online!
A similar shorter recursion. The idea is that we can recursively travel left or down, but once we've gone left, we set to flag b to zero and ignore the results of any further travel down. The result is that we travel to each cell in the rectangle exactly one, like this:
O < O < O < O
            v
O < O < O < O
            v
O < O < O < O

Other ideas
Here are some partial ideas that didn't lead to decent golfs, but maybe someone can make use of them.
The one-dimensional summation (on a half-open range)
w=lambda i,n:sum(i^j for j in range(n))

can be expressed recursively as
w=lambda i,n:i+n and 4*w(i/2,n/2)+n%2*(n^i^1)+n/2

(Python 2 used for floor division.)
We also have an efficient formula
$$f(m-1,n-1) = \sum_{i=0}^{\infty} {\frac{m n - |m \odot 2^{i}||n \odot 2^{i}|}{2} 2^i}$$
where \$ \odot k\$ is the symmetric modulo-\$(2k)\$ operator mapping to the range from \$-k\$ to \$k\$. This summation can be truncated where \$2^i\$ is bigger than the inputs, since further terms will be zero.

-~x*-~y can be ~x*~y.

Also, an attempt to remove some -~s turned out to be 53 bytes.

Good work here! +1

Wolfram Language (Mathematica), 28 bytes
Array[BitXor,{##}+1,0,Plus]&

Try it online!

Nice use of the fourth argument!

Wow, this is incredibly short for a Mathematica submission! +1

You can save three bytes by taking a list as input

Ruby, 36 bytes
->x,y{(0..y+x*y+=1).sum{|r|r/y^r%y}}

Try it online!

What is the |r| doing?

@RGS It defines the name of the variable which is used inside the block, iterating over every value between 0 and y+x*y+=1. Kind of like for( r = 0; r <= y+x*(y+1); r = r + 1 ){

APL (Dyalog Extended), 15 bytes
+/,{⊥≠/⊤⍵}¨⍳1+⎕

Try it online!
Full program.
How it works
+/,{⊥≠/⊤⍵}¨⍳1+⎕
              ⎕  ⍝ Take a pair [x y] from stdin
           ⍳1+   ⍝ Generate indices from [0 0] to [x y] inclusive
   {     }¨      ⍝ For each pair,
       ⊤⍵        ⍝   Convert two numbers into two-column bit matrix
                 ⍝   (each column is binary representation of each number)
     ≠/          ⍝   Reduce each row with not-equals (XOR)
    ⊥            ⍝   Convert the resulting binary representation back to integer
+/,              ⍝ Sum all elements and implicit print

Nice APL submission +1

05AB1E, 6 bytes
Ý`δ^˜O

Try it online or verify all test cases.
Explanation:
Ý       # Push a list in the range [0,value] for each value in the (implicit) input-pair
 `      # Push both these lists separated to the stack
  δ     # Apply double-vectorized:
   ^    #  XOR them together
    ˜O  # And then take the flattened sum
        # (after which the result is output implicitly)

Thanks for your submission! Was it after or before the morning meetings? ;)

@RGS Uhh, dunno anymore haha. I think slightly before based on that '13 hours ago'. ;)

Alright! I see you like golfing :D

@RGS What makes you think that, haha. Is it my multiple answers a day? My 65k+ rep? My 7+ gold badges? Me joining 3.5 years ago, but still active today? xD But yes, I indeed like golfing while I'm waiting for things to compile/build at work.

Oh man, I wish I was coding in a compiled language :P I am gonna propose that back at work, so that I can enjoy some code golf while everything builds...

J, 23 17 bytes
-6 bytes thanks to Bubbler!
1#.1#.XOR/&(i.,])

Try it online!
K (oK), 25 bytes
{+/2/'~=/'(64#2)\''+!1+x}

Try it online!
Most probably can be golfed further.

J, 17 bytes using outer product instead of catalogue.

@Bubbler Of course! That's much, much better!

Thanks for your two solutions +1 Why don't you have two different answers?

@RGS Well, I'm not sure... They turned out to be quite different.

Jelly, 7 bytes
^þ/;RSS

Try it online!
A monadic link taking a pair of integers and returning an integer.
A couple of alternative 7-byters:
Ż€^þ/SS
‘Ḷ^þ/SS

So short! Thanks for the alternatives +1

Burlesque, 18 bytes
psqrzMPcp{q$$r[}ms

Try it online!
ps   # Parse to arr of ints
qrz  # Boxed range [0,N]
MP   # Map push
cp   # Cartesian product
{
 q$$ # Boxed xor
 r[  # Reduce by
}ms  # Map sum

Nice solution +1 Do the several letters together represent a single function name?

@RGS there's no such things as a function, it's all stack. The q is shorthand for putting it in a block. e.g. qrz = {rz}. Operations are elements of the stack too, and most operations are 2 chars. Some, like maps and reduce, take blocks of operations as an argument and apply them.

I understand, thanks for the explanation!

C (gcc), 48 bytes
R;f(x,y){R=++x*++y;for(y=0;--R;y+=R%x^R/x);x=y;}

Try it online!

Thanks for your C submission +1

Nice! How does this work?

@S.S.Anne xnor has used the same algorithm for his python solution and written a good explanation.

Japt -x, 6 bytes
ô ï^Vô

Try it
ô ï^Vô     :Implicit input of integers U & V
ô          :Range [0,U]
  ï        :Cartesian product with
    Vô     :Range [0,V]
   ^       :Reduce each pair by XORing
           :Implicit output of sum of resulting array

I like the two eyes ô at the ends of the code +1

Java 8, 58 bytes
(x,y)->{int t=++x*-~y;for(y=0;--t>0;)y+=t%x^t/x;return y;}

Port of @xibu's C answer, so make sure to upvote him!
Try it online.
Explanation:
(x,y)->{        // Method with two integer parameters and integer return-type
  int t=++x     //  Increase `x` by 1 first with `++x`
        *-~y;   //  Create a temp integer `t`, with value `x*(y+1)`
  for(y=0;      //  Reset `y` to 0 to reuse as result-sum
      --t>0;)   //  Loop as long as `t-1` is larger than 0,
                //  decreasing it before every iteration with `--t`
    y+=         //   Increase the result-sum by:
       t%x      //    `t` modulo-`x`
          ^     //    Bitwise XOR-ed with:
           t/x; //    `t` integer-divided by `x`
  return y;}    //  And then return the result-sum `y`

Straightforward! Thanks +1

Clojure, 72 bytes
(defn s[x y](apply +(for[a(range(inc x))b(range(inc y))](bit-xor a b))))

Ungolfed:
(defn sumxy[x y]
  (apply + (for [a (range (inc x))
                 b (range (inc y)) ]
              (bit-xor a b))))

Tests:
(println (s  5 46) " <-> "  6501)
(println (s  0 12) " <-> "    78)
(println (s 25 46) " <-> " 30671)
(println (s  6 11) " <-> "   510)
(println (s  4 23) " <-> "  1380)
(println (s 17 39) " <-> " 14808)
(println (s  5 27) " <-> "  2300)
(println (s 32 39) " <-> " 29580)
(println (s 14 49) " <-> " 18571)
(println (s  0 15) " <-> "   120)
(println (s 11 17) " <-> "  1956)
(println (s 30 49) " <-> " 41755)
(println (s  8  9) " <-> "   501)
(println (s  7 43) " <-> "  7632)
(println (s 13 33) " <-> "  8022)

Try it online!

So many parenthesis :p +1

Lisp (of which Clojure is a variant) was one of the earliest high-level languages. It probably would have been more widely adopted were it not for the high costs incurred by the untimely post-war depletion of the Strategic Parenthesis Reserve. However, despite such setbacks, Lisp and its derivatives have been influential in key algorithmic techniques such as recursion and condescension. See the "...History of Programming Languages" page. :-)

I don't think I even understand all the jokes and references, but that blog post is making me laugh so much :D thanks for this!

JavaScript (ES6), 41 bytes
Takes input as (x)(y) (or the other way around). Computes the sum recursively, the obvious way.
x=>g=(y,Y=y)=>~x&&(x^y)+g(y?y-1:x--&&Y,Y)

Try it online!

Good answer! I thought you were going to find some weird formula with the bits of x and y! Nothing came to mind?

@RGS The carries implied by a sum usually doesn't mix well with bitwise operations. So I doubt a magic formula exists. (But I'd love to see one.)

If time efficiency were the goal, there are some simple formulas that come quite close (and can then be corrected by brute-forcing a much shorter list).

Python 3, 59 58 bytes
Saved a byte thanks to Neil and HyperNeutrino!!!
lambda x,y:sum(a^b for a in range(x+1)for b in range(y+1))

Try it online!

You have an extra space that you can remove after the ) in range(x+1)

C (gcc), 61 52 bytes
Saved 9 bytes thanks to Arnauld!!!
b;s;f(x,y){for(s=b=y;~x;b--||(b=y,x--))s+=x^b;s-=y;}

Try it online!

Do you really have to have the three variables before the f? Can't you stuff them somewhere else or something? :/

@RGS Tried several variations and they had either more or the same byte count. :(

52 bytes

@Arnauld That's diabolical - thanks! :-)

Wolfram Language (Mathematica), 33 bytes
Sum[i~BitXor~j,{i,0,#},{j,0,#2}]&

Try it online!

Thanks for this! Also, be sure to check out this Mathematica answer!

Japt -x, 8 bytes
ò@Vò^XÃc

Try it

8 bytes: ò@Vò^XÃc.

I also like the eyes and nose here: ò@ò

Zsh, 31 bytes
eval '<<<$[' +{0..$1}^{0..$2} ]

Try it online!
Uses eval to expand the <<<$[ ] after expanding the lists. The TIO link adds set -x so you can see what the brace expansion looks like.

Thanks for your zsh submission!

C (gcc), 51 bytes
d,r;f(x,y){for(d=y;~d||(x--,d=y),~x;)r+=x^d--;d=r;}

Try it online!

Nice answer! +1 keep up the good work

50 bytes

Perl 5 -pa, 36 bytes
map{//;map$\+=$_^$',0..$F[0]}0..<>}{

Try it online!
Takes in inputs on separate lines.

Thanks for your Perl 5 submission! Why did you go for Perl 5 and not any other version? Like a more recent version?

@RGS Perl 5 is very different from Perl 6, so much so that the latter has been renamed to Raku to prevent confusion. Perl 5 is what most people refer to as just Perl

Oracle SQL, 126 bytes
This isn't a golfing language and it doesn't have a bitwise XOR operator but:
SELECT SUM(x+y-2*BITAND(x,y))FROM(SELECT LEVEL-1 x FROM T CONNECT BY LEVEL<x+2),(SELECT LEVEL-1 y FROM T CONNECT BY LEVEL<y+2)

Assumes that there is a table T with columns X and Y containing one row that has the input values.
So for the inputs:
CREATE TABLE t(x,y) AS SELECT 5,46 FROM DUAL;

This outputs:

| SUM(X+Y-2*BITAND(X,Y)) |
| ---------------------: |
|                   6501 |

db<>fiddle here

As an aside, its only 81 characters in PostgreSQL:
SELECT sum(a#b)FROM t,generate_series(0,t.x)AS x(a),generate_series(0,t.y)AS y(b)

db<>fiddle here
But its less fun as that has a built-in XOR operator and series generation.

Really cool solution! thanks for it +1

Julia 1.0, 33 bytes
(x,y)->sum(i⊻j for i=0:x,j=0:y)

Try it online!

This Julia answer is really short +1 good job

authors: Bob Jarvis - Слава Україні


text:
Polyglot "Hello world" in Fortran and Lisp
Simple challenge: The code must be both valid Lisp and valid Fortran, and must print out "hello world" in both.
Note: I've sunk about 5 hours into this at this point, I'm not even sure it's possible at this point...
Details:

Must be in a single source file.
Any version of Fortran and any Lisp are allowed (specify which).
Smallest source code (by bytes) satisfying this wins.

Some stuff I've tried so far that might help people:
continue is a no-op in Fortran. So continue; ... will just execute ... in Fortran, and just refer to a variable continue in Lisp. (since ; is a line comment in most lisps). I haven't been able to leverage this into anything useful yet though.

@JoKing yea, you're right.

Possible duplicate of Build a polyglot for Hello World

Taking a pre-existing challenge and arbitrarily restricting the set of languages in which answers are valid does not make a new, non-duplicate challenge.

@pppery I view this as a separate challenge because of how different the syntax is between the two languages. This was also inspired by a harder problem asking for a polyglot between these two specific language, which seemed impossible considering that I wasn't even able to write hello world polyglot between the two.

The hello world polyglot is not helpful too me since I am specifically looking at polyglots between Lisp and Fortran. (As @DeathIncarnate's solution shows, however, this is not as interesting as I initially thought, since his solution makes it trivial to write a polyglot for the two.)

If you would like a specific language answer to a question you can post a bounty on that question.

classic stack exchange

Fortran (GFortran) -ffixed-form, 183 53+12=65 bytes
	;print*,"Hello world!"
	;end
*(print "Hello world!")

Try it online!
Common Lisp, 53 bytes
Try it online!

Damn, that's clever.

I believe single semi-colons work as well, as well as just end instead of end program

@JoKing Yeah, forgot I'd used full end program because I wanted to see if it would ignore post-end stuff

You can drop the space after the comma as well I think

@CoffeeTableEspresso How's that for you? F77 style saving the day.

@DeathIncarnate damn, that's even shorter than my one where I gave up and used -D...

@CoffeeTableEspresso Much as I appreciate it, you may want to wait before accepting. It's only been an hour. Better people than me may yet try and blow this out of the water.

Well, now that this has been closed as duplicate I'll accept it...

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Single Digit Representations of Natural Numbers
Task
Write a program/function that when given a positive integer \$n\$ and a digit \$d\$ which is not 0 outputs a way to represent \$n\$ using only addition, subtraction, multiplication, exponentiation, division, concatenation, parenthesis and the digit \$d\$.
Examples
n =  6, d = 1  =>  (1 + 1) * (1 + 1 + 1)
n =  6, d = 1  =>  1 + 1 + 1 + 1 + 1 + 1
n = 10, d = 1  =>  1 || 1 - 1
n = 12, d = 1  =>  1 || (1 + 1)
n = 64, d = 2  =>  2 ^ (2 + 2 + 2)
n =  1, d = 9  =>  9 / 9

Note: In the examples || represents concatenation
Output Format

Concatenation must be explicit with a separate operator
Output can be a string, list of operations and numbers or a list of lists in place of brackets.
You may choose the precedence of the operators but it must be consistent for all outputs produced by your program/function
Output may be in polish, reverse polish or infix notation but it must be consistent for all outputs produced by your program/function.
You can use custom symbols for representing the digits and operations but the symbols used for representing the digits and operations should be distinct.

Scoring
This is code-challenge, Your score will be
100*B + S

Where B is the number of bytes in the program/function, and S is the sum of the number of times the digit \$d\$ appears in the representation of \$n\$ with the digit \$d\$ as returned by your program/function for all \$n \le 1000\$ and all \$d\$ from 1 to 9
Lowest score wins
Example: if your program is abcd and all representation of \$n\$ returned by your program has 5 occurrences of \$d\$ then its score will be (4 * 100) + (5 * 1000 * 9) = 45400
Rules

Your program/function should run deterministically, so that it always returns the same representation for a given \$n\$ and \$d\$ (and hence always gets the same score).
Your answer must include not only your submission, but also the code you used to calculate the S part of its score. This need not be written in the same language as your submission, and will not be counted towards its byte count. You are encouraged to make it readable.
Your answer must include the precedence of the operators needed to evaluate the outputs produced by your program/function
You must actually run your test program and calculate/verify your score before submitting your entry. If your submission runs too slowly for you to verify its score then it is not qualified to compete, even if you know what its score would be in principle.

Inspired by this video

https://arxiv.org/pdf/1502.03501.pdf

@J42161217 Wow, that looks like an exhaustive list, apart from the fact that this challenge allows concatenation later on (e.g. it lists 21,1 as 11+11-1, when the optimal answer here would be (1+1)||1)

Is the precedence of || after those of + and -?

@a'_' precedence of the operators is up to you but it must be consistent for all outputs produced by your function and should be stated in you submission

Does the / operator represent integer division?

@RootTwo, No it represents fractional division

May we make the precedence of all operators the same?

@EmbodimentofIgnorance, Do you mean that everything will be evaluated left to right if so it is fine

Is reverse polish output acceptable rather than infix notation?

@GuillermoPhillips yes using reverse polish notation is acceptable

Python 3, 210 bytes · 100 + 59045 digits = 80045
def f(n,d):
 m={d:d},
 while{n}-{*m[0]}:m={z:(p[x],o,q[y])for p,q in zip(m,m[::-1])for x in p for y in q for z,o in zip([x+y,x-y,x*y,y<9and x**y,x%y<1and x//y,int(f"{x}{y}")],"+-*^/|")if z>0},*m
 return m[0][n]

Try it online!
Scoring
Scoring goes much faster using this modified version that solves 1 through 1000 all at once:
def f_gen(d):
 m={d:d},
 while 1:yield from m[0].items();m={z:(p[x],o,q[y])for p,q in zip(m,m[::-1])for x in p for y in q for z,o in zip([x+y,x-y,x*y,y<9and x**y,x%y<1and x//y,int(f"{x}{y}")],"+-*^/|")if z>0},*m

def size(expr):
    return 1 if isinstance(expr, int) else size(expr[0]) + size(expr[2])

score = 0
for d in range(1, 10):
    s = set(range(1, 1001))
    for n, expr in f_gen(d):
        if n in s:
            s -= {n}
            score += size(expr)
            print(n, expr)
            if not s:
                break
print(score)

JavaScript (Node.js), Score:  87900 ... 83274  82574
229 bytes x 100 + 59674 digits
Takes input as (d)(n). Returns a string. Uses | for concatenation.
d=>n=>[0,v=[d],F={[d]:d},s={[d]:0}].map(_=>v.map(x=>v.map(y=>[x+y,x-y,x*y,x/y,x**y,[x]+y].map((z,o)=>z<0|z>1e4||z%1?0:(!F[z]&&V.push(+z))|(S=s[x]-~s[y])<s[z]?F[s[z]=S,z]=`(${F[x]+'+-*/^|'[o]+F[y]})`:0)),V=[])&&v.push(...V))&&F[n]

Try it online!
Scoring
Because the golfed version is quite slow, the total score was computed with the following ungolfed version which, given \$d\$, computes the formulas for all \$n\in[1..1000]\$ at once.
Although it works on TIO, the output is too long. So the link below is an example for \$d=9\$.
Try it online!
const OP = ['+', '-', '*', '/', '^', '||'];

function solve(d) {
  let value = [ d ],
      formula = { [d] : d },
      size = { [d] : 0 },
      total = 0;

  for(let i = 0; i < 4; i++) {
    let newValue = [];

    value.forEach(x => {
      value.forEach(y => {
        [0, 1, 2, 3, 4, 5].forEach(o => {
          let v;

          switch(o) {
            case 0: v = x + y; break;
            case 1: v = x < y ? null : x - y; break;
            case 2: v = x * y; break;
            case 3: v = x % y ? null : x / y; break;
            case 4: v = x ** y; break;
            case 5: v = +(x.toString() + y.toString()); break;
          }

          if(v !== null && v <= 10000) {
            let sz = size[x] + size[y] + 1;

            if((formula[v] === undefined && newValue.push(v)) || sz < size[v]) {
              formula[v] = '(' + formula[x] + OP[o] + formula[y] + ')';
              size[v] = sz;
            }
          }
        });
      });
    });
    value.push(...newValue);
  }

  for(let n = 1; n <= 1000; n++) {
    console.log(n, size[n] + 1, formula[n]);
    total += size[n] + 1;
  }
  console.log('-->', total);
  return total;
}

let score = 0;

for(let d = 1; d <= 9; d++) {
  score += solve(d);
}
console.log('Final score:', score);

why is this happening?

@J42161217 Your input is too large.

@J42161217 This gives (((3+(3*3))^3)/3) on my laptop. The number of computed formulas is especially large for $d=3$, so there might be a heap memory overflow on TIO.

-5 bytes by changing concatenation operator to |. Try it online!

@Mukundan Ah, I didn't notice we were allowed to use custom symbols. Thanks for the heads up.

Wren, 107 bytes, score: 138373
Thanks to @Mukundan for the golfing so far!
(This answer was written before @GammaFunction did so.)
Fn.new{|n,d|"%(n)".map{|i|Num.fromString(i)}.map{|i|i<1?[d,-d]:[d]*(i/d).floor+["%(d)/%(d)"]*(i%d)}.join()}

Try it online!

Doesn't handle n with 0 as a digit (e.g.: 601)

@Mukundan In your OP you represent 10 as 1 || 1 - 1. Is 1 ||  allowed?

@GammaFunction, no representing 10 as 1 ||  is not allowed

Zsh, 89 81 75 bytes, score: 135173
(total digit count is 127673)

for c (${(s::)1})(repeat c/$2 s+=($2);repeat c%$2 s+=($2/$2);<<<${s=$2-$2})

Try it online!
(This generates the same operations that @a'_''s method does. I thought of it independently, then saw his score using it, then implemented it.)

You can use custom symbols for representing the digits and operations [...]

We take advantage of that here; concatenation is represented by a newline and addition is represented by space. Concatenation has lower precedence than addition, which has lower precedence than division.
for c (${(s::)1})(          # for each digit c in n
                            # repeat $x expands $x in arithmetic mode
    repeat c/$2 s+=($2)     # append d to $s, c/d times
    repeat c%$2 s+=($2/$2)  # append d/d to $s, c%d times
    <<<${s=$2-$2}           # if $s is still unset, set it to d-d
                            # <<< prints $s, implicitly joined on spaces
)                           # exit the subshell, effectively unsetting $s

Brainfuck, 30 bytes * 100 + 9009000 = 9012000
Uses the fact that n = (d/d)*n:
,>,>+<<->.>.<.<[->>>.<<.>.<.<]

In that program, the character representing division is ASCII 1 and the character representing addition is ASCII 0, so the output isn't very readable.
With this TIO link I include a brief header making the output readable. There is still the minor inconvenience that input are ASCII characters (the link has a new line, ASCII 10, in the input, hence the program prints
9/9+9/9+9/9+9/9+9/9+9/9+9/9+9/9+9/9+9/9

To make 10. If instead you use this interpreter, you can type easier to understand input, using \ to insert the values of the ascii characters, instead of using the ascii characters. So, using \10\57 as input in this program gives the same result as the program on TIO.

How do I input n greater than 256?

@Mukundan unfortunately, you don't. But the program works in theory for any n and d and that is how I computed the score, under that assumption

Charcoal, 150 bytes × 100 + 81773 digits = 96773
⪫Ｅθ§⪪§⪪”}∧⟦NＪgＹＺＧ；|⪫v4⌈-LiςΠg➙∨Ｃ⊕⊙Nψ≧Fδ∨↧↧«3Ｙ!‴2ⅈ⸿⟦⁰J◨(⁴⦄4b¶¤⦄→₂⊞GςＧ⸿≡←ε⭆R？ρq＆Σ<×HJ⁶�⧴Q<"k~3Ｖu⌊+ＬΠ↓1βπt“P³∨Ｒ▶Ａ↓ⅉs▷"«‖κ-σ_←U/Ｖ!Ｕ⊕⁷↙Ｕ3M⁼³ＲＶＶ¤HＱ:”;Ｉη,Ｉι&

Try it online! Link is to verbose version of code. Uses & (low precedence) as concatenation and # to represent the input digit. Explanation: Simply looks up all of the digit patterns in a (compressed) hand-crafted lookup table and concatenates the relevant digits together. Proof of digit count.

I had a look at your lookup table. Do you then recursively use different patterns until you get to the input number? Or how does it work?

@RGS It's exactly as described... let's say you want 64 using 2s, then it would look up the patterns for 6 and 4 in the table, and output them with concatenation, giving #+#+#&#+# i.e. 2+2+2&2+2=6&4=64.

W n, 22 bytes * 100 + 127673 = 129 873
A blatant rip-off of my Wren answer.
☺◘Y╔û çτ◘↑═uon↕I6≡ÿÑ°t

Uncompressed:
1,             % Split number to chunks of 1
  c}           % Construct the list [input]
    ac/*       %   Repeat that input/current times
  c:{          % The list [input,input]
     '/,       % The string input/input
        }      % The list [input/input]
         acm*  %   Repeat that list input%current times
             + % Join these two lists
      |        % If that's the empty list:
  c:_{         %   Yield the list [input,-input]
       M       % Do that for every thing in the input

Explanation and TIO?

Ruby, Score: 127,473 (178 bytes * 100 + 109,673)
->n,d{n.to_s.chars.map{|c|g=d.to_s;c<?1?g+?-+g:(i=c.to_i)==d ?d:(d*d==i)?g+?*+g:i%d<1?([d.to_s]*(i/d))*?+:i>d ?g+?++f[i-d,d]:(i+1==d&&i>1)?g+?-+f[d-i,d]:[d==1?d:g+?/+g]*i*?+}*?|}

Try it online!
This uses | as concatenation. It could also definitely be cleverer. I just kept adding cases to try to minimse the occurences of d.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/