1

Topic: Magic age

Good afternoon, dear colleagues! Today at me  If my age to write down in the form of a decimal number we receive certain  number. Then - we change digit places. We receive the correct value of my age in a hexadecimal type. A question: how many years to me knocked today? P.S. It is desirable to show the code (in any language known to you), proving your case.

2

Re: Magic age

Hello, AlexGin, you wrote: AG> Good afternoon, dear colleagues! AG> today at me  AG> If my age to write down in the form of a decimal number we receive certain  number. AG> then - we change digit places. AG> we receive the correct value of my age in a hexadecimal type. AG> a question: how many years to me knocked today? AG> P.S. It is desirable to show the code (in any language known to you), proving your case. A*10+B=B*16+A 3A=5B A=5 B=3 53=0x35

3

Re: Magic age

Hello, AlexGin, you wrote: AG> Good afternoon, dear colleagues! AG> today at me  AG> If my age to write down in the form of a decimal number we receive certain  number. AG> then - we change digit places. AG> we receive the correct value of my age in a hexadecimal type. AG> a question: how many years to me knocked today? AG> P.S. It is desirable to show the code (in any language known to you), proving your case. Python: https://repl.it/@doctorlans/Determine-AlexGin-Age

4

Re: Magic age

Hello, AlexGin, you wrote: AG> P.S. It is desirable to show the code (in any language known to you), proving your case. package main import "fmt" func main () {for i: = 10; i <100; i ++ {a, b: = i/10, i%10 if a+b*16 == i {fmt. Printf ("%d == 0x%d%d\n", i, b, a)}}} $ go run test.go 53 == 0x35 It's no fun to be old, more shortly

5

Re: Magic age

Hello, D.Lans, you wrote: AG>> P.S. It is desirable to show the code (in any language known to you), proving your case. DL> Python: DL> https://repl.it/@doctorlans/Determine-AlexGin-Age not . It is necessary on a C ++ 20 by means of metaprogramming to make

6

Re: Magic age

Hello, Pzz, you wrote: Pzz> Hello, AlexGin, you wrote:... Pzz> $ go run test.go Pzz> 53 == 0x35 Pzz> It's no fun to be old, is shorter Than my year - my riches very much were pleasant To me your decision - in the plan mathematical. P.S. If I am not mistaken - language Go.

7

Re: Magic age

Hello, kov_serg, you wrote: _> Hello, D.Lans, you wrote: AG>>> P.S. It is desirable to show the code (in any language known to you), proving your case. DL>> Python: DL>> https://repl.it/@doctorlans/Determine-AlexGin-Age _> not . It is necessary on a C ++ 20 by means of metaprogramming It is possible to make and on that that  is: #include <string> #include <sstream> #include <map> #include <vector> #include <algorithm>//std:: for_each #include <memory> using namespace std; using MAP_IH = map <int, string>; using INT_VECTOR = vector <int>; class CHexCount {public: CHexCount (); ~CHexCount (); MAP_IH& GetMapIntHex (); INT_VECTOR CalculateMagicNumbers (); private: MAP_IH m_mapIntHex;}; CHexCount:: CHexCount () {for (int i = 1; i <128; i ++) {stringstream ss; ss <<std:: hex <<i; string sOut = ss.str (); m_mapIntHex [i] = sOut;} }... INT_VECTOR CHexCount:: CalculateMagicNumbers () {INT_VECTOR vectMagicNums; std:: for_each (cbegin (m_mapIntHex), cend (m_mapIntHex), [&vectMagicNums] (pair <int, string> pairIntHex) {stringstream ss; ss <<pairIntHex.first; string strInt = ss.str (); string strHex = pairIntHex.second; int iStrSize1 = strInt.size (); int iStrSize2 = strHex.size (); if ((iStrSize1 == 2) && (iStrSize2 == 2)) {char chrInt0 = strInt [0]; char chrInt1 = strInt [1]; if ((strHex [0] == chrInt1) && (strHex [1] == chrInt0)) {vectMagicNums.push_back (pairIntHex.first);}}}); return vectMagicNums;}

8

Re: Magic age

Hello, kov_serg, you wrote: DL>> Python: DL>> https://repl.it/@doctorlans/Determine-AlexGin-Age _> Not . It is necessary on a C ++ 20 by means of metaprogramming to make https://godbolt.org/g/yJ588p

9

Re: Magic age

Hello, vopl, you wrote: V> Hello, kov_serg, you wrote: DL>>> Python: DL>>> https://repl.it/@doctorlans/Determine-AlexGin-Age _>> Not . It is necessary on a C ++ 20 by means of metaprogramming to make V> https://godbolt.org/g/yJ588p the Old kind C ++ template <int n> struct a C {enum {ab=C <n-1>:: ab+1, a=ab/10, b=ab%10, h=b*16+a, r = (ab == h)? ab:C <n-1>:: r};}; template <> struct a C <0> {enum {r, ab=r};}; #include<iostream> int main (int argc, char ** argv) {std:: cout <<"age =" <<a C <99>:: r <<std:: endl; return 0;}

10

Re: Magic age

The job did not read. AG> a question: how many years to me knocked today? AG> P.S. It is desirable to show the code (in any language known to you), proving your case. The answer: 53 #include <iostream> void main () {int year; std:: cout <<"Vvedite god vashego rozhdeniya:"; std:: cin>> year; std:: cout <<2018 - year;}

11

Re: Magic age

Hello, AlexGin, you wrote: AG> Good afternoon, dear colleagues! AG> today at me  AG> If my age to write down in the form of a decimal number we receive certain  number. AG> then - we change digit places. AG> we receive the correct value of my age in a hexadecimal type. AG> a question: how many years to me knocked today? AG> P.S. It is desirable to show the code (in any language known to you), proving your case. SQL Server DECLARE @s bigint = 10, @e bigint = 100; WITH Z AS (SELECT 0 z FROM (VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15)) T (n)), Y AS (SELECT 0 z FROM Z a, Z b, Z c, Z d, Z e, Z f, Z g, Z h, Z i, Z j, Z k, Z l, Z m, Z n, Z o, Z p), N AS (SELECT ROW_NUMBER () OVER (PARTITION BY 0 ORDER BY z) n FROM Y) SELECT TOP 1 @s + n - 1 age FROM N/* not to put at all it is more top 1 */WHERE @s + n - 1 = (@s + n - 1) than % 16 * 10 + (@s + n - 1) / 16

12

Re: Magic age

Hello, D.Lans, you wrote: DL> SQL Server DL> DL> DECLARE @s bigint = 10 DL>, @e bigint = 100 DL>; WITH DL> Z AS (SELECT 0 z FROM (VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15)) T (n)), DL> Y AS (SELECT 0 z FROM Z a, Z b, Z c, Z d, Z e, Z f, Z g, Z h, Z i, Z j, Z k, Z l, Z m, Z n, Z o, Z p), DL> N AS (SELECT ROW_NUMBER () OVER (PARTITION BY 0 ORDER BY z) n FROM Y) DL> SELECT TOP 1 @s + n - 1 age FROM N/* not to put at all it is more top 1 */DL> WHERE @s + n - 1 = (@s + n - 1) than % 16 * 10 + (@s + n - 1) / 16 DL> Postgres SELECT age FROM generate_series (10, 99) AS age WHERE age = age%16*10 + age/16;

13

Re: Magic age

Hello, AlexGin, Here my son solved such problems in the third (!!) a class without abstruse "programming" everyone there. Unless about hexadecimal system he yet does not know - all problems dared at swaps of digits in customary decimal system. And the correct decision was resulted by the colleague kov_serg.

14

Re: Magic age

Hello, Vlad_SP, you wrote: V_S> Here my son solved such problems in the third (!!) a class without abstruse "programming" everyone there. Means - there is an occasion to be proud of the son!!! V_S> unless about hexadecimal system he yet does not know - all problems dared at swaps of digits in customary decimal system. And the correct decision was resulted by the colleague kov_serg.  - the correct decisions can be more than one. Colleagues kov_serg and vopl gave the mathematical decision. Thus a companion vopl made for this purpose an aaplet. All remaining - programmed the decision a trial and error method. This approach  also has the right to life

15

Re: Magic age

Hello, AlexGin, you wrote:... AG> Colleagues kov_serg and vopl gave the mathematical decision. AG> thus a companion vopl made for this purpose an aaplet. AG> all remaining - programmed the decision a trial and error method. This approach  also has the right to life Generally that, I too

16

Re: Magic age

Hello, vopl, here still the ambush that in our century "numeral technologies" to write on an analog leaflet an analog pencil purely mathematical decision which was resulted by the colleague kov_serg - occupies less time, than even start strongly simple IDE (CodeBlocks, for example). And if it is not visible - to pay what for differences more to waste time?

17

Re: Magic age

Hello, Vlad_SP, you wrote: V_S> Hello, vopl, V_S> here still the ambush that in our century "numeral technologies" to write on an analog leaflet an analog pencil purely mathematical decision which was resulted by the colleague kov_serg - occupies less time, than even start strongly simple IDE (CodeBlocks, for example). And if it is not visible - to pay what for differences more to waste time? Well, ... Depends on the task and correctness of a choice of the tool, in my opinion. How many years Diophantus lived? On the calculator it chik-chik-is ready. And on a piece of paper I would puff with  these...

18

Re: Magic age

AG> P.S. It is desirable to show the code (in any language known to you), proving your case. Eshell V9.3.2 (abort with ^G) 1> [io:format ("~b~n", [N]) || N <-lists:seq (11,99), lists:reverse (integer_to_list (N, 16)) == integer_to_list (N)]. 53

19

Re: Magic age

Hello, Vlad_SP, you wrote: V_S> Here my son solved such problems in the third (!!) a class without abstruse "programming" everyone there. Unless about hexadecimal system he yet does not know - all problems dared at swaps of digits in customary decimal system. I to the daughter told about numeration systems and taught to convert between DEC, BIN and HEX in its first class.

20

Re: Magic age

In Excel formulas: 10 =LEFT (B4,1) =RIGHT (B4,1) =VALUE (D4&C4) =DEC2HEX (E4) =TRIM (B4) =TRIM (F4) 10 1 0 1 1 FALSE 11 1 1 11 B FALSE 12 1 2 21 15 FALSE 13 1 3 31 1F FALSE 14 1 4 41 29 FALSE 15 1 5 51 33 FALSE 16 1 6 61 3D FALSE 17 1 7 71 47 FALSE 18 1 8 81 51 FALSE 19 1 9 91 5B FALSE 20 2 0 2 2 FALSE 21 2 1 12 Cs FALSE 22 2 2 22 16 FALSE 23 2 3 32 20 FALSE 24 2 4 42 2A FALSE 25 2 5 52 34 FALSE 26 2 6 62 3E FALSE 27 2 7 72 48 FALSE 28 2 8 82 52 FALSE 29 2 9 92 5C FALSE 30 3 0 3 3 FALSE 31 3 1 13 D FALSE 32 3 2 23 17 FALSE 33 3 3 33 21 FALSE 34 3 4 43 2B FALSE 35 3 5 53 35 TRUE