<commit_before>#!/usr/bin/swipl -f
% vim: filetype=prolog
% Count numbers that are doubled odd numbers.

:- initialization(main).

main :-
  new(Dir, directory('.')),
  new(Frame, frame('Select file')),
  new(Browser, browser),
  new(Dialog, dialog),
  new(ProcessButton, button('Process!', message(@prolog, processfile, Browser?selection?key))),
  new(QuitButton, button('Quit', message(@prolog, halt))),
  send(Dialog, append(ProcessButton)),
  send(Dialog, append(QuitButton)),
  send(Browser, members(Dir?files)),
  send(Frame, append(Browser)),
  send(Dialog, below(Browser)),
  send(Frame, open).

processfile(X) :-
  see(X),
  count(0, X),
  seen.

count(X, F) :-
  read(N),
  (
    N == end_of_file ->
      showResult(X, F);
      (
        isOurNumber(N) ->
          X1 is X + 1;
          X1 is X
      ),
      count(X1, F)
  ).

showResult(X, F) :-
  new(D, dialog('RESULT')),
  new(B, button(X, message(D, destroy))),
  new(V, view(F)),
  send(D, append(B)),
  send(D, append(V, below)),
  send(V, load(F)),
  send(D, open).

isOurNumber(X) :-
  isEven(X),
  Y is X div 2,
  not(isEven(Y)).

isEven(X) :-
  Y is X mod 2,
  isZero(Y).

isZero(0).<commit_msg>move away! showresult from count function<commit_after>#!/usr/bin/swipl -f
% vim: filetype=prolog
% Count numbers that are doubled odd numbers.

:- initialization(main).

main :-
  new(Dir, directory('.')),
  new(Frame, frame('Select file')),
  new(Browser, browser),
  new(Dialog, dialog),
  new(ProcessButton, button('Process!', message(@prolog, processfile, Browser?selection?key))),
  new(QuitButton, button('Quit', message(@prolog, halt))),
  send(Dialog, append(ProcessButton)),
  send(Dialog, append(QuitButton)),
  send(Browser, members(Dir?files)),
  send(Frame, append(Browser)),
  send(Dialog, below(Browser)),
  send(Frame, open).

processfile(F) :-
  see(F),
  count(0, N),
  showResult(N, F),
  seen.

count(X, D) :-
  read(N),
  (
    N == end_of_file ->
      D is X;
      (
        isOurNumber(N) ->
          X1 is X + 1;
          X1 is X
      ),
      count(X1, D)
  ).

showResult(X, F) :-
  new(D, dialog('RESULT')),
  new(B, button(X, message(D, destroy))),
  new(V, view(F)),
  send(D, append(B)),
  send(D, append(V, below)),
  send(V, load(F)),
  send(D, open).

isOurNumber(X) :-
  isEven(X),
  Y is X div 2,
  not(isEven(Y)).

isEven(X) :-
  Y is X mod 2,
  Y =:= 0.
{'fraction_non_alphanumeric': 0.19425675675675674, 'fraction_numerical': 0.006756756756756757, 'mean_word_length': 3.419776119402985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4754983', 'n_tokens_mistral': 943, 'n_tokens_neox': 914, 'n_words': 207}