Look-and-say sequence
import "std/string.zc"
fn look_and_say(s: string) -> String {
let res = String::from("");
let digit = s[0];
let count = 1;
for i in 1..strlen(s) {
if s[i] == digit {
count++;
} else {
res.append_c("");
digit = s[i];
count = 1;
}
}
res.append_c("");
return res;
}
fn main() {
let s: char[100];
strcpy(s, "1");
for i in 1..=15 {
println "";
let las = look_and_say(s);
strcpy(s, las.c_str());
}
}
Output:
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
11131221133112132113212221
3113112221232112111312211312113211
1321132132111213122112311311222113111221131221
11131221131211131231121113112221121321132132211331222113112211
311311222113111231131112132112311321322112111312211312111322212311322113212221
Attribution: This is a community solution for the Rosetta Code task Look-and-say sequence in Zen C.
This article uses material from the Rosetta Code article Look-and-say sequence, which is released under the GNU Free Documentation License 1.3. A list of the original authors can be found in the page history.