Skip to content

Instantly share code, notes, and snippets.

View mvw's full-sized avatar

Marc van Woerkom mvw

  • Germany, European Union
View GitHub Profile
# n*k different objects in k bins of size n each
#
# http://math.stackexchange.com/q/1940138/86776
load "set.rb"
def fac(n)
if n == 0
return 1
end
result = 2286878604508883/69984000000000 = 32.67716341605057
D = 6
def f(i, j)
i2 = i.clone
i2[j] -= 1
i2[j-1] += 1
return i2
end
def e(i)
found 1: (0, 0, 5), w = 8
found 2: (0, 1, 4), w = 0
found 3: (0, 2, 2), w = 4
found 4: (0, 3, 0), w = 8
found 5: (1, 0, 3), w = 10
found 6: (1, 1, 2), w = 2
found 7: (1, 2, 0), w = 6
found 8: (2, 0, 2), w = 0
found 9: (2, 1, 0), w = 4
found 10: (3, 0, 0), w = 2
# ordertypes.rb
# http://math.stackexchange.com/q/1657371/86776
NMAX=68
found = 0
(0..NMAX).each do |n1|
w1 = 68 - n1 * 22
(0..NMAX).each do |n2|
w2 = w1 - n2 * 20
N = 100
def brute_force
puts "searching {#{-N}, #{N}}^2, checking #{(2*N+1)**2} pairs:"
found = 0
checked = 0
(-N..N).each do |m|
a = m*m
ap = a + 1
(-N..N).each do |n|
N = 10000
def brutus
m = N+N
xm = N
ym = N
(1..N).each do |y|
y_cube = y * y * y
(1..N).each do |x|
if 360 * x == y_cube
test1:
succeeded: 1002001
failed: 0
success rate: 100.0 %
test2:
succeeded: 1000000
failed: 0
success rate: 100.0 %
# digit_wise_average.rb
# the usual average of two numbers
def average(a, b)
(a + b) / 2.0
end
# convert "n" into array of digits regarding "base"
# lowest power stored first
def to_a(n, base)
searching ..
k = 1:
n digits:
[0:1, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0]
OK - congrats!
k = 2017:
n digits:
[0:198, 1:202, 2:202, 3:201, 4:202, 5:202, 6:201, 7:202, 8:202, 9:201]
OK - congrats!