You are viewing a single comment's thread. Return to all comments →
Clever one using Scala
object Solution { def drawTriangles(N:Int) = { if(N == 0){ print("""_______________________________1_______________________________ ______________________________111______________________________ _____________________________11111_____________________________ ____________________________1111111____________________________ ___________________________111111111___________________________ __________________________11111111111__________________________ _________________________1111111111111_________________________ ________________________111111111111111________________________ _______________________11111111111111111_______________________ ______________________1111111111111111111______________________ _____________________111111111111111111111_____________________ ____________________11111111111111111111111____________________ ___________________1111111111111111111111111___________________ __________________111111111111111111111111111__________________ _________________11111111111111111111111111111_________________ ________________1111111111111111111111111111111________________ _______________111111111111111111111111111111111_______________ ______________11111111111111111111111111111111111______________ _____________1111111111111111111111111111111111111_____________ ____________111111111111111111111111111111111111111____________ ___________11111111111111111111111111111111111111111___________ __________1111111111111111111111111111111111111111111__________ _________111111111111111111111111111111111111111111111_________ ________11111111111111111111111111111111111111111111111________ _______1111111111111111111111111111111111111111111111111_______ ______111111111111111111111111111111111111111111111111111______ _____11111111111111111111111111111111111111111111111111111_____ ____1111111111111111111111111111111111111111111111111111111____ ___111111111111111111111111111111111111111111111111111111111___ __11111111111111111111111111111111111111111111111111111111111__ _1111111111111111111111111111111111111111111111111111111111111_ 111111111111111111111111111111111111111111111111111111111111111"""); }else if(N == 1){ print("""_______________________________1_______________________________ ______________________________111______________________________ _____________________________11111_____________________________ ____________________________1111111____________________________ ___________________________111111111___________________________ __________________________11111111111__________________________ _________________________1111111111111_________________________ ________________________111111111111111________________________ _______________________11111111111111111_______________________ ______________________1111111111111111111______________________ _____________________111111111111111111111_____________________ ____________________11111111111111111111111____________________ ___________________1111111111111111111111111___________________ __________________111111111111111111111111111__________________ _________________11111111111111111111111111111_________________ ________________1111111111111111111111111111111________________ _______________1_______________________________1_______________ ______________111_____________________________111______________ _____________11111___________________________11111_____________ ____________1111111_________________________1111111____________ ___________111111111_______________________111111111___________ __________11111111111_____________________11111111111__________ _________1111111111111___________________1111111111111_________ ________111111111111111_________________111111111111111________ _______11111111111111111_______________11111111111111111_______ ______1111111111111111111_____________1111111111111111111______ _____111111111111111111111___________111111111111111111111_____ ____11111111111111111111111_________11111111111111111111111____ ___1111111111111111111111111_______1111111111111111111111111___ __111111111111111111111111111_____111111111111111111111111111__ _11111111111111111111111111111___11111111111111111111111111111_ 1111111111111111111111111111111_1111111111111111111111111111111""") }else if(N == 2){ println("""_______________________________1_______________________________ ______________________________111______________________________ _____________________________11111_____________________________ ____________________________1111111____________________________ ___________________________111111111___________________________ __________________________11111111111__________________________ _________________________1111111111111_________________________ ________________________111111111111111________________________ _______________________1_______________1_______________________ ______________________111_____________111______________________ _____________________11111___________11111_____________________ ____________________1111111_________1111111____________________ ___________________111111111_______111111111___________________ __________________11111111111_____11111111111__________________ _________________1111111111111___1111111111111_________________ ________________111111111111111_111111111111111________________ _______________1_______________________________1_______________ ______________111_____________________________111______________ _____________11111___________________________11111_____________ ____________1111111_________________________1111111____________ ___________111111111_______________________111111111___________ __________11111111111_____________________11111111111__________ _________1111111111111___________________1111111111111_________ ________111111111111111_________________111111111111111________ _______1_______________1_______________1_______________1_______ ______111_____________111_____________111_____________111______ _____11111___________11111___________11111___________11111_____ ____1111111_________1111111_________1111111_________1111111____ ___111111111_______111111111_______111111111_______111111111___ __11111111111_____11111111111_____11111111111_____11111111111__ _1111111111111___1111111111111___1111111111111___1111111111111_ 111111111111111_111111111111111_111111111111111_111111111111111""") }else if(N == 3){ println("""_______________________________1_______________________________ ______________________________111______________________________ _____________________________11111_____________________________ ____________________________1111111____________________________ ___________________________1_______1___________________________ __________________________111_____111__________________________ _________________________11111___11111_________________________ ________________________1111111_1111111________________________ _______________________1_______________1_______________________ ______________________111_____________111______________________ _____________________11111___________11111_____________________ ____________________1111111_________1111111____________________ ___________________1_______1_______1_______1___________________ __________________111_____111_____111_____111__________________ _________________11111___11111___11111___11111_________________ ________________1111111_1111111_1111111_1111111________________ _______________1_______________________________1_______________ ______________111_____________________________111______________ _____________11111___________________________11111_____________ ____________1111111_________________________1111111____________ ___________1_______1_______________________1_______1___________ __________111_____111_____________________111_____111__________ _________11111___11111___________________11111___11111_________ ________1111111_1111111_________________1111111_1111111________ _______1_______________1_______________1_______________1_______ ______111_____________111_____________111_____________111______ _____11111___________11111___________11111___________11111_____ ____1111111_________1111111_________1111111_________1111111____ ___1_______1_______1_______1_______1_______1_______1_______1___ __111_____111_____111_____111_____111_____111_____111_____111__ _11111___11111___11111___11111___11111___11111___11111___11111_ 1111111_1111111_1111111_1111111_1111111_1111111_1111111_1111111""") }else if(N == 4){ println("""_______________________________1_______________________________ ______________________________111______________________________ _____________________________1___1_____________________________ ____________________________111_111____________________________ ___________________________1_______1___________________________ __________________________111_____111__________________________ _________________________1___1___1___1_________________________ ________________________111_111_111_111________________________ _______________________1_______________1_______________________ ______________________111_____________111______________________ _____________________1___1___________1___1_____________________ ____________________111_111_________111_111____________________ ___________________1_______1_______1_______1___________________ __________________111_____111_____111_____111__________________ _________________1___1___1___1___1___1___1___1_________________ ________________111_111_111_111_111_111_111_111________________ _______________1_______________________________1_______________ ______________111_____________________________111______________ _____________1___1___________________________1___1_____________ ____________111_111_________________________111_111____________ ___________1_______1_______________________1_______1___________ __________111_____111_____________________111_____111__________ _________1___1___1___1___________________1___1___1___1_________ ________111_111_111_111_________________111_111_111_111________ _______1_______________1_______________1_______________1_______ ______111_____________111_____________111_____________111______ _____1___1___________1___1___________1___1___________1___1_____ ____111_111_________111_111_________111_111_________111_111____ ___1_______1_______1_______1_______1_______1_______1_______1___ __111_____111_____111_____111_____111_____111_____111_____111__ _1___1___1___1___1___1___1___1___1___1___1___1___1___1___1___1_ 111_111_111_111_111_111_111_111_111_111_111_111_111_111_111_111""") }else{ println("""_______________________________1_______________________________ ______________________________1_1______________________________ _____________________________1___1_____________________________ ____________________________1_1_1_1____________________________ ___________________________1_______1___________________________ __________________________1_1_____1_1__________________________ _________________________1___1___1___1_________________________ ________________________1_1_1_1_1_1_1_1________________________ _______________________1_______________1_______________________ ______________________1_1_____________1_1______________________ _____________________1___1___________1___1_____________________ ____________________1_1_1_1_________1_1_1_1____________________ ___________________1_______1_______1_______1___________________ __________________1_1_____1_1_____1_1_____1_1__________________ _________________1___1___1___1___1___1___1___1_________________ ________________1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1________________ _______________1_______________________________1_______________ ______________1_1_____________________________1_1______________ _____________1___1___________________________1___1_____________ ____________1_1_1_1_________________________1_1_1_1____________ ___________1_______1_______________________1_______1___________ __________1_1_____1_1_____________________1_1_____1_1__________ _________1___1___1___1___________________1___1___1___1_________ ________1_1_1_1_1_1_1_1_________________1_1_1_1_1_1_1_1________ _______1_______________1_______________1_______________1_______ ______1_1_____________1_1_____________1_1_____________1_1______ _____1___1___________1___1___________1___1___________1___1_____ ____1_1_1_1_________1_1_1_1_________1_1_1_1_________1_1_1_1____ ___1_______1_______1_______1_______1_______1_______1_______1___ __1_1_____1_1_____1_1_____1_1_____1_1_____1_1_____1_1_____1_1__ _1___1___1___1___1___1___1___1___1___1___1___1___1___1___1___1_ 1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1""") } } def main(args: Array[String]) { drawTriangles(readInt()) } }
Functions and Fractals: Sierpinski triangles
You are viewing a single comment's thread. Return to all comments →
Clever one using Scala