Skip to content

Instantly share code, notes, and snippets.

@Faheetah
Created March 23, 2021 03:47
Show Gist options
  • Save Faheetah/41f2fa206900fbf12d0d27c1b8dc3ce7 to your computer and use it in GitHub Desktop.
Save Faheetah/41f2fa206900fbf12d0d27c1b8dc3ce7 to your computer and use it in GitHub Desktop.
How many permutations of rows can make 51 stars, max of 25 per row, max of 10 rows, can alternate
defmodule FlagStars do
def calculate() do
Enum.reduce(1..25, [], fn first, acc ->
acc ++ Enum.reduce(1..25, [], fn second, acc ->
acc ++ Enum.reduce(1..10, [], fn rows, acc ->
acc ++ cond do
(rows * first) == 51 -> [{first, rows}]
((div(rows, 2) + rem(rows, 2)) * first) + (div(rows, 2) * second) == 51 -> [{first, second, rows}]
true -> []
end
end)
end)
end)
|> Enum.uniq()
|> Enum.each(&(print_stars(&1)))
end
def print_stars({first, rows}) do
IO.puts "#{rows} rows with #{first} each"
Enum.each(1..rows, fn _ ->
IO.puts String.duplicate("*", first)
end)
IO.puts "\n"
end
def print_stars({first, second, rows}) do
IO.puts "#{rows} rows alternating #{first} and #{second}"
Enum.each(1..rows, fn row ->
case rem(row, 2) do
1 -> IO.puts String.duplicate("*", first)
0 -> IO.puts String.duplicate("*", second)
end
end)
IO.puts "\n"
end
end
FlagStars.calculate()
6 rows alternating 1 and 17
*
****************
*
****************
*
****************
5 rows alternating 1 and 24
*
************************
*
************************
*
6 rows alternating 2 and 15
**
***************
**
***************
**
***************
9 rows alternating 3 and 9
***
*********
***
*********
***
*********
***
*********
***
7 rows alternating 3 and 13
***
*************
***
*************
***
*************
***
6 rows alternating 3 and 14
***
**************
***
**************
***
**************
5 rows alternating 3 and 21
***
*********************
***
*********************
***
6 rows alternating 4 and 13
****
*************
****
*************
****
*************
6 rows alternating 5 and 12
*****
************
*****
************
*****
************
5 rows alternating 5 and 18
*****
******************
*****
******************
*****
7 rows alternating 6 and 9
******
*********
******
*********
******
*********
******
6 rows alternating 6 and 11
******
***********
******
***********
******
***********
9 rows alternating 7 and 4
*******
****
*******
****
*******
****
*******
****
*******
6 rows alternating 7 and 10
*******
**********
*******
**********
*******
**********
5 rows alternating 7 and 15
*******
***************
*******
***************
*******
6 rows alternating 8 and 9
********
*********
********
*********
********
*********
7 rows alternating 9 and 5
*********
*****
*********
*****
*********
*****
*********
6 rows alternating 9 and 8
*********
********
*********
********
*********
********
5 rows alternating 9 and 12
*********
************
*********
************
*********
6 rows alternating 10 and 7
**********
*******
**********
*******
**********
*******
6 rows alternating 11 and 6
***********
******
***********
******
***********
******
5 rows alternating 11 and 9
***********
*********
***********
*********
***********
7 rows alternating 12 and 1
************
*
************
*
************
*
************
6 rows alternating 12 and 5
************
*****
************
*****
************
*****
6 rows alternating 13 and 4
*************
****
*************
****
*************
****
5 rows alternating 13 and 6
*************
******
*************
******
*************
3 rows alternating 13 and 25
*************
*************************
*************
6 rows alternating 14 and 3
**************
***
**************
***
**************
***
3 rows alternating 14 and 23
**************
***********************
**************
6 rows alternating 15 and 2
***************
**
***************
**
***************
**
5 rows alternating 15 and 3
***************
***
***************
***
***************
3 rows alternating 15 and 21
***************
*********************
***************
6 rows alternating 16 and 1
****************
*
****************
*
****************
*
3 rows alternating 16 and 19
****************
*******************
****************
3 rows with 17 each
*****************
*****************
*****************
3 rows alternating 18 and 15
******************
***************
******************
3 rows alternating 19 and 13
*******************
*************
*******************
3 rows alternating 20 and 11
********************
***********
********************
3 rows alternating 21 and 9
*********************
*********
*********************
3 rows alternating 22 and 7
**********************
*******
**********************
3 rows alternating 23 and 5
***********************
*****
***********************
3 rows alternating 24 and 3
************************
***
************************
3 rows alternating 25 and 1
*************************
*
*************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment