text:
Count the Matchsticks
Most people here are familiar with seven segment displays, which are also used in matchstick puzzles. Below are the digits 0 through 9 and letters a through z, except k,m,t,v,w, written in this format.
 _        _   _         _    _    _    _    _
| |   |   _|  _|  |_|  |_   |_     |  |_|  |_|
|_|   |  |_   _|    |   _|  |_|    |  |_|   _|

 _       _      _  _  _                        _   _      _               _
|_| |_  |   _| |_ |_ |   |_  |   | |   _   _  |_| |_|  _ |_      |_| |_|  _|
| | |_| |_ |_| |_ |  |_| | | | |_| |_ | | |_| |     | |   _| |_| | |   | |_

The challenge here is simple. Given an input string, output the number of matchsticks required to represent that string. If the string contains a character outside of the above representation, ignore it (count it as 0).
For example, for input 53, a total of 10 matchsticks are required, 5 for the 5 and 5 for the 3, so the output is 10.
For input hello a total of 19 matchsticks are required, h (4), e (5), l (3), l (3), o (4), so the output is 19.
For clarity, here are the matchsticks required to build each character:
0 -> 6
1 -> 2
2 -> 5
3 -> 5
4 -> 4
5 -> 5
6 -> 6
7 -> 3
8 -> 7
9 -> 6
a -> 6
b -> 5
c -> 4
d -> 5
e -> 5
f -> 4
g -> 5
h -> 4
i -> 2
j -> 4
l -> 3
n -> 3
o -> 4
p -> 5
q -> 5
r -> 2
s -> 5
u -> 3
x -> 5
y -> 4
z -> 5

Now for the twist, and there are two of them.

The first is that the input is considered case-insensitive. That is, A and a should both count for 6 matchsticks, even though the visual representation looks like an uppercase A.
Your score is your source code run through this algorithm, plus the length of your source code in bytes, lower is better. For example, if your source code was abc123, your score would be 6+5+4+2+5+5 = 27 + 6 = 33. If your source code was #&@()*, your score would be 0 + 6 = 6.

Input/Output Examples
0    -> 6
53   -> 10
111  -> 6
112  -> 9
8888 -> 28
hello -> 19
PPCG  -> 19
Programming Puzzles & Code Golf -> 99
#&()mt!!~ -> 0
*DḌƤÆE%Ḅċ0 -> 16

Rules

If applicable, you can assume that the input/output will fit in your language's native Integer type.
The input and output can be given by any convenient method.
Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
Standard loopholes are forbidden.

T is commonly written as
|_\n|_
(lowercase t)

@12Me21 I had contemplated doing something like that, but I didn't feel it looked close enough to the letter, so I left it out.

What about your letter X (H)? (well, I it doesn't matter now that there's an answer.)

For chars outside [0-9a-z], should we count 0 matchsticks? That's what I understand from Your score is your source code run through this algorithm, plus the length of your source code in bytes.

@EriktheOutgolfer Yes, that's correct.

Python 2, 97 bytes + 237 matches = 334
lambda w:sum(map(('1ir'*2+'7lnu'*3+'4cfhjoy'*4+'235bdegpqsxz'*5+'069a'*6+'8'*7).count,w.lower()))

Try it online!
This works by generating a string where each buildable character appears the same amount of matchsticks required to build that character

One character can be saved with +'069a8'*6+'8') instead of +'069a'*6+'8'*7).

@xbarbie indeed, but that would rise the match count, resulting in +3 points

JavaScript (ES6), 198 (102 bytes + 96 matchsticks)
Saved 5 points thanks to @l4m2
v=>[...v].map(w=>t+=('{w__^_{]|{{_^__^_^w^~]~]^__w_~]~~_^_'[parseInt(w,36)]+v).charCodeAt()%9,t=+[])|t

Try it online!
How?
We use the ASCII code modulo 9 of characters that do not add any penalty to encode the numbers of matchsticks.
 char. | code | modulo 9
-------+------+-----------------
   ~   |  126 |   0
   v   |  118 |   1  (not used)
   w   |  119 |   2
   ]   |   93 |   3
   ^   |   94 |   4
   _   |   95 |   5
   {   |  123 |   6
   |   |  124 |   7

We do not have to worry about the case because parseInt() is case-insensitive.
For characters that do not match [0-9A-Za-z], parseInt() returns NaN and the string lookup results in undefined. Once coerced to a string, "undefined".charCodeAt() returns the ASCII code of "u", which is 117. Conveniently, 117 modulo 9 gives 0 as expected.

v=>[...v].map(w=>t+='~{w__^_{]|{{_^__^_^w^~]~]^__w_~]~~_^_'.charCodeAt(1+parseInt(w,36))%9,t=+[])|t 1 less

Perl 5 with -pF, 95 bytes + 14, 109
eval~"Û£ÔÂ„…ÊÏÉÎÍÍÊÌÊËËÊÊÉÉÈÌÇÈÆÉžÉÊœË›ÊšÊ™Ë˜Ê—Ë–Í•Ë“Ì‘ÌËÊŽÊÍŒÊŠÌ‡Ê†ËÂÐÑÐ˜‚ÒÁ„Ô“œ‚™¿¹"}{
This is equivalent to:
$\+={z506122535445566738796a6b5c4d5e5f4g5h4i2j4l3n3o4p5q5r2s5u3x5y4=~/./g}->{+lc}for@F

but using the ~ operator we can use high-byte characters and avoid a lot of characters without really sacrificing bytes.
Still quite a way off Ton's score, even with assistance!
Try it online!
This solution contains unprintables so here's a reversible hex dump to verify the byte-count:
00000000: 6576 616c 7e22 dba3 d4c2 8485 cacf c9ce  eval~"..........
00000010: cdcd cacc cacb cbca cac9 c9c8 ccc7 c8c6  ................
00000020: c99e c99d ca9c cb9b ca9a ca99 cb98 ca97  ................
00000030: cb96 cd95 cb93 cc91 cc90 cb8f ca8e ca8d  ................
00000040: cd8c ca8a cc87 ca86 cbc2 81d0 d1d0 9882  ................
00000050: d2c1 84d4 939c 8299 908d bfb9 227d 7b    ............"}{

Why the }{ ? Drop it and the -n option. Also you keep forgeting +lc instead of lc() :-)

@TonHospel Goddammit! I even looked through both our posts and I couldn't remember what post I'd seen it on and + doesn't immediately spring to mind! I need n on my machine and forget I can drop it!

Sorry, I misspoke. I meant "drop the }{ and -p" (and replace it by -n if your perl still needs it. It nowadays doesn't count anyways)

@TonHospel I hadn't updated my code to the latest, oops...

Jelly, 42 bytes + 0 matchsticks = 42 points
“ṄḟṭkɗØæ⁶ṡ“£ƈṠ¤żȥṬ}ė$t¿ƬⱮȷ|çƓ’×/ṚṚæ.ċÐ€ØW$

Thanks to @JonathanAllan for -2 points!
Try it online!
How it works
“ṄḟṭkɗØæ⁶ṡ“£ƈṠ¤żȥṬ}ė$t¿ƬⱮȷ|çƓ’

Literals that begin with “ and end with ’ split on “, replace the remaining characters with their 1-based indices in Jelly's code page, then convert from bijective base 250 to integer.
This particular literal encodes
[3096734725226860846495, 211369264881118657055472842435156679693648].

×/ reduces by multiplication, yielding
654554542403034552503005456545545424030345525030054562554563760

(Encoding this integer directly would save 6 bytes, but cost 28 matchsticks.)
ṚṚ reverses twice; the first call promotes an integer to its digit array. This yields
[6, 5, 4, 5, 5, 4, 5, 4, 2, 4, 0, 3, 0, 3, 4, 5, 5, 2, 5, 0, 3, 0, 0, 5, 4, 5, 6, 5, 4, 5, 5, 4, 5, 4, 2, 4, 0, 3, 0, 3, 4, 5, 5, 2, 5, 0, 3, 0, 0, 5, 4, 5, 6, 2, 5, 5, 4, 5, 6, 3, 7, 6, 0]

ċÐ€ØW$ counts (ċ) the occurrences of each (Ð€) character of "A...Za...z0...9_" (ØW) in the input string.
Finally æ. takes the dot product, multiplying each character count by the corresponding cost in matchsticks, then taking the sum.

Use a factorisation of the big number to save one byte and base decompression and modulo instead of D to save another. Try it online

byte ...err point :)

And one more with Ɗ. Thanks!

Jelly, 34 bytes + 3 matches = 37
⁽[ɱ×“®-&]Ṙṙ£⁺ÐĊṂⱮɼ ’‘ḤṚæ.ŒlċÐ€ØWṚƊ

A monadic link accepting a list of characters and returning an integer.
Try it online!
How?
Works in a similar way to Dennis' Jelly answer but took enough effort that I feel it warrants another answer. The core difference is that it lower-cases the input for a cost of three matches (Œl contains an l) which then allows for a much smaller number to be used to create the cost array. The tricky bit was finding a way to construct that number without matches while staying concise.
ØW yields "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" so counting lower-cased input occurrences always starts with 26 zeros. We can reverse this and perform a dot-product with an array of length 37 instead of one of length 63.
⁽[ɱ×“®-&]Ṙṙ£⁺ÐĊṂⱮɼ ’‘ḤṚæ.ŒlċÐ€ØWṚƊ - Link: list of characters
⁽[ɱ                                - literal                                     23913
    “®-&]Ṙṙ£⁺ÐĊṂⱮɼ ’               - literal         136861653160003879166772353166783
   ×                               - multiply  = 3272772712015172762515027281277281879
                    ‘              - increment = 3272772712015172762515027281277281880
                     Ḥ             - double    = 6545545424030345525030054562554563760
                      Ṛ            - reverse (implicit decimal list) -> [0,6,7,3,6,5,4,5,5,2,6,5,4,5,0,0,3,0,5,2,5,5,4,3,0,3,0,4,2,4,5,4,5,5,4,5,6]
                                   -                     (to align with: _ 9 8 7 6 5 4 3 2 1 0 z y x w v u t s r q p o n m l k j i h g f e d c b a)
                                 Ɗ - last four links as a monad:
                         Œl        -   lower-case (the input)
                              ØW   -   word -> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"
                            Ð€     -   map across right:
                           ċ       -     count (right character in lower-cased input)
                                Ṛ  -   reverse (to align with the values as shown above)
                       æ.          - dot-product

Perl 5 -p, 90 64 code + 9 eval harness + 14 matchsticks = 87
Replace the hex codes by their literal 1 byte variant (not UTF-8 as TIO tries to) for the claimed score
eval~"\xdb\xa3\xd4\xc2\x86\xd0\xcf\xd2\xc6\x9e\xd2\x85\xd0\xc9\xcd\xca\xca\xcb\xca\xc9\xcc\xc8\xc9\xc9\xca\xcb\xca\xca\xcb\xca\xcb\xcd\xcb\xcf\xcc\xcf\xcc\xcb\xca\xca\xcd\xca\xcf\xcc\xcf\xcf\xca\xcb\xca\xd0\x8d\x99\x90\x8d\xdf\x93\x9c\xc2\x81\xd0\xd1\xc0\xd0\x98"}{

Try it online!
Code Inside the complemented string:
$\+=y/0-9a-z/625545637665455454240303455250300545/rfor lc=~/.?/g

PHP 176 bytes = 397 score
<?$n="6255456376";$l="065455454240303455250300545";$a=strtolower($argv[1]);for($i=0;$i<strlen($a);$i++)$t+=(is_numeric($a[$i])?$n[$a[$i]]:$l[max((ord($a[$i])-96),0)]);echo$t;

Try it online!

Welcome to PPCG!

SOGL V0.12, 34 bytes + 18 = 52
ā⁄,u{²²z+;W"⁾o∫k9÷│>Γ{σ¬μ┼“'=υ─wι+

Try it Here!
Golfed, but not scoring as much:
0,u{²²z+;W"⁾o∫k9÷│>Γ{σ¬μ┼“8─wι+

Ruby, 125 bytes + 87 matchsticks = 212
->m{v=->w,k{w.scan(/./).map &k};v[m,->t{v["!#&&;&=$(==&;&&;&;#;!$!$;&&#&!$!!&;&",->k{k.ord%11}][t.to_i 36].to_i+(t==?0?6:0)}].sum}

Try it online!
Heavily inspired by Arnauld's Javascript answer.
Normally the cost of declaring a lambda to be used only twice is not worth it, but the matchstick weight of "scanap" in .scan(/./).map changed that. This was a fun challenge!
->m{
  v=->w,k{w.scan(/./).map &k};                # v is a lambda taking a string and a block
  v[m,->t{                                    # Transform each char t of the input:
    v["!#&&;&=$(==&;&&;&;#;!$!$;&&#&!$!!&;&", # Transform each char of this magic string
      ->k{k.ord%11}                           #  into a matchstick count ([0,2,5,5,4,5...])
    ][t.to_i 36]+                             # Parse t as a base 36 index into the counts
    (t==?0?6:0)                               # If t was "0", add 6 matchsticks
  }].sum                                      # Add the counts for all characters
}

R, 112 bytes + 319 matches = 431 score
sum(strtoi(el(strsplit(chartr("0-9a-z","625545637665455454240303455250300545",tolower(scan(,""))),""))),na.rm=T)

Try it online!
Kudos to Giuseppe who came up with this improvement.
Old version, 143 bytes + 454 matches = 597 score
b=el(strsplit(chartr("0123456789abcdefghijlnopqrsuxyz","6255456376654554542433455253545",tolower(readline())),""))
sum(as.numeric(b[b%in%0:9]))

To make the el() function work on TIO, you need to use library(methods).
Gosh dang it, is R verbose!

TIO, for whatever reason, doesn't automatically load the methods package, but since it's a base package, I've always shoved it in the header and don't count it for the byte-count. readline also won't work on TIO since it's not an interactive session. This is definitely golfable, though.

112 bytes + 319 penalty = 431 score

^ needs quotes around input containing spaces, though.

Also, I just started a chatroom for R golfing!! I've seen a lot of answers in R lately by a lot of different users, which is quite encouraging :)

@Giuseppe I think you should post your answer separately. It is different in principle and much superior to mine.

It's really the same approach, just golfed! Using chartr to encode the data was quite brilliant.

MATL, score 166 156
Code length 41 + output for code used as input 115.
'%p#21jgyDT7o?pe}['TIW:qZajk4Y22Y2h&mXz)s

Try it online!

Python 3, 138 + 265 = 403 bytes
k='0123456789abcdefghijlnopqrsuxyz'
m=lambda t:sum([ord(''[k.index(v)])if v in k else 0for v in t.lower()])

Try it online!

Perl 6, 87 bytes + 26 matchsticks = 113
{+[+] (~''.ords~~m:g/\w/)[m:g/<[/..{]-[\W_]>/>>.&{:٣٦(~$_)}]}

Try it online!
Uses some non-ASCII Unicode characters. The lookup table is encoded in a Unicode string:
say ''.ords;
# (625545 637665 455454 240303 455250 300545)

Characters are converted to indices with base-36 conversion using Arabic-Indic numerals:
:٣٦('z'); # is equivalent to
:36('z');

sed, 367 (source code bytes) + 532 (amount of matchsticks for the source code) = 899
s/[^0-9a-jln-suxyz]//Ig;/^$/{s/.*/0/;b};s/.+/&; %1ir %%7lnu %%%4cfhjoy %%%%235bdegpqsxz %%%%%069a %%%%%%8/;:1;s/([^% ])(.+ (%+)[^ ]*\1)/%\3 \2/I;/ ;/!b1;s/;.+//;s/^/,;/;:2;s/(;[^%]*)(%+)/\2\1/;:3;s/,%{10}/%,/;s/^%/,&/;/%{10}/b3;/;.*%/b2;:4;s/,[;,]/,0,/;/,[;,]/b4;s/%{9}/9/g;s/%{8}/8/g;s/%{7}/7/g;s/%{6}/6/g;s/%{5}/5/g;s/%%%%/4/g;s/%%%/3/g;s/%%/2/g;s/%/1/g;s/[^0-9]//g

Try it Online
Multi-line version:
s/[^0-9a-jln-suxyz]//Ig
/^$/{s/.*/0/;b}
s/.+/&; %1ir %%7lnu %%%4cfhjoy %%%%235bdegpqsxz %%%%%069a %%%%%%8/
:1
s/([^% ])(.+ (%+)[^ ]*\1)/%\3 \2/I
/ ;/!b1
s/;.+//
s/^/,;/
:2
s/(;[^%]*)(%+)/\2\1/
:3
s/,%{10}/%,/
s/^%/,&/
/%{10}/b3
/;.*%/b2
:4
s/,[;,]/,0,/
/,[;,]/b4
s/%{9}/9/g
s/%{8}/8/g
s/%{7}/7/g
s/%{6}/6/g
s/%{5}/5/g
s/%%%%/4/g
s/%%%/3/g
s/%%/2/g
s/%/1/g
s/[^0-9]//g

Explanation:
The above script reads standard input line by line (into the pattern space -- the usual "sed way") and, for each line, it outputs the amount of matchsticks necessary to represent all the matchstick-representable characters in that line. The computations for each line of input happen as follows:

s/[^0-9a-jln-suxyz]//Ig

First, we remove every character for which we don't have a corresponding matchstick representation (as given on the question) from the pattern space. That is, we remove every character which isn't either a numeral from "0" to "9", a letter from "a" to "j", "n" to "s", "l", "u", "x", "y" or "z". Uppercase and lowercase letters are treated the same.
/^$/{s/.*/0/;b}

If we end up with an empty pattern space, we print 0 (automatically followed by a newline, like sed always does unless you pass a special flag to it), skip all posterior lines of the script and proceed into next "sed cycle" (i.e., read the next line of input and repeat processing all over again from the first command until there are no more lines of input to be processed).
s/.+/&; %1ir %%7lnu %%%4cfhjoy %%%%235bdegpqsxz %%%%%069a %%%%%%8/

Otherwise, if the pattern space is not empty, we now divide it into two "sub-spaces" separated by a semicolon: first comes the input space, which is initially formed by all characters which weren't removed from the pattern space after the execution of line 1; next comes the semicolon, and after it the map space.
The map space tells us how many matchsticks beside 1 are needed to represent each relevant alphanumeric character. If we want to know how many matchsticks are necessary to represent any alphanumeric character in the map space, we look for the first sequence of contiguous %'s on the left of that character, and the answer will be the number of %'s in that sequence plus 1. So, for example, the number of matchsticks necessary to represent a "b" is 4 + 1 = 5; to represent a "4", 3 + 1 = 4, to represent a "y", 3 + 1 = 4; and so on.
:1
s/([^% ])(.+ (%+)[^ ]*\1)/%\3 \2/I
/ ;/!b1

This is a loop. Now we will replace every character in the input space by the (complete) sequence of %'s whose number indicates the necessary amount of matchsticks to represent that character, and follow that sequence by a white space character (again, uppercase and lowercase letters are given the same treatment). The criterion to determine whether the loop should end is to check whether there's a white space character on the immediate left of the semicolon in the pattern space: if that condition holds, we terminate the loop and continue into the next line.
s/;.+//
s/^/,;/

Those two lines remove the semicolon and everything after it from the pattern space and then insert a comma and a semicolon into the beginning of the pattern space. We now have the pattern space divided once again into two new sub-spaces: the analog result space before the semicolon, and the analog input space after it.
The analog input space is just what we have previously called the "input space", but in a different form: it now contains sequences of %'s separated by white space. The total number of such %'s in the analog input space is the same number of matchsticks necessary to represent the initial input character string, i.e., that number is the result. But we must print that result in decimal notation, not as a sequence of percent signs. The purpose of the analog result space is to hold an analog representation of each digit of the result while we compute that result by summing each contiguous sequence of %'s in the analog input space one by one. The next loop performs that sum:
:2
s/(;[^%]*)(%+)/\2\1/
    :3
    s/,%{10}/%,/
    s/^%/,&/
    /%{10}/b3
/;.*%/b2

First, after label 2, we move the next contiguous sequence of %'s after the semicolon from the analog input space into the immediate left of the semicolon, in the analog result space;
Next, we step into a sub-loop (label 3) which performs the following computations:

If there's a contiguous sequence of ten %'s after a comma in the analog result space, we remove those %'s and put a single % immediately at the left of the comma. To put it simply, this indicates that one of the decimal places in the result has acquired more than 9 units, so we take 10 units away from that decimal place and add 1 unit to the next larger decimal place;
If a "%" is the first character in the pattern space, we insert a new comma immediately before it. This indicates that the sum has reached a value whose decimal representation has one more decimal place on the left than the previous value;
If there are still any contiguous sequence of ten %'s in the analog result space, we go back to label 3 and repeat this process. Otherwise, we exit this sub-loop and step into the next line.

Now, if there is still any "%" in the analog input space (i.e., after the semicolon), it means that there is still some number of matchsticks to be added to the total sum -- so we go back to label 2.

Once the sum is complete, we step into the final loop of the code:
:4
s/,[;,]/,0,/
/,[;,]/b4

Here, we check every pair of characters formed by a comma on the left and either a semicolon or a comma on the right. We replace all such pairs of characters by a "0" inside two commas.
s/%{9}/9/g
s/%{8}/8/g
s/%{7}/7/g
s/%{6}/6/g
s/%{5}/5/g
s/%%%%/4/g
s/%%%/3/g
s/%%/2/g
s/%/1/g

The above piece of code is quite simple: we replace each contiguous sequence of %'s in the analog result space by a decimal digit character which corresponds to the number of %'s in each particular sequence.
s/[^0-9]//g

Finally, we remove every non-numeral character from the pattern space and what remains is the final result in the familiar decimal notation. That value is printed on standard output and the next sed cycle begins, if there are any more input lines to be processed.

C (gcc), 134 bytes + 38 matchsticks = 172
v(t,w)char*t;{t=(w=*t++)?v(t)+(isalnum(w|=w>'@'&w<'['?' ':!w)?")%(('()&*))('(('('%'#&#&'((%(#&##('("[w-=w>'`'?'W':'_'-'/']-'#':!w):w;}

Try it online!

Java 10, 452 432 416 404 score (145 bytes + 259 matches)
k->{int m=0,t;for(var w:k)for(t=m-m;t<'';)m+="1ir 7lnu 4cfhjoy 235bdegpqsxz 069a 8".split(" ")[t++].contains((char)(w|32)+"")?-~t:t-t;return m;}

Explanation:
Try it online.
k->{                   // Method with character-array parameter and int return-type
  int m=0,             //  Result-integer, starting at 0
      t;               //  Index-integer
  for(var w:k)         //  Loop over the input String-array
    for(t=m-m;t<'';)   //   Inner loop over the parts array with index [0,6)
      m+="1ir 7lnu 4cfhjoy 235bdegpqsxz 069a 8".split(" ")[t++]
                       //     If the current part ordered by amount of matches (2-8)
         .contains((char)(w|32)+"")?
                       //     contains the current (lowercase) letter
          -~t          //      Increase the result by the index + 2
         :             //     Else:
          t-t;         //      The result remains the same by adding 0
  return m;}           //  Return the result

Variable names $ραετ are used instead of letters. EDIT: Variable names kmtvw are now used instead, because they can't be formed by matches according to the challenge description.
'' (unprintable) is used instead of 6.
m-m and t-t are used instead of 0.
(char)(w|32)+"" with character-array input used instead of w.toLowerCase() with String-array input.

05AB1E, 30 bytes + 70 matches = 100 score
žLÃlv•Ƶγ¤и©X´≠Ø&c3Íεç•žhA«ykèO

Try it online!

-5 thanks to Emgina

Al = A. You also don't need the }.

AutoHotkey, 148 bytes + 345 matchsticks = 493
This one was a bit of a challenge to shorten.
n:=["1ir","7lnu","4cfhjoy","235bdegpqsxz","09a5",7+1]
Loop Parse,i
{r:=A_LoopField
Loop % n.Length()
{l:=A_Index
if InStr(n[l],r)
u+=l+1
}}
send % u

Python 3, 123 bytes + 65 matches = 188
lambda w,m='',t='',k=ord:sum(~-k((m+t+m+''+t)[k(v)%77])*('/'<v<'{')for v in w)

An unnamed function accepting a string and returning an integer.
Contains many non-printable characters (specifically bytes one to eight).
Try it online!

Charcoal, 48 bytes + 3 = 51
ＩΣＥθ⎇№α↥ιＩ§”)➙⊞←!Σw➙⊙↘⁴↘”⌕α↥ι∧№ＩＸ²φιＩ§”)⧴u↑$◨”Ｉι

Try it online! Link is to verbose version of code. Explanation:
ＩΣＥθ

Loop over the characters of the input, calculating the number of matchsticks of each, then sum the result, convert to string, and implicitly print.
⎇№α↥ι

If it's a letter...
Ｉ§”)➙⊞←!Σw➙⊙↘⁴↘”⌕α↥ι

Look up the number of matchsticks in the compressed string 65455454240303455250300545.
∧№ＩＸ²φι

Else if it appears in the value of 2 ** 1000...
Ｉ§”)⧴u↑$◨”Ｉι

Look up the number of matchsticks in the compressed string 6255456376.

PHP, 98+253=351
for(;$k=ord($argn[$v++]);)$m+=$k>64?_65455454240303455250300545[$k&31]:_6255456376[$k-47];print$m;

Run as pipe with -nr or try it online.


text:
The repetitive byte counter
Your task is to write a non-empty program / function of byte count L, which, when repeated M times, checks whether a given positive integer N is equal to L × M.
You should, in theory, support an arbitrary number of repetitions (an arbitrary positive integer value of M), but it's fine if, due to language limitations, it cannot work over a certain threshold.  Reading the source code of your program or accessing information about it is strictly forbidden.
For providing output, you should choose a consistent value for one of the states (either truthy or falsy) and use any other (not necessarily consistent) possible output for the other state (Discussion).
Your answers will be scored by your initial program's length L (in bytes), with less bytes being better.
Example
Let's say your (initial) program is ABCDE. Then:

ABCDE (1 repetition) should check if the input equals 5.
ABCDEABCDE (2 repetitions) should check if the input equals 10.
ABCDEABCDEABCDE (3 repetitions) should check if the input equals 15. Etc...

The score of this sample code would be 5, as the initial source is 5 bytes long.

Just to clarify: source code of length L concatenated after itself M times should return whether its input N is equal to L*M?

Jelly, 1 byte
’

Output is 0 for a match, non-zero for a non-match.
Try it online!
How it works
This makes advantage of the overly liberal output format. Repeating ’ M times simply decrements the input M times, so the result will be zero if and only if the input is LM, where L = 1.

Oh god I didn't see this coming... (inb4 everyone ports it to other esolangs...)

I did have a 0-byte answer in mind, but, eh, [tag:quine]. :P

My first thought. Beaten by 23 minutes :(

Haskell, 8 bytes
(-8+).id

Try it online!
Like many other answers it returns 0 for truthy and non-0 for falsy by repeatedly subtracting the length of the code from the input number.

I was so close to tinkering to getting to this...

Retina, 21 20 bytes
\d+
*
^$
_
^_{20}

_

Try it online! Just repeat the part in the Code window to see how it handles the multiples.
Gives 0 for the correct multiple and positive integers for everything else.
Explanation
Let's look at the single program first:
\d+
*

This converts a decimal number to unary (using _ as the unary digit).
^$
_

If the string is empty (which can't happen at this point, because the input is guaranteed to be positive), we replace it with a single _.
^_{20}

Now we get rid of the first 20 underscores. Iff the input was 20, this results in an empty string.
_

And finally we count the number of underscores in the result, which is zero iff the input was 20.

Now what happens when we repeat the source code. Since we don't insert a linefeed when joining the programs, the first line will go right at the end of the last line, we get this when the double the program:
\d+
*
^$
_
^_{20}

_\d+
*
^$
_
^_{20}

_

Now instead of counting the underscores, we end up with the following stage:
_\d+
*

This stage does nothing, because there are no more digits in the working string at this point, so the regex can't match.
^$
_

Now this stage becomes relevant. If the input was a smaller multiple of 20, the string has been emptied by the previous copy of the source code. In that case, we turn it into a single underscore, which we know can never be turned into an empty string again by our program. This way we ensure that only the Mth multiple is accepted (and not all multiples up to the Mth).
^_{20}

We remove the first 20 underscores once more. So M repetitions of the source code will remove 20M underscores from the string, if possible.
_

And when we get to the end of the program, we still count underscores so that valid inputs give zero.

x86 32-bit machine code fragment, 1 byte
48                      dec    eax

Input in EAX, output in EAX: 0 for true, non-zero for false.  (Also leaves the ZF flag set for true, unset for false, so you could je  was_equal).  As a "bonus", you don't have to worry about wrapping; 32-bit x86 can only address 4GiB of memory, so you can't make M large enough to wrap all the way around and find 1 == 2**32 + 1 or something.
To make a callable function, append a 0xC3 ret instruction after repeating 0x48 M times.   (Not counted in the total count, because many languages need to repeat just the function body, or an expression, to be able to compete).
Calleable from GNU C with the prototype __attribute__((regparm(1))) int checkeqM(int eax); GNU C's regparm x86 function attribute, like -mregparm, uses EAX to pass the first integer arg.
For example, this complete program takes 2 args, and JITs M copies of the instruction + a ret into a buffer, and then calls it as a function.  (Requires executable heap; compile with gcc -O3 -m32 -z execstack)
/******* Test harness: JIT into a buffer and call it ******/
// compile with gcc -O3 -no-pie -fno-pie -m32 -z execstack
// or use mprotect or VirtualProtect instead of -z execstack
// or mmap(PROT_EXEC|PROT_READ|PROT_WRITE) instead of malloc

// declare a function pointer to a regparm=1 function
// The special calling convention applies to this function-pointer only
// So main() can still get its args properly, and call libc functions.
// unlike if you compile with -mregparm=1
typedef int __attribute__((regparm(1))) (*eax_arg_funcptr_t)(unsigned arg);

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    if (argc<3) return -1;
    unsigned N=strtoul(argv[1], NULL, 0), M = strtoul(argv[2], NULL, 0);

    char *execbuf = malloc(M+1);   // no error checking
    memset(execbuf, 0x48, M);     // times M  dec eax
    execbuf[M] = 0xC3;            // ret
    // Tell GCC we're about to run this data as code.  x86 has coherent I-cache,
    // but this also stops optimization from removing these as dead stores.
    __builtin___clear_cache (execbuf, execbuf+M+1);
     //   asm("" ::: "memory");  // compiler memory barrier works too.

    eax_arg_funcptr_t execfunc = (eax_arg_funcptr_t) execbuf;
    int res = execfunc(N);
    printf("%u == %u  =>  %d\n", N,M, res );
    return !!res;   // exit status only takes the low 8 bits of return value
}

non-PIE executables are loaded lower in virtual memory; can do a bigger contiguous malloc.
$ gcc -g -O3 -m32 -no-pie -fno-pie -fno-plt -z execstack coderepeat-i386.c
$ time ./a.out 2747483748 2747483748   # 2^31 + 600000100 is close to as big as we can allocate successfully
2747483748 == 2747483748  =>  0

real    0m1.590s     # on a 3.9GHz Skylake with DDR4-2666
user    0m0.831s
sys     0m0.755s

$ echo $?
0

 # perf stat output:
       670,816      page-faults               #    0.418 M/sec
 6,235,285,157      cycles                    #    3.885 GHz
 5,370,142,756      instructions              #    0.86  insn per cycle

Note that GNU C doesn't support object sizes larger than ptrdiff_t (signed 32-bit), but malloc and memset do still work, so this program succeeds.
ARM Thumb machine code fragment, 2 bytes
 3802            subs    r0, #2

First arg in r0 and return value in r0 is the standard ARM calling convention.  This also sets flags (the s suffix).  Fun fact; the non-flag-setting version of sub is a 32-bit wide instruction.
The return instruction you need to append is bx lr.
AArch64 machine code fragment, 4 bytes
d1001000        sub     x0, x0, #0x4

Works for 64-bit integers.  Input / output in x0, as per the standard calling convention.  int64_t foo(uint64_t);
AArch64 doesn't have a Thumb mode (yet), so 1 instruction is the best we can do.

Note for anyone else who comes across this: the call to __builtin___clear_cache is only necessary because you're executing memory that you got from malloc. If you got the memory from mmap instead, the optimization doesn't happen.

Yes, gcc happens not to break if you omit __builtin___clear_cache after writing into a mmaped buffer.  But only because gcc doesn't know about mmap(MAP_ANONYMOUS) and considers the stores a possibly visible side-effect that the called function might read.  So it happens to work, but there's no reason not to follow the rules and tell the compiler that some stores are actually used, definitely not dead.

V, 16 (or 1) bytes
Boring answer:
<C-x>

one byte.
Less boring answer:
uÓ^$/0
16Ø^a$

Try it online!
Hexdump:
00000000: 75d3 5e24 2f30 0a31 3601 d85e 1261 240a  u.^$/0.16..^.a$.

I actually wrote this about 5 minutes after the challenge came out. It took me 30 minutes to patch this horrible pile of spaghetti code that I call a language.

Python 3, 27 bytes
int=lambda x,i=int:i(x)-27;

Try it online!
Code repeated twice:
int=lambda x,i=int:i(x)-27;int=lambda x,i=int:i(x)-27;

Try it online!

TI-Basic (83 series), 4 bytes
:Ans-4

Takes input in Ans: for example, you might type 17:prgmCODEGOLF to run this with an input of 17. Prints (and returns in Ans) the value 0 if the input is equal to L × M, and a nonzero value otherwise.
Note that the : is part of the code, so if you are entering this into the program editor, you should see
PROGRAM:CODEGOLF
::Ans-4

if you enter it once and
PROGRAM:CODEGOLF
::Ans-4:Ans-4:An
s-4

if you enter it three times.

Perl 5 -p, 6 bytes
$_-=6;

Try it online!
uses 0 for equal

Also a valid Perl 6 -p solution.

Brachylog, 2 bytes
-₂

Try it online!

Brain-Flak, 24 bytes
({}[(((()()()){}){}){}])

Try it online!
Returns 0 for equal and something else for not equal.
How it works:
({} #pop the top of the stack
  [(((()()()){}){}){}] #subtract 24
) #push the result.

This code run n times will subtract n * 24 from the input, giving 0 only when the input = n*24.

Stax, 1 byte
v

Try it online!

Haskell, 12 bytes
(-)$0
 +12--

Try it online!
Outputs 0 for truthy and some non-zero integer for falsy.
Alternate solution, 12 bytes
id
 .(-)12--

Try it online!

Befunge-98, 15 bytes
]#<@.-&+
>fv
v+

Try it online!
Try it doubled!
Uses 0 for equal and anything else for unequal.
Explanation:
This code repeated many times will look something like this:
]#<@.-&+
>fv
v+]#<@.-&+
>fv
v+]#<@.-&+
>fv
 .
 .
 .
v+]#<@.-&+
>fv
v+

] right turn. Sends the IP down.

> move east. Sends the IP right.

f push a 16.

v move south. Sends the IP down. If this is the last time, Goto step 8.

] right turn. Sends the IP left.

+ add. Adds the 16 to the top of the stack.

v move south. Sends the IP down. Goto step 2.

< move west. Send the IP left.

# skip. jump over the ] and wrap around to the end.

+ add. Adds the 16 to the top of the stack.

& input. Push a number from the user.

- subtract. get the difference of sum we were working on and the input.

. print. Print the result.

@ end.

Lua, 56 46 bytes
a=(a or io.read())-46io.write(a<=0 and a or"")

Outputs a 0 (without a trailing newline) if equal and either nothing or a series of negative numbers (with preceding zero in some cases) if not equal.
Alone: Try it online!
Repeated a bunch of times: Try it online!
Explanation
a=(a or io.read())-46

On the first iteration (when a hasn't been defined yet and is therefore nil), sets a to a number taken from input, otherwise to itself. In both cases, 46 is then subtracted from a.
io.write(a<=0 and a or"")

This just prints a if it is less than (to take care of cases where the input was larger than the total length) or equal to zero, and the empty string otherwise.
-10 bytes for remembering that Lua does conversions between numbers and strings automatically. Whoops.

Pure Bash, 15
Input given as a command-line parameter.  Output as a shell exit code - 1 for TRUE and 0 for FALSE.
(((a+=15)-$1))

Try it online x1
Try it online x2
Try it online x3

Charcoal, 13 bytes
ＰＩ⁼Ｉθ×¹³Ｌ⊞Ｏυω

Try it online! Based on my answer to I double the source, you double the output! Explanation:
         ⊞Ｏυω   Push empty string to predefined empty list
        Ｌ       Take the length
     ×¹³        Multiply by 13
  ⁼Ｉθ           Compare to the input
 Ｉ              Cast to string
Ｐ               Print without moving the cursor

Manages to output 1 for truthy and 0 for falsy. Subsequent repetitions compare the input against 13, 26, 39, 52 etc. but each time the answer is overprinted so only the final answer is seen.

JavaScript ES6, 32 Bytes
((f=k=>n=>n>0?n==k:f(k+32))(32))

if true be 0 and false as others, 31 bytes
(f=k=>n=>n>0?n-k:_=>f(k+_))(31)

console.log([
    ((f=k=>n=>n>0?n==k:f(k+32))(32)) (31),
    ((f=k=>n=>n>0?n==k:f(k+32))(32)) (32),
    ((f=k=>n=>n>0?n==k:f(k+32))(32)) (33),
    ((f=k=>n=>n>0?n==k:f(k+32))(32)) (64),
    ((f=k=>n=>n>0?n==k:f(k+32))(32))((f=k=>n=>n>0?n==k:f(k+32))(32)) (32),
    ((f=k=>n=>n>0?n==k:f(k+32))(32))((f=k=>n=>n>0?n==k:f(k+32))(32)) (63),
    ((f=k=>n=>n>0?n==k:f(k+32))(32))((f=k=>n=>n>0?n==k:f(k+32))(32)) (64),
    ((f=k=>n=>n>0?n==k:f(k+32))(32))((f=k=>n=>n>0?n==k:f(k+32))(32))((f=k=>n=>n>0?n==k:f(k+32))(32)) (96)
]);

MIPS, 4 bytes
Uses $a0 as argument and return value.
0x2084fffc    addi $a0, $a0, -4

MIPS, 8 bytes (using MIPS calling convention)
0x2084fff8    addi $a0, $a0, -8
0x00041021    move $v0, $a0

x86, 5 bytes
This is my first x86 answer so feedback welcome. Uses _fastcall convention with ecx as first argument.
83 e9 05                sub    $0x5,%ecx
89 c8                   mov    %ecx,%eax

Peter Cordes has a 1 byte solution in the comments.

Brainfuck commentary: The hard part is getting brainfuck to return a single value. Otherwise something like this would be easy.
- >,[-<->] < .

Your x86 code fragment would be the same size for 32-bit integers, no need to limit to 8.  But if you used a custom calling convention (arg in AL, retval somewhere else,), you could use the 2-byte AL special encoding sub $4, %al / mov %al, %dl.  Or still return in AL/EAX and then you get Dennis's solution, with dec %eax (1 byte in 32-bit mode).  And yes, custom calling conventions are fine for asm.  It's asm, not just "asm that's easy to call from C"; real code written in asm does use custom calling conventions where it helps, so this is totally justifiable.

ARM's normal calling convention is first arg in r0 which is also the retval, so Thumb sub r0, #2 is 2 bytes.

Note that neither of these are functions: they require a ret at the end of the repeat block before you could call them.  Normally I include the ret in byte counts for my x86 asm answers.  But I think bending the rules here to just the function body makes sense, otherwise many languages can't compete at all.

(nvm, this doesn't leave the retval in %al).  xchg %eax, %ecx / sub $4, %al / xchg %eax, %ecx is 4 bytes, and follows the _fastcall convention.  Using the AL, imm8 and xchg-with-eax short encodings are often helpful for code golf.

@PeterCordes thank you for providing such a detailed response! I was under the impression that some standard calling convention must be followed, otherwise it wouldn't qualify as a function, though as you said actually returning would make this challenge difficult. I also for some reason thought using 32 bit registers would require a 32 bit immediate, but that is probably me reading the instruction reference wrong.

@PeterCordes I do remember seeing that instructions that deal with eax have shorter forms. That's interesting to me. I am used to reading gdb asm output, so passing in in eax is unfamiliar territory.

I usually use objdump -drwC -Mintel to get a hexdump of the machine-code bytes.  add r32, imm8 is also 3 bytes: opcode + ModR/M + imm8.  All instructions that can take an imm32 have an alternative opcode that takes a sign-extended imm8.  See http://felixcloutier.com/x86/ADD.html for example; all the "classic" ALU instructions (but not MOV) that date back to 8086 have all those encodings, including the special AL/AX/EAX ones with no modr/m, just op + imm8/16/32. This answer has examples

And BTW, apparently the Irvine32 library passes an arg in EAX.  So does gcc -mregparm=3.  I don't know why the usual x86 and x86-64 calling conventions avoid that; it's not unusual for functions to want to return their first arg, or a modified copy of their first arg (e.g. strcpy, strchr, or strlen).  Or use a retval as an arg like foo( bar() )

@PeterCordes why not post your 1 byte solution? I think it's great.

I thought it was just an improvement to yours; Dennis already came up with the "idea" of a single-byte dec.  But sure, I decided to write it up, and included a main that calls it from C after JITing a buffer (to make the answer interesting, and to show off  :P, and because I was curious how fast it would run).  Tested for inputs of about 2.6 GiB, above that malloc fails in 32-bit mode.

@PeterCordes do you mind adding the tip about calling conventions here? https://codegolf.stackexchange.com/questions/132981/tips-for-golfing-in-x86-x64-machine-code I've found it to be very useful. Also any other tips should be documented in my opinion

Octave: 23 bytes
+23;[ans,i]((N==ans)+1)

If N = L*M, the expression returns 0+i (i.e. a purely imaginary number), otherwise the expression results in a complex number with a real component.
For a slightly nicer result at the cost of an extra byte:
+24;[ans,-1]((N==ans)+1)

If N = L*M the expression returns -1, otherwise a positive number.
Demo:
N=48;
+24;[ans,-1]((N==ans)+1)                                                 #>> 24
+24;[ans,-1]((N==ans)+1)+24;[ans,-1]((N==ans)+1)                         #>> -1
+24;[ans,-1]((N==ans)+1)+24;[ans,-1]((N==ans)+1)+24;[ans,-1]((N==ans)+1) #>> 23

PS, you can get the same result with +24;if N==ans;-1;end;ans but the bytecount is the same

Vyxal, 1 byte
‹

Try it Online!
Outputs 0 for truthy and something else for falsy.
Port of the other answers, decrements.

JavaScript (ES6), 47 bytes
This is using the same technique as Benoit Esnard in this answer (from I double the source, you double the output!).
Prints 0 if n = 47 * M, or a non-zero value otherwise.
n=prompt(setTimeout`alert(n)`)-47/*
n-=47//*///

Demo for M = 1

n=prompt(setTimeout`alert(n)`)-47/*
n-=47//*///

Demo for M = 2

n=prompt(setTimeout`alert(n)`)-47/*
n-=47//*///n=prompt(setTimeout`alert(n)`)-47/*
n-=47//*///

Brain-Flak, 24 bytes
({}[(((()()()){}){}){}])

Try it online!
Just subtracts 24 from the input.  Outputs 0 for true and anything else for false.
Brain-Flak, 68 bytes
{<>}<>(({}[((((()()()()){}){}()){}){}])<>{})((){[()](<{}<>>)}{}<>{})

Try it online!
This one is more sophisticated it outputs 1 for true and 0 for false.

source: Stack Exchange

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

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

sort: votes


text:
Given a grid, starting at the center and spiraling out, and an ID what is the Position?
Grid:
+---------------+---------------+---------------+---------------+---------------+
| id:  20       | id:  19       | id:  18       | id:  17       | id:  16       |
| pos: (-2, -2) | pos: (-1, -2) | pos: (0, -2)  | pos: (1, -2)  | pos: (2, -2)  |
+---------------+---------------+---------------+---------------+---------------+
| id:  21       | id:  6        | id:  5        | id:  4        | id:  15       |
| pos: (-2, -1) | pos: (-1, -1) | pos: (0, -1)  | pos: (1, -1)  | pos: (2, -1)  |
+---------------+---------------+---------------+---------------+---------------+
| id:  22       | id:  7        | id:  0        | id:  3        | id:  14       |
| pos: (-2, 0)  | pos: (-1, 0)  | pos: (0, 0)   | pos: (1, 0)   | pos: (2, 0)   |
+---------------+---------------+---------------+---------------+---------------+
| id:  23       | id:  8        | id:  1        | id:  2        | id:  13       |
| pos: (-2, 1)  | pos: (-1, 1)  | pos: (0, 1)   | pos: (1, 1)   | pos: (2, 1)   |
+---------------+---------------+---------------+---------------+---------------+
| id:  24       | id:  9        | id:  10       | id:  11       | id:  12       |
| pos: (-2, 2)  | pos: (-1, 2)  | pos: (0, 2)   | pos: (1, 2)   | pos: (2, 2)   |
+---------------+---------------+---------------+---------------+---------------+

Challenge:
Given a grid, starting at the center and spiraling out, and an ID what is the Position in the fewest number of bytes?
f(0) = [0, 0]
f(2) = [1, 1]
f(5) = [0, -1]
f(14) = [2, 0]
f(24) = [-2, -2]

f(id) = [x, y]

Notes:

Grid will always be N x N in size
Position x and y are int32 in size
id is always >= 0

Welcome to PPCG!

Related.

@user202729 - updated.

What is N, and how is that important? I think the grid is infinite?

This is a good challenge, but I think we've had it already: https://codegolf.stackexchange.com/q/87178/20260

@xnor - Bummer. I searched but didn't find that. The only difference is how the spiral is wound up.

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


text:
"Hello, name!";
Challenge
Your challenge is to make a simple program that takes the [input] and formats it as "Hello, [input]!"
Input
Either a function call variable or STDIN, this is the name. Can contain any character, UTF-8, and can be empty - would result in Hello,!. Also newlines in the input are fine -
On a new
line
->
Hello, On a new
line!

Why? Because the challenge is not about if the message makes sense or not, it's about 'how quickly can you format?'.
Output
Hello, !
Example
Here would be a program in CJam:
"Hello, %s!"qae%

lolad -> Hello, lolad!

John Smith -> Hello, John Smith!

this is a
new line ->
Hello, this is a
new line!

<null> -> Hello, !

Winner
The winner is the answer with the shortest bytes, as always.

This appears to mainly be outputting the input, with some extra text added, which is already a challenge. Therefore I have voted to close this question as a duplicate.

Despite their similarities this challenge differs in a non-trivial way from Simple cat program: Simple cat program restricts submissions to full programs while this challenge does not.

Retina, 13 bytes
'!>`^
Hello,

Try it online!
Explanation
^
Hello,

This part prepends the Hello, (and a space) to the input. Then > lets us configure the implicit output of the program and with '! we can append the exclamation mark to the output (basically a generalisation of printing with a trailing linefeed).

pl, 9 bytes
Hello, _!

Try it online!

Java 8, 18 bytes
s->"Hello, "+s+"!"

Try it online.

05AB1E, 8 7 bytes
”Ÿ™, ÿ!

Try it online!

Perl 5, 19 bytes
say"Hello, ",<>,"!"

Try it online!

Elixir, 23 bytes
fn a->"Hello, #{a}!"end

Try it online!
Elixir, 32 bytes
IO.puts"Hello, #{IO.read :all}!"

Try it online!

Add++, 21 bytes
x:"Hello, "
+?
+"!"
O

Try it online!

Japt, 12 bytes
Couldn't think of a simpler solution.
"Hello, {N}!

Try it online!

Compressing the string will save you 2 bytes.

V / vim, 11 bytes
iHello, <esc>A!

<esc> is a literal escape character
Try it online! (V)

AWK, 21 bytes
{print"Hello, "$0"!"}

Try it online!

sed, 15 bytes
s/.*/Hello, &!/

Try it online!

ReRegex, 17 bytes
Trivial and probably as short as it can get.
Hello, (?#input)!

Try it online!

JavaScript, 17 bytes
s=>`Hello, ${s}!`

4, 111 bytes
3.6009960199602996207252062002020200052062009020200152052062012020200252062044520620325207218215217219620335204

Try it online!
Nothing too special going on here. This is just a glorified cat program.

Ruby, 33 bytes
A lambda, accepting a string and returning a string:
->s{"Hello,#{s.size>0?' '+s:s}!"}

Try it online!
Ruby + -p, 16 bytes (not fully compliant)
A full program, which does not support empty inputs (prints nothing) or inputs containing newlines (treats each line as a separate input):
$_="Hello, #$_!"

Try it online!
The fun trick here: when string interpolation is done on a variable name starting with $, the curly braces can be dropped from the normal #{} wrapper.

Haskell, 21 bytes
("Hello, "++).(++"!")

Try it online!


text:
Running gene crossover algorithm
Your task is to accept as input two gene sequences, and a sequence of "cross over points", and return the gene sequence that results from the indicated cross overs.
What I mean by this is, say you have the sequences [A, A, A, A, A, A, A] and [Z, Z, Z, Z, Z, Z, Z], and cross over points of 2 and 5. The resulting sequence would be [A, A, Z, Z, Z, A, A], because:

Cross Here:   V     V
Indices:  0 1 2 3 4 5 6

Genes 1:  A A A A A A A
Genes 2:  Z Z Z Z Z Z Z

Result:   A A Z Z Z A A
              ^     ^

Note that while I'm using letters here for clarity, the actual challenge uses numbers for genes.
The result is the first sequence until a cross over point is encountered, then the result takes from the second sequence until another cross over point is encountered, then the result takes from the first sequence until a cross over point is encountered...
Input:

Input can be any reasonable form. The two sequences can be a pair, with the points as the second argument, all three can be separate arguments, a single triplet of (genes 1, genes 2, cross-points), a map with named keys...

The cross points will always be in order, and will always be inbounds. There won't be duplicate points, but the list of cross over points may be empty.

Gene sequences will always be the same length, and will be non-empty.

Indices can be 0 or 1 based.

Genes will always be numbers in the range 0-255.

It doesn't matter which argument is "genes 1" or "genes 2". In the case of no cross over points, the result can either be either entirely "genes 1" or "genes 2".

Output

Output can be any reasonable form that isn't ambiguous. It can be a array/list of numbers, an array of string numbers, a delimited string of numbers (some non-numeric character must separate the numbers)...

It can be returned or printed to the std-out.

Entries can by full programs or functions.

Test Cases (genes 1, genes 2, cross points) => result:
[0], [1], [0] => [1]
[0, 1], [9, 8], [1] => [0, 8]
[0, 2, 4, 6, 8, 0], [1, 3, 5, 7, 9, 1], [1, 3, 5] => [0, 3, 5, 6, 8, 1]
[1, 2, 3, 4], [5, 6, 7, 8], [] => [1, 2, 3, 4]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 2, 3, 6, 8] => [1, 1, 0, 1, 1, 1, 0, 0, 1, 1]

This is Code Golf.

Your worked example would be a bit clearer if the crossover indices weren't also elements in the sequences.

Fixed. Changed it to A's and Z's. Hope that's clearer.

Jelly, 12 10 bytes
ṁ⁹L‘¤ḣ"ḷ"/

Try it online!
Argument 1: seq1, seq2
Argument 2: cross points (0-indexed)

There was a reason... this does not work for one of the test cases!

Also fails in other scenarios, e.g.

Looks like something like ;⁹ZL‘¤Ṭ+\ịŒDḢ would be required :(

@JonathanAllan I actually managed to find a 12-byte version quite different than what you suggested. :)

@JonathanAllan ...and then I discovered a completely different 10-byte version, checked with both your links and another test case (relax, I did remember to change to 0-based indexing). :D

JavaScript (ES6), 47 45 bytes
Saved 2 bytes thanks to @ETHproductions
Takes input as a triplet [a, b, c] where a and b are the gene sequences and c is the list of 0-indexed cross-points.
x=>x[i=j=0].map(_=>x[(j+=x[2][j]==i)&1][i++])

Try it online!
Commented
x =>                    // given x = [ geneSeqA, geneSeqB, crossPoints ]
  x[i = j = 0]          // initialize i = gene sequence pointer and j = cross point pointer
  .map(_ =>             // for each value in the first gene sequence:
    x[(                 //   access x[]
      j += x[2][j] == i //     increment j if i is equal to the next cross point
    ) & 1]              //   access either x[0] or x[1] according to the parity of j
    [i++]               //   read gene at x[0][i] or x[1][i]; increment i
  )                     // end of map()

I believe you can do something like x[(j+=x[2][j]==i)%2][i++] to save a couple of bytes.

@ETHproductions Thanks! I foolishly tried to add a 3rd variable to keep track of the pointer in x[2] but overlooked this optimization.

Haskell, 58 53 51 45 bytes
(fst.).foldl(\(a,b)p->(take p a++drop p b,a))

The two gene sequences are taken as a pair of lists and the cross points as a second argument.
Try it online!
foldl           -- fold the pair of genes into the list of
                -- cross points and on each step
    \(a,b) p -> -- let the pair of genes be (a,b) and the next cross point 'p'
      (take p a++drop p b,a)
                -- let 'b' the new first element of the pair, but
                --   drop the first 'p' elements and
                --   prepend the first 'p' elements of 'a'
                -- let 'a' the new second element
fst             -- when finished, return the first gene

APL (Dyalog 16.0), 26 bytes
+/a⎕×(~,⊢)⊂≠\d←1@⎕⊢0⍴⍨≢a←⎕

Try it online!
Input is a, c, then b. c is 1 indexed.
How?
a←⎕ - get a.
0⍴⍨≢ - create array of 0s at its length.
1@⎕⊢ - take c and change the 0s to 1s on the indices.
d← - assign to d.
⊂≠\d - expand d with xor to create the selection sequence (0 for a, 1 for b), and enclose.
(~,⊢) - take d and its inverse.
a⎕× - and multiply respectively with inputted b and a.
+/ - sum each pair of elements, yielding the as on 0s and bs on 1s.

⊢0⍴⍨≢ -> ≠⍨ (tip)

@ngn I can't get it to work [tio]

you need a , before 1-element vectors in the input

Python 2, 43 bytes
def f(a,b,l):
 for p in l:a[p:],b=b[p:],a*1

Try it online!
Outputs by modifying the argument a. Instead as a program:
50 bytes
a,b,l=input()
for p in l:a[p:],b=b[p:],a*1
print a

Try it online!

Python 3, 61 60 bytes
f=lambda a,b,c,d=0:c and a[d:c[0]]+f(b,a,c[1:],c[0])or a[d:]

Try it online!
-1 byte from Jonathan Frech
Explanation:
f=lambda a,b,c,d=0:c and a[d:c[0]]+f(b,a,c[1:],c[0])or a[d:]
f=lambda a,b,c,d=0:
 # recursive lambda: a and b are the two lists,
 # c is the crossovers, and d is where to start
                   c and
 # if there is at least one crossover left
 #  then
                         a[d:c[0]]
 #  return the items of the first list from the
 #  starting point up to the first crossover
                                  +f(b,a,c[1:],c[0])
 #  plus the result of the inverted lists with
 #  the remaining crossovers, starting where
 #  the first part left off
                                                    or
 # else
                                                       a[d:]
 #  the first list from the starting point to the end

Possible 60 bytes; assuming that a[d:c[0]]+f(b,a,c[1:],c[0]) will never be false.

Perl 5 -a, 45 40 bytes
Give input in the order "control", "second sequence", "first sequence" as separate lines on STDIN
#!/usr/bin/perl -alp
@{$.}=@F}for(map${$.^=$%~~@1}[$%++],@2){

Try it online!

R,  84 79 bytes
function(G,K){o=G[,1]
m=1:nrow(G)
for(i in K)o[m>=i]=G[m>=i,match(i,K)%%2+1]
o}

Try it online!
Takes input as a matrix of 2 columns and a vector.

J, 24 bytes
4 :'(2|+/\1 x}I.#{.y)}y'

Try it online!
I don't count the f=: chars, because it works equally well as an anonymous function (as demonstrated in a TIO sample)
Note: It doesn't work for empty list of cross over points!
An explicit oneliner, x is the left argument - the list of cross over points, y is the right argument, a two-row table of the sequences.
Explanation:
4 :' ... ' - a dyadic verb
(...)}y - Each atom of operand (...) selects an atom from the corresponding positions of the items of y
#{.y - takes the first sequence and find its length
    #{. 0 2 4 6 8 0,: 1 3 5 7 9 1
6

I. creates a list of zeros with length the argument
   I.6
0 0 0 0 0 0

1 x} changes the items of the rigth argument (a list of zeroes) to 1 at indices indicated by x (the list of cors over points)
   1(1 3 5)}I.6
0 1 0 1 0 1

+/\ running sums of a list
   +/\ 0 1 0 1 0 1
0 1 1 2 2 3

2| modulo 2
   2|+/\ 0 1 0 1 0 1
0 1 1 0 0 1

Assembled:
    0 1 1 0 0 1 } 0 2 4 6 8 0 ,: 1 3 5 7 9 1
0 3 5 6 8 1

SWI-Prolog, 78 bytes
A/B/[0|C]/D:-B/A/C/D. [H|A]/[_|B]/C/[H|D]:-maplist(succ,E,C),A/B/E/D. A/_/_/A.

Usage: Call "Genes1/Genes2/CrossoverPoints/X" where "Genes1", "Genes2", "CrossoverPoints" are bracket-enclosed, comma-separated lists.

Jelly, 13 bytes
ṬœṗÐ€ż/JḂị"ƊF

A dyadic link accepting the (1-indexed) crossover points on the left and a list of the two sequences on the right which returns the resulting list.
Try it online!
How?
ṬœṗÐ€ż/JḂị"ƊF - Link: list, C; list, S     e.g. [2,4,6]; [[0,2,4,6,8,0],[1,3,5,7,9,1]]
Ṭ             - untruth C                       [0,1,0,1,0,1]
   Ð€         - map across S with:
 œṗ           -   partition at truthy indices   [[0],[2,4],[6,8],[0]]  /  [[1],[3,5],[7,9],[1]]
      /       - reduce with:
     ż        -   zip                           [[[0],[1]],[[2,4],[3,5]],[[6,8],[7,9]],[[0],[1]]]
           Ɗ  - last three links as a monad:
       J      -   range of length               [1,2,3,4]
        Ḃ     -   bit (modulo by 2)             [1,0,1,0]
          "   -   zip with:
         ị    -     index into                  [[0],[3,5],[6,8],[1]]
            F - flatten                         [0,3,5,6,8,1]

@Carcigenicate - thanks I just noticed after asking :D

Ḃ: What a useless thing for indexing into a 2-element list. ż/: How useless of a complication, it's cruelly flattened away by a big truck anyway!

Charcoal, 19 bytes
ＡθＡηＥ§θ⁰§§θＬΦ⊕κ№ηλκ

Try it online! Link is to verbose version of code. Takes input as a pair of string gene sequences and a 0-indexed list of crossing points. Explanation:
Ａθ                  Input the pair of gene sequences into `q`
  Ａη                Input the list of crossing points into `h`
    Ｅ§θ⁰            Loop over one of the gene sequences
              κ     Current index
             ⊕      Incremented
            Φ  №ηλ  Intersect implicit range with crossing points
           Ｌ        Take the length
         §θ         Cyclically index into the pair of gene sequences
        §         κ Take the appropriate element of that sequence
                    Implicitly output on separate lines

Alternatively, ⭆ could be subsituted for Ｅ to print the result as a string. Try it online!

C (clang), 79 bytes
*g[2],*c,l,m;f(i,j,k){for(i=j=k=0;i<l;g[0][i++]=g[k][i])m&&c[j]==i?k=!k,j++:0;}

Try it online!
Inputs:
g[0] is gene-sequence 1,
g[1] is gene-sequence 2,
c is cross-over points.
l is length of g[0] and g[1]
m is length of c
All array inputs are arrays of integers with 0-based index.

Outputs:
Output is stored in g[0]
macro a() in footer does pretty-printing of test-cases and result


text:
Print a number that number of times
Example
Input -> 5
Output -> 55555
Input -> 12
Output -> 121212121212121212121212
Criteria
Least number of bytes wins!

Welcome to PPCG! Unfortunately, this challenge has already been asked before. In the future, you can try posting your challenge in the sandbox to get feedback on it before posting it to the main site.

...except that this question is better since it does not ban built-in functions ;p

Try it online! - 1 byte


text:
Minimize Least Used Binary Bits in Fractions
Introduction
For a given rational number r, find a pair of integers p,q so that p/q=r and the number of less used bits in p and q are minimized (details below).
Challenge
A positive rational number r can be expressed as the ratio of two positive integers, r=p/q. The representation is not unique. For each of these representations, both p and q can be expressed in its binary form and the number of 0s and 1s in the representation can be counted (not including leading zeros).
We count the number of appearance of the less appeared digit for both p and q (denoted g(p) and g(q)) and finally define f(p,q)=max(g(p),g(q)).
For example, the number 35 can be written as 35/1 or 175/5, and we convert both the numerator and the denominator to binary. Then we can count
35 -> 100011, 3 zeros, 3 ones. g(35)=min(3,3)=3
 1 ->      1, 0 zero ,  1 one.  g(1)=min(1,0)=0

f(35,1)=max(g(35),g(1))=3.

And for 175/5
175 -> 10101111. 2 zeros, 6 ones. g(175)=min(2,6)=2
  5 ->      101. 1 zero,  2 ones.   g(5)=min(1,2)=1.

f(175,5)=max(g(175),g(5))=2.

Therefore, if we want to minimize f(p,q) while keeping the rate of p/q constant, p=175,q=5 is a better choice than p=35,q=1. An even better choice is p=1015,q=29 since f(1015,29)=1. It is also easy to prove that there are no valid choice that makes f(p,q) equals 0, so this the optimal choice.
Your task is to write a full program or function that computes a choice of (p,q) for a given rational number r such that f(p,q) is minimized (sub-optimal solutions are OK but there are penalties), while keeping the program as short as possible.
Test cases
The outputs are not unique.
Input
Output

63/1
63/1 0

17/9
119/63 1

35/1
1015/29 1

563/1
2815/5 2

You may also wish to see whether you can get an answer without penalty(see below) for 595/1.
Scoring
Your score will be composed of two parts: the code-length and the penalties. The code-length is measured in bytes.
The penalties are calculated by running your program on all test cases in the given test set. For each r in the test set, if your program outputs p,q, you get a penalty of max(f(p,q)-2,0). That is, you get no penalty (nor bounty) for any answer that gives a f value less than or equal to 2.
The final score is calculated by final_penalty*codelength^(1/4), with lower score better.
Test set
The test set for calculating the penalty can be found in this
pastebin.
Basically, it contains all rational numbers which when expressed in reduced fraction p/q has the property 128>p>q (and of course, (p,q) coprime), along with all integers from 128 to 1023(inclusive). The second column in the pastebin are the f(p,q) calculated by a naive method. The final line in the pastebin shows the total penalty of this naive method. It is 2343.
Specs

Input can be given in any reasonable form. For example, a rational if your program supports it, or a tuple or a list of the numerators and denominators in any order (and you should assume them to be coprime). Same flexiblility for output.
You need to output p and q in a reasonable form and also f(p,q) (To avoid 0-byte programs, thanks to @Lynn).
You should be able to score your own program (Thanks for the suggestion by @user202729). So in your answer, please specify all of the following: the final penalty, the code length in bytes, and the score. Only the score needs to be included in the title of your answer.

Sandbox post: deleted

(which naive method?)

Enumerating all cases up to a limit.

There are languages in which the 0-byte program copies input to output. This is a valid answer that scores a perfect score of 0 by the final_penalty*codelength^(1/4) formula, so you might want to tweak it.

Changed to require that f(p,q) be included in the output.

Can I output only the multiplier (p'/p) and f(p',q')?

If I programmed correctly, this program computes the optimal result, and total penalty is 2330, and the largest multiplier is 261599.

Node.js, Score = 7873
This is both naive and rather long...

Code size = 129 bytes
Total penalty = 2336
Score = round(1291/4 * 2336) = 7873

Takes input as [p, q]. Returns [p', q', f(p, q)].
f=(a,r=[k=6e3])=>k--?f(a,(i=Math.max(...a.map(n=>(g=n=>n?g(n>>1,n&1?++o:++z):o<z?o:z)(a=(p=a,n*k),o=z=0))))>r[2]?r:[p,a,i],k--):r

Try it online! for the test cases
or compute the total penalty by processing the whole test set

Alternate version, Score = 8426
A modified version to reach a total penalty of 2330. But it's not worth it...

Code size = 171 bytes
Total penalty = 2330
Score = round(1711/4 * 2330) = 8426

Same I/O format as the main version.
f=(a,r=[k=5e3])=>k--?f(a,(i=Math.max(...a.map(n=>(g=n=>n?g(n>>1,n&1?++o:++z):o<z?o:z)(a=(p=a,n*([7007,7901,16239,32695,130527,261599][k]||k-5)),o=z=0))))>r[2]?r:[p,a,i]):r

Try it online!
It includes some hardcoded values for the highest multipliers. They were found by generating all bitmasks m with up to 32 bits and no more than 5 0's, keeping the values for which m mod p = 0, checking the score of q * m / p and finally doing the same operation with the inverted bitmask of m of the same length (no more than 5 1's with all other bits set to 0).

Julia 0.6, Score = 7702
g(x,b=[bin(x)...])=min(sum(b.=='0'),sum(b.=='1'))
f(a,b)=((r,i)=findmin(map(i->max(g(a*i),g(b*i)),1:10^5));[r,a*i,b*i])

Try it online!
A naive and slow solution. Output of f is [f(p,q),p',q']

Length = 119 bytes
Penalty = 2332
Score = round(119^.25*2332) = 7702

To run this on the test set, I've downloaded the paste bucket as a txt file called results.txt
and removed the last row. I used this code to evaulate the penalty using all cores of my machine:
all_res = open("results.txt","r") do f
    map(row->parse.(Int,split(split(row," ")[1], "/")), readlines(f))
end

addprocs(7)
@everywhere g(x,b=[bin(x)...])=min(sum(b.=='0'),sum(b.=='1'))
@everywhere f(a,b)=((r,i)=findmin(map(i->max(g(a*i),g(b*i)),1:10^5));[r,a*i,b*i])

penalty = @parallel (+) for iter in all_res
    max(f(iter[1],iter[2])[1]-2,0)
end

C++ (GCC), score = 11222

Length: 538 (<-- less verbose than Java)
Penalty: 2330

#import<bits/stdc++.h>
using namespace std;uint32_t f(uint32_t x){int s=__builtin_popcount(x);return min(s,32-__builtin_clz(x)-s);}int i(vector<int>const&a,vector<int>const&b){int i=0,j=0;while(i<a.size()&j<b.size()){if(a[i]==b[j])return a[i];else++(a[i]<b[j]?i:j);}return 0;}int main(){vector<array<vector<int>,6>>T(1024);int p,q,a;for(a=1;a<1024;++a){for(unsigned m=1;m<500000;++m)for(p=f(a*m);p<6;++p)T[a][p].push_back(m);}while(cin>>p>>q){for(a=1;;++a){unsigned m=i(T[p][a],T[q][a]);if(m){cout<<p*m<<' '<<q*m<<' '<<a<<'\n';break;}}}}

Runs in 5 seconds on my machine.
Input format: something like this
2 1
3 1
3 2
4 1
4 3
5 1
5 2

Output format: something like this
2 1 1
3 1 1
3 2 1
4 1 1
4 3 1
5 1 1
5 2 1

(p', q', f(p', q') on each line)

Ungolfed code:
/* the program will not work without END_ANS and END_INPUT being
correctly set but it can be easily calculated by a naive algorithm
END_ANS must be greater than all of the answers,and END_INPUT
must be greater than all of the inputs */
int constexpr END_ANS=6,//<-- according to the naive algorithm
END_INPUT=1024,END_M=4194304;
/* END_M is an parameter to the algorithm. As this gets larger,
the algorithm takes more resource but the answer gets better.
NOTE: (END_INPUT-1) * (END_M-1) must not overflow integer.
*/

static_assert((END_INPUT-1)*(long long)(END_M-1)<4294967296LL);

#include<iostream>
#include<vector>
#include<array>
#include<algorithm>

uint32_t f(uint32_t x){
    uint32_t len=32-__builtin_clz(x),
    sum=__builtin_popcount(x);
    return std::min(sum,len-sum);
}

/**Return a common value between two vectors,or 0 if not found.
The input vectors must be sorted.*/
int intersect(std::vector<int>const&a,std::vector<int>const&b){
    int i=0,j=0;
    while(i<a.size()&j<b.size()){
        if(a[i]==b[j])return a[i];
        else++(a[i]<b[j]?i:j);
    }
    return 0;
}

int main() {
    std::vector<std::array<std::vector<int>,END_ANS>>T(END_INPUT);
    //T[i][f1] = all values of m s.t. f(i*m) <= f1
    for(int i=1;i<END_INPUT;++i){
        for(unsigned m=1;m<END_M;++m)
            for(int fi=f(i*m);fi<END_ANS;++fi)
                T[i][fi].push_back(m);
    }

    // THIS PART IS USED FOR CALCULATING SCORE
    int score=0;

    int p,q;while(std::cin>>p>>q){
        for(int ans=1;;++ans){
            unsigned m=intersect(T[p][ans],T[q][ans]);
            if(m){
                std::cout<<p*m<<' '<<q*m<<' '<<ans<<'\n';

                // THIS PART IS USED FOR CALCULATING SCORE
                score+=std::max(ans-2,0);

                break;
            }
        }
    }

    // THIS PART IS USED FOR CALCULATING SCORE
    std::cerr<<score<<'\n';

}

Note: There are some hardcoded constants in the program (maximum input value, maximum ans, etc.) I assume it's allowed because otherwise most programs can work in 32-bit integer range anyway.
For each (p,q) pair, the program tests all pairs (p×m,q×m) for all m in range [1,MAX_M[ and find the optimal value, in a smart way.
Because the result is the same for MAX_M=500000 and MAX_M=4194304 (the largest value such that all intermediate computations still fit in an uint32_t (unsigned 32-bit integer)), I just use MAX_M=500000 so the program runs faster.
Bash+Jelly script to calculate score:
jelly eun 'ỴḲṛ/VƊ€_2»0S' "'''$(cat result.txt)'''" # <- weird input format

tl;dr: Tested all values of m up to 4194304 (exclusive), best penalty so far = 2330.

I may be able to kill a few more bytes by changing between unsigned, uint32_t and int, but it's not very important anyway.

Extended to 60000000 (6e7) now.

I think I have an idea how to find the optimal solution...

Yes, the optimal value is 2330.

Jelly, 7437

Code size = 10 bytes
Total penalty = 4182
Score = round(101/4 * 4182) = 7437

Takes input as [p, q], returns [f(p, q), [p', q']].
BC,Bḅ1ZṀṂ,

Try it online!
How?
This code simply computes f(p, q) without trying to apply any multiplier.
BC,Bḅ1ZṀṂ, - main link taking [p, q]              --> e.g. [61, 40]
B          - convert to binary                    --> [[1,1,1,1,0,1], [1,0,1,0,0,0]]
 C         - 1-complement                         --> [[0,0,0,0,1,0], [0,1,0,1,1,1]]
   B       - convert to binary again              --> [[1,1,1,1,0,1], [1,0,1,0,0,0]]
  ,        - pair                                 --> [ [[0,0,0,0,1,0], [0,1,0,1,1,1]],
                                                        [[1,1,1,1,0,1], [1,0,1,0,0,0]] ]
    ḅ1     - convert from unary base,             --> [[1, 4], [5, 2]]
             which effectively sums the lists
      Z    - zip, so that number of 0-bits and    --> [[1, 5], [4, 2]]
             number of 1-bits are paired together
       ṀṂ  - maximum of the minimum               --> max(min(1, 5), min(4, 2)) =
                                                      max(1, 2) =
                                                      2
         , - pair with the input to comply with   --> [2, [61, 40]]
             the expected output format

:| TODO convex hull optimization ...

(why don't you S to sum?)

@user202729 There must be a way to have it working with S but I'm not sure how to do it. Applying S on e.g. [[1,1,0,0],[0,0,0,1]] will result in [1,1,0,1], which is not what I want. (Disclaimer: I have little to no experience in Jelly.)

... Either ZS or S€, which doesn't really help.


text:
Golf A Free Lunch
Find a maximally profitable sequence of exchanges given an exchange rate table.

As an example consider the currencies Ariary (your home currency), Baht, Cedi, and Denar where the rate from one to another (after any transaction rate has been levied) is given by the (row, column) entry in the exchange rate table below:
                       TO
       A          B          C          D

   A   0.9999     1.719828   4.509549   0.709929

F  B   0.579942   0.9999     2.619738   0.409959
R
O  C   0.219978   0.379962   0.9999     0.149985
M
   D   1.39986    2.429757   6.409359   0.9999

Obviously exchanging A for A is not a great idea as this desk will happily charge you for doing nothing.
Less obviously, but true with this table, exchanging A for any other currency and then exchanging back again is a loss maker:
via B: 1.719828 × 0.579942 = 0.997400489976
via C: 4.509549 × 0.219978 = 0.992001569922
via D: 0.709929 × 1.39986  = 0.99380120994

However, exchanging A to D then D to B then B back to A does profit (given enough capital not to succumb to rounding):
0.709929 × 2.429757 × 0.579942 = 1.0003738278192194

One could repeatedly take this "free lunch" while the opportunity exists.
But an even more enticing chain exists here, namely A to D then D to C then C to B and finally B back to A:
0.709929 × 6.409359 × 0.379962 × 0.579942 = 1.0026612752037345

Challenge Details
Given an exchange rate table in any reasonable format which fixes the meaning of the home-currency (e.g. 1st row and 1st column are always the home-currency)
(or given such a table and a home-currency index)
find a* maximal arbitrage sequence of exchanges starting and ending with the home currency as indexes into the currency list without repeating the use of any exchange (i.e. a Y->X exchange may follow an X->Y one, but an X->Y may not follow an X->Y).
If no such profitable opportunity exists yield an empty list, or some other result not confusable with an identified opportunity.
- e.g. for the above example (A->D,D->C,C->B,B->A):

using 0-indexing one might return [[0,3],[3,2],[2,1],[1,0]] or [0,3,2,1,0]
using 1-indexing one might return [[1,4],[4,3],[3,2],[2,1]] or [1,4,3,2,1]

Other formats are fine so long as there is no ambiguity.
- One thing to watch out for is that it is possible for the best opportunity to be a single transaction from home->home (a foolish desk). If you decide to go with excluding the home currency index from both ends of the flat option above (i.e. [3,2,1] or [4,3,2]) and an empty list for "no opportunity" then make sure the home->home is not also an empty list.
* If multiple equally profitable valid opportunities happen to exist, return any of them, some of them, or all of them.
The Bellman-Ford algorithm is one way to approach this, but probably not the best suited for golf.
Test Cases
Inputs shown are in the arrangement used in the example, and the results shown use 0-indexing to list the to-currency-indices (when an opportunity exists the home currency is at the trailing end only; no opportunity is an empty list).
[[0.999900, 1.719828, 4.509549, 0.709929],
 [0.579942, 0.999900, 2.619738, 0.409959],
 [0.219978, 0.379962, 0.999900, 0.149985],
 [1.399860, 2.429757, 6.409359, 0.999900]]  ->  [3, 2, 1, 0]

[[0.9999, 1.5645, 0.9048, 1.0929],
 [0.6382, 0.9999, 0.5790, 0.6998],
 [1.1051, 1.7269, 0.9999, 1.2087],
 [0.9131, 1.4288, 0.8262, 0.9999]]  ->  [1, 2, 0]

[[0.9999, 1.4288, 0.8262, 0.9131],
 [0.6998, 0.9999, 0.5790, 0.6382],
 [1.2087, 1.7269, 0.9999, 1.1051],
 [1.0929, 1.5645, 0.9048, 0.9999]]  ->  [1, 2, 3, 1, 0]

[[1.002662, 1.719828, 4.509549, 0.709929],
 [0.579942, 0.999900, 2.619738, 0.409959],
 [0.219978, 0.379962, 0.999900, 0.149985],
 [1.399860, 2.429757, 6.409359, 0.999900]]  ->  [3, 2, 1, 0, 0]

[[1.002662, 1.719828, 4.509549, 0.709929],
 [0.579942, 1.002604, 2.619738, 0.409959],
 [0.219978, 0.379962, 1.003000, 0.149985],
 [1.399860, 2.429757, 6.409359, 1.002244]]  ->  [3, 3, 2, 2, 1, 1, 0, 0]

[[0.9999, 1.4288, 0.8262, 0.9131],
 [0.6998, 0.9999, 0.5790, 0.6382],
 [1.2087, 1.7269, 1.0001, 1.1051],
 [1.0929, 1.4974, 0.9048, 0.9999]]  ->  [1, 2, 2, 0]

[[0.9999, 1.3262, 0.7262, 0.9131],
 [0.6998, 0.9999, 0.5490, 0.6382],
 [1.2087, 1.7269, 0.9999, 1.2051],
 [1.0929, 1.5645, 0.9048, 0.9999]]  ->  [3, 2, 3, 1, 0]

[[0.9999, 1.5645, 0.9048, 0.5790],
 [0.6382, 0.9999, 0.5790, 0.3585],
 [1.1051, 1.7269, 0.9999, 0.6391],
 [1.7271, 2.6992, 1.5645, 0.9999]]  ->  [1, 2, 0]  and/or  [3, 2, 0]

[[0.9999, 1.2645, 0.7048, 0.3790],
 [0.4382, 0.9999, 0.3790, 0.1585],
 [1.0001, 1.5269, 1.0001, 0.4391],
 [1.5271, 2.4992, 1.3645, 0.9999]]  ->  []

[[0.9999, 1.2645, 0.7048, 0.3790],
 [0.4382, 0.9999, 0.3790, 0.1585],
 [0.9999, 1.5269, 1.4190, 0.4391],
 [1.5271, 2.4992, 1.3645, 0.9999]]  ->  [2, 2, 0]

This is code-golf so the shortest solution in bytes wins, but competition should be made intra-language too, so don't let code-golfing languages put you off submitting in your favourite one!

JavaScript (ES6), 122 113 103 bytes
Takes input as a transposed matrix with respect to the format described in the challenge. Returns a string describing the exchanges in (from,to) format.
a=>(g=(s,x=b=0,h='')=>a.map((r,y)=>~h.search(k=`(${x},${y})`)||g(s*r[x],y,h+k),x|s<b||(b=s,p=h)))(1)&&p

First test case: Try it online!
More test cases: Try it online!
Commented
a => (                  // given the exchange rate matrix a[][]
  g = (                 // g = recursive function taking:
    s,                  //   s = current amount of money
    x = b = 0,          //   x = ID of current currency, b = best result so far
    h = ''              //   h = exchange history, as a string
  ) =>                  //
  a.map((r, y) =>       // for each row at position y in a[]:
    ~h.search(          //   if we can't find in h ...
      k = `(${x},${y})` //     ... the exchange key k from currency x to currency y
    ) ||                //   then:
    g(                  //   do a recursive call to g() with:
      s * r[x],         //     s = new amount obtained by applying the exchange rate
      y,                //     x = y
      h + k             //     h = h + k
    ),                  //   end of recursive call
    x | s < b ||        //   if x is our home currency and s is greater than or equal to b
    (b = s, p = h)      //   then set b to s and set p to h
  )                     // end of map()
)(1)                    // initial call to g() with s = 1
&& p                    // return p

Python 2, 143 125 124 bytes
lambda M:g(M)[1]
g=lambda M,s=[],p=1,x=0:max([(p,s)]*-~-x+[g(M,s+[(x,y)],p*M[x][y],y)for y in range(len(M))if(x,y)not in s])

Try it online!
Uses 0-based indexing (0 is the home currency); returns a list of tuples of the exchanges yielding the max payout.
The approach is brute force: via the recursion, we end up visiting every non-edge-repeating path starting at 0 (for n being the number of currencies, this gives a maximum depth of n^2). For the subset of these paths also ending with '0', we maximize the payoff.

Haskell, 175 bytes
e?l|e`elem`l=0|2>1=1
w[]=[]
w l=[maximum l];0!q=[q]
n!c@(v,i,(h,l))=do{j<-[0..3];c:((n-1)!(v*l!!i!!j*(i,j)?h,j,((i,j):h,l)))}
z l=w$filter(\(v,e,_)->v>1&&e==0)$12!(1,0,([],l))

Try it here


text:
Drunkard's Journey Home
Drunkard's Journey Home
In this challenge you are to write a program which simulates a drunkard stumbling his way home from the bar.
Input:
The input will be an adjacency matrix (representing a directed graph) which represents paths the drunkard can take. At each location, the drunkard will choose one path at random (Each option has an approximately equal chance and is independent of prior choices) to follow.
Assume that the drunkard always starts at the bar (first row in the adjacency matrix).
If the drunkard enters a dead-end it can be assumed that he has either made his way home or has been arrested for public intoxication and the program should return his path.
It can be assumed that the graph will always contain at least one dead-end.
It can also be assumed that the drunkard will always be able to exit the bar (the first row will not be all zeroes) and that if the drunkard would be stuck in a location, that the row would be represented by all zeroes.
Output:
The output will be the path the drunkard took in his attempt to make his way home. The values for the locations can be either zero or one indexed.
Examples:
Input
[1,0,1,1]
[0,0,0,0]
[1,0,0,0]
[1,1,1,1]

Possible Outputs
[0,2,0,3,2,0,0,3,1]
[0,3,0,3,1]

Input
[0,1,1,1,0,1]
[1,0,1,0,1,1]
[0,0,0,0,0,0]
[0,0,0,0,0,1]
[1,0,0,0,0,0]
[0,0,0,0,0,0]

Possible outputs
[0,1,5]
[0,5]
[0,1,4,0,2]
[0,3,5]
[0,3,0,1,4,0,5]

Deterministic path:

Input
[0,0,1,0]
[0,0,0,1]
[0,1,0,0]
[0,0,0,0]

Output
[0,2,1,3]

This brings back some student memories... I mean, err, I'm talking about directed graphs, of course! o:-)

Can we take input as an array of strings such as [ '1011', '0000', '1000', '1111' ]?

Is it possible for the bar to be a dead end?  In other words, will the first row ever be all zeroes?  Also, will there ever be a row that only leads to itself, and will we have to detect that as an end condition?  In other words, will there ever be a row i with all zeros except at column i?

I'm just waiting for somebody to write an answer in Taxi

How do you get the last path in the 2nd example?  From my understanding, 0 links to 1,2,3,5, but the last output has it going from 0 to 4

@phflack I think I wasn't thinking very clearly when I was writing them and I wrote half 0 indexed half 1 indexed

Mathematica, 72 bytes
{1}//.{r___,x_}:>{r,x,n=1;Check[RandomChoice[#[[x]]->(n++&/@#)],##&[]]}&

This is a function takes the matrix as an argument and returns a list, and it uses 1-indexing.
The basic idea is to start with
{1}//.

which repeatedly applies the rule that follows to the list {1} until it stops changing. The rule matches the pattern
{r___,x_}:>

which means "a list with zero or more elements called r followed by an element called x." This gives x as the last element in the current list, and we replace the list with
{r,x,<stuff>}

which is the original list with <stuff> appended. The stuff in question is
RandomChoice[#[[x]]->(n++&/@#)]

which takes #[[x]] (the xth element of the input matrix) as a list of weights and maps them to n++&/@#, which is short for Range@Length@# (i.e. {1,2,3,...} with the appropriate length). This will throw an error if the weights are all zero, which is why it's wrapped in a
Check[...,##&[]]

which will return ##&[] if an error message is generated. This is just a fancy way of writing Sequence[], which acts as a "nothing" element ({1,2,Sequence[],3} evaluates to {1,2,3}) and therefore leaves the list unchanged, causing the //. to stop replacing.

R, 72 69 66 bytes
function(m,o=1)while({print(o);any(x<-m[o,])})o=sample(which(x),1)

Try it online!
Takes input as a logical matrix, and prints the 1-based indices to the console.

MATL,15 bytes
1`GyY)ft?th1ZrT

Output is 1-based.
Try it online! First input. Second input. Third input.
Explanation
1          % Push 1: initial value of current row index
`          % Do...while
  G        %   Push input matrix
  y        %   Duplicate from below: pushes copy of current row index
  Y)       %   Get that row
  f        %   Find: push (possibly empty) array of indices of non-zero entries
  t        %   Duplicate
  ?        %   If non-empty
    th     %     Attach a copy of itself. This is needed in case the array
           %     contains a single number n, because then the randsample
           %     function would incorrectly treat that as the array [1 2 ... n]
    1Zr    %     Randsample: pick 1 entry at random with uniform probability
    T      %     Push true
           %   End (implicit)
           % End (implicit). Proceed with a new iteration if the top of the
           % stack is truthy. This happens if the current row had some
           % non-zero entry, in which case true was pushed (and is now
           % consumed). If the current row was all zeros, the top of the stack
           % is an empty array that was produced by the find function, which is
           % falsy (and is also consumed now). In that case the loop is exited,
           % and then the stack contains a collection of numbers which
           % collectively describe the path
           % Implicit display

Perl 5 -a0, 53 51 bytes
Give input matrix as separate tight strings on STDIN
$!/usr/bin/perl -a0
$n=!say$%;$F[$%]=~s:1:($%)=@-if 1>rand++$n:eg&&redo

Try it online!
Damages @F during the loop body but it gets repaired by redo

JavaScript (ES6), 87 bytes
f=(a,y=0)=>[y,.../1/.test(r=a[y])?f(a,(g=_=>r[k=Math.random()*r.length|0]?k:g())()):[]]

Try it online!

Alternate version, 81 bytes
Takes input as an array of binary strings. The maximum supported size is 16x16.
f=(a,y=0)=>[y,...+(r=a[y])?f(a,(g=_=>+r[k=Math.random()*r.length|0]?k:g())()):[]]

Try it online!

Python, 136 bytes
Using zero indexing, assuming randrange has been imported. Takes an input m as the adjacency matrix
113 no imports
s=lambda m,c=0,p=[0],x=0:1 in m[c]and(m[c][x]and s(m,x,p+[x],randrange(len(m)))or s(m,c,p,randrange(len(m))))or p
136 with imports
import random as r;s=lambda m,c=0,p=[0],x=0:1 in m[c]and(m[c][x]and s(m,x,p+[x],r.randrange(len(m)))or s(m,c,p,r.randrange(len(m))))or p

I would recommend to use 136 as your main byte count, as per consensus import statements count towards it.

Ruby, 70 67 65 bytes
f=->m,i=0{m[i].sum<1?[]:m[i][x=rand(m.size)]<1?f[m,i]:[x]+f[m,x]}

Thanks to benj2240 for saving 2 bytes!
Try it online!

You can save a couple bytes with m[i].sum<1?:[]

@benj2240 Wow, I never knew that was possible. Now I realized .sum was introduced in 2.4. I used to do .reduce(0, :+)...

Perl 6, 38 bytes
{0,{.[$^l].grep(?*,:k).roll}...^!*.kv}

Try it online!

Java 10, 135 bytes
m->{var R="0 ";for(int r=0,c,t;;R+=(r=c)+" "){t=0;for(int x:m[r])t+=x;if(t<1)return R;for(t=c=m.length;m[r][c*=Math.random()]<1;)c=t;}}

0-indexed
Explanation:
Try it online.
m->{                   // Method with integer-matrix parameter and String return-type
  var R="0 ";          //  Result-String, starting at "0 "
  for(int r=0,         //  Row-integer, starting at 0
          c,           //  Column-integer
          t;           //  Temp-integer
      ;                //  Loop indefinitely
       R+=             //    After every iteration: Append the result with:
          (r=c)+" "){  //     The current column and a delimiter-space,
                       //     And set the current row to this column at the same time
    t=0;               //   (Re-)set `t` to 0
    for(int x:m[r])    //   Loop over the values of the current row
      t+=x;            //    And add them to `t`
    if(t<1)            //   If the entire row only contained zeroes:
      return R;        //    Return the result
    for(t=c=m.length;  //   Set `t` (and `c`) to the size of the matrix
        m[r][c*=Math.random()]<1;)
                       //   Loop until we've found a 1,
                       //   picking a random column in the range [0,`c`)
      c=t;}}           //    Reset the range of `c` to `t` (the size of the matrix)

Haskell, 123 118 bytes
import System.Random
i#m|sum(m!!i)<1=pure[]|1<2=do{x<-randomRIO(0,length m-1);[i#m,x#m>>=pure.(x:)]!!(m!!i!!x)}
f=(0#)

Try it online!

APL (Dyalog Unicode), 32 34 bytes
t←⎕
{}{s[?≢s←⍸⍵⊃t]}⍣{~0∊t⊃⍨⎕←⍵}1

Try it online!
Takes a nested binary array as input. Outputs each iteration on separate lines.

Python, 97 94 bytes
f=lambda a,i=0,j=0:sum(a[i])and[i]*a[i][j]+f(a[:],(i,j)[a[i][j]],id(a)**7%~-2**67%len(a))or[i]

Try it online!

See this answer for more explanation about the random number generator:
id(a)**7%~-2**67


text:
Find out if this a valid Stack Cats program, in Stack Cats style!
Background
Stack Cats is a reversible esoteric language made by Martin Ender. Each command in Stack Cats is either the inverse of itself (represented as a symmetric character, such as -_:T|), or has its inverse command (represented as the mirror image, such as () {} [] <>). Stack Cats has a strong syntactic requirement that the whole program should be the mirror image of itself. Note that this means any valid Stack Cats program is a natural mirror-image ambigram.
Here is the whole command set of Stack Cats:

Self-symmetric: !*+-:=ITX^_|
Symmetric pairs: () {} [] <> \/

Any other characters are invalid; any input having a character not in the character set above should output false.
The language has additional constraint that () and {} pairs must be always balanced, but for the sake of simplicity, you don't have to check for this condition.
The following are some examples of a valid Stack Cats program (again, note that you don't check for balanced parens):
{[+]==[+]}
[)>^<(]
({T)}|{(T})
<(*]{[:!-_:>}<[<)*(>]>{<:_-!:]}[*)>

These are not:
b<+>d
())(
({[<++<]})

Challenge
Write a program or function that determines if the given string is a valid Stack Cats program. Your code should also be a natural mirror-image ambigram, which means:

Your code should be a mirror image of itself.

Your code may have one or more newlines, as long as the whole code, displayed naturally, is a mirror image of itself.
You can omit or add trailing whitespaces on each line, since it doesn't change the display.
Tab characters are not allowed since they have some ambiguity on display.

Note: your code does not have to be a valid Stack Cats program; it may contain certain extra characters that are not allowed in Stack Cats. (See below for the complete list.)
For example, the following two programs are symmetric (and thus a valid submission), while the third is not:
({bTd})
[<q|p>]
({bTd})
  IXI
({bTd})
IXI

Regarding "mirror symmetry", only Stack Cats-style vertical symmetry is considered (e.g. ({IH}) is not a valid submission, even though it has horizontal mirror symmetry).
Your code can only contain these sets of characters, plus newline:

Self-symmetric: space (0x20) + !"'*+-.8:=AHIMOTUVWXY^_ovwx|
Symmetric pairs: () /\ <> [] bd pq {}

The character set is chosen to be strictly symmetric or self-symmetric when displayed as code on SE.
Input and Output
The input range is any one-line string of printable ASCII characters.
You can choose to take input as a string, a list of chars, or a list of ASCII values.
You can choose to output either:

Any of the truthy/falsy values as defined by the language of your choice

The actual result values may differ between inputs (e.g. output 1 for a truthy input and 2 for another truthy one).
Swapping truthy and falsy values is not allowed.

Any two constant values for true/false respectively

In this case, the result values should exactly be one of the two constant values.

You should specify your input method and output values in your submission.
Winning Condition
This is code-golf, so lowest bytes in each language wins.
Notes

Standard loopholes are forbidden as usual.
Of course you can solve this in Stack Cats, but the catch is that you can't use a flag that allows you to reduce your code size by half. And it's a seriously hard language to pick up. :P

Why sharp # disallowed?

@tsh It's slightly skewed in many fonts, including the code font on SE (at least it's what I see on Chrome).

@DLosc I tried to clarify some points around it. But if you think the description is still unclear, please feel free to edit.

Related. Related.

JavaScript (ES6), 487 467 378 298 292 280 266 264 bytes
Saved 14 bytes thanks to @Bubbler
I=>(V=v=>!I[v]||((T=o=>[[]][+!!A[o]]||[(I[v]!=A[o]||A)[o^o<88/8]]+T(++o))(8-8)==I.pop())*V(++v))(V|(A='(){}[]<>\\/ !*+-:=ITX^_|'))//\\(('|_^XTI=:-+*! \//<>[]{}()'=A)|V)((v++)V*(()qoq.I==(8-8)((o++)T+[[8\88>o^o](A||[o]A=![v]I)]||[[o]A!!+][[]]<=o=T))||[v]I!<=v=V)<=I

Defines an anonymous function that takes an array of chars and returns the desired output. Output is truthy/falsy; usually 1/0, but the empty string gives true.
How?
The most obvious trick is to use //\\ as a center point to comment out the mirrored version of the code. After that, it becomes a game of figuring out the shortest way to solve the problem using only the charset given.
The first issue we run into is the lack of keywords and built-ins. We miraculously still have .pop(), but everything else will have to be done via the allowed operators (which includes a[b] and f(c)), with recursion to emulate loops.
The second issue is the lack of logical operators. Neither & and ? are allowed, which means the only decision-making operator we can use is ||. Therefore, we have to carefully structure our logic to account for this.
The first thing I did was to define a function T that mirrors an individual character. The basic idea is to loop through each character in a string of mirror-able chars, testing each for equality with the given char. If it is equal, we return its mirror—the char at index^1 for (){}[]<>\/, or the char itself for the rest.
The first problem I ran into here was getting either the mirrored char or a falsy value on each iteration. The solution I eventually came up with was (x!=A[o]||A)[o^o<88/8], where x is the input character, A is the mirroring alphabet, and o is the current index. If x is not the same as A[o], this gives true, and the index expression evaluates to undefined; otherwise, the ||A is activated, and we end up getting A[o^(o<11)].
The second problem is how to terminate the recursion. I found that the best way to do this is to simply concatenate the results of every iteration, returning the empty string when the end of A is reached. This presents us with two further problems: converting the undefineds to empty strings, and returning the empty string || something. These can be solved with array abuse: [a]+"" gives the string representation of a, or the empty string if a is undefined. As a bonus, [] is truthy but stringifies to the empty string, so we can conveniently use this as a "truthy empty string".
Now we can use the T function to mirror any single character. We do this recursively, comparing the mirror of I[v++] to I.pop() until the end of the array of chars is reached. We can't use && or & to check if all of the comparisons are truthy, but so use * instead. Multiplying all of these results together gives 1 if every character is the mirror of the one opposite, or 0 if any comparison fails.
And that is basically how this answer works. I probably didn't explain it very clearly, so please ask any questions you may have and point out any mistakes I have made.

U=([A,...H])=>!(V=H.pop())||!(W=([x,...X]=(T="!*+-:=ITX^_|")+"(){}[]<>\\/",[o,...O]=T+")(}{][></\\")=>!x||((o!=A)+(x!=V))*(W(X,O)))()*U(H)//... 280 bytes

@tsh commas are not allowed in the source code, as they are not symmetrical (in the SE code font) and have no mirror (in ASCII, anyway)

sorry, i missed that part.

@tsh I missed it too at first, and spent 20 minutes on a solution only to realize it couldn't be valid :P

Anyway, since you had already posted a JavaScript solution. We do not need another JSF*k solution now... // If I were you,  I would fix this by just compile it to JSF*k...

Starting with o=> should be fine, as I explicitly allowed "list of chars" as an input method.

@Bubbler Thanks, overlooked that possibility.

Stax, 76 70 bytes
:Wx^^MH_=_"{([</!*+-:=ITX^_|":W-!*pq*!-W:"|_^XTI=:-+*!\>])}"_=_HM^^xW:

Run and debug it
Stax is friend of Stack Cats and has internals to generate the later half of a Stack Cats program from the first half. If we don't care about the restriction on the source and don't need to check the charset, here is a 4-byte solution:
4 bytes
:R_=

Run and debug it
Explanation
:Wx^^MH_=_"{([</!*+-:=ITX^_|":W-!*pq...
:W                                         "Mirror" the string
                                           Equivalent to appending the reverse of the string to itself
                                           And map `{([</\>])}` to its mirror in the appended string
  x^^                                      2, but we can't just use `2` here ...
     MH                                    Partition the "mirror"ed string to two parts, take the later part.
       _=                                  The string is the same as the original one (*)
                                           `:Wx^^MH_=` is just `:R_=`, but we can't use `R` here ...
         _                                 Input string
          "{([</!*+-:=ITX^_|":W-           Remove valid characters from input
                                !          The final string is empty (**)
                                 *         (*) and (**)
                                  p        Pop and print result
                                   q       Peek stack and print
                                           Since the stack is now empty, this causes the program to terminate
                                    ...    Not executed

The existence of R and W is really interesting. Program termination by pq combination is also impressive to me.

Thank you. The instructions are actually two bytes: :R and :W. I feel that I can't help telling everyone there are internals in Stax that do this.

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


text:
unRSA: solve the private key
Given positive integer n and e, knowing that e<n and that n is the product of two different odd primes(but the primes are not directly given to you), find such a positive integer d smaller than n that, for each integer m, (me)d ≡ m (mod n).
Your program should handle n up to 24096 in 1TB space, but not necessary reasonable time. You can assume such a d exist.
Sample Input: n=53*61=3233, e=17
Sample output: d=413
Note that your program will not be given the prime factor of n.
Shortest code in bytes win.

Is n given to us via its prime factors as in the sample input? May we assume n is odd?

@xnor Challenge edited.

(now the challenge had been clarified, there is no reason to close as unclear)

Are we guaranteed that e>1?

@xnor Apart from making the problem trivial, is there any other problems with it? May some algorithm only work correctly with e>1 (except one that start brute-forcing at 2, but I don't think that's very special)?

@user202729 No problems, it's was just a corner case for a golfed I was looking it.

For solutions that don't work for some special cases, just make note about that

1 We requires every solutions equally, or, bonuses in code-golf are bad. 2 Because the site is based on [se], having too many poorly-received questions can cause you to be question-banned, while they are not even questions. That's a limit of [se], not PPCG. 3 (about the colliding ball challenge) Putting puzzles (solve an equation) in the challenge is often discouraged, because once the first person post their answer, otherusers can just use that approach. Not to say that puzzles are always bad, however.

Python 3, 77 bytes
def f(n,e):r=range(n);all(any(m-pow(m,e*d,n)for m in r)or print(d)for d in r)

Try it online!
Direct translation of the requirement. any(...) becomes false when the smallest correct d is found, and print(d) returns None, making all(...) stop running.
76 bytes, if unlimited memory is allowed
def f(n,e):r=range(n);all(any(m**(e*d)%n-m for m in r)or print(d)for d in r)

Try it online!

Python 2, 65 bytes
n,e=input()
p=s=1
while n%~p:p+=1
while s%e:s-=p*n/~p+p
print s/e

Try it online!
Finds a prime factor p of n to obtain the order φ(n)=(p-1)(n/p-1). Then, solves the modular equation d * e % φ(n) == 1 by counting up values s of the form s = 1 + c * φ(n) until a multiple of eis obtained. Since all expressions are arithmetical without exponents, only log-space is used.
The code actually uses p to stand for one below the prime to save bytes on initialization.

Python 2, 78 bytes
lambda n,e:pow(e,F(F(n))-1,F(n))
F=lambda n:sum(k/n*k%n==1for k in range(n*n))

Try it online!
A direct expression using Dennis's totient function implementation.

Nope, only for square-free numbers.

Jelly, 5 bytes
Thanks to xnor for -2 bytes! (pointing out ÆṪ, totient function)
ÆṪæi@

Try it online!
Previously I used Æf’Pæi@ at 7 bytes.

Let me check how sympy.ntheory.factor_.factorint and sympy.numbers.igcdex works...

It looks like you're factoring to compute (p-1)(q-1), but would totient function ÆṪ be shorter and memory-efficient enough?

@xnor I searched for "euler" and can only find ÆE. Thanks!

Now I should check this... | No problem, totient uses factorint internally, which uses "trial division, Pollard rho algorithm, or p-1 algorithm", all of them use polynomial memory (if I read correctly).

The Carmichael function Æc should also work if that's any better.

@xnor Which also uses factorint. There are no apparent benefit except the result is smaller.