Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

60
LINES

< > BotCompany Repo | #1010210 // Find an odd integer [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 616K of libraries. Click here for Pure Java version (15358L/111K).

1  
!7
2  
3  
static int n, limit = 1000000;
4  
5  
sS inputDiagrams = [[
6  
  CirclesAndLines(circles=[Circle(text="Find", x=d("0.27089337175792505"), y=d("0.18181818181818182")), Circle(text="an integer", x=d("0.5965417867435159"), y=d("0.19922630560928434")), Circle(text="odd", x=d("0.5936599423631124"), y=d("0.5145067698259188"))], lines=[Arrow(a=t5, b=t26, text=""), Arrow(a=t26, b=t47, text="that is")])
7  
  CirclesAndLines(circles=[Circle(text="A standard function that enumerates", x=d("0.3011527377521614"), y=d("0.2688588007736944")), Circle(text="integers", x=d("0.5561959654178674"), y=d("0.4448742746615087")), Circle(text="\"enumerateIntegers\"", x=d("0.7521613832853026"), y=d("0.6808510638297872"))], lines=[Arrow(a=t5, b=t26, text=""), Arrow(a=t26, b=t47, text="is")])
8  
  CirclesAndLines(circles=[Circle(text="A standard function that tests", x=d("0.3645533141210375"), y=d("0.2011605415860735")), Circle(text="an integer", x=d("0.2377521613832853"), y=d("0.5764023210831721")), Circle(text="odd", x=d("0.47982708933717577"), y=d("0.5725338491295938")), Circle(text="\"odd\"", x=d("0.7132564841498559"), y=d("0.562862669245648"))], lines=[Arrow(a=t5, b=t26, text="what"), Arrow(a=t5, b=t47, text="for property"), Arrow(a=t5, b=t68, text="is")])
9  
]];
10  
11  
p {
12  
  Web web = webFromCALStructures_noMerge(inputDiagrams);
13  
  showWeb(web);
14  
  
15  
  infoBox("Thinking...");
16  
  
17  
  WebNode find = web_findNode(web, "Find");
18  
  WebNode op = web_operand(find);
19  
  print("Finding: " + op);
20  
  S plural = plural(dropArticle(web_text(op)));
21  
  print("Plural: " + plural);
22  
  
23  
  Pair<WebNode> finder = web_findTriple(web, "A standard function that enumerates", "", plural);
24  
  print("Finder: " + finder);
25  
  if (finder == null) fail("No finder");
26  
  S sfName = web_operandText(finder.b, "is");
27  
  if (sfName == null) fail("No sf");
28  
  print("Using function: " + sfName);
29  
  Iterator iterator = getIterator(makeAndCall(sfName));
30  
31  
  new L testers;
32  
  
33  
  for (Pair<S, WebNode> p : web_forwardRelationsTextPlusNodes(op)) {
34  
    //print("Condition: " + p);
35  
    if (eqic(p.a, "that is")) {
36  
      S property = p.b.text();
37  
      testers.add(ai_makeTester(web, web_text(op), property));
38  
    }
39  
    else fail("Unknown condition: " + p);
40  
  }
41  
  
42  
  infoBox("Iterating...");
43  
44  
  search: while (iterator.hasNext()) {
45  
    ping();
46  
    if (++n > limit) {
47  
      print("Limit of " + limit + " reached, cancelling.");
48  
      break;
49  
    }
50  
    
51  
    O o = iterator.next();
52  
    
53  
    for (O tester : testers)
54  
      if (!isTrue(callF(tester, o)))
55  
        continue search;
56  
        
57  
    infoBox("Answer found in step " + n + "!!! >> " + o);
58  
    break;
59  
  }
60  
}

Author comment

Began life as a copy of #1010203

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1010210
Snippet name: Find an odd integer [OK]
Eternal ID of this version: #1010210/11
Text MD5: e647d59d178827baa612fb6beda7d331
Transpilation MD5: aceec6ffc0c2b785e83fcbd0abc5332b
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-06 20:50:31
Source code size: 2641 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 496 / 990
Version history: 10 change(s)
Referenced in: [show references]