13
2
You have a box with a single digit number in each corner:
1|2
---
3|4
If we concatenate the digits along rows left to right, we get 12 and 34. If we concatenate the digits along columns top to bottom, we get 13 and 24. If we add all of these numbers, we get 12+34+13+24 = 83.
Challenge
Write a program to print all such boxes where the sum calculated as above is equal to 100.
Assuming each corner contains a single digit number between 1 and 9, there are 9 combinations: 1157, 1247, 1337, 1427, 1517, 2138, 2228, 2318, and 3119. (Note that there are 25 combinations if we include 0, but we're not for this challenge.)
Note that the example 1234 doesn't work since 12+34+13+24 does not equal 100.
Input
None
Output
Answer boxes in the following format:
A|B
---
C|D
Output should be printed to STDOUT or closest alternative.
Rules
- AB + CD + AC + BD = 100
- Each corner will contain the positive integers 1-9 only.
- 0 is excluded.
- Numbers can be used more than once.
- You need to draw the boxes, as above. (
A|B\n---\nC|D\n) - You need to output all valid answers.
- An additional trailing newline is fine.
- code-golf, so shortest code in bytes wins.
- Standard loopholes and T&C's apply.
This is my first submission so please do let me know if I need to clarify anything.
Could you show what the output is supposed to be? Also, what about a trailing newline character? – Spikatrix – 2015-07-20T12:18:09.650
Nice challenge. I think you need to explicitly tell what numbers need to be added. The line "The two, concatenated, two digit numbers across PLUS the two, two digit numbers down have to equal 100." is not clear enough. I only figured out using the example of 1234. Also, I am only getting 9 such combinations. Can you please mention the 16 combinations ? – Optimizer – 2015-07-20T12:18:13.823
Sure, I'll update the question to be more specific. Thanks. – Denham Coote – 2015-07-20T12:21:24.513
Sorry @Optimizer, I forgot a few solutions that contained 0 in my list. You are correct. – Denham Coote – 2015-07-20T12:28:56.437
Welcome to PPCG. For future reference, I think this would have been better if you had included zero. The reason is, with only 9 combinations it makes sense to hardcode the solutions, which is 36 characters (or 6 combinations / 24 characters if you count diagonal reflections as equivalent.) Including zero would have made it worthwhile to write code to search for all combinations. But as you already have an answer , I wouldn't change the rules now. – Level River St – 2015-07-20T13:06:06.473
@steveverrill ah, here I thought I was making it more interesting as one would need to manually exclude answers with '0' (if searching through the possible answers) – Denham Coote – 2015-07-20T13:14:17.890
So I can choose which of the 9 solutions I want to output? – Peter Taylor – 2015-07-20T15:32:15.423
Oh, sorry for not being specific. No, you should output all valid combinations. – Denham Coote – 2015-07-20T15:54:14.940
1I made a few edits to the explanation and formatting. If it doesn't match your original intent, please roll back the edit. – Alex A. – 2015-07-20T16:33:27.597
1@DenhamCoote actually, my semi-hardcoded solution was quite interesting to do, because it's only semi-hardcoded. This has been an exception to the rule, because questions where blatant hardcoding is the best / most obvious option often don't produce interesting answers (see recent borromean rings question for example.) Thank you for the question. – Level River St – 2015-07-20T17:56:14.627
Are trailing spaces in the blank lines allowedd? – kirbyfan64sos – 2015-07-20T22:11:41.040
@kirbyfan64son since the blank lines are in fact optional, sure, trailing spaces in blank lines are ok. – Denham Coote – 2015-07-20T22:18:12.167
One question for you regulars: Am I supposed to 'accept' the answer with the fewest bytes, or are the upvotes the decider? If I should, how long does one typically wait? Thank you very much to everyone who has answered so far! – Denham Coote – 2015-07-21T11:55:33.757
Accept the answer with fewest bytes, as that is what's stated in your question (in accordance with the codegolf tag.) This means languages like Pyth or Cjam nearly always win. The fairness of this has been questioned by many new users on meta, but the answer is always the same: an interesting answer in a verbose language gains more reputation from its upvotes, so failing to get accepted doesn't matter. It's strongly preferred to verify the answer yourself before accepting. BTW, questions which "win" by getting the most upvotes are tagged popularity contest (These are disliked by many people.) – Level River St – 2015-07-21T22:22:23.357
Ah, thanks for that! I didn't set a time limit on this, so how long is usually appropriate before accepting? A week? Then, if I accept and then a shorter answer comes, should I change the accepted answer? (Sorry, don't know what's considered rude. Also, why are popularity contests disliked? Surely, just don't take part if it's not someone's cup of tea?) – Denham Coote – 2015-07-21T22:32:55.387
1Accepting an answer may give the impression the question is finished, so I'd leave it a while yet. If you get more answers afterwards, you can change the acceptance, but that means you have to keep a lookout, which you may not have time to do. Popularity contests are disliked because they are often lazily written and overly broad, often of the type "Do X in the most complex way possible." Generally the only good popularity questions are in image processing, where human evaluation is the only way to decide if the algorithm is good or not. Image processing excludes pure art which is off topic. – Level River St – 2015-07-22T08:26:11.310