Created
December 17, 2013 14:44
-
-
Save edbond/8005978 to your computer and use it in GitHub Desktop.
pack links limited by line width
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ["YIIzO", "turcUUfN", "EhSethGlS", "p_fhwdsts", "C", "HRoz", "_QXH", "EFDMpgc", "N", "DbKdomnTiu", "CVtLGKsP", "MAZx", "rlLuMB", "qipauyMRkp", "t", "RV", "uIldIkV", "lKaYnIeWs", "_FKzuYmBMo", "SVlI", "vXwgdmxF", "UI", "bC lZ", "D", "zVHGWTtBD", "WQcf", "JzEAJ", "BLItG", "fvPqgfonB", "Uz_", "G", "w", "k", "qkbIEgNrQ", "pY", "CX", "OGw_", "TRJds", "vXLGltC_q", "KNnvml", "Se ED"] | |
| {:vlazit=>["YIIzO", "turcUUfN"], :ne_vlazit=>["EhSethGlS", "p_fhwdsts", "C", "HRoz", "_QXH", "EFDMpgc", "N", "DbKdomnTiu", "CVtLGKsP", "MAZx", "rlLuMB", "qipauyMRkp", "t", "RV", "uIldIkV", "lKaYnIeWs", "_FKzuYmBMo", "SVlI", "vXwgdmxF", "UI", "bC lZ", "D", "zVHGWTtBD", "WQcf", "JzEAJ", "BLItG", "fvPqgfonB", "Uz_", "G", "w", "k", "qkbIEgNrQ", "pY", "CX", "OGw_", "TRJds", "vXLGltC_q", "KNnvml", "Se ED"], :length=>215} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # alphabet | |
| a = ('A'..'Z').to_a + ('a'..'z').to_a + [' ', '_'] | |
| # random N links | |
| N = 40 | |
| # max length of link text | |
| M = 10 | |
| links = (0..N).map { (0..rand(M)).map { a.sample }.join.strip } | |
| puts links.inspect | |
| # Max line length | |
| L = 20 | |
| m = { vlazit: [], ne_vlazit: [], length: 0 } | |
| a = links.inject(m) do |acc, link| | |
| l = link.size | |
| if (acc[:length] + l) <= L | |
| acc[:vlazit] << link | |
| else | |
| acc[:ne_vlazit] << link | |
| end | |
| acc[:length] += l | |
| acc | |
| end | |
| puts a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment