logic

Matrix arrangement issues in php

家住魔仙堡 提交于 2019-12-04 02:03:54
I would like to know some solutions to such a problem. It is given a number lets say 16 and you have to arrange a matrix this way 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7 the language doesn't matter, (preferably PHP); [EDIT: Update] If language doesn't matter: Go to: http://rosettacode.org/wiki/Spiral_matrix In PHP: Here you go: <?php function getSpiralArray($n) { $pos = 0; $count = $n; $value = -$n; $sum = -1; do { $value = -1 * $value / $n; for ($i = 0; $i < $count; $i++) { $sum += $value; $result[$sum / $n][$sum % $n] = $pos++; } $value *= $n; $count--; for ($i = 0; $i < $count; $i++) { $sum

How to copy file from one directory to other in azure through java service?

谁说胖子不能爱 提交于 2019-12-04 02:00:24
问题 I am creating application to copy file from one directory to another. jSON input is : { "accountName" : "name", "accountKey" : "key", "source" : "directory1/directory2/directory3/directory4", "destination" : "directory1/directory2", "fileToCopy" : "1" } Directory 4 is under directory 3, 3 is under 2 and 2 is under 1. Want to copy file named as "1" from directory 4 to directory 2. My java code is : @Override public JSONObject copyFile(JSONObject jsonInput) throws IOException,

Swapping column values in Oracle

冷暖自知 提交于 2019-12-04 00:55:36
I was solving one of the puzzles and came across swapping column values using DML queries: SELECT * FROM TEMP_TABLE; ID1, ID2 -------- 20, 15 20, 15 20, 15 Solution is mathematical calculation: UPDATE TEMP_TABLE SET ID1=ID1+ID2; UPDATE TEMP_TABLE SET ID2=ID1-ID2; UPDATE TEMP_TABLE SET ID1=ID1-ID2; Now, I am trying to figure out whether this can be applied to Strings or not, please suggest. SELECT * FROM TEMP_TABLE_NEW; ID1, ID2 -------- ABC, XYZ ABC, XYZ ABC, XYZ René Nyffenegger There's no need to have three update statements, one is sufficient: UPDATE temp_table_new SET id1 = id2, id2 = id1;

How to call REST API for azure file storage using postman?

我的未来我决定 提交于 2019-12-03 21:50:46
I want to call REST API related to file storage of azure through postman. Here is how I am making my request : I am making request to list all shares in file storage account as described here : https://docs.microsoft.com/en-us/rest/api/storageservices/list-shares I am getting below error: "The Date header in the request is incorrect." What changes I should make ? Edit1 : When I provided date n correct format, I have error like this : I am getting below error: "The MAC signature found in the HTTP request '' is not the same as any computed signature. Server used following string to sign: 'GET"

Algorithm to determine the “usual” cash payment amounts for a given price

陌路散爱 提交于 2019-12-03 16:16:16
You walk into a store, select several products, then go to the counter to pay your bill. The total is some amount ( A ). You reach into your wallet, purse, or pocket and put down some cash ( P ), where P >= A , and the cashier gives you change. Given the set of coins and bills that are in circulation, what are the most likely values for P ? Some examples, assuming that the available bills are $5, $10, $20, $50 and $100, and the available coins are 5c, 10c and 25c: A = $151.24 P[1] = $160 (8x$20) or ($100 + 3x$20) P[2] = $155 ($100 + $50 + $5) A = $22.65 P[1] = $25 ($20 + $5) P[2] = $30 ($20 +

Logic Behind Social Login

和自甴很熟 提交于 2019-12-03 14:37:45
问题 I have created a nice little login script for my website that lets users login with Facebook or Google at the moment. What I am trying to do is set some checks to make sure that duplicates do not appear in the database. Here are some scenarios I have covered : Login with Google/Facebook account and I have already registered this account, This will log the user straight in as they have already linked this account. User has already registered with Google account, yet clicks Facebook because

How to persist branching logic into database?

瘦欲@ 提交于 2019-12-03 13:26:34
We are building a survey engine for our internal use. I would like to know how to persist the question branching logic into the database? Any body done this before or any ideas on the schema for the database? If the user responses with an answer, we need to skip to the next questions based on the logic added to the questions Each question can have multiple logic added to it. For eg: Question: Is it Sunny, Raining or Cloudy? Answer: Raining. The next question should be based on the previous answer. if(Raining) { } if(Sunny) { } if(Cloudy) { } how do I persist the above to the database and go

Test if string is not equal to either of two strings

故事扮演 提交于 2019-12-03 11:27:51
I am just learning RoR so please bear with me. I am trying to write an if or statement with strings. Here is my code: <% if controller_name != "sessions" or controller_name != "registrations" %> I have tried many other ways, using parentheses and || but nothing seems to work. Maybe its because of my JS background... How can I test if a variable is not equal to string one or string two? This is a basic logic problem: (a !=b) || (a != c) will always be true as long as b != c. Once you remember that in boolean logic (x || y) == !(!x && !y) then you can find your way out of the darkness. (a !=b) |

oracle sql date not later than today

ぃ、小莉子 提交于 2019-12-03 11:03:52
问题 I need to display some data if it's a - new data - updated data let's say, I will be basing these data from a publishdate column and updated column where publishdate and updateddate are both timestamps ? . so how to compute the date if it's a new one ? 回答1: For last 24 hours: Where publish_date >= sysdate -1 or anytime today (midnight forward) where publish_date >= trunc(sysdate) If this is a big table, I assume you have an index on publish_date. If you use trunc(publish_date), it may not be

Split down a number in seconds to days, hours, minutes, and seconds?

蹲街弑〆低调 提交于 2019-12-03 09:32:17
问题 I've heard that it's possible to accomplish this using the modulus % operator present in most programming languages. The real question is, how? I'm unfamiliar with how modulus works, so I've had difficulties using it in the past. Given the present time here in seconds since 1970, 1307758473.484 , how can I calculate how many years that is, days that is, hours that is, and minutes that is using modulus? I'm essentially looking to format it like this: "5 years, 10 days, 12 hours, 7 minutes, and