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
| module CombinatorialHierarchy where | |
| {- https://en.wikipedia.org/wiki/Combinatorial_hierarchy | |
| 3, 2^3-1, 2^7-1, 2^127-1 | |
| seq: | |
| 3, 7, 127, 170141183460469231731687303715884105727 | |
| cumulative sum: |
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
| #!/usr/bin/env python | |
| # The way I usually write it. | |
| """ | |
| rep customers: | |
| seq onecust: | |
| invest | |
| alt movement: | |
| payin | |
| withdraw |
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
| #!/usr/bin/env python | |
| data = """a 9 | |
| b 2 | |
| c 2 | |
| d 4 | |
| e 12 | |
| f 2 | |
| g 3 | |
| h 2 |
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
| /* Exercise 1-13. Write a program to print a histogram of the lengths | |
| of words in its input. */ | |
| /* | |
| input = (special | word)* | |
| special = blank | tab | newline | |
| word = non-special+ | |
| */ | |
| #include<stdio.h> |
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
| /* Count words, lines and characters.*/ | |
| /* | |
| The number of lines is just the number of newline chars. Every | |
| character, including newline is counter as a character. EOF is not a | |
| character. | |
| I use a structure design rather than an IN/OUT state flag. | |
| A sequence of chars not including blank, tab or newline is a |
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
| #include<assert.h> | |
| #include<stdio.h> | |
| /* htoi(): convert hext digit string to native int. */ | |
| /* | |
| left-to-right recursive: | |
| htoir("2") == 2 | |
| htoir("A") == 10 | |
| htoir("23") == 16*htoir("2") + 3 |
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
| /* | |
| Display the length of the the longest line from text input. | |
| */ | |
| /* | |
| [Skip the write-up as I did not follow it when writing the code.] | |
| A simple text file is an iteration of lines, followed by EOF. | |
| simple = body + EOF |
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
| #include<assert.h> | |
| #include<stdio.h> | |
| #include<string.h> | |
| /* The function squeeze removes all instances of specified characters | |
| from the input string array. The characters to be excluded are given in | |
| a second argument.*/ | |
| struct testrec { | |
| char inpu[30]; |
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
| #!usr/bin/env python | |
| from __future__ import print_function | |
| """ | |
| A tree is a restricted graph. Both trees and graphs may represented as | |
| a set of (parent, child) pairs. | |
| """ | |
| t = set([(1,2), (1,3), (1,7), (2,4), (2,5), (4,6), (7,8), (7,9)]) |
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
| import types | |
| # - - - - - countdown - - - - - | |
| def countdown(n): | |
| # Tail recursive call will overflow Python's stack for large n. | |
| return n if n == 0 else countdown(n-1) | |
| assert countdown(5) == 0 |
NewerOlder