-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2257 - MinusOne #2563
Comments
4.5 beta has TCO - however this is still not enough for the final test case as it only goes up to 1000 iterations. |
@somebody1234 I'd love to understand what's going on in your solution, care to explain (or link me to resources that explain the techniques)? :) |
The
Do note however that this is generally not very useful since: Worth noting though, that |
Worth noting that if/when this gets merged, there will be a much, much easier way to do this (and type-level arithmetic in general) |
中文解答。可能有问题,欢迎交流。
在 JavaScript 中可以使用 While 循环轻松调用无限次数,但是在 TypeScript 的类型系统中(在这段代码中),需要手动枚举。x2e3、x1e3、x1e2、x1e1 这几个函数就是用来手动调用 next 属性的。每次执行 x2e3,同时执行十次 x1e3;每次执行 x1e3,同时执行十次 x1e2... 这算是一个类似 for 循环之类的东西,最后,执行 x1e1 获取 next 属性。 可以通过计算获得一楼的代码到底执行了多少次 x1e1:2 * 10 * 10 * 10 === 2000,所以最多只能计算到 MinusOne<1999>,从 MinusOne<2000> 开始,代码就会报错。如果需要计算更大的数字,则要手动改造 x2e3 来获得更多次循环。 我的这段代码也许更易读一些:TypeScript Playground |
TS Playground.
Uses tuples for arithmetic, and a trampoline to bypass instantiation limit. Since it's rated as medium difficulty though, this is probably completely overkill and I'm probably missing something blindingly obvious.
The text was updated successfully, but these errors were encountered: