Try to solve the 6 number 1 target android game using oracle (sql or pl/sql)
Gurus and mentors/friends,.
Today, had little space in my time to work, so I tried to reproduce an android game called "6 numbers between 1-target" in oracle.
All that I need help from you all is to make more effective/robust and garnish with a little bit of awesomeness (preferable in SQL ? I don't)
Please note that if you are busy, skip this question.
------------------------------------------------------------------------------------------------
Game goes like this:
-------------------------
computer gives you only 6 numbers...
for example: 50,9,5,8,6,7
And using mathematics as operators '+','-',' *', ' / ' we need to get a result comparable to 292. (this number 292 is also given by computer..)
All that we need is the formula apt for 292 out of these 6 numbers (pouvez/do not use all these numbers) using these operators (you can use them without the restrictions of many times where they are used and also the decimal places are truncated.).
So solutions can be: 50 * 6 - 8 + 5/9/7, 50 * 6 - 8 or 50 * 6 - 8 + 5/7/9 etc... (multiple answers are possible, all boiling down giving 292)
I just tried to write it this way, but its time consuming because levels rise. So I thought that I would be the dice in this forum for the best solution. (or maybe suggestions to improve my solution below)
------------------------------------
create table demo (str varchar2 (100), number of val);
-----------------------------------
DECLARE
l_str VARCHAR2 (100);
l_result NUMBER;
BEGIN
EXECUTE IMMEDIATE 'demo truncate table ';
WHILE (TRUE) LOOP - I know it's wrong, but it's the game after all and I needed iterations to go until I get to a solution.
BEGIN
FOR rec
IN (WITH operators AS
(Op SELECT COLUMN_VALUE
TABLE (sys.odcivarchar2list ('+',)
'-',
'*',
'/'))
ORDER OF DBMS_RANDOM. VALUE ()),
t AS
(SELECT SUBSTR (SYS_CONNECT_BY_PATH (letter, ','), 2))
Word
FROM (SELECT LEVEL LVL,
REGEXP_SUBSTR (str,
'[^,]+',
1,
LEVEL)
LETTER
FROM (SELECT '7,8,5,50,9,6' FROM DUAL str) t
CONNECT BY LEVEL < =.
REGEXP_COUNT (STR, ',') + 1).
WHERE = 6
CONNECT BY NOCYCLE lvl! = lvl PRIOR),
TT AS
(SELECT REGEXP_SUBSTR (Word,
'[^,]*',
1,
1)
col1,
(SELECT val
FROM (SELECT val op
Operators
ORDER OF DBMS_RANDOM. VALUE ())
WHERE ROWNUM = 1)
OP1,
REGEXP_SUBSTR (Word,
'[^,]*',
1,
3)
col2,
(SELECT val
FROM (SELECT val op
Operators
ORDER OF DBMS_RANDOM. VALUE ())
WHERE ROWNUM = 1)
OP2,
REGEXP_SUBSTR (Word,
'[^,]*',
1,
5)
col3,
(SELECT val
FROM (SELECT val op
Operators
ORDER OF DBMS_RANDOM. VALUE ())
WHERE ROWNUM = 1)
OP3,
REGEXP_SUBSTR (Word,
'[^,]*',
1,
7)
COL4,
(SELECT val
FROM (SELECT val op
Operators
ORDER OF DBMS_RANDOM. VALUE ())
WHERE ROWNUM = 1)
OP4,
REGEXP_SUBSTR (Word,
'[^,]*',
1,
9)
col5,
(SELECT val
FROM (SELECT val op
Operators
ORDER OF DBMS_RANDOM. VALUE ())
WHERE ROWNUM = 1)
OP5,
REGEXP_SUBSTR (Word,
'[^,]*',
1,
11)
col6
T)
SELECT col1
|| OP1
|| col2
|| OP2
|| COL3
|| OP3
|| COL4
|| OP4
|| col5
|| OP5
|| col6
formula
TT
ORDER OF DBMS_RANDOM. VALUE ()) LOOP
EXECUTE IMMEDIATE ' begin: result: = ' | Rec.Formula | '; end; »
With the HELP OF THE l_result;
l_str: = rec.formula;
INSERT INTO demo
VALUES (rec.formula, TRUNC (l_result));
-COMMIT;
END LOOP;
END;
IF (l_result = 292) THEN
EXIT;
END IF;
END LOOP;
END;
/
--------------------------------------------------------------------------------------------------
Thanks in advance! (even for those who have opened this question )
See you soon,.
Manik.
EDIT: this solution is not all of the possible options. Go here for a shorter, faster, more complete solution.
Here's a solution that includes parentheses. It follows the rules of "game show" as odie_63 said: the result of an intermediate calculation must be a positive integer, and each integer entry can be used at most once.
There is some unnecessary parentheses, but they do not change the logic or the defined solution.
It works in about 70 seconds on my PC.
WITH input AS ( select '50,9,8,7,6,5' nums, 292 targ from dual ), nums AS ( select power(2, row_number() over(order by num desc) - 1) bits, num FROM ( SELECT to_number(regexp_substr(nums,'[^,]+',1,ROWNUM)) num FROM input CONNECT BY to_number(regexp_substr(nums,'[^,]+',1,ROWNUM)) IS NOT NULL ) ), ma_1 (BITS, op, num, cumul_num, str, num_parens) AS ( SELECT BITS, NULL, num, num, num||NULL, 0 FROM nums UNION ALL SELECT (o.BITS + n.BITS) - BitAND(o.BITS, n.BITS), n.op, n.num, decode(n.op,'+', o.cumul_num + n.num, o.cumul_num * n.num), o.str || n.op || n.num, 1 FROM ma_1 o JOIN ( SELECT * FROM nums, (SELECT '*' op FROM dual UNION ALL SELECT '+' FROM dual) ) n ON nvl(o.op,n.op) = n.op AND n.num < o.num ), ds_2 (BITS, op, num, cumul_num, str, num_parens) AS ( SELECT BITS, op, 0, cumul_num, str, num_parens FROM ma_1 where bits < 63 or cumul_num = (select targ from input) UNION ALL SELECT (o.BITS + n.BITS) - BitAND(o.BITS, n.BITS), o.op, n.num, decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num) END, o.str || decode(o.op,'+','-','/') || n.num, 1 FROM ds_2 o JOIN nums n ON o.op IS NOT NULL and n.num > o.num AND bitand(o.BITS, n.BITS) = 0 AND decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num) = trunc(decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num)) AND decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num) > 0 ), fmt_3 as ( SELECT BITS, op, cumul_num num, cumul_num, case when num_parens = 1 and bits < 63 then '(' end || str || case when num_parens = 1 and bits < 63 then ')' end str, num_parens FROM ds_2, input where bits < 63 or cumul_num = targ ), ma_4 (BITS, op, num, cumul_num, str, num_parens) AS ( SELECT BITS, op, num, cumul_num, str, num_parens FROM fmt_3 UNION ALL SELECT (o.BITS + n.BITS) - BitAND(o.BITS, n.BITS), o.op, n.num, decode(o.op,'*', o.cumul_num + n.num, o.cumul_num * n.num), o.str || decode(o.op,'*','+','*') || n.str, least(o.num_parens+1, 2) FROM ma_4 o JOIN fmt_3 n on o.num_parens > 0 and o.op = nvl(n.op,o.op) AND n.num < o.num and bitand(o.bits, n.bits) = 0 ), ds_5 (BITS, op, num, cumul_num, str, num_parens) AS ( SELECT BITS, op, 0, cumul_num, str, num_parens FROM ma_4 where bits < 63 or cumul_num = (select targ from input) UNION ALL SELECT (o.BITS + n.BITS) - BitAND(o.BITS, n.BITS), o.op, n.num, decode(o.op, '*', o.cumul_num - n.num, o.cumul_num / n.num) END, o.str || decode(o.op,'*','-','/') || n.str, least(o.num_parens+1, 2) FROM ds_5 o JOIN fmt_3 n on o.num_parens > 0 and o.op = nvl(n.op,o.op) AND n.num > o.num and bitand(o.bits, n.bits) = 0 AND decode(o.op, '*', o.cumul_num - n.num, o.cumul_num / n.num) = trunc(decode(o.op, '*', o.cumul_num - n.num, o.cumul_num / n.num)) AND decode(o.op, '*', o.cumul_num - n.num, o.cumul_num / n.num) > 0 ), fmt_6 as ( SELECT BITS, op, cumul_num num, cumul_num, case when num_parens = 2 and bits < 63 then '(' end || str || case when num_parens = 2 and bits < 63 then ')' end str, num_parens FROM ds_5, input where bits < 63 or cumul_num = targ ), ma_7 (BITS, op, num, cumul_num, str, num_parens) AS ( SELECT BITS, op, num, cumul_num, str, num_parens FROM fmt_6 UNION ALL SELECT (o.BITS + n.BITS) - BitAND(o.BITS, n.BITS), o.op, n.num, decode(o.op,'+', o.cumul_num + n.num, o.cumul_num * n.num), o.str || o.op || n.str, least(o.num_parens+1, 3) FROM ma_7 o JOIN fmt_6 n on o.num_parens > 1 and n.num_parens != 1 and o.op = nvl(n.op,o.op) AND n.num < o.num and bitand(o.bits, n.bits) = 0 ), ds_8 (BITS, op, num, cumul_num, str, num_parens) AS ( SELECT BITS, op, 0, cumul_num, str, num_parens FROM ma_7 where bits < 63 or cumul_num = (select targ from input) UNION ALL SELECT (o.BITS + n.BITS) - BitAND(o.BITS, n.BITS), o.op, n.num, decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num) END, o.str || decode(o.op,'+','-','/') || n.str, least(o.num_parens+1, 3) FROM ds_8 o JOIN fmt_6 n on o.num_parens > 1 and n.num_parens != 1 and o.op = nvl(n.op,o.op) AND n.num > o.num and bitand(o.bits, n.bits) = 0 AND decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num) = trunc(decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num)) AND decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num) > 0 ), fmt_9 as ( SELECT BITS, op, cumul_num num, cumul_num, case when num_parens = 3 and bits < 63 then '(' end || str || case when num_parens = 3 and bits < 63 then ')' end str, num_parens FROM ds_8, input where bits < 63 or cumul_num = targ ), ma_10 (BITS, op, num, cumul_num, str, num_parens) AS ( SELECT BITS, op, num, cumul_num, str, num_parens FROM fmt_9 UNION ALL SELECT (o.BITS + n.BITS) - BitAND(o.BITS, n.BITS), o.op, n.num, decode(o.op,'*', o.cumul_num + n.num, o.cumul_num * n.num), o.str || decode(o.op,'*','+','*') || n.str, least(o.num_parens+1, 4) FROM ma_10 o JOIN fmt_9 n on o.num_parens > 2 and n.num_parens != 2 and o.op = nvl(n.op,o.op) AND n.num < o.num and bitand(o.bits, n.bits) = 0 ), ds_11 (BITS, op, num, cumul_num, str, num_parens) AS ( SELECT BITS, op, 0, cumul_num, str, num_parens FROM ma_10 where bits < 63 or cumul_num = (select targ from input) UNION ALL SELECT (o.BITS + n.BITS) - BitAND(o.BITS, n.BITS), o.op, n.num, decode(o.op, '*', o.cumul_num - n.num, o.cumul_num / n.num) END, o.str || decode(o.op,'*','-','/') || n.str, least(o.num_parens+1, 4) FROM ds_11 o JOIN fmt_9 n on o.num_parens > 2 and n.num_parens != 2 and o.op = nvl(n.op,o.op) AND n.num > o.num and bitand(o.bits, n.bits) = 0 AND decode(o.op, '*', o.cumul_num - n.num, o.cumul_num / n.num) = trunc(decode(o.op, '*', o.cumul_num - n.num, o.cumul_num / n.num)) AND decode(o.op, '*', o.cumul_num - n.num, o.cumul_num / n.num) > 0 ), fmt_12 as ( SELECT BITS, op, cumul_num num, cumul_num, case when num_parens = 4 and bits < 63 then '(' end || str || case when num_parens = 4 and bits < 63 then ')' end str, num_parens FROM ds_11, input where bits < 63 or cumul_num = targ ), ma_13 (BITS, op, num, cumul_num, str, num_parens) AS ( SELECT BITS, op, num, cumul_num, str, num_parens FROM fmt_12 UNION ALL SELECT (o.BITS + n.BITS) - BitAND(o.BITS, n.BITS), o.op, n.num, decode(o.op,'+', o.cumul_num + n.num, o.cumul_num * n.num), o.str || o.op || n.str, least(o.num_parens+1, 5) FROM ma_13 o JOIN fmt_12 n on o.num_parens > 3 and n.num_parens != 3 and o.op = nvl(n.op,o.op) AND n.num < o.num and bitand(o.bits, n.bits) = 0 ), ds_14 (BITS, op, num, cumul_num, str, num_parens) AS ( SELECT BITS, op, 0, cumul_num, str, num_parens FROM ma_13 where bits < 63 or cumul_num = (select targ from input) UNION ALL SELECT (o.BITS + n.BITS) - BitAND(o.BITS, n.BITS), o.op, n.num, decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num) END, o.str || decode(o.op,'+','-','/') || n.str, least(o.num_parens+1, 5) FROM ds_14 o JOIN fmt_12 n on o.num_parens > 3 and n.num_parens != 3 and o.op = nvl(n.op,o.op) AND n.num > o.num and bitand(o.bits, n.bits) = 0 AND decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num) = trunc(decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num)) AND decode(o.op, '+', o.cumul_num - n.num, o.cumul_num / n.num) > 0 ) select str, dbms_aw.eval_number(str) check_result from ( select str from ds_14, input where cumul_num = targ ) order by str;
STR | CHECK_RESULT |
---|---|
((((6*5) + 8) * 9)-50) | 292 |
((((8*6) + 9) * 5) + 7) | 292 |
((((8*6)-5) * 7)-9) | 292 |
(((50*5) + 8) * 7/6)-9 | 292 |
(((50*9) + 6) * 5/8) + 7 | 292 |
(((50+8) * 5) + 9-7) | 292 |
+ ((50*5) (7 * 6)) | 292 |
((50*6) + 8-7-9) | 292 |
((50*6)-8) | 292 |
((50 + 6-5-8) * 7)-9 | 292 |
((50+7) * 5) + 9 + 6-8 | 292 |
((50 + 8-7) * 6)-5-9 | 292 |
((50 + 8-9) * 6) + 5-7 | 292 |
((50 + 9 + 6-8) * 5) + 7 | 292 |
((50 + 9 + 7-6) * 5)-8 | 292 |
(8 * 6 * 5) + 50 + 9 - 7 | 292 |
Tags: Database
Similar Questions
-
I called Amazon to try to recover the serial number of my old iPod classic two weeks ago, and they gave me a kind of account; They pronounce it account 'seen - It '. I don't have to ask how, because I thought I knew, but I was wrong. Would what type of account be? And how it's spelled? The name of the account is a tiny s followed a 7-digit number. (Of course I will not type the numbers.)
I would go to a forum for Amazon, because they can be better equipped to answer a question on their system. If synchronize you the device with iTunes, the number can be there in the backup section. Find the serial number of your Apple - Apple Support product
-
My OS has been updated from Windows 7 to Windows 10 without disabling the Adobe Acrobat 9 installed on the machine. Now I'm not able to activate the reinstalled Adobe Acrobat. When I try to record the serial number, it is not accepted and is considered as invalid. Is it others to activate the serial No. ?
Hello
Please see error: "serial number is not valid for this product". Adobe Creative Suite and serial number incorrect error
Alternatively, you can contact customer service
Hope that helps!
Kind regards
Sheena
-
As I try to enter the serial number of my first sweet item that I just downloaded, the system tells me that I am not connected to the internet and I can't finalize the instrallation
Please see:
'Please connect to the Internet to continue' error keeps popping up.
Error: "could not connect to the server.
I hope this helps.
Concerning
Megha Rawat
-
I try to enter the serial number to register my software, but the label outside of the box, he's starting with the letters and it does not accept the letters... . Only numbers
Serial numbers contain no letters, so maybe it's your redemption code, for use on adobe.com to get your serial number.
Here are a few links to look for more information
https://helpx.Adobe.com/x-productkb/global/redemption-code-help.html#productboxorprepaidca rd
-
I have purchased Adobe Design Standard CS6 2013 with serial number, but can't find the to no download on a new mac laptop. When I try and add the serial number to 24 digits on my account it doesn't seem to work?
CS6 - http://helpx.adobe.com/x-productkb/policy-pricing/cs6-product-downloads.html
You can also download the demo version of the software through the page linked below and then use your current serial number to activate it.
Don't forget to follow the steps described in the Note: very important Instructions in the section on the pages of this site download and have cookies turned on in your browser, otherwise the download will not work correctly.
CS6: http://prodesigntools.com/adobe-cs6-direct-download-links.html
-
Hello, I just installed CS6 master collection in the history of the order, and when I try to enter the serial number it tells me that: serial number you provided is valid, but no product calling can not be found on this computer. Then it gives me options in the drop-down menu, but the Master Collection CS6 is the only one not listed is not in a menu drop-down.
Your CS6 must have been bought an upgrade. He asks you to select/provide is the name/serial number of the previous version, you bought that qualifies you to install and activate the CS6 upgrade version... it would probably be CS5.5 CS3.
Error "this serial number is not for a product calling it" | CS6, CS5.5, CS5
http://helpx.Adobe.com/Creative-Suite/KB/error-serial-number-qualifying-product.html
-
right click on windows Explorer causes crash! Sometimes when I try to empty the trash, it also blocks? I use windows 7?
Right-click accidents are caused by third-party shell extensions. To identify the culprit, you must use a utility like ShellExView and disable context menus not Microsoft managers one by one (or disable items in a batch) and observe.
ShellExView - Manager of Windows Shell extensions:
http://www.NirSoft.NET/utils/shexview.htmlAnd instructions are here (see "Method 2")
http://WindowsXP.MVPs.org/slowrightclick.htmRamesh Srinivasan, Microsoft MVP [Windows Desktop Experience]
-
How to change the password of a schema by using Oracle SQL Developer
Hi need to change the password of a schema by using Oracle SQL Developer, how can I do?
or maybe http://www.thatjeffsmith.com/archive/2012/11/resetting-your-oracle-user-password-with-sql-developer/
-
I need to install the Oracle client until I can use Oracle SQL Developer?
Hi all
I used to use the PL/SQL Developer to connect to the Oracle server, and before it can work, I have to install Oracle on my PC client.
So I wonder to know if I use Oracle SQL Developer, what I have to do the same thing? If not, why?
Thank you very much.Hello Serge,
you don't need a client. Developer SQL uses JDBC to connect.
Concerning
Marcus -
Try to find the model number to get the necessary drivers
I'm trying to figure out what my information for my Ideapad Y550 laptop computer support. I will reinstall windows and try to find the necessary drivers for my laptop, after I format my hd. I know that my laptop is a Y 550 series with a model number 4186, however, there is one last step choose your model specified before retrieving the necessary drivers. (http://support.lenovo.com/en_US/downloads/default.page?selector=expand#) I tried looking at the sticker on the bottom of my laptop and I tried to open system information under System Tools, without a bit of luck. I have not tried to pass through the BIOS, but simply because I don't think I would have to order to fiind this simple information. I tried Googling, and like many, does not. Does it really matter what model to choose for my drivers or I can pick and hope for the best?
' afternoon...
Welcome to the community.
Here is your driver Y550 matrix: http://support.lenovo.com/en_US/research/hints-or-tips/detail.page?&DocID=HT073108
He must have just about everything what you need
HTH.
-
I enter my serial number in lightroom and I am told that it is unacceptable! What should I do?
Find the serial number of your Adobe product quickly
Using redemption code
http://helpx.Adobe.com/x-productkb/global/redemption-code-help.html
-
HP laptop: enter the model number and get a "game too many results.
My HP laptop dies after 6 weeks. When I contact support, he asks the model number. I enter: say "15-ay041wm" is what the box and laptop. I get a reply that says.
"Sorry, too many results match your search for 15-1y041wm.
"So I try HP Notebook, I get the same mesaage above, except with the HP laptop ' instead of '15-ay041wm.
Because no matter where I'm going, he wants the model number and I give, I can't help. No cat, no nothing.
So someone can tell me how to get support?
If HP is unable to handle the number of model of it's own computers, so I'm not very confident.
Here are the free support number to call in the USA/Canada... 1 800-474-6836.
Now here's another question, you can report to HP on if you want...
You must stay online and listen to the automated assistant trying to talk to you to talk to a representative... visit the HP website... go to this support forum (which has no official presence in HP), etc.
After a minute or two, the Assistant to say, if you can't get online, will stay on the line to speak to a customer services representative.
This is when you will have the opportunity to speak with a support person and report the problem to open a pension case.
-
I am trying to retrieve the phone number of a unit of BB 10. Testing with the ripple and the BlackBerry 10 Dev Simulator. I tried many variations, and when the code runs is always that the phone is not always defined. All the world made a call to blackberry.identity.phone.getLineIds () or blackberry.identity.phone.getLineNumber ()?
If so, post you the code and the config.XML you used to get this working?
I saw this post, and I tried the example code that is supposed to work, but I can ' t get the code working list.
Hello
That API is not supported on BB10 (only BBOS).
-
Hi all
I developed an application where I have 6 pages and 5 tabs and based on the user role I posted the tabs for the user to access these pages.
But when the user, who doesn't have access to the particular page (say, page 2), but still the user can navigate to it directly by typing the page number in the URL.
I want to avoid such scenarios.
eg: http://Apex.Oracle.com/f?p=110:2 , when the user type this in the address bar, it navigates the user to this page even if this particular user does not have access to this page.
How to prevent the user to navigate through the URL, if the user tries to navigate directly through URLS rather than tabs, I have to give the error message.
Version: ORACLE APEX 4.2
Thank you
Good reading this recent post
Re: Authentication at the Page level
All links to a page and the page itself must be secure.
You can also consider the protection of session state to prevent tampering of the URL.
Maybe you are looking for
-
iTunes Store >; purchase question
In iTunes, listed under iTunes Store > purchases, I see that the 250 most recent numbers that I bought. How can I access other (I bought up to 800 songs over the years). I bought a new iMac and to import my old iMac to my new songs purchased. The eas
-
Pavillion g7 nitebook: creation of recovery disks
Just bought a refurbished laptop (new never been used) that comes with windows 8. I want to spend to 8.1 and then windows 10. My problem is that it's said I can only create a recovery disk once. If I create a recovery disc now until I have the upgrad
-
Hello, I buy W520, by market research I founf this W520 is ideal for me. But in seeking, I have some confusion, I found (W520) this model have two different keyboard, one contains the Enter key rectangular staraight, and the other have the Enter key
-
Controlling the STDIN STDOUT of a legacy in LabVIEW application
I have a legacy DOS base program that runs in a command line interface in Windows. Normal use which is a type of operator in a command, look at the result, then type in another command based on the results. I need launch this application, KEEP IT O
-
Printer goes offline on its own
My first Officejet Pro 8500 (A909n) has suddenly gone 'offline '. When I go to tools, network, Wireless Setup Wizard"the printer detects my network and joins it. I print something without any problem, but later, when I try to print something else, s