Sum of the digits of n is substring of n: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: Added a Haskell example) |
|||
Line 101: | Line 101: | ||
--------------------------- TEST ------------------------- |
--------------------------- TEST ------------------------- |
||
main :: IO () |
main :: IO () |
||
main = |
main = |
||
mapM_ putStrLn $ showMatches <$> [999, 10000] |
|||
let limit = 999 |
|||
⚫ | |||
showMatches :: Int -> String |
|||
⚫ | |||
showMatches limit = |
|||
⚫ | |||
( show (length xs) |
|||
putStrLn $ |
|||
⚫ | |||
<> " matches in [0.." |
<> " matches in [0.." |
||
<> show limit |
<> show limit |
||
<> "]\n" |
<> "]\n" |
||
) |
|||
putStrLn $ |
|||
unlines |
<> unlines |
||
(unwords |
( unwords |
||
<$> chunksOf 10 (justifyRight w ' ' <$> xs) |
|||
) |
|||
<> "\n" |
|||
where |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
justifyRight :: Int -> Char -> String -> String |
justifyRight :: Int -> Char -> String -> String |
||
justifyRight n c = (drop . length) <*> (replicate n c <>) |
justifyRight n c = (drop . length) <*> (replicate n c <>)</lang> |
||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>48 matches in [0..999] |
<pre>48 matches in [0..999] |
||
0 1 2 3 4 5 6 7 8 9 |
0 1 2 3 4 5 6 7 8 9 |
||
10 20 30 40 50 60 70 80 90 100 |
10 20 30 40 50 60 70 80 90 100 |
||
109 119 129 139 149 159 169 179 189 199 |
109 119 129 139 149 159 169 179 189 199 |
||
200 300 400 500 600 700 800 900 910 911 |
200 300 400 500 600 700 800 900 910 911 |
||
912 913 914 915 916 917 918 919 |
912 913 914 915 916 917 918 919 |
||
365 matches in [0..10000] |
|||
0 1 2 3 4 5 6 7 8 9 |
|||
10 20 30 40 50 60 70 80 90 100 |
|||
109 119 129 139 149 159 169 179 189 199 |
|||
200 300 400 500 600 700 800 900 910 911 |
|||
912 913 914 915 916 917 918 919 1000 1009 |
|||
1018 1027 1036 1045 1054 1063 1072 1081 1090 1108 |
|||
1109 1118 1127 1128 1136 1138 1145 1148 1154 1158 |
|||
1163 1168 1172 1178 1181 1188 1190 1198 1209 1218 |
|||
1227 1236 1245 1254 1263 1272 1281 1290 1309 1318 |
|||
1327 1336 1345 1354 1363 1372 1381 1390 1409 1418 |
|||
1427 1436 1445 1454 1463 1472 1481 1490 1509 1518 |
|||
1527 1536 1545 1554 1563 1572 1581 1590 1609 1618 |
|||
1627 1636 1645 1654 1663 1672 1681 1690 1709 1718 |
|||
1727 1736 1745 1754 1763 1772 1781 1790 1809 1810 |
|||
1811 1812 1813 1814 1815 1816 1817 1818 1819 1827 |
|||
1836 1845 1854 1863 1872 1881 1890 1909 1918 1927 |
|||
1936 1945 1954 1963 1972 1981 1990 2000 2099 2107 |
|||
2117 2127 2137 2147 2157 2167 2177 2187 2197 2199 |
|||
2299 2399 2499 2599 2699 2710 2711 2712 2713 2714 |
|||
2715 2716 2717 2718 2719 2799 2899 2999 3000 3106 |
|||
3116 3126 3136 3146 3156 3166 3176 3186 3196 3610 |
|||
3611 3612 3613 3614 3615 3616 3617 3618 3619 4000 |
|||
4105 4115 4125 4135 4145 4155 4165 4175 4185 4195 |
|||
4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 |
|||
5000 5104 5114 5124 5134 5144 5154 5164 5174 5184 |
|||
5194 5410 5411 5412 5413 5414 5415 5416 5417 5418 |
|||
5419 6000 6103 6113 6123 6133 6143 6153 6163 6173 |
|||
6183 6193 6310 6311 6312 6313 6314 6315 6316 6317 |
|||
6318 6319 7000 7102 7112 7122 7132 7142 7152 7162 |
|||
7172 7182 7192 7210 7211 7212 7213 7214 7215 7216 |
|||
7217 7218 7219 8000 8101 8110 8111 8112 8113 8114 |
|||
8115 8116 8117 8118 8119 8121 8131 8141 8151 8161 |
|||
8171 8181 8191 9000 9010 9011 9012 9013 9014 9015 |
|||
9016 9017 9018 9019 9100 9110 9120 9130 9140 9150 |
|||
9160 9170 9180 9190 9209 9219 9229 9239 9249 9259 |
|||
9269 9279 9289 9299 9920 9921 9922 9923 9924 9925 |
|||
9926 9927 9928 9929 10000</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |