Libraryless. Click here for Pure Java version (1059L/7K/24K).
!752 sclass Vessel { new L<S> data; int index; *() {} *(L<S> *data, int *index) {} void add(S s) { data.add(simplify(s)); } bool consume(S s) { if (end()) ret false; s = simplify(s); /*if (same(next(), s)) { ++index; ret true; } ret false;*/ //++index; if (!same(next(), s)) { --index; ret false; } ret true; } void restart() { index = 0; } // may be null if index after end S next() { ret end() ? null : get(data, index++); } bool end() { ret index >= l(data); } public Vessel clone() { ret new Vessel(cloneList(data), index); } } static S simplify(S s) { ret s.trim().toUpperCase(); } static bool same(S a, S b) { ret eq(a, b); } static new L<Vessel> vessels; p { new Vessel v; v.add("There is RAIN"); v.add("I need a COAT"); vessels.add(v); } synchronized answer { if (!tb()) null; for (Vessel v : vessels) { if (v.consume(s)) { S answer = v.next(); v.restart(); if (nempty(answer)) ret answer; } } }
Began life as a copy of #1003040
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: | #1003041 |
Snippet name: | Rain / Coat (Vessel) |
Eternal ID of this version: | #1003041/1 |
Text MD5: | 2b758d5e374a508cf6fdf14b73c47a37 |
Transpilation MD5: | dba08909d2457b46d152f8d179569031 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-04-24 03:07:16 |
Source code size: | 1188 bytes / 80 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 615 / 684 |
Referenced in: | #3000382 - Answer for ferdie (>> t = 1, f = 0) |