Skip to content

Instantly share code, notes, and snippets.

@oguz-ismail
Last active November 17, 2023 07:36
Show Gist options
  • Save oguz-ismail/c59d712373b346e799e8fe85b396263b to your computer and use it in GitHub Desktop.
Save oguz-ismail/c59d712373b346e799e8fe85b396263b to your computer and use it in GitHub Desktop.
bc <<EOF
$(awk -F, '
NR == 1 {
print "t = " $0
next
}
{
j = 0
for (i = 1; i <= NF; i++) {
if ($i == "x")
continue
print "i[" j "] = " i-1
print "n[" j "] = " $i
j++
}
print "c = " j
}' input.txt)
for (i = 0; i < c; i++)
w[i] = n[i] - t%n[i]
w = w[0]
b = n[0]
for (i = 1; i < c; i++)
if (w[i] < w) {
w = w[i]
b = n[i]
}
w*b
for (i = 0; i < c; i++)
b[i] = (n[i] - i[i]%n[i]) % n[i]
p = 1
for (i = 0; i < c; i++)
p *= n[i]
for (i = 0; i < c; i++)
p[i] = p/n[i]
for (i = 0; i < c; i++) {
m = p[i]%n[i]
for (x = 1; m*x % n[i] != 1; x++) {
}
x[i] = x
}
for (i = 0; i < c; i++)
s += b[i]*p[i]*x[i]
s%p
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment