실론, 202 바이트
object u satisfies{Integer*}{iterator()=>object satisfies Iterator<Integer>{variable value i=0;late Iterator<Integer>n;next()=>if(++i%7<1||'7'in"``i``")then(i<8then(n=iterator())else n).next()else i;};}
이것은 함수가 아니라 무한 시퀀스 (Iterable)를 구현하는 객체 선언입니다. 객체를 직접 인쇄하여 다음을 print(u)
출력 할 수 있습니다 .
{ 1, 2, 3, 4, 5, 6, 1, 8, 9, 10, 11, 12, 13, 2, 15, 16, 3, 18, 19, 20, 4, 22, 23, 24, 25, 26, 5, 6, 29, 30, ... }
더 인쇄하려면을 사용하십시오 printAll(u)
. 다음 코드는 줄 바꿈을 사용하고 합계와 위에 표시된 처음 30 개 요소를 인쇄합니다.
shared void run() {
printAll(u.take(7^7), "\n");
print(sum({0, * u.take(7^7)}));
print(u);
}
ungolfed 및 주석이 달린 버전은 다음과 같습니다.
// Prints cantor's unspeakable numbers.
//
// Question: http://codegolf.stackexchange.com/q/101231/2338
// My answer: http://codegolf.stackexchange.com/a/101297/2338
// this object u (which is like a singleton class with its single instance)
// implements the Iterable<Integer> interface.
object u satisfies {Integer*} {
// That interface has just one formal method,
// `shared formal Iterator<Integer> iterator()`.
// Lets implement it by ...
iterator()
// ... providing for each call ...
=>
// ... a new (anonymous) object, which
// implements the Iterator<Integer> interface.
object satisfies Iterator<Integer> {
// This is the counter (the type `Integer`
// is longer than `value`, so we infer it).
// We start at 0.
variable value i = 0;
// This is a nested Iterator. It will be
// initialized when first needed, so we don't
// get an endless recursion when creating the
// first iterator.
late Iterator<Integer> n;
// `shared formal Integer next()` is the single method
// of Iterator which needs to be implemented.
next()
// each time it is called, the following
// expression will be evaluated.
=>
// increment the counter, then check if it
// is an unspeakable number.
if (++i % 7 < 1 || '7' in "``i``")
then
// if so, take the nested iterator (and the
// first time, for i == 7, create it first),
// and take its next element.
(i < 8 then (n = iterator()) else n).next()
else
// otherwise, just return i.
i;
};
}