black Posted April 1, 2008 Report Share Posted April 1, 2008 Piemērs: 1 => a 2 => b 3 => c ... 27 => z 28 => aa 29 => ab ... utt. Vai kāds nav redzējis kādu gatavu formulu? Link to comment Share on other sites More sharing options...
PheliX Posted April 1, 2008 Report Share Posted April 1, 2008 domā kautko tādu: http://en.wikipedia.org/wiki/Hexavigesimal ? Link to comment Share on other sites More sharing options...
black Posted April 1, 2008 Author Report Share Posted April 1, 2008 Yep. Link to comment Share on other sites More sharing options...
bubu Posted April 1, 2008 Report Share Posted April 1, 2008 Formula ir ļoti vienkārša, vajag tik pamatskolas matemātiku zināt: $s = ""; while ($x > 0) { $s = chr(ord('a') + $x%26) . $s; $x /= 26; } Link to comment Share on other sites More sharing options...
black Posted April 1, 2008 Author Report Share Posted April 1, 2008 1. aprīlis, ja? $x dalot ar 26, mēs iegūsim arvien mazāku daļskaitli. Link to comment Share on other sites More sharing options...
Aleksejs Posted April 1, 2008 Report Share Posted April 1, 2008 black, nē, lai cik tas būtu neticami... :D bubu ir uzrakstījis visu pareizi. Link to comment Share on other sites More sharing options...
black Posted April 1, 2008 Author Report Share Posted April 1, 2008 Hmm, jā, Atvainojos. It works. Beigās nonācu pie šāda: function int2token($x) { $s = ""; while ($x >= 1) { $x = $x - 1; $s = chr(ord('a') + ($x%26)) . $s; $x = $x / 26; } return $s; } Link to comment Share on other sites More sharing options...
Aleksejs Posted April 1, 2008 Report Share Posted April 1, 2008 priekš kam $x = $x - 1 ? Link to comment Share on other sites More sharing options...
black Posted April 1, 2008 Author Report Share Posted April 1, 2008 Pieņemsim, ka x sākumā ir viens. Tad ord('a') + ($x%26) būs 'b'. Es gribētu, lai sākas ar 'a'. Link to comment Share on other sites More sharing options...
black Posted April 1, 2008 Author Report Share Posted April 1, 2008 Vispār, iesaku izmēģināt sākotnējo 'bubu' ieteikto algoritmu :) Vienkārši uztaisām ciklu ar 1-100 un paskatāmies, kādus burtus atgriež. Link to comment Share on other sites More sharing options...
bubu Posted April 1, 2008 Report Share Posted April 1, 2008 Tādā gadījumā no $x to 1 atņem pirms while cikla sākuma. Citādi tur nesanāks tas, ko gribi. Link to comment Share on other sites More sharing options...
black Posted April 1, 2008 Author Report Share Posted April 1, 2008 Izmēģini savu versiju :) Būs interesanti. Link to comment Share on other sites More sharing options...
bubu Posted April 1, 2008 Report Share Posted April 1, 2008 $x dalot ar 26, mēs iegūsim arvien mazāku daļskaitli. Ah pareiz, tev taisnība. Sorry, pieradums pie stingrāk tipizētām valodām liek manīt... php ikdienā neprogrammēju, tāpēc daudzkas piemirstas. Aizvieto to dalīšanas rindu par $x = intval($x / 26); un tad būs ok. Link to comment Share on other sites More sharing options...
Recommended Posts