{"id":3942,"date":"2021-05-06T22:48:58","date_gmt":"2021-05-06T22:48:58","guid":{"rendered":"https:\/\/www.gubatron.com\/blog\/?p=3942"},"modified":"2021-05-06T22:48:58","modified_gmt":"2021-05-06T22:48:58","slug":"pascal-triangle-generator-in-python-and-then-in-haskell-the-gubatron-method","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/pascal-triangle-generator-in-python-and-then-in-haskell-the-gubatron-method\/","title":{"rendered":"Pascal Triangle Generator in Python, and then in Haskell &#8211; The Gubatron Method"},"content":{"rendered":"<p>Here&#8217;s in python, imperatively, and then in functional style without the need for loops.<\/p>\n<style>.gist table { margin-bottom: 0; }<\/style>\n<div style=\"tab-size: 8\" id=\"gist107589678\" class=\"gist\">\n<div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n<div class=\"gist-data\">\n<div class=\"js-gist-file-update-container js-task-list-container\">\n<div id=\"file-pascal-py\" class=\"file my-2\">\n<div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-python  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"pascal.py content, created by gubatron on 02:45AM on January 27, 2021.\"\n    ><\/p>\n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n<p>  <template class=\"js-file-alert-template\"><\/p>\n<div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg><br \/>\n    <span><br \/>\n      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.<br \/>\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a><br \/>\n    <\/span><\/p>\n<div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters<br \/>\n<\/a>\n<\/div>\n<\/div>\n<p><\/template><br \/>\n<template class=\"js-line-alert-template\"><br \/>\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\"><br \/>\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg><br \/>\n<\/span><\/template><\/p>\n<table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"pascal.py\">\n<tr>\n<td id=\"file-pascal-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n<td id=\"file-pascal-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def pascal(n):<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n<td id=\"file-pascal-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    if n == 1:<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n<td id=\"file-pascal-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">        return [ 1 ]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n<td id=\"file-pascal-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    if n == 2:<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n<td id=\"file-pascal-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">        return [ 1, 1 ]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n<td id=\"file-pascal-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    prev = pascal(n-1)<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n<td id=\"file-pascal-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">    results = []<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n<td id=\"file-pascal-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">    for i in range(n):<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n<td id=\"file-pascal-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">        if i == 0:<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n<td id=\"file-pascal-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">          continue<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n<td id=\"file-pascal-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">        if i == n-1:<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n<td id=\"file-pascal-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">            break<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n<td id=\"file-pascal-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">        results.append(prev[i] + prev[i-1])<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n<td id=\"file-pascal-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n<td id=\"file-pascal-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">    return [1] + results + [1]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n<td id=\"file-pascal-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n<td id=\"file-pascal-py-LC17\" class=\"blob-code blob-code-inner js-file-line\"># functional style, no loops<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n<td id=\"file-pascal-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">def pascal_fp(n):<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n<td id=\"file-pascal-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">    if n == 1:<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n<td id=\"file-pascal-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">        return [ 1 ]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n<td id=\"file-pascal-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">    prev = pascal_fp(n-1)<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n<td id=\"file-pascal-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">    return list(map(lambda x,y:x+y, [0] + prev, prev + [0]))<\/td>\n<\/tr>\n<\/table>\n<\/div><\/div>\n<\/p><\/div>\n<\/div><\/div>\n<div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/gubatron\/ed966ea4e614d6733715376ad5cfb85f\/raw\/aa6f7f492bd0597d3b0a06155cdd7495be6a004c\/pascal.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a><br \/>\n        <a href=\"https:\/\/gist.github.com\/gubatron\/ed966ea4e614d6733715376ad5cfb85f#file-pascal-py\" class=\"Link--inTextBlock\"><br \/>\n          pascal.py<br \/>\n        <\/a><br \/>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n<\/p><\/div>\n<\/div>\n<p>Here&#8217;s in Haskell, I call it the gubatron&#8217;s method, explained in the comments.<br \/>\nSaw it by looking at a pattern while trying to solve it in paper, it just clicked.<br \/>\nNot sure if this is how other people code this solution.<\/p>\n<style>.gist table { margin-bottom: 0; }<\/style>\n<div style=\"tab-size: 8\" id=\"gist107590545\" class=\"gist\">\n<div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n<div class=\"gist-data\">\n<div class=\"js-gist-file-update-container js-task-list-container\">\n<div id=\"file-pascal-hs\" class=\"file my-2\">\n<div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-haskell  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"pascal.hs content, created by gubatron on 04:01AM on January 27, 2021.\"\n    ><\/p>\n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n<p>  <template class=\"js-file-alert-template\"><\/p>\n<div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg><br \/>\n    <span><br \/>\n      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.<br \/>\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a><br \/>\n    <\/span><\/p>\n<div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters<br \/>\n<\/a>\n<\/div>\n<\/div>\n<p><\/template><br \/>\n<template class=\"js-line-alert-template\"><br \/>\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\"><br \/>\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg><br \/>\n<\/span><\/template><\/p>\n<table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"pascal.hs\">\n<tr>\n<td id=\"file-pascal-hs-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n<td id=\"file-pascal-hs-LC1\" class=\"blob-code blob-code-inner js-file-line\">&#8212; Gubatron&#39;s method<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n<td id=\"file-pascal-hs-LC2\" class=\"blob-code blob-code-inner js-file-line\">&#8212; n=3 [1, 2, 1]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n<td id=\"file-pascal-hs-LC3\" class=\"blob-code blob-code-inner js-file-line\">&#8212; copy the list and append a 0 on the left of the first<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n<td id=\"file-pascal-hs-LC4\" class=\"blob-code blob-code-inner js-file-line\">&#8212; and append a 0 at the end of the second<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n<td id=\"file-pascal-hs-LC5\" class=\"blob-code blob-code-inner js-file-line\">&#8212;      [0, 1, 2, 1]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n<td id=\"file-pascal-hs-LC6\" class=\"blob-code blob-code-inner js-file-line\">&#8212;      [1, 2, 1, 0]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n<td id=\"file-pascal-hs-LC7\" class=\"blob-code blob-code-inner js-file-line\">&#8212; add them up!<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n<td id=\"file-pascal-hs-LC8\" class=\"blob-code blob-code-inner js-file-line\">&#8212; n=4  [1, 3, 3, 1]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n<td id=\"file-pascal-hs-LC9\" class=\"blob-code blob-code-inner js-file-line\">&#8212;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n<td id=\"file-pascal-hs-LC10\" class=\"blob-code blob-code-inner js-file-line\">&#8212; append 0s to both sides and add them up<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n<td id=\"file-pascal-hs-LC11\" class=\"blob-code blob-code-inner js-file-line\">&#8212; n=4  [1, 3, 3, 1]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n<td id=\"file-pascal-hs-LC12\" class=\"blob-code blob-code-inner js-file-line\">&#8212;      [0, 1, 3, 3, 1]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n<td id=\"file-pascal-hs-LC13\" class=\"blob-code blob-code-inner js-file-line\">&#8212;      [1, 3, 3, 1, 0]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n<td id=\"file-pascal-hs-LC14\" class=\"blob-code blob-code-inner js-file-line\">&#8212; n=5  [1, 4, 6, 4, 1]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n<td id=\"file-pascal-hs-LC15\" class=\"blob-code blob-code-inner js-file-line\">&#8212; and so on<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n<td id=\"file-pascal-hs-LC16\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n<td id=\"file-pascal-hs-LC17\" class=\"blob-code blob-code-inner js-file-line\">&#8212; add two lists, for clarity<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n<td id=\"file-pascal-hs-LC18\" class=\"blob-code blob-code-inner js-file-line\">addLists :: Num c =&gt; [c] -&gt; [c] -&gt; [c]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n<td id=\"file-pascal-hs-LC19\" class=\"blob-code blob-code-inner js-file-line\">addLists l1 l2 = zipWith (+) l1 l2<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n<td id=\"file-pascal-hs-LC20\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n<td id=\"file-pascal-hs-LC21\" class=\"blob-code blob-code-inner js-file-line\">pascal :: (Eq a1, Num a1, Num a2) =&gt; a1 -&gt; [a2]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n<td id=\"file-pascal-hs-LC22\" class=\"blob-code blob-code-inner js-file-line\">pascal 1 = [ 1 ]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n<td id=\"file-pascal-hs-LC23\" class=\"blob-code blob-code-inner js-file-line\">pascal n =<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n<td id=\"file-pascal-hs-LC24\" class=\"blob-code blob-code-inner js-file-line\"> let prev = pascal(n-1)<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n<td id=\"file-pascal-hs-LC25\" class=\"blob-code blob-code-inner js-file-line\">     zero_prev = [0] ++ prev<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n<td id=\"file-pascal-hs-LC26\" class=\"blob-code blob-code-inner js-file-line\">     prev_zero = prev ++ [0]<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n<td id=\"file-pascal-hs-LC27\" class=\"blob-code blob-code-inner js-file-line\"> in<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n<td id=\"file-pascal-hs-LC28\" class=\"blob-code blob-code-inner js-file-line\"> addLists zero_prev prev_zero<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n<td id=\"file-pascal-hs-LC29\" class=\"blob-code blob-code-inner js-file-line\"> <\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n<td id=\"file-pascal-hs-LC30\" class=\"blob-code blob-code-inner js-file-line\">&#8212; [1,2,3] -&gt; &quot;1 2 3&quot;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n<td id=\"file-pascal-hs-LC31\" class=\"blob-code blob-code-inner js-file-line\">listToString = unwords. map show<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n<td id=\"file-pascal-hs-LC32\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n<td id=\"file-pascal-hs-LC33\" class=\"blob-code blob-code-inner js-file-line\">&#8212; mapM_ -&gt; map    monadic    so no weird IO errors are triggered<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n<td id=\"file-pascal-hs-LC34\" class=\"blob-code blob-code-inner js-file-line\">printTriangle n = mapM_ putStrLn (map listToString (map pascal [1..n]))<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n<td id=\"file-pascal-hs-LC35\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L36\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"36\"><\/td>\n<td id=\"file-pascal-hs-LC36\" class=\"blob-code blob-code-inner js-file-line\">main = do<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L37\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"37\"><\/td>\n<td id=\"file-pascal-hs-LC37\" class=\"blob-code blob-code-inner js-file-line\">    input &lt;- getLine<\/td>\n<\/tr>\n<tr>\n<td id=\"file-pascal-hs-L38\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"38\"><\/td>\n<td id=\"file-pascal-hs-LC38\" class=\"blob-code blob-code-inner js-file-line\">    printTriangle . (read :: String -&gt; Int) $ input<\/td>\n<\/tr>\n<\/table>\n<\/div><\/div>\n<\/p><\/div>\n<\/div><\/div>\n<div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/gubatron\/c690b46f72e0bb1bab378da8a49348c1\/raw\/992266b0fc1f8a77904c4eb2292183aecab8c2f2\/pascal.hs\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a><br \/>\n        <a href=\"https:\/\/gist.github.com\/gubatron\/c690b46f72e0bb1bab378da8a49348c1#file-pascal-hs\" class=\"Link--inTextBlock\"><br \/>\n          pascal.hs<br \/>\n        <\/a><br \/>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n<\/p><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s in python, imperatively, and then in functional style without the need for loops. 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 Show hidden characters [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15,1640,65],"tags":[282,1641,1642,1458],"class_list":["post-3942","post","type-post","status-publish","format-standard","hentry","category-code","category-haskell","category-python","tag-coding","tag-haskell","tag-pascal-triangle","tag-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-11A","jetpack-related-posts":[{"id":446,"url":"https:\/\/www.gubatron.com\/blog\/como-es-que-convierto-de-decimal-a-binario\/","url_meta":{"origin":3942,"position":0},"title":"Como es que convierto de decimal a binario?","author":"gubatron","date":"January 22, 2007","format":false,"excerpt":"Recuerdo que esto fue uno de los primeros ejercicios de programacion que me pusieron a hacer en Haskell, convertir de decimal a binario. Aqui una simple implementacion propia en python mientras estaba practicando pal google code jam (que la hice por gusto pq python tiene modulos para convertir de cualquier\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":235,"url":"https:\/\/www.gubatron.com\/blog\/open-sourcing-since-the-early-days\/","url_meta":{"origin":3942,"position":1},"title":"Open Sourcing since the early days","author":"gubatron","date":"January 11, 2006","format":false,"excerpt":"Back in 1998 I was on my first year of Software Engineering in UCAB, our Algorithms and Programming I (by Prof. Omar Mendez and Alvaro Reb\u00f3n) course was dictated using a functional language which at the time sounded esoteric to us, Haskell. (I'm glad I started with Haskell, We knew\u2026","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":234,"url":"https:\/\/www.gubatron.com\/blog\/free-haskell-guide-by-gubatron-oct-1998\/","url_meta":{"origin":3942,"position":2},"title":"Free Haskell Guide by Gubatron &#8211; Oct 1998","author":"gubatron","date":"January 11, 2006","format":false,"excerpt":"","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":382,"url":"https:\/\/www.gubatron.com\/blog\/guia-de-ejercicios-y-comandos-para-el-uso-de-haskell-1998\/","url_meta":{"origin":3942,"position":3},"title":"Guia de Ejercicios y Comandos para el uso de Haskell (1998)","author":"gubatron","date":"October 20, 2006","format":false,"excerpt":"Descarga mi Guia de Ejercicios Esta guia la escribi en 3er semestre de Ingenieria Informatica despues de ver mi primer curso de Algoritmos y Programacion, para este curso la facultad decidio que era un buen experimento ensenarnos a hacer nuestros primeros programas con un lenguaje funcional llamado Haskell. Echenle un\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":764,"url":"https:\/\/www.gubatron.com\/blog\/python-ip2num-num2ip-store-an-ip-string-as-a-4-byte-int\/","url_meta":{"origin":3942,"position":4},"title":"[Python] ip2num \/ num2ip &#8211; Store an IP string as a 4 byte int.","author":"gubatron","date":"March 27, 2008","format":false,"excerpt":"This is probably everywhere, maybe python also comes with it, but I wanted to have my own implementation, and I'll leave it here for future reference. Basically, sometimes you don't want to store IPs in Strings cause they take too much space, instead you want to be a good programmer\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":241,"url":"https:\/\/www.gubatron.com\/blog\/flirting-with-python-a-pastebincom-plugin-for-xchat\/","url_meta":{"origin":3942,"position":5},"title":"Flirting with Python &#8211; A pastebin.com plugin for xchat","author":"gubatron","date":"January 20, 2006","format":false,"excerpt":"Here's the first version of an xchat plugin some friends from Venezuela and I wrote. This is one of our first attempts to code something useful in python that'll we hope gets to be used by someone on the opensource community who often uses pastebin.com to show their code and\u2026","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=3942"}],"version-history":[{"count":1,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3942\/revisions"}],"predecessor-version":[{"id":3943,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3942\/revisions\/3943"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=3942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=3942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=3942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}