<commit_before>config param digits = 4;

def number2tuple(n: int) {
  var nn: digits*int;
  for param i in 1..digits do
    nn(i) = n/10**(digits-i)%10;
  return nn;
}

def tuple2number(nn: digits*int) {
  var n: int;
  for param i in 1..digits do
    n += nn(i)*10**(digits-i);
  return n;
}

def smallest(n: int) {
  var nn = number2tuple(n);
  for param i in 1..digits-1 do
    for param j in 1..digits-1 do
      if nn(j) > nn(j+1) then
        nn(j) <=> nn(j+1);
  return tuple2number(nn);
}

def biggest(n: int) {
  var nn = number2tuple(n);
  for param i in 1..digits-1 do
    for param j in 1..digits-1 do
      if nn(j) < nn(j+1) then
        nn(j) <=> nn(j+1);
  return tuple2number(nn);
}

def sortedNumbers(param p: int = 1, start: int = 0) {
  if p == digits {
    for i in max(start,1)..9 do
      yield i;
  } else {
    for i in start..9 do
      for j in sortedNumbers(p+1, i) do
        yield i*10**(digits-p)+j;
  }
}

var D: domain(int);
var FD: domain(int);

for i in sortedNumbers() {
  writeln(i);
  for j in D do {
writeln("----", j);
    D -= j;
  }
  var j = i;
  while !D.member(j) {
writeln("--", j);
    D += j;
    j = biggest(j) - smallest(j);
  }
  if !FD.member(j) {
    while !FD.member(j) {
      FD += j;
      writeln(j, " - ");
      j = biggest(j) - smallest(j);
    }
    writeln();
  }
}<commit_msg>Reworked digits3 solution to declare an indefinite domain in a loop and avoid the need of having to clear it out.<commit_after>config param digits = 4;

def number2tuple(n: int) {
  var nn: digits*int;
  for param i in 1..digits do
    nn(i) = n/10**(digits-i)%10;
  return nn;
}

def tuple2number(nn: digits*int) {
  var n: int;
  for param i in 1..digits do
    n += nn(i)*10**(digits-i);
  return n;
}

def smallest(n: int) {
  var nn = number2tuple(n);
  for param i in 1..digits-1 do
    for param j in 1..digits-1 do
      if nn(j) > nn(j+1) then
        nn(j) <=> nn(j+1);
  return tuple2number(nn);
}

def biggest(n: int) {
  var nn = number2tuple(n);
  for param i in 1..digits-1 do
    for param j in 1..digits-1 do
      if nn(j) < nn(j+1) then
        nn(j) <=> nn(j+1);
  return tuple2number(nn);
}

def sortedNumbers(param p: int = 1, start: int = 0) {
  if p == digits {
    for i in max(start,1)..9 do
      yield i;
  } else {
    for i in start..9 do
      for j in sortedNumbers(p+1, i) do
        yield i*10**(digits-p)+j;
  }
}

var FD: domain(int);

for i in sortedNumbers() {
  var D: domain(int);
  var j = i;
  while !D.member(j) {
    D += j;
    j = biggest(j) - smallest(j);
  }
  if !FD.member(j) {
    while !FD.member(j) {
      FD += j;
      write(j, " ");
      j = biggest(j) - smallest(j);
    }
    writeln();
  }
}
{'fraction_non_alphanumeric': 0.16716196136701336, 'fraction_numerical': 0.02637444279346211, 'mean_word_length': 2.3002450980392157, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4489570', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1109, 'n_words': 334}