/YQv'%i/%i+'wYD3L)61yUYQVwV47b&h
オンラインでお試しください!
説明
考えてみて[1, 2, 3, 3, 6]
、[2, 9, 3, 2, 4]
入力として。
/ % Implicit inout. Divide element-wise
% STACK: [0.5 0.222 1 1.5 1.5]
YQ % Rational approximation (with default tolerance)
% STACK: [1 2 1 3 3], [2 9 1 2 2]
v % Conctenate all stack elements vertically
% STACK: [1 2; 2 9; 1 2; 3 2; 3 2]
'%i/%i+' % Push this string (sprintf format specifier)
% STACK: [1 2; 2 9; 1 2; 3 2; 3 2], '%i/%i+'
wYD % Swap, sprintf
% STACK: '1/2+2/9+1/1+3/2+3/2+'
3L) % Remove last entry
% STACK: '1/2+2/9+1/1+3/2+3/2'
61 % Push 61 (ASCII for '=')
% STACK: '1/2+2/9+1/1+3/2+3/2', 61
y % Duplicate from below
% STACK: '1/2+2/9+1/1+3/2+3/2', 61, '1/2+2/9+1/1+3/2+3/2'
U % Evaluste string into a number
% STACK: '1/2+2/9+1/1+3/2+3/2', 61, 4.722
YQ % Rational approximation
% STACK: '1/2+2/9+1/1+3/2+3/2', 61, 85, 18
VwV % Convert to string, swap, convert to string
% STACK: '1/2+2/9+1/1+3/2+3/2', 61, '18', '85'
47 % Push 47 (ASCII for '/')
% STACK: '1/2+2/9+1/1+3/2+3/2', 61, '18', '85', 47
b % Bubble up in stack
% STACK: '1/2+2/9+1/1+3/2+3/2', 61, '85', 47, '18'
&h % Concatenate all stack elements horizontally. Implicitly display
% STACK: '1/2+2/9+1/1+3/2+3/2=85/18'