text:
A083569: Smallest m not occurring earlier such that m+n is prime
Define a 1-indexed sequence as follows:

A083569(1) = 1
A083569(n) where n is an integer greater than 1, is the smallest integer m not occurring earlier such that m+n is a prime number.

Your task is to take in n and return A083569(n).
 n  A083569(n)
 1  1
 2  3
 3  2
 4  7
 5  6
 6  5
 7  4
 8  9
 9  8
10 13
11 12
12 11
13 10
14 15
15 14
16 21
17 20
18 19
19 18
20 17

More testcases can be found here. The original sequence on OEIS can be found here.
This is code-golf. Shortest answer in bytes wins. Standard loopholes apply.

@Mr.Xcoder "Define a 1-indexed sequence as follows"

Haskell, 87 86 83 80 74 69 bytes
Thanks to xnor for suggesting some changes that saved 3 bytes!
f n=[m|m<-[1..],all((>0).mod(n+m))[2..n+m-1],all((/=m).f)[1..n-1]]!!0

Try it online!
I'm new to Haskell, and Haskell golfing, feedback is appreciated!
Explanation
We define a function f n.  We define f n to be the first element !!0 of the list:
[m|m<-[1..],all((>0).mod(n+m))[2..n+m-1],all((/=m).f)[1..n-1]]

Broken down that is:
[m|          # Numbers m
m<-[1..],    # From the integers greater than 0
all          # Forall x
(>0).mod(n+m)# n+m mod x is not zero
[2..n+m-1]   # from the integers from 2 to n+m-1
all          # Forall
((/=m).f)    # when f is applied the result is not m
[1..n-1]     # from the integers from 1 to n-1

Welcome to Haskell golfing! The[2,3..] can just be [2..], counting up by 1 is default. There's a built-in notElem.

@xnor Thanks! I ended up finding a better way around using notElem but the first tip was helpful and I'll make sure to keep that second one in my back pocket.

Looks like your new revision gets f 1 wrong, should be 1.

@xnor Fixed, unfortunately at the cost of 3 bytes.

Jelly, 16 15 bytes
Rɓ²R+⁸ÆPTḟḢṭµ/Ṫ

This assumes A083569(n) ≤ n² (the sequence appears to be growing linearly).
Try it online!
How it works
Rɓ²R+⁸ÆPTḟḢṭµ/Ṫ  Main link. Argument: n

R                Range; yield [1, ..., n].
 ɓ               Begin a dyadic chain with swapped arguments.
            µ/   Reduce the range by that chain.
                 If we call the chain f, this computes f(2,1), then f(3,f(2,1)),
                 then f(4,f(3,f(2,1)), etc.
                 The left argument is an integer k, the right one an array A.
  ²                Square; yield k².
   R               Range; yield [1, ..., k²].
    +⁸             Add k, yielding [1+k, ..., k²+k].
      ÆP           Test each sum for primality.
        T          Truth; get all indices of 1‘s. This finds all m in [1, ..., k²]
                   such that m+k is prime.
         ḟ         Filterfalse; remove all resulting elements that appear in A.
          Ḣ        Head; extract the first remaining result.
           ṭ       Tack; append the extracted integer to A.
                 This computes the first n elements of the sequence.
              Ṫ  Tail; extract the last, n-th element.

Indeed, A083569(n) is at most the nth prime larger than n by its definition, which is at most the 2nth prime, which (for n≥3) is less than 4n*log(n) by results of Rosser–Schoenfeld.

While @GregMartin verified it, it's still a pretty wild assumption to make...

@Challenger5 I prefer "educated guess".

Pyth - 18 17 15 bytes
Thanks to @isaacg for saving me two bytes!
Back on this site, after being busy for a while, will hopefully golf this one further.
esmaYf&-TYP_+Th

Try it online here.

Welcome back to PPCG!

@LeakyNun Thanks :)

-TY is one byte shorter than !/YT, and truthy in the same cases.

You can save another byte by changing +hdT to +Th.

@isaacg, oh does it cast the first element to a list? That's really cool.

x86-64 Assembly, 57 55 bytes
I'm new to golfing, so comments/feedback are appreciated.
Note: this is optimized for machine code length, not for source length.
0: 89 f8 ff cf 74 32 97 89 fe 89 f1 ff c6 89 f0 99
1: f7 f1 85 d2 e0 f7 85 c9 75 ed 89 f9 ff c9 56 29
2: fe 56 57 51 89 fc e8 d3 ff ff ff 59 5f 5e 39 c6
3: e0 ef 96 5e 74 d1 c3

Defines a function, using the standard convention (i.e. return value in eax, first argument in edi, all registers caller-saved except ebx) that takes an unsigned 32-bit integer and returns the smallest m etc.
Source:
    .globl a083569
    // edi = original, probably don't touch
    // esi = candidate prime, if it's not a repeat we return edi-this
a083569:
    mov %edi, %eax
    dec %edi
    jz end
    xchg %eax, %edi
    mov %edi, %esi
primecheck:
    mov %esi, %ecx
    inc %esi
primeloop:
    mov %esi, %eax
    cdq
    div %ecx
    test %edx, %edx
    loopnz primeloop
/* end */
    // if esi isn't prime, then ecx is now one or greater.
    test %ecx, %ecx
    jnz primecheck
    // esi is now our target prime: check if it's not already one
    mov %edi, %ecx
    dec %ecx
    push %rsi   /* we need a flag-safe way to restore this later */
    sub %edi, %esi
chkdup:
    push %rsi
    push %rdi
    push %rcx
    mov %ecx, %edi
    call a083569
    pop %rcx
    pop %rdi
    pop %rsi
    cmp %eax, %esi
    loopne chkdup
/* end loop - chkdup */
    xchg %esi, %eax
    pop %rsi
    je primecheck
/* end outer loop - primecheck */
end:
    ret

Try it online!

C# (.NET Core), 169 bytes
n=>{if(n<2)return 1;var p=new int[n-1];int i=0,j,s;for(;i<n-1;)p[i]=f(++i);for(i=1;;i++){for(j=2,s=i+n;j<s&&s%j++>0;);if(j==s&!System.Array.Exists(p,e=>e==i))return i;}}

Try it online!
By far the most inefficient way to calculate the results, so please refrain from calculating f(n) for n>=30 with this code. The first step is to recursively calculate the values from f(1) to f(n-1) and then proceed to calculate f(n) by searching for the first i such that n+i is prime and i is not in the previous values list.

Python, 194 170 110 bytes
84 bytes saved by Leaky Nun
2 bytes saved by mathmandan
def s(n):
 a=[s(j)for j in range(1,n)];i=1
 while(i in a)|any((i+n)%j<1for j in range(2,i+n)):i+=1
 return i

Defines a function s(n) that takes a number as input and returns A083569(n).
Try it Online

You might consider including this TIO link.

You can use p=lambda n:any(n%i<1for i in range(2,n)) for the primality check.

110 bytes

You can use  bitwise or to save a couple bytes: while(i in a)|any(...

Clojure, 158 155 bytes
#(loop[r[0 1]i 1](if(= i %)(last r)(recur(conj r(nth(for[j(range):when(=((set r)j)(seq(for[k(range 2(+ 1 i j)):when(=(mod(+ 1 i j)k)0)]j)))]j)0))(inc i))))

This might still have some fat, I'm not quite happy with (+ 1 i j) but this was the easiest way to handle base case n = 1 and the rest. ((set r)j) returns nil if j is not in the set, and (seq ()) on an empty list returns nil as well. Calculates n = 1000 in 48 seconds.
Update: removed nil from = check as the code works correctly also without it.

Ruby, 62+8 = 70 bytes
Uses the -rprime flag.
f=->n,o=[]{o<<f[n-1,o]if n>1;Prime.find{|i|i>n&&o|[i-n]!=o}-n}

Try it online!

Husk, 16 bytes
!¡λḟȯṗ+→L¹`-N);1

Try it online!
1-indexed.


text:
Let's learn some soil pH chemistry!
Andrew is a chemist, interested in the acidity of solutions and in agriculture. After months of research (Google is not his friend), he came up with the following table* regarding the human-readable level of acidity in terms of the pH (potential of Hydrogen):

         Denomination        |         pH range
                             |
    -------------------------+-----------------------------
    Ultra acidic             |          below 3.5
    -------------------------+------------------------------
    Extremely acidic         |    between 3.5 and 4.4
    -------------------------+------------------------------
    Very strongly acidic     |    between 4.5 and 5.0
    -------------------------+------------------------------
    Strongly acidic          |    between 5.1 and 5.5
    -------------------------+------------------------------
    Moderately acidic        |    between 5.6 and 6.0
    -------------------------+------------------------------
    Slightly acidic          |    between 6.1 and 6.5
    -------------------------+------------------------------
    Neutral                  |    between 6.6 and 7.3
    -------------------------+------------------------------
    Slightly alkaline        |    between 7.4 and 7.8
    -------------------------+------------------------------
    Moderately alkaline      |    between 7.9 and 8.4
    -------------------------+------------------------------
    Strongly alkaline        |    between 8.5 and 9.0
    -------------------------+------------------------------
    Very strongly alkaline   |          over 9.0

Given a non-negative decimal number representing the pH of a substance, output its Denomination. You can take input and provide output by any standard method. The data types you are allowed to take input with are:

Float
Double
Your language's standard decimal number data type
String

And you must output a String representing the denomination. Built-ins related to chemistry are forbidden (Sorry, Mathematica!).
Approximation Rule: If the pH you receive is between an upper bound of a denomination and the lower bound of the next one (e.g. between 7.8 and 7.9), it gets approximated to the closest value between the two: if the pH ≥ upperBound of the first + 0.5, then it should receive the second denomination, but if the pH < upperBound of the first + 0.5, then it should receive the first one (e.g 7.85 is approximated to 7.9, but 7.84999 is approximated to 7.8). See the test cases for clarifications.
Test Cases:

Input ->  Output

6.40  ->  Slightly acidic
8.399 ->  Moderately alkaline
3.876 ->  Extremely acidic
10.60 ->  Very strongly alkaline
0.012 ->  Ultra acidic
7.30  ->  Neutral
7.85  ->  Moderately alkaline (the approximation rule is applied)
7.849 ->  Slightly alkaline (the approximation rule is applied)
6.55  ->  Neutral (the approximation rule is applied)

This is code-golf, so the shortest valid submission (in bytes) wins!
*Andrew did not come up with that, it was Wikipedia!

Sandbox for those who can see deleted posts.

yeah this doesn't really work with actual acidity levels. anything more acidic than lemon juice is ultra acidic

@DestructibleLemon If lemon juice is Ultra acidic, then Fluoroantimonic acid, that behaves like having −31.3 is a total atomic bomb :))

oh, I see where you went wrong. 3.5 ph is not ultra acidic, but it is ultra acidic if the soil you are growing plants in is 3.5 ph. what I mean is, this table refers to soil ph

@DestructibleLemon That's what this challenge is about: soil pH :)... This is totally what I intended :§

Brownie points for an answer in Python or Swift :)

How isn't [tag:kolmogorov-complexity] suited for this? You must compress the denomination strings...

@Mr.Xcoder if the problem were to print the table, that would be a kolmogorov-complexity problem. But since the problem is to take a number as input and return a string, this is not a kolmogorov-complexity problem (I could be wrong about this, but that's the answer I got on one of my past posts)

@musicman523 Ok, I was really confused

Can you add 3.49 and 9.01 as test cases as the outer limits are differents from the inner ones

Is the input restricted to being a valid value of "your language's standard decimal number data type"?

IMHO there should be a category, like "mapping", for this kind of challenge. It's basically "map elements in this specific set onto this other set".

@immibis  Yes, you are guaranteed that the value is valid

@Mr.Xcoder So if I use Boolfuck again, where the standard data type is a bit, the input can only be 0 or 1 (decimal)?

@immibis I really do not know what to say about this, but I will allow it.

I feel like it should be natural logarithm of hydronium....

Jelly,  77 73  71 bytes
“£RĿÐƭðṚ°ƲṂṾẒ=ʂXḣsịɠ<»Ḳµ,Ṛ;€"“¡D⁺“a&»j“¿<z»W¤ṙ3
×20<“FYeoy³ƓɗʋṆ‘Sị¢⁾. y

A monadic link taking the number and returning a list of characters; or a full program printing the result.
Try it online!
How?
“ ... »Ḳµ,Ṛ;€"“¡D⁺“a&»j“¿<z»W¤ṙ3 - Link 1, name list: no arguments
“ ... »                          - compression of "Ultra Extremely Very.strongly Strongly Moderately Slightly"
       Ḳ                         - split at spaces
        µ                        - monadic chain separation, call that adjectives
          Ṛ                      - reverse adjectives
         ,                       - pair these two lists
              “¡D⁺“a&»           - compression of [" alkaline"," acidic"]
             "                   - zip with:
           ;€                    -   concatenate for €ach
                             ¤   - nilad followed by links as a nilad
                       “¿<z»     -   compression of "Neutral"
                            W    -   wrap in a list
                      j          - join
                              ṙ3 - rotate left by 3: ["Strongly alkaline","Moderately alkaline","Slightly alkaline","Neutral","Slightly acidic","Moderately acidic","Strongly acidic","Very.strongly acidic","Extremely acidic","Ultra acidic","Ultra alkaline","Extremely alkaline","Very.strongly alkaline"]

×20<“FYeoy³ƓɗʋṆ‘Sị¢⁾. y - Main link: number, pH
×20                     - multiply by 20
    “FYeqy³ƓɗʋṆ‘        - code-page indexes = [70,89,101,111,121,131,147,157,169,180]
   <                    - less than? (vectorises)
                        -   i.e.: pH < [3.5,4.45,5.05,5.55,6.05,6.55,7.35,7.85,8.45,9]
                S       - sum
                  ¢     - call last link (1) as a nilad
                 ị      - index into (1-indexed and modular)
                        - ...note that the sum is never 11 or 12, so "Ultra alkaline" and
                        -    "Extremely alkaline" wont be fetched, but that a sum of 0
                        -    fetches "Very.strongly alkaline", as required.
                   ⁾.   - literal list of characters ['.', ' ']
                      y - translate (replace any '.' with a ' ' i.e. for "Very.strongly")
                        - if running as a full program, implicit print

I always enjoy competition between 05AB1E and Jelly... Only 2 bytes away

Jelly beats 05AB1E?!?!

PHP, 199 bytes
foreach([35,9.5,6,5,5,5,8,5,6,5.5]as$l)$p+=$argn*10>=$s+=$l;$p-=$argn==9;echo[Ultra,Extremely,"Very strongly",Strongly,Moderately,Slightly][$p>6?12-$p:$p],[" acidic",Neutral," alkaline"][1+($p<=>6)];

Try it online!

C# (.NET Core), 236 bytes
p=>{var l=new[]{70,89,101,111,121,131,147,157,169,180,280};var a="Ultra,Extremely,Very strongly,Strongly,Moderately,Slighty, acidic,Neutral, alkaline".Split(',');int i=0;for(;p*20>=l[i];i++);return i==6?a[7]:i<6?a[i]+a[6]:a[12-i]+a[8];}

Try it online!
This solution considers that p cannot be greater than 14.

T-SQL, 305 299 bytes
DECLARE @ char(999)=REPLACE(REPLACE(REPLACE(REPLACE('SELECT TOP 1i FROM(VALUES(''Very s$#9&S$#8.4&Moderately#7.8&Slightly#7.3&Neutral'',6.5&Slightly@6&Moderately@5.5&S$@5&Very s$@4.4&Extremely@3.4&Ultra@-1))x(i,j),t WHERE j<a','#',' alkaline'','),'@',' acidic'','),'&','),('''),'$','trongly')EXEC(@)

Input is via a pre-existing table t with DECIMAL(4,1) column a, per our Input/Output rules.
Because of the DECIMAL(4,1) data type, any "approximation rule" rounding takes place when the value is entered into the input table, so doesn't need to be explicitly managed by my code.
After the space-saving REPLACES are performed, this is a simple SQL query joining our input table with our list of values:
SELECT TOP 1 i
FROM(VALUES
    ('Very strongly alkaline',9),
    ('Strongly alkaline',8.4),
    ('Moderately alkaline',7.8),
    ('Slightly alkaline',7.3),
    ('Neutral',6.5),
    ('Slightly acidic',6),
    ('Moderately acidic',5.5),
    ('Strongly acidic',5),
    ('Very strongly acidic',4.4),
    ('Extremely acidic',3.4),
    ('Ultra acidic',-1)
) x(i,j), t
WHERE j<a

I reverse the order so TOP 1 picks the first one less than our input value.
Even this form (after removing line breaks and extra spaces) is pretty good, at 318 bytes. Adding the overhead of the DECLARE, REPLACES AND EXEC only becomes worth it with all the repeated phrases.
EDIT: Save 6 bytes by removing unnecessary ".0" on several values

05AB1E, 81 80 79 77 76 74 bytes
'Äˆ“¢³¿™ly³¾‚Òw““³¾§ÓªÅ“«#Â¦¦’šÉaƒ£’«Š’w¡Îic’«)˜™'wð:I•t{~À•ST+.¥70+20/‹Oè

Try it online!
Test suite
Explanation
'Äˆ                   # push the string "neutral"
“¢³¿™ly³¾‚Òw“         # push the string "slightly moderately strongly veryw"
“³¾§ÓªÅ“              # push the string "strongly extremely ultra"
«                     # concatenate the top 2 items on the stack
 #                    # split on spaces
  Â                   # push a reversed copy
   ¦¦                 # remove the first 2 elements of the copy ("ultra", "extremely")
’šÉaƒ£’«              # append the string "walkaline" to each ("walk"+"a"+"line")
        Š             # move down 2 places on the stack
’w¡Îic’«              # append the string "wacidic" to each ("w"+"acid"+"ic")
        )˜            # wrap stack in a list and flatten
          ™           # title case each
           'wð:       # replace each instance of "w" with a space
I                     # push input
 •t{~À•               # push the base 255 compressed number 920006021
       ST+            # split to list of digits and add 10 to each
          .¥          # undelta (compute increments from 0)
            70+       # add 70 to each
               20/    # divide each by 20
                  ‹   # compute input less than for each
                   O  # sum
                    è # use this to index into list of strings

This is surprisingly long for 05AB1E

Late to the party, but still curious: does anyone directly program in this language (even if only for code golfing) or is this the output of some sort of a "compiler" ?

@avl42: We code directly in this language yes (generally only for golfing of course). I'd hate to see someone use this in production code ;) It is an interpreted language so code you write in this language gets interpreted to python code.

@Emigna I'd say "translated" rather than "interpreted" (it's kind of opposite meaning)

@anatolyg: Yes, you are correct there. I always think interpreted for some reason, probably due to python. It is translated into an interpreted language :)

Would have been better for my sanity, if the line noise were the result of some translation, not the outset ;-)

JavaScript (ES6), 192 189 185 184 bytes
k=>([...'09544474540'].some(n=>(i--,k-=++n)<0,i=7,k=k*10-33.5),'Neutral,Slightly,Moderately,Strongly,Very strongly,Extremely,Ultra'.split`,`[i<0?-i:i]+(i?i>0?' acidic':' alkaline':''))

Test cases

let f =

k=>([...'09544474540'].some(n=>(i--,k-=++n)<0,i=7,k=k*10-33.5),'Neutral,Slightly,Moderately,Strongly,Very strongly,Extremely,Ultra'.split`,`[i<0?-i:i]+(i?i>0?' acidic':' alkaline':''))

console.log(f(6.40))  //  Slightly acidic
console.log(f(8.399)) //  Moderately alkaline
console.log(f(3.876)) //  Extremely acidic
console.log(f(10.60)) //  Very strongly alkaline
console.log(f(0.012)) //  Ultra acidic
console.log(f(7.30))  //  Neutral
console.log(f(7.85))  //  Moderately alkaline
console.log(f(7.849)) //  Slightly alkaline
console.log(f(6.55))  //  Neutral

Retina, 228 bytes
$
.00
\.(.)\.?(.).*
$1$2
.+
$*
1{900,}
VA
1{845,}
STA
1{785,}
MA
1{735,}
SLA
1{655,}
Neutral
1$
1 acidic
1{605,}
SL
1{555,}
M
1{505,}
ST
1{445,}
V
1{350,}
Extremely
1+
Ultra
M
Moderately
V
Very sT
T
trongly
L
lightly
A
 alkaline

Try it online! Link includes test suite. Explanation:
$
.00
\.(.)\.?(.).*
$1$2

Multiply the input by 100 by suffixing a spare decimal point and two zeros then deleting the decimal point and all but two digits after it.
.+
$*

Convert to unary.
1{900,}
VA
1{845,}
STA
1{785,}
MA
1{735,}
SLA

Handle all the alkalis, converting into abbreviations that will be expanded later.
1{655,}
Neutral

Handle neutral.
1$
1 acidic

Anything left must be acidic. (But leave the 1 in case the pH is 0.001)
1{605,}
SL
1{555,}
M
1{505,}
ST
1{445,}
V
1{350,}
Extremely
1+
Ultra

Handle all the acids.
M
Moderately
V
Very sT
T
trongly
L
lightly
A
 alkaline

Expand the abbreviations.

Wow, I think it took a while to golf it down...

Python 2, 202 bytes
-15 bytes thanks to @JonathanAllan
lambda k:'Neutral_Slightly_Moderately_Strongly_Very strongly_Extremely_Ultra'.split('_')[abs(sum(round(k*10)>ord(i)for i in'",27<AINT')+(k>9)-(3.45<k<3.5)-6)]+(' acidic'*(k<6.55)or' alkaline'*(k>=7.35))

Try it online!

You took my brownie points.

Excel, 240 bytes
=CHOOSE((A1<6.55)+(A1<6.05)+(A1<5.55)+(A1<5.05)+(A1<4.45)+(A1<3.5)+(A1>=7.35)+(A1>=7.85)+(A1>=8.45)+(A1>9)+1,"Neutral","Slightly","Moderately","Strongly","Very Strongly","Extremely","Ultra")&IF(A1<6.55," acidic",IF(A1>=7.35," alkaline",""))

Javascript, 222 209 bytes
x=>'Very strongly,Strongly,Moderately,Slightly,Neutral,Extremely,Ultra'.split(',',7,x-=0.049)[x>9?0:x>8.4?1:x>7.8?2:x>7.3?3:x>6.5?4:x>6?3:x>5.5?2:x>5?1:x>4.4?0:x>3.5?5:6]+(x<6.5?' acidic':x>7.3?' alkaline':'')

Still golfing it a little

var f = x=>'Very strongly,Strongly,Moderately,Slightly,Neutral,Extremely,Ultra'.split(',',7,x-=0.049)[x>9?0:x>8.4?1:x>7.8?2:x>7.3?3:x>6.5?4:x>6?3:x>5.5?2:x>5?1:x>4.4?0:x>3.5?5:6]+(x<6.5?' acidic':x>7.3?' alkaline':'')

console.log(f(6.40));
console.log(f(8.399));
console.log(f(3.876));
console.log(f(10.60));
console.log(f(0.012));
console.log(f(7.30));
console.log(f(7.85));
console.log(f(7.849));
console.log(f(6.55));

I don't think you need to assign the function to a variable.

source: Stack Exchange

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

sort: votes


text:
How far away is n to the next power of b?
Let n and b be positive integers larger than 1.
Output the distance from n to the next power of b.
For n=5 and b=3, the next power of 3 from 5 is 9 (3^2 = 9), so the output is 9 - 5 = 4.
For n=8 and b=2, the next power of 2 from 8 is 16 (2^4 = 16), so the output is 16 - 8 = 8. Note that n is a power of 2 in this example.
Testcases:
  n b output
212 2 44
563 5 62
491 5 134
424 3 305
469 8 43
343 7 2058
592 7 1809
289 5 336
694 3 35
324 5 301
  2 5 3

This is code-golf. Shortest answer in bytes wins. Standard loopholes apply.

Jelly,  4  3 bytes
ạæċ

A dyadic link taking n on the left and b on the right and returning the result.
Try it online!
How?
ạæċ - Link: number n, number b | n,b ∈ ℕ
 æċ - ceiling n to the next power of b
ạ   - absolute difference between n and that

Crossed out 4 is still regular 4 ;(

@Uriel But   ;)

tfw your initially initial thought is "oh it's æċ!" instead of "oww this is sooo hard..."

Oh it might not exist in the history, but I did change from a 4 byter. It was æċ_⁸

@JonathanAllan Since it wasn't in the history it didn't make sense and that's why I edited that out.

x86-64 Assembly (Windows x64 Calling Convention), 14 13 bytes
An inefficient (but svelte!) iterative approach (with credit to @Neil for inspiration):
               HowFarAway PROC
6A 01             push   1
58                pop    rax         ; temp = 1
               Loop:
0F AF C2          imul   eax, edx    ; temp *= b
39 C8             cmp    eax, ecx
72 F9             jb     Loop        ; keep looping (jump) if temp < n
29 C8             sub    eax, ecx    ; temp -= n
C3                ret                ; return temp
               HowFarAway ENDP

The above function takes two integer parameters, n (passed in the ECX register) and b (passed in the EDX register), and returns a single integer result (in the EAX register). To call it from C, you would use the following prototype:
unsigned HowFarAway(unsigned n, unsigned b);

This is limited to the range of a 32-bit integer. It can be easily modified to support 64-bit integers by using the full long registers, but it would cost more bytes to encode those instructions. :-)

So, you can't set eax to 1 in fewer than 4 bytes?

Hmm… Not in any of the normal ways that a sane programmer would use, but you could push 1+pop rax in only 3 bytes. But… then you wouldn't have to skip the multiplication, so that would still be a reasonable savings because you could drop the jmp.

Ah, I knew there had to be a way to golf a byte off!

You can do the same with the SysV calling convention on Linux, with a TIO demo.

Of course you can. You can do it with any calling convention that passes at least the first two integer parameters in registers. System V, Win x64, Win32 __fastcall, etc. The registers just change, and I had to pick one. Coin came up "Windows".

Dyalog APL, 10 bytes
2 bytes saved thanks to @ZacharyT
⊢-⍨⊣*1+∘⌊⍟

Try it online!
Takes n as right argument and b as left argument.
Calculates b⌊logbn + 1⌋ - n.

Nice, I was just about to post this exact solution

@KritixiLithos I had hard time with the floor trick. you think it could be made into a train?

Yeah, it can: ⊣-⍨⊢*1+∘⌊⍟⍨.

@ZacharyT nice one!

I get ⊢-⍨⊣*1+∘⌊⍟ for 10 bytes but with swapped arguments so that n is the right argument and b is the left argument. I used ZacharyT's trick of 1+∘⌊ to get it down this far.

@KritixiLithos I was just about to update this with the same one

I was just about to comment the same thing!

@Jenny_mathy to handle cases where the number is an exact power of the base, like n=8 b=2. using ceiling would find 8-8 instead of 16-8.

Good job. Nice teamwork.

C (gcc), 39 35 bytes
New undefined behavior thanks to Erik
f(n,b,i){for(i=b;b<=n;b*=i);n=b-n;}

Try it online!

f(n,b,i){for(i=b;b<n;b*=i);n=b-n;} saves 5 bytes, and is supported by gcc

@EriktheOutgolfer why not b-=n?

@LeakyNun Because it's the first argument you need to save the return value to.

Umm, you didn't update the code.

Can you do b-=n if you swap the order of b and n?

R, 38 34 bytes
pryr::f({a=b^(0:n)-n;min(a[a>0])})

Anonymous function. Stores all values of b to the power of everything in the range [0,n], subtracts n from each, subsets on positive values, and returns the min.
TIO has a non-pryr version, called as f(n,b); this version needs to be called as f(b,n).
Saved 4 bytes thanks to Jarko Dubbeldam, who then outgolfed me.
Try it online!

Nice, way shorter than the recursion I had in mind.

pryr::f({a=b^(0:n)-n;min(a[a>0])}) is a few bytes shorter.

Thanks. I've had bad luck using pryr::f when I define a new variable in the function; looks like it works here.

Hmm, it's always worth checking :) What annoys me is if you have something like sapply(x, sum) or whatever, that it adds sum to the arguments.

Cubix, 24 20 bytes
-4 bytes thanks to MickyT
Pwp.I|-.;)^0@O?|uq;<

Reads in input like n,b
Fits on a 2x2x2 cube:
    P w
    p .
I | - . ; ) ^ 0
@ O ? | u q ; <
    . .
    . .

Explanation:
I|I0 : read the input, push 0 (counter) to the stack
^w puts the IP to the right place for the loop:

Pp- : compute b^(counter), move n to top of stack, compute b^(counter) - n
? : turn left if negative, straight if 0, right if positive

Positive: O@ : output top of stack (distance) and exit.
Negative : |? : proceed as if the top of the stack were zero

<;qu;) : point the IP in the right direction, pop the top of the stack (negative/zero number), move n to the bottom of the stack, u-turn, pop the top of the stack (b^(counter)) and increment the counter
IP is at ^w and the program continues.

Watch it online!
Try it online!

Using your same procedure, just a different path Pwp.I|-.;)^0@O?|uq;<

@MickyT genius! I feel like every time I submit a cubix answer, you come along and shave off four or five bytes...

Haskell, 20 bytes
n%b=until(>n)(*b)1-n

Try it online!
until saves the day

Augh, I knew there must have been a builtin for that. Nice.

R, 30 bytes
pryr::f(b^floor(log(n,b)+1)-n)

Evaluates to the function
function (b, n)
b^floor(log(n, b) + 1) - n

Which takes the first power greater or equal than n, and then substracts n from that value.
Changed ceiling(power) to floor(power+1) to ensure that if n is a power of b, we take the next power.

1 byte shorter using %/%1 instead of floor()

AWK, 34 32+2 bytes
{for(n=$2;n<=$1;n*=$2);}$0=n-$11

Try it online!
Requires the -M option for arbitrary precision to handle the 12345678901234567890 1000000 => 999987654321098765432110 case.
The non-loop version requires the same number of bytes:
$0=$2^int(log($1)/log($2)+1)-$1

After almost 5 years, saved 2 bytes in each formulation by removing unnecessary grouping symbols. Thanks @PaoloVlw

Aahhh... I see that I may not need the 2 bytes for the "large" answer, since I accidentally grabbed Toby Speight's inputs rather than the original inputs.  Oh well. This should allow it to work for all cases.

These save both versions 2 bytes each: {for(n=$2;n<=$1;n*=$2);}$0=n-$1 and $0=$2^int(log($1)/log($2)+1)-$1.

@PauloVlw It's nice to know that someone is still interested in AWK. :)

05AB1E, 9 8 bytes
sLmʒ‹}α¬

Try it online!
Explanation
s         # swap order of the inputs
 L        # range [1 ... n]
  m       # raise b to each power
   ʒ‹}    # filter, keep only the elements greater than n
      α   # calculate absolute difference with n for each
       ¬  # get the first (smallest)

You beat me by a minute. That's exactly what I wrote, but I used ć instead of ¬.

@Riley: Also works with filter, but unfortunately doesn't save any bytes.

@Emigna unfortunately doesn't save any bytes *saves byte(s)*

@EriktheOutgolfer: Yes, well. It was an additional change utilizing the weird way implicit input works that saved a byte :)

Do the inputs have to be in that order?

@carusocomputing: Yes. It actually saves a byte to have them in the "wrong" order as I can reuse n implicitly, both in the filter comparison and the absolute difference calculation.

MATL, 10 9 bytes
yy:YAn^w-

Try it online!
Explanation
Consider inputs 694 and 3 as an example.
y    % Implicitly take two inputs. Duplicate from below
     % STACK: 694, 3, 694
y    % Duplicate from below
     % STACK: 694, 3, 694, 3
:    % Range
     % STACK: 694, 3, 694, [1 2 3]
YA   % Base conversion (of 694 with "digits" given by [1 2 3]
     % STACK: 694, 3, [3 3 2 3 1 2]
n    % Number of elements
     % STACK: 694, 3, 6
^    % Power
     % 694, 729
w    % Swap
     % STACK: 729, 694
-    % Subtract. Implicitly display
^    % 35

C, 42 40 bytes
Thanks to commenter @Steadybox for the tip
o;p(n,b){for(o=b;n>=b;)b*=o;return b-n;}

Using for instead of while saves two bytes: o;p(n,b){for(o=b;n>=b;)b*=o;return b-n;}

Suggest n/b instead of n>=b

Mathematica, 24 bytes
#2^⌊1/#~Log~#2⌋#2-#&

thanks Martin
I/O

[343, 7]
2058

You can use 1/Log@## or #2~Log~#. Or even better swap the order of the inputs and use Log@##.

And then #^Floor[...]# is shorter than #^(Floor[...]+1). And there's the Unicode operators for Floor as well.

yes, yes of course.I'm working on all these.you are quick!

Don't forget Log@##! Actually, if you swap the argument order, #^⌊Log@##⌋#-#2& should be possible for -5 bytes (I think)!

Java (OpenJDK 8), 42 bytes
Based on @GovindParmar's C answer.
n->b->{for(int o=b;n>=b;b*=o);return b-n;}

Try it online!

Python 2,  42 41  35 bytes
Saved 6 thanks to loopy walt! (A superior recursive algorithm.)
f=lambda n,b:n<1or b*f(n/b,b)-(n%b)

A recursive function which repeatedly integer divides by b until that yields 0 (n<1) yielding 1 (well, True which works like 1) at the tail and multiplies back up by b removing the remainder after division by b at each step. That is, we subtract n from b^k in base b, "digit" by "digit".
Try it online!

https://tio.run/##Jc3LCoMwEIXhdfsUgyAkMr2YizXSPkwGGyq0o9hs@vRpoquPAz@c5RdfM@uUwuPtPzR6YKSB7wSeR6ATw7wCNUHwhZBkCnnG5zfCxCCEahUqicJ2Gm3WuHZXGdTFzmGf1UbjrXRObarebV3n9k7n3ko5HA/LOnEU5QGr@noOVR1EU6aU6Q8 is a bit shorter but having to output the result with format "%.0f" is probably cheating.

@rici Nice, I think it may be OK to use floating point arithmetic. I'll add it as an alternative (another byte may be saved by switching forms due to b-n never being zero at the same time as n<b is true).

35 bytes (Python2) I believe.

Much better, thanks @loopywalt (I think I'd have posted as my own if I'd seen this and written that!) Do let me know if you think there is a clearer description or if I have any mistakes.

Not much glory to earn with very late answers... Re clarity, perhaps mention that we are basically subtracting (from b^k) n digit-by-digit in base b.

JavaScript (ES6), 29 bytes
Very similar to Rick's approach but posted with his permission (and some help saving a byte).
n=>b=>g=(x=b)=>x>n?x-n:g(x*b)

Try it

f=
n=>b=>g=(x=b)=>x>n?x-n:g(x*b)
oninput=_=>o.value=f(+i.value)(+j.value)()
o.value=f(i.value=324)(j.value=5)()
*{font-family:sans-serif;}
input{margin:0 5px 0 0;width:50px;}
<label for=i>n: </label><input id=i type=number><label for=j>b: </label><input id=j type=number><label for=o>= </label><input id=o>

Japt, 16 8 bytes
This feels longer than it needs to be! That's a bit better!
nVpUìV l

Try it
nVpUìV l     :Implicit input of integers U=n & V=b
n            :Subtract U from
 Vp          :  Raise V to the power of
   UìV       :    Convert U to a base-V digit array
       l     :    Get the length

Desmos, 30 27 bytes
f(n,b)=b^{floor(log_bbn)}-n

Try It On Desmos
-3 thanks to @Aiden Chow and @Steffan
Gotta love using your favorite graphing calculator for code golf. Taken from the R answer.

log_b(n)+1 can be log_bbn (link). btw aiden chow found this, not me

Vyxal, 8 bytes
ɾe'¹>;hε

Try it Online!
Port of 05AB1E.
How?
ɾe'¹>;hε
ɾ        # Inclusive range from one to (implicit) first input
 e       # For each element, push it to the power of the (implicit) second input
  '¹>;   # Filter for only elements greater than the first input
      h  # Get the first item
       ε # Get the absolute difference of the first item and the (implicit) first input

Haskell, 31 bytes
f n b=[b^x-n|x<-[1..],b^x>n]!!0

Try it online!

Perl 6,  31 30  29 bytes
->\n,\b{(b,b* *...*>n).tail -n}

Test it (31)
->\n,\b{b**(log(n,b).Int+1)-n}

Test it (30)
{$^b**(log($^a,$b).Int+1)-$a}

Test it (29)
{($^b,$b* *...*>$^a).tail-$a}

Test it (29)

PARI/GP, 26 24 bytes
f(n,b)=b^logint(b*n,b)-n

JavaScript (ES6), 31 bytes
f=(n,b,i=b)=>b>n?b-n:f(n,b*i,i)

Test cases:

f=(n,b,i=b)=>b>n?b-n:f(n,b*i,i)

console.log(f(212, 2)) // 44
console.log(f(563, 5)) // 62
console.log(f(491, 5)) // 134
console.log(f(424, 3)) // 305
console.log(f(469, 8)) // 43
console.log(f(343, 7)) // 2058
console.log(f(592, 7)) // 1809
console.log(f(289, 5)) // 336
console.log(f(694, 3)) // 35
console.log(f(324, 5)) // 301

You can save a byte by currying (it didn't matter whether I tried currying both n and b or just n), because that saves you from having to pass n recursively.

Thanks @Neil, but I'm having trouble figuring out how to do that(?)

The two versions I came up with were n=>g=(b,p=b)=>p>n?p-n:g(b,p*b) and n=>b=>(g=p=>p>n?p-n:g(p*b))(b).

Would f=(n,i)=>g=(b=i)=>b>n?b-n:g(b*i) work for 30 bytes? It would need to be called like so: f(324,5)(). EDIT: Ah, @Neil beat me to it.

@Neil, thanks, I need more practice with currying.

@Shaggy, I think you should post your solution, but use currying to bring it down to 29 bytes:  n=>i=>g=(b=i)=>b>n?b-n:g(b*i)

@RickHitchcock, as long as you don't feel it's too similar to yours?

Nope, go for it : )

I've already upvoted.

Octave, 32 bytes
@(n,b)b^(fix(log(n)/log(b))+1)-n

Try it online!

Octave, 26 bytes
@(n,b)b^sum(b.^(0:n)<=n)-n

Verify all test cases!

Ruby, 38 bytes
Two different approaches:
->(n,b){p b**(Math.log(n,b).to_i+1)-n}

Try it online!
->(n,b){p b**(0..n).find{|x|b**x>n}-n}

Try it online!

Japt, 9 bytes
_q}a@nVpX

Test it online!
Explanation
_  q}a@  nVpX
Z{Zq}aX{UnVpX}  // Ungolfed
                // Implicit: U, V = input integers
     aX{     }  // For each integer X in [0...1e9), take
          VpX   //   V to the power of X
        Un      //   minus U,
Z{  }           // and return the first one Z where
  Zq            //   Math.sqrt(Z) is truthy.
                //   Math.sqrt returns NaN for negative inputs, and 0 is falsy, so this is
                //   truthy iff Z is positive. Therefore, this returns the first positive
                //   value of V**X - U.
                // Implicit: output result of last expression

... Wait. What?

@Shaggy I've added an explanation, hopefully this helps.

Brachylog, 7 bytes
^ʰ↙X>₁-

Try it online!
Takes input as a list [b, n].
    >₁     n is strictly less than
^ ↙X       some power of
 ʰ         b,
      -    and their difference is
           the output.

Forth (gforth), 45 bytes
: f >r 1 begin i * 2dup < until rdrop - abs ;

Try it online!
Code Explanation
: f          # start a new word definition
  >r         # store b on the return stack for quick access
  1          # create a counter to store powers of b
  begin      # start an indefinite loop
    i *      # multiply the counter by b
    2 dup <  # duplicate the counter and n. Check if n is less than the counter
  until      # if it is, end the loop
  rdrop      # remove b from the return stack
  - abs      # subtract and get absolute value (avoid negative)
;            # end the word definition

Husk, 6 bytes
≠Ω>¹*³

Try it online!
≠Ω>¹*³      # ¹ and ³ duplicate arguments ⁰ and ², so parses as:
≠Ω>⁰*²²⁰
            # now:
 Ω>⁰*²²     # Ω = Iterate function f until test result t is truthy, starting with x:
      ²     #     x is arg 2
    *²      #     f is *² = times arg 2, so iterating generates power series of arg 2
  >⁰        #     t is >⁰ = greater than arg 1
            # then:
≠           # get the absolute difference to
       ⁰    # arg 1

J, 17 bytes
[-~]^[:>.]^.[:>:[

Usage
   f =: [-~]^[:>.]^.[:>:[
   424 f 3
305

Explanation
Performs pow(b, ceil(log(n+1))) where log has base b.

dc, 23 bytes
snsb1[lb*dln!<F]dsFxln-

I had hoped to be able to use Z to count digits in a given radix, but it seems to count only in decimal.  And we might want a base larger than dc supports.  So this takes the obvious approach of successively multiplying by b until a value larger than n is reached, at which point we subtract n and leave the result at top of stack.
Annoyingly, we need !< rather than > comparison because the condition excludes an answer of 0.
Demo
for i in '212 2' '563 5' '491 5' '424 3' '469 8' '343 7'\
         '592 7' '289 5' '694 3' '324 5' '2 5' \
         '12345678901234567890 1000000'
do printf '%s => ' "$i"; dc -e '?rsnsb1[lb*dln!<F]dsFxln-p' <<<"$i"
done

212 2 => 44
563 5 => 62
491 5 => 134
424 3 => 305
469 8 => 43
343 7 => 2058
592 7 => 1809
289 5 => 336
694 3 => 35
324 5 => 301
2 5 => 3
12345678901234567890 1000000 => 999987654321098765432110

TXR Lisp, 51 bytes
(defun f(n b)(-[(ginterate(op >= n)(op * b)1)-1]n))

Legend: ginterate, op.

PHP>=7.1, 46 bytes
for([,$n,$b]=$argv;0>=$d=$b**$i++-$n;);echo$d;

PHP Sandbox Online

Python 3, 50 48 bytes
Thanks to EriktheOutgolfer for saving 2 bytes!
lambda n,b:b**-~int(math.log(n,b))-n
import math

Try it online!
Python doesn't have any fancy log or ceiling builtins, so I just went with the obvious approach with a little bit of golfing flair.

import math;lambda n,b:b**-~int(math.log(n,b))-n saves two bytes and is allowed per meta consensus.

@EriktheOutgolfer ceil would not work.

@EriktheOutgolfer I wasn't using ceil because it doesn't work for powers of b, but as @Uriel pointed out importing before still saves a byte.

You can reformat it to be completely fine: Try it online!. Just place the import after the lambda, and add f= in the header.

@Mr.Xcoder Ah, you are correct! I don't know why that didn't occur to me.

Lua, 74 73 Byte
A straight forward solution, I'm using 10 bytes to ensure that the arguments are treated as numbers, and not strings. Outputs to STDIN.
Edit: forgot to remove the space in w=1 n=n+0, saves one byte
n,b=...b=b+0p=b w=1n=n+0while p<=n do p=math.pow(b,w)w=w+1 end print(p-n)

Explained
Try it online!
n,b=...           -- unpack the argument into the variable n and b
b=b+0             -- set b's type to number
n=n+0             -- set n's type to number
p=b               -- set a variable to track the current value of the powered b
w=1               -- set the nth power
while p<=n        -- iterate untill the current power is greater or equals to n
do
  p=math.pow(b,w) -- raise b to the power w
  w=w+1           -- increment w
end
print(p-n)        -- outputs p minus the following power of b

I don't know Lua that well, but is the space between 1 and end needed?

@ZacharyT In Lua, hexadecimal numbers can be inlined if they start with a number, 1end would start to be interpreted as the number 1e then throw an error because 1en isn't a valid hexadecimal value. This only occure when the letter following the number is [abcdef] as other letters can't be interpreted as hexadecimal value -> w=1while doesn't throw an error.

Welcome back to PPCG!

Python 2, 48 41 bytes

@Rod's loop simplification saved 7 bytes!

Full program without recursion or bit twiddling:
i=1;n,b=input()
while n>=i:i*=b
print i-n

Try it online!
Input format: n, b.

You can simplify the loop to reduce 7 bytes

@Rod Would have never thought of that :). Thanks a lot!

QBIC, 23 bytes
{p=:^q~p>:|_xp-b|\q=q+1

Takes parameter b first, then n.
Explanation
{       DO
p=:^q   SET p to input b (read as 'a' by QBIC fromt he cmd line) ** q (starts as 1)
~p>:    IF p exceeds 'n' (read as 'b' by QBIC fromt he cmd line)
|_xp-b| THEN QUIT, printing p minus b
\q=q+1  ELSE increase q, re-run

Common Lisp, 73 bytes
(defun f(n b)(setq a b)(loop(when(> b n)(return(- b n)))(setq b(* b a))))

Try it online!

APL(NARS), 13 chars, 26 bytes
{-⍺-⍵*1+⌊⍵⍟⍺}

test:
  f←{-⍺-⍵*1+⌊⍵⍟⍺}
  212 f 2
44
  563 f 5
62
  592 f 7
1809

JavaScript (ES6), 49 bytes
f=(n,b)=>b**(m=Math).floor(m.log(n)/m.log(b)+1)-n

Julia 1.0, 25 bytes
n\b=b^floor(1+log(b,n))-n

Try it online!

Python 3, 48 bytes
lambda n,b:b**int(math.log(n,b)+1)-n;import math

Try it online!
I really wish log was builtin

Perl 5 -pa, 28 bytes
$.*=$F[1]until$.>$_;$_=$.-$_

Try it online!

all_licenses: 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/


text:
Solve an Anagram
See also: Granma loves Ana
You will be given a string of lowercase ASCII letters. Using this dictionary file (UPDATED), your task is to solve the anagram. To solve an anagram, you must output all words or groups of words that can be formed using each letter from the input string exactly once, separated by newlines. Groups of the same words in a different order are not unique and should not be output separately; however, the order of the words does not matter. The order of output solutions also does not matter. If the input cannot form a word, output nothing.
Some useful test cases:
Input:  viinlg
Output: living

Input:  fceodglo
Output: code golf

Input:  flogflog
Output: golf golf

Input:  ahwhygi
Output: highway
        high way

Input:  bbbbbb
Output:

Rules/caveats:

You may access the dictionary list any way you like. Command line argument, stdin, reading from file, or reading from internet are all acceptable.
Input will consist of lowercase ASCII letters only. You are not required to output results in any particular case.
You will not be given a string that already forms a valid word (you may, however, be given a string that forms multiple words, such as bluehouse).
Trailing newlines are allowed but not required.
Standard loopholes apply.

This is code-golf. Shortest code in bytes wins. Good luck!

Sandbox post.

Should we use 1 space to separate sets of words or any non-letter separator suffices?

@EriktheOutgolfer To separate sets of words, any separator is fine; however you should still separate words within a single solution with a space.

@Christian Rules say you must separate sets of words with newlines though.

@EriktheOutgolfer Then why did you ask "Should we use 1 space to separate sets of words"? Your question confused me, and there should be no reason to prefer anything over newlines for separating sets. I'd say stick to the spec.

@Christian What I meant is the separator in-between words of the same set.

@EriktheOutgolfer Yeah, stick with spaces then.

Out of curiosity, where did the dictionary file come from? It's pretty small.

@SteveBennett I put together the medium and long files from here: https://github.com/first20hours/google-10000-english

No I mean, how was it constructed? How did you choose which words to put in it?

@SteveBennett I didn't choose the words. I got the files from that GitHub repo.

Oh, sorry, I get it now, thanks.

Python 2, 341 327 337 320 bytes
This solution assumes the dictionary is stored in a variable w as a set of strings. The first set of combinations does not need to use combinations_with_replacement, but using the latter saves bytes.
from itertools import*
d,o,j,c={},sorted,''.join,combinations_with_replacement
s,w=o(raw_input()),input()
l=len(s)
r=range(l)
for x in w:d.setdefault(j(o(x)),[]).append(x)
b=set(chain(*[d[j(x)]for y in r for x in c(s,y+1)if j(x) in d]))
print'\n'.join(' '.join(x)for y in r for x in c(b,y+1)if(len(j(x)),o(j(x)))==(l,s))

Try it online!
Input - Anagrammed word followed by the dictionary of words as a set:
anagram_word
{'entry1', 'entry2', ...., 'entryN'}

Edit: Updated Inputs.

Python 3, 248 202 bytes
from itertools import*
A=set()
def f(s,*G,i=1,A=A):
 if' '>s:A|={' '.join(sorted(G))}
 for _ in s:s[:i]in S and f(s[i:],s[:i],*G);i+=1
I,*S=iter(input,'')
for p in permutations(I):f(''.join(p))
print(A)

Try it online!
Input is as follows:
word_input
dic_entry_1
dic_entry_2
....
dic_entry_N
                 # <<< empty line + \n

Speeding it up:
For testing purposes, if you change from I,*S=iter(input,'') to I=input();S=set(iter(input,'')), the runtime will be reduced drastically and the output will be the same.
Explanation:
In every permutation of the input, it tries to split recursively the permutation in all possible locations, starting from left to right, without skipping letters, with words that are in the dictionary. If a split combination matches all the input permutation, the split words are sorted and added to a set that will be printed at the and of the evaluation.

Javascript, 139 137 129 Bytes
-2 Bytes thanks to @FelipeNardiBatista
-8 Bytes thanks to reading the docs ;)
k=>w=>{t=w;return k.reduce((a,v)=>{r=([...v].every(c=>w.includes(c)&&((w=w.replace(c,""))||!0)))?a.concat(v):a;w=t;return r},[])}

Takes in the dictionary as input in form of an array of strings.

var arr = ["living", "code", "golf", "highway", "high", "way"];

var _=
k=>w=>{t=w;return k.reduce((a,v)=>{r=([...v].every(c=>w.includes(c)&&((w=w.replace(c,""))||!0)))?a.concat(v):a;w=t;return r},[])};

console.log(_(arr)("viinlg"));
console.log(_(arr)("fceodglo"));

Explanation:
For every word in dictionary, check if every letter is contained in the chosen word, while simultaneously removing it from the word. At the end of every dictionary entry, restore the word to its unaltered state to check for further matches.

@FelipeNardiBatista You're right, I forgot to golf that name. Thanks :)

Vyxal j, 82 bitsv2, 10.25 bytes
ð+Þ×vṠ'sṠ⁰s=

Try it Online!
Makes sure to output all acronyms with a single space to separate.

Scala, 156 bytes
Golfed version. Try it online!
(l:Seq[String],k:String)=>l.filter(w=>w.foldLeft((k,true)){case((r,b),c)=>val i=r.indexOf(c);if(i>=0)(r.substring(0,i)+r.substring(i+1),b)else(r,false)}._2)

Ungolfed version. Try it online!
object Main {
  def main(args: Array[String]): Unit = {
    val arr = List("living", "code", "golf", "highway", "high", "way")

    def checkAvailability(str: String, keyword: String): Boolean = {
      keyword.foldLeft((str, true)) { case ((remaining, result), ch) =>
        val idx = remaining.indexOf(ch)
        if (idx >= 0) (remaining.substring(0, idx) + remaining.substring(idx + 1), result && true)
        else (remaining, false)
      }._2
    }

    def filterList(arr: List[String], keyword: String): List[String] = {
      arr.filter(word => checkAvailability(keyword, word))
    }

    println(filterList(arr, "viinlg"))
    println(filterList(arr, "fceodglo"))
  }
}

OCaml, 224 bytes
Golfed version. Try it online!
let f s t=List.filter(fun w->List.fold_left(fun(x,y)c->let i=String.index_opt x c in match i with Some j->String.sub x 0 j^String.sub x(j+1) (String.length x-j-1),y|None->x,false)(t,true)(String.to_seq w|>List.of_seq)|>snd)s

Ungolfed version. Try it online!
let filter_strings lst str =
  let rec filter_chars str char =
    let i = String.index_opt str char in
    match i with
    | Some idx -> String.sub str 0 idx ^ String.sub str (idx + 1) (String.length str - idx - 1), true
    | None -> str, false
  in
  List.filter (fun word ->
    let _, ok = List.fold_left (fun (str, b) c -> let str', b' = filter_chars str c in str', b && b') (str, true) (String.to_seq word |> List.of_seq) in
    ok) lst

let () =
  let arr = ["living"; "code"; "golf"; "highway"; "high"; "way"] in
  let result1 = filter_strings arr "viinlg" in
  let result2 = filter_strings arr "fceodglo" in
  print_endline (List.fold_left (fun a b -> if a = "" then b else a ^ "," ^ b) "" result1);
  print_endline (List.fold_left (fun a b -> if a = "" then b else a ^ "," ^ b) "" result2)

Elixir, 188 bytes
Golfed version. Try it online!
f=fn(l,k)->Enum.filter(l,fn w->elem(Enum.reduce(String.graphemes(w),{k,true},fn c,{r,b}->if String.contains?(r,c),do: {String.replace(r,c,"",global: false),b},else: {r,false}end),1)end)end

Ungolfed version. Try it online!
defmodule Main do
  def run do
    filter_strings = fn (lst, k) ->
      Enum.filter(lst, fn w ->
        str = Enum.reduce(String.graphemes(w), {k, true}, fn c, {r, b} ->
          case String.contains?(r, c) do
            true -> {String.replace(r, c, "", global: false), b}
            _ -> {r, false}
          end
        end)
        elem(str, 1)
      end)
    end

    arr = ["living", "code", "golf", "highway", "high", "way"]
    IO.inspect(filter_strings.(arr, "viinlg"))
    IO.inspect(filter_strings.(arr, "fceodglo"))
  end
end

Main.run

Erlang(escript), 156 bytes
Golfed version. Try it online!
f(L,K)->lists:filter(fun(W)->{_,B}=lists:foldl(fun(C,{R,A})->case lists:member(C,R)of true->{lists:delete(C,R),A};_->{R,false}end end,{K,true},W),B end, L).

Ungolfed version. Try it online!
-module(main).
-export([main/1]).

filter_strings(L, K) ->
    lists:filter(fun(W) ->
        {_, B} = lists:foldl(
            fun(C, {R, Acc}) ->
                case lists:member(C, R) of
                    true -> {lists:delete(C, R), Acc};
                    false -> {R, false}
                end
            end,
            {K, true},
            W
        ),
        B
    end, L).

main(_) ->
    Arr = ["living", "code", "golf", "highway", "high", "way"],
    io:format("~p~n", [filter_strings(Arr, "viinlg")]),
    io:format("~p~n", [filter_strings(Arr, "fceodglo")]).

Racket, 299 bytes
Golfed version. Try it online!
(define(i s c)(let f([l(string->list s)][n 0])(if(null? l)#f(if(char=?(car l)c)n(f(cdr l)(+ 1 n))))))
(define(f l k)(filter(λ(w)(let g([r k][b #t][l(string->list w)])(if(null? l)b(let*([c(car l)][n(i r c)])(if(not(eqv? n #f))(g(string-append(substring r 0 n)(substring r(+ n 1)))b(cdr l))#f)))))l))

Ungolfed version. Try it online!
#lang racket

(define (string-index s c)
  (let loop ([s-list (string->list s)] [index 0])
    (cond
      [(null? s-list) #f]
      [(char=? (car s-list) c) index]
      [else (loop (cdr s-list) (+ 1 index))])))

(define (filter-strings l k)
  (filter (lambda (w)
            (let loop ([r k] [b #t] [wl (string->list w)])
              (if (null? wl)
                  b
                  (let* ([c (car wl)]
                         [i (string-index r c)])
                    (if (not (eqv? i #f))
                        (loop (string-append (substring r 0 i) (substring r (+ i 1))) b (cdr wl))
                        #f))))) l))

(define arr '("living" "code" "golf" "highway" "high" "way"))
(displayln (filter-strings arr "viinlg"))
(displayln (filter-strings arr "fceodglo"))

F#(.NET Core), 171 bytes
Golfed version. Try it online!
let f l (k:string) = l |> List.filter(fun w -> let mutable r = k in w |> Seq.forall(fun (c:char) -> match r.IndexOf(c) with | -1 -> false | i -> r <- r.Remove(i,1); true))

Ungolfed version. Try it online!
open System

let filterStrings (l: string list) (k: string) =
    l |> List.filter(fun (w: string) ->
        let mutable r = k
        let mutable b = true
        for c in w do
            let i = r.IndexOf(c)
            if i >= 0 then
                r <- r.Remove(i, 1)
            else
                b <- false
        b)

let arr = ["living"; "code"; "golf"; "highway"; "high"; "way"]
printfn "%A" (filterStrings arr "viinlg")
printfn "%A" (filterStrings arr "fceodglo")