How to print numbers from 1 to 10 using a loop in Brainfuck? Is it even possible? - loops

How to print numbers from 1 to 10 using a loop in Brainfuck? Is it even possible?
I am looking for a solution to this issue.

+++++++++++++++++++++++++++++++++++++++++++++++++ Cell 0 to '1'
>++++++++++ cell 1 to '\n'
>+++++++++ cell 2 to 9 as counter
[ Print numbers 1 to 9
<< Data pointer to cell 0
.+ Print and increment cell 0
>. Data pointer to cell 1 and print the newline
>- Data pointer to cell 2 and decrement counter
] Loop till counter is 0
+++++++++ Set cell 2 to 9
[ Set cell 0 to '1'
<<- Data pointer to cell 0 and decrement
>>- Data pointer to cell 2 and decrement counter
] Loop till counter is 0
<<. Data pointer to cell 0 and print '1'
-. Decrement cell 0 and print '0'
>. Data pointer to cell 1 and print newline
Readable version:
+++++++++++++++++++++++++++++++++++++++++++++++++>
++++++++++>
+++++++++[<<.+>.>-]
+++++++++[<<->>-]
<<.-.>.
Output:
1
2
3
4
5
6
7
8
9
10
Live demo:
Brainf**k print 1 to 10
Brainf**k Visualizer

TL;DR
-[>+<-----]>---<++++++++++<++++++++++[>>.+<.<-]>>---------.-.
Try it online!
END TL;DR
In order to program in BrainF**k, pretend like every program (even simple ones) will need to start out with a layout.
The pseudo-code for this would be something like:
Generate the character '0'
Move left and generate '\n'
Move left and generate the counter (10 numbers in this case)
Loop: Get back to the character '0', print it, increment it to '1', go to the newline, print it, go to the counter, and decrement it. End it when the counter is 0
Generate '1' and print it
Generate '0' and print it
However, the last two steps could be simplified to just:
Go back to the digit '9'
Decrement it until '1' and print
Decrement it until '0' and print
This saves a lot of time and bytes characters.
To generate the character '0', you generate the integer 48 (because that's it's ASCII value). To do this you can go to Esolangs' BF Constants. Looking up the number 48, we find -[>+<-----]>---
Our program so far is -[>+<-----]>--- to generate 0
Next, move left and generate \n (newline). We can use <++++++++++. Notice how it is completely plus signs. This is because there is not much room to reduce the character count at the number 10.
Our program so far is -[>+<-----]>---<++++++++++
Then, move left and generate the counter. We want the counter to be 10 to print numbers from 0 to 9. <++++++++++.
Our program so far is -[>+<-----]>---<++++++++++<++++++++++
After that, start the loop [. Go to the '0' >>, print it ., increment it +, go to the newline and print <., Go to the counter and decrement it, and end the loop when it is zero <-]. [>>.+<.<-]
Our program so far is -[>+<-----]>---<++++++++++<++++++++++[>>.+<.<-]
Finally, go to the '9' >>, decrement it until it is 1 and print ---------., and decrement it until it is 0 and print -.. ---------.-.
The program is finished.

++++++++++++++++++++++++++++++++++++++++++++++++ Let address 0 be the digit we want to print, starting with '0'
>++++++++++ Let address 1 be our newline character
>+++++++++ Let address 2 be our counter, starting at 9
[
- Decrement the counter
<<+. Increment the digit we want to print and print it
>. Print the newline
> Make sure we're at the counter again before we loop back
]
<< Move back to address 0
--------. Make address 0 '1'
-. Make address 0 '0'
Live demo

This is possible. Here's the code: ++++++++++>++++++++++[>+++++<-]>-.<<.>>+.<<.>>+.<<.>>+.<<.>>+.<<.>>+.<<.>>+.<<.>>+.<<.>>+.<<.>>--------.-. It could be shorter, however, it still accomplishes the same task. Brainf*** can theoretically perform any computation, as it is Turing complete. This is just one of those computations.

I suggest the following:
+++++++++>>++++++++[-<++++++>][-]>++++[-<++++++++>]<<<[->+.>.<<]>[-]+++++++[-<+++++++>]<.-.
It outputs 1 2 3 4 5 6 7 8 9 10.
We have this (each line is after the next cell-affecting instruction, which are + - .):
| C1 | C2 | C3 | C4 | Output |
+----+----+----+----+-----------------------+
| 0 | 0 | 0 | 0 | |
| 1 | 0 | 0 | 0 | |
| 2 | 0 | 0 | 0 | |
...
| 8 | 0 | 0 | 0 | |
| 9 | 0 | 0 | 0 | |
... (first loop)
| 9 | 48 | 0 | 0 | |
| 9 | 48 | 0 | 1 | |
| 9 | 48 | 0 | 2 | |
| 9 | 48 | 0 | 3 | |
| 9 | 48 | 0 | 4 | |
| 9 | 48 | 0 | 3 | | (enter second loop)
| 9 | 48 | 1 | 3 | |
| 9 | 48 | 2 | 3 | |
...
| 9 | 48 | 8 | 3 | |
| 9 | 48 | 8 | 2 | |
| 9 | 48 | 9 | 2 | |
...
| 9 | 48 | 16 | 2 | |
| 9 | 48 | 16 | 1 | |
| 9 | 48 | 17 | 1 | |
...
| 9 | 48 | 24 | 1 | |
| 9 | 48 | 24 | 0 | |
| 9 | 48 | 25 | 0 | |
...
| 0 | 48 | 32 | 0 | | (exit second loop)
| 8 | 48 | 32 | 0 | | (enter third loop)
| 8 | 49 | 32 | 0 | |
| 8 | 49 | 32 | 0 | 1 |
| 8 | 49 | 32 | 0 | 1_ | (underscores are spaces)
| 7 | 49 | 32 | 0 | 1_ |
| 7 | 50 | 32 | 0 | 1_ |
| 7 | 50 | 32 | 0 | 1_2 |
| 7 | 50 | 32 | 0 | 1_2_ |
| 6 | 50 | 32 | 0 | 1_2_ |
| 6 | 51 | 32 | 0 | 1_2_ |
| 6 | 51 | 32 | 0 | 1_2_3 |
| 6 | 51 | 32 | 0 | 1_2_3_ |
| 5 | 51 | 32 | 0 | 1_2_3_ |
| 5 | 52 | 32 | 0 | 1_2_3_ |
| 5 | 52 | 32 | 0 | 1_2_3_4 |
| 5 | 52 | 32 | 0 | 1_2_3_4_ |
| 4 | 52 | 32 | 0 | 1_2_3_4_ |
| 4 | 53 | 32 | 0 | 1_2_3_4_ |
| 4 | 53 | 32 | 0 | 1_2_3_4_5 |
| 4 | 53 | 32 | 0 | 1_2_3_4_5_ |
| 3 | 53 | 32 | 0 | 1_2_3_4_5_ |
| 3 | 54 | 32 | 0 | 1_2_3_4_5_ |
| 3 | 54 | 32 | 0 | 1_2_3_4_5_6 |
| 3 | 54 | 32 | 0 | 1_2_3_4_5_6_ |
| 2 | 54 | 32 | 0 | 1_2_3_4_5_6_ |
| 2 | 55 | 32 | 0 | 1_2_3_4_5_6_ |
| 2 | 55 | 32 | 0 | 1_2_3_4_5_6_7 |
| 2 | 55 | 32 | 0 | 1_2_3_4_5_6_7_ |
| 1 | 55 | 32 | 0 | 1_2_3_4_5_6_7_ |
| 1 | 56 | 32 | 0 | 1_2_3_4_5_6_7_ |
| 1 | 56 | 32 | 0 | 1_2_3_4_5_6_7_8 |
| 1 | 56 | 32 | 0 | 1_2_3_4_5_6_7_8_ |
| 0 | 56 | 32 | 0 | 1_2_3_4_5_6_7_8_ |
| 0 | 57 | 32 | 0 | 1_2_3_4_5_6_7_8_ |
| 0 | 57 | 32 | 0 | 1_2_3_4_5_6_7_8_9 |
| 0 | 57 | 32 | 0 | 1_2_3_4_5_6_7_8_9_ | (exit third loop)
+----+----+----+----+-----------------------+
Then cell C2 is set to 0 and used to set cell C1 to 49 (charater 1).
It prints C1, then removes one and prints it again, giving an output of:
1_2_3_4_5_6_7_8_9_10 (underscores are spaces)
It's for me the simplest program to print the integers from 1 to 10.
If you want each number to be on its own line, replace the >>>++++[-<++++++++>]<<< by ++++++++++.
Issue [SOLVED]: instead of printing 10 at the end, it prints :...

Related

Shallow jest-enzyme unit test generates coverage for entire application tree

I have (for demonstration purposes) an extremely simple React component:
import React, { Component } from 'react';
import { fetchUser, fetchNews } from '../../infrastructure/actions';
class Layout extends Component {
render() {
return (
<div />
);
}
}
export default Layout;
and a simple Jest snapshot test:
import React from 'react';
import { shallow } from 'enzyme';
import Layout from '../Layout';
describe('rendering', () => {
it('should render valid snapshot when loading', () => {
const jsx = (<Layout />);
const element = shallow(jsx);
expect(element).toMatchSnapshot();
});
});
The relevant line here is the
import { fetchUser, fetchNews } from '../../infrastructure/actions';
infrastructure/actions/index.js is a barrel file full of Redux actions, thus:
export { fetchNews, FETCH_NEWS } from './news/fetchNews';
export { fetchUser, FETCH_USER} from './user/fetchUser';
// ...etc
My issue is that even though nothing in the import statement is being used in the shallow-rendered component, Jest's code coverage report is treating EVERY module in the infrastructure/actions/index.js file as having been both imported and executed, leaving me with a useless code coverage report that looks like this.
--------------------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------------------------------------|----------|----------|----------|----------|-------------------|
All files | 56.08 | 38.46 | 5.17 | 56.08 | |
display/containers | 100 | 100 | 100 | 100 | |
Layout.js | 100 | 100 | 100 | 100 | |
infrastructure/actions | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
infrastructure/actions/characters | 50 | 0 | 0 | 50 | |
fetchCharacters.js | 50 | 100 | 0 | 50 | 3 |
fetchedCharactersFailure.js | 50 | 100 | 0 | 50 | 3 |
fetchedCharactersSuccess.js | 50 | 100 | 0 | 50 | 3 |
untrackCharacter.js | 50 | 100 | 0 | 50 | 5 |
untrackCharacterFailure.js | 50 | 100 | 0 | 50 | 3 |
untrackCharacterSuccess.js | 50 | 100 | 0 | 50 | 3 |
upsertCharacter.js | 50 | 0 | 0 | 50 | 5 |
upsertCharacterFailure.js | 50 | 100 | 0 | 50 | 3 |
upsertCharacterSuccess.js | 50 | 100 | 0 | 50 | 3 |
infrastructure/actions/help | 50 | 100 | 0 | 50 | |
submitContactForm.js | 50 | 100 | 0 | 50 | 5 |
submitContactFormFailure.js | 50 | 100 | 0 | 50 | 3 |
submitContactFormSuccess.js | 50 | 100 | 0 | 50 | 3 |
infrastructure/actions/news | 50 | 100 | 0 | 50 | |
fetchNews.js | 50 | 100 | 0 | 50 | 3 |
fetchedNewsSuccess.js | 50 | 100 | 0 | 50 | 3 |
infrastructure/actions/public | 50 | 0 | 0 | 50 | |
fetchPublicThreads.js | 50 | 100 | 0 | 50 | 3 |
fetchPublicViews.js | 50 | 100 | 0 | 50 | 3 |
fetchedPublicThreadsFailure.js | 50 | 100 | 0 | 50 | 3 |
fetchedPublicThreadsSuccess.js | 50 | 100 | 0 | 50 | 3 |
fetchedPublicViewsFailure.js | 50 | 100 | 0 | 50 | 3 |
fetchedPublicViewsSuccess.js | 50 | 100 | 0 | 50 | 3 |
untrackPublicView.js | 50 | 100 | 0 | 50 | 5 |
untrackPublicViewFailure.js | 50 | 100 | 0 | 50 | 3 |
untrackPublicViewSuccess.js | 50 | 100 | 0 | 50 | 3 |
upsertPublicView.js | 50 | 0 | 0 | 50 | 5 |
upsertPublicViewFailure.js | 50 | 100 | 0 | 50 | 3 |
upsertPublicViewSuccess.js | 50 | 100 | 0 | 50 | 3 |
infrastructure/actions/tags | 50 | 100 | 0 | 50 | |
fetchTags.js | 50 | 100 | 0 | 50 | 3 |
fetchedTagsSuccess.js | 50 | 100 | 0 | 50 | 3 |
infrastructure/actions/threads | 50 | 0 | 0 | 50 | |
bulkUntrackThreads.js | 50 | 100 | 0 | 50 | 5 |
bulkUntrackThreadsFailure.js | 50 | 100 | 0 | 50 | 3 |
bulkUntrackThreadsSuccess.js | 50 | 100 | 0 | 50 | 3 |
bulkUpdateThreads.js | 50 | 100 | 0 | 50 | 5 |
bulkUpdateThreadsFailure.js | 50 | 100 | 0 | 50 | 3 |
bulkUpdateThreadsSuccess.js | 50 | 100 | 0 | 50 | 3 |
exportThreads.js | 50 | 100 | 0 | 50 | 5 |
exportThreadsFailure.js | 50 | 100 | 0 | 50 | 3 |
exportThreadsSuccess.js | 50 | 100 | 0 | 50 | 3 |
fetchActiveThreads.js | 50 | 100 | 0 | 50 | 3 |
fetchActiveThreadsStatus.js | 50 | 100 | 0 | 50 | 3 |
fetchArchivedThreads.js | 50 | 100 | 0 | 50 | 3 |
fetchedActiveThreadsFailure.js | 50 | 100 | 0 | 50 | 3 |
fetchedActiveThreadsStatusChunkFailure.js | 50 | 100 | 0 | 50 | 3 |
fetchedActiveThreadsStatusChunkSuccess.js | 50 | 100 | 0 | 50 | 3 |
fetchedActiveThreadsStatusFailure.js | 50 | 100 | 0 | 50 | 3 |
fetchedActiveThreadsStatusSuccess.js | 50 | 100 | 0 | 50 | 3 |
fetchedActiveThreadsSuccess.js | 50 | 100 | 0 | 50 | 3 |
fetchedArchivedThreadsFailure.js | 50 | 100 | 0 | 50 | 3 |
fetchedArchivedThreadsSuccess.js | 50 | 100 | 0 | 50 | 3 |
generateRandomThread.js | 50 | 100 | 0 | 50 | 5 |
generatedRandomThreadSuccess.js | 50 | 100 | 0 | 50 | 3 |
setFilteredTag.js | 50 | 100 | 0 | 50 | 3 |
untrackThread.js | 50 | 100 | 0 | 50 | 5 |
untrackThreadFailure.js | 50 | 100 | 0 | 50 | 3 |
untrackThreadSuccess.js | 50 | 100 | 0 | 50 | 3 |
upsertThread.js | 50 | 0 | 0 | 50 | 5 |
upsertThreadFailure.js | 50 | 100 | 0 | 50 | 3 |
upsertThreadSuccess.js | 50 | 100 | 0 | 50 | 3 |
infrastructure/actions/ui | 50 | 0 | 0 | 50 | |
closeBulkUntrackThreadsModal.js | 50 | 100 | 0 | 50 | 3 |
closeUntrackCharacterModal.js | 50 | 100 | 0 | 50 | 3 |
closeUntrackPublicViewModal.js | 50 | 100 | 0 | 50 | 3 |
closeUntrackThreadModal.js | 50 | 100 | 0 | 50 | 3 |
closeUpsertCharacterModal.js | 50 | 100 | 0 | 50 | 3 |
closeUpsertPublicViewModal.js | 50 | 100 | 0 | 50 | 3 |
closeUpsertThreadModal.js | 50 | 100 | 0 | 50 | 3 |
openBulkUntrackThreadsModal.js | 50 | 100 | 0 | 50 | 3 |
openUntrackCharacterModal.js | 50 | 100 | 0 | 50 | 3 |
openUntrackPublicViewModal.js | 50 | 100 | 0 | 50 | 3 |
openUntrackThreadModal.js | 50 | 100 | 0 | 50 | 3 |
openUpsertCharacterModal.js | 50 | 0 | 0 | 50 | 5 |
openUpsertPublicViewModal.js | 50 | 0 | 0 | 50 | 5 |
openUpsertThreadModal.js | 50 | 0 | 0 | 50 | 5 |
setActiveHelpTab.js | 50 | 100 | 0 | 50 | 5 |
setActiveSettingsTab.js | 50 | 100 | 0 | 50 | 5 |
setActiveToolsTab.js | 50 | 100 | 0 | 50 | 5 |
setMaintenanceModeOn.js | 50 | 100 | 0 | 50 | 3 |
toggleHeaderDropdown.js | 50 | 100 | 0 | 50 | 5 |
toggleMobileSidebar.js | 50 | 100 | 0 | 50 | 5 |
toggleNewsAside.js | 50 | 100 | 0 | 50 | 5 |
toggleSidebar.js | 50 | 100 | 0 | 50 | 5 |
infrastructure/actions/user | 50 | 100 | 0 | 50 | |
fetchUser.js | 50 | 100 | 0 | 50 | 3 |
fetchedUserFailure.js | 50 | 100 | 0 | 50 | 3 |
fetchedUserSuccess.js | 50 | 100 | 0 | 50 | 3 |
submitUserAccountInfo.js | 50 | 100 | 0 | 50 | 5 |
submitUserChangePassword.js | 50 | 100 | 0 | 50 | 5 |
submitUserForgotPassword.js | 50 | 100 | 0 | 50 | 5 |
submitUserLogin.js | 50 | 100 | 0 | 50 | 5 |
submitUserLogout.js | 50 | 100 | 0 | 50 | 5 |
submitUserRegistration.js | 50 | 100 | 0 | 50 | 5 |
submitUserResetPassword.js | 50 | 100 | 0 | 50 | 5 |
userAccountInfoFailure.js | 50 | 100 | 0 | 50 | 3 |
userAccountInfoSuccess.js | 50 | 100 | 0 | 50 | 3 |
userChangePasswordFailure.js | 50 | 100 | 0 | 50 | 3 |
userChangePasswordSuccess.js | 50 | 100 | 0 | 50 | 3 |
userForgotPasswordFailure.js | 50 | 100 | 0 | 50 | 3 |
userForgotPasswordSuccess.js | 50 | 100 | 0 | 50 | 3 |
userLoginFailure.js | 50 | 100 | 0 | 50 | 3 |
userLoginSuccess.js | 50 | 100 | 0 | 50 | 3 |
userRegistrationFailure.js | 50 | 100 | 0 | 50 | 3 |
userRegistrationSuccess.js | 50 | 100 | 0 | 50 | 3 |
userResetPasswordFailure.js | 50 | 100 | 0 | 50 | 3 |
userResetPasswordSuccess.js | 50 | 100 | 0 | 50 | 3 |
infrastructure/actions/userSettings | 50 | 100 | 0 | 50 | |
fetchUserSettings.js | 50 | 100 | 0 | 50 | 3 |
fetchedUserSettingsFailure.js | 50 | 100 | 0 | 50 | 3 |
fetchedUserSettingsSuccess.js | 50 | 100 | 0 | 50 | 3 |
setShowDashboardThreadDistribution.js | 50 | 100 | 0 | 50 | 5 |
updateUserSettings.js | 50 | 100 | 0 | 50 | 5 |
updatedUserSettingsFailure.js | 50 | 100 | 0 | 50 | 3 |
updatedUserSettingsSuccess.js | 50 | 100 | 0 | 50 | 3 |
infrastructure/constants | 100 | 100 | 100 | 100 | |
analytics.js | 100 | 100 | 100 | 100 | |
utility | 62.5 | 100 | 50 | 62.5 | |
testHelpers.js | 62.5 | 100 | 50 | 62.5 | 12,13,16 |
--------------------------------------------------|----------|----------|----------|----------|-------------------|
Needless to say, this negates the purpose of the code coverage report, since none of these files except for two of them are even related to the component under test -- and even for the ones that are, their code shouldn't be executed by this test.
Also of note -- down at the bottom the code coverage report, it references analytics.js which is actually imported by one of the child files of infrastructure/actions/index.js, not by the barrel file itself, meaning that the coverage is somehow traveling even further down the dependency tree.
As soon as I remove the line importing the actions, the coverage file immediately behaves itself again and reflects only the component being tested.
This also happens if I import a component which would (presumably) be used somewhere in the layout; I immediately start seeing coverage indications for that component and its children all the way down, even though I am only doing a shallow rendering in my component under test.
I've tried to use jest.mock() to mock these imports prior to running the shallow() method, but it doesn't seem to make any difference to the coverage output.
All of this leads me to believe I've done something wrong in setting my test environment up; I'd appreciate any guidance on what might cause this effect.
For those curious, I did some more digging and realized that this is actually expected behavior -- an imported file by default executes when it is imported, so while none of the functions inside the imported files were executed, the lines on which they were initialized were still being hit by virtue of their being imported.
The solution for this is to use Jest mocking to mock all the imports used by the system under test as part of your test initialization. I added this line to the bottom of the test file (Jest hoists it to the top of the tests during execution):
jest.mock('../../../infrastructure/actions', () => ({}));
(i.e. when an import calls for actions/index.js, then import a function that returns an empty object instead). And everything went back to normal.

if the maximum capacity of character is 256 how to store character array of 1000?

If the maximum capacity of character is 256 how to store character array of 1000?
is it possible to declare:
char s[1000];
Yes, it is certainly possible.
char s[1000];
You can think of 1000 as the "length" of the array and 256 as the "width". You get an array of 1000 chars. Each char is 8 bits (on the machine you're using, at least), and can therefore store 256 distinct values. (And, actually, it would probably be more appropriate to think of the "width" as being 8, not 256.)
Here is your array, with each box representing one char:
+---+---+---+---+---+---+---+---+- -+---+
s: | | | | | | | | | ... | |
+---+---+---+---+---+---+---+---+- -+---+
0 1 2 3 4 5 6 7 999
Or here it is showing the individual bits:
+---+---+---+---+---+---+---+---+- -+---+
s: | | | | | | | | | | | 7
+---+---+---+---+---+---+---+---+- -+---+
| | | | | | | | | | | 6
+---+---+---+---+---+---+---+---+- -+---+
| | | | | | | | | | | 5
+---+---+---+---+---+---+---+---+- -+---+
| | | | | | | | | | | 4
+---+---+---+---+---+---+---+---+- -+---+ bit
| | | | | | | | | ... | | 3 number
+---+---+---+---+---+---+---+---+- -+---+
| | | | | | | | | | | 2
+---+---+---+---+---+---+---+---+- -+---+
| | | | | | | | | | | 1
+---+---+---+---+---+---+---+---+- -+---+
| | | | | | | | | | | 0
+---+---+---+---+---+---+---+---+- -+---+
0 1 2 3 4 5 6 7 999
array index
Suppose we put a string in the array, either by calling strcpy:
strcpy(s, "Hello!");
or my initializing it when we declare it:
char s[1000] = "Hello!";
By bytes it looks like this:
+---+---+---+---+---+---+---+---+- -+---+
s: | H | e | l | l | o | ! |\0 | | ... | |
+---+---+---+---+---+---+---+---+- -+---+
0 1 2 3 4 5 6 7 999
Or by bits it looks like this:
+---+---+---+---+---+---+---+---+- -+---+
s: | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | | 7
+---+---+---+---+---+---+---+---+- -+---+
| 1 | 1 | 1 | 1 | 1 | 0 | 0 | | | | 6
+---+---+---+---+---+---+---+---+- -+---+
| 0 | 1 | 1 | 1 | 1 | 1 | 0 | | | | 5
+---+---+---+---+---+---+---+---+- -+---+
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | | 4
+---+---+---+---+---+---+---+---+- -+---+ bit
| 1 | 0 | 1 | 1 | 1 | 0 | 0 | | ... | | 3 number
+---+---+---+---+---+---+---+---+- -+---+
| 0 | 1 | 1 | 1 | 1 | 0 | 0 | | | | 2
+---+---+---+---+---+---+---+---+- -+---+
| 0 | 0 | 0 | 0 | 1 | 0 | 0 | | | | 1
+---+---+---+---+---+---+---+---+- -+---+
| 0 | 1 | 0 | 0 | 1 | 1 | 0 | | | | 0
+---+---+---+---+---+---+---+---+- -+---+
0 1 2 3 4 5 6 7 999
array index
And there are 993 spaces in the array left over.
[P.S. to nitpickers: Yes, those are ASCII codes, and no, character encoding is not specified by the C Standard. But I think we can safely assume that those are the codes the questioner would see.]
The 256 is the number of values in a single char (which is often an 8 bits byte, and 256 = 28).
(caveat, the C11 standard allows wider char-s, e.g. of 32 bits; but this is very uncommon)
A string is an array or a memory zone containing several char-s, and conventionally terminated by a zero byte.
You can have very big strings, notably using C dynamic memory allocation. For instance, on some computers
char*hugestring = malloc(1000000000);
can succeed. Then you could fill that billion-bytes string. On many computers, that malloc call would fail, and you always need to check the result of malloc, at least by following the above line with
if (!hugestring) { perror("malloc hugestring"); exit(EXIT_FAILURE); };
If you use malloc, don't forget to later call free (you need to have conventions about who is responsible for that); otherwise you have a memory leak. BTW the asprintf, strdup and open_memstream functions are very useful (but not available everywhere) to conveniently build dynamically allocated strings (internally malloc is used by them). Tools like valgrind are helpful to help detecting memory leaks.
You can also have arrays. If they are local variables (a.k.a. automatic variables) they generally sit in the call stack (unless the compiler optimized for them).
For example, using snprintf to safely fill a local buffer (without buffer overflow),
char buffer[100];
snprintf(buffer, sizeof(buffer), "x=%d, name=%s", x, name);
but it is unreasonable to have large call frames, so a local array should generally be less than a few hundred bytes (or perhaps a few thousands of them). The entire call stack is generally limited to one or a few megabytes. Details are system specific.
Be aware of character encoding issues. In 2017 read at least utf8everywhere.org and about Unicode.... so think of char as a byte (since some UTF-8 characters need several bytes, so take several char-s to be represented, hence on my Linux desktop strlen("être") is 5 and sizeof("être") is 6 since the accentuated ê letter is UTF-8 encoded in two bytes). You might use some library like libunistring.
Look also into some C reference.
You seem to misinterpret what you refer to as "capacity" of a char. char is an 8-bit value, which means it can range anywhere from 0000 0000b () to 1111 1111b (255).
This only refers to one individual value. This means you can write char c = 20;, but not char c = 1000;.
As such, this means that there are 256 different possible values for a single char.
Arrays are a different concept: An array stores multiple values of one specific type - such as an array of characters.
To answer you question: Yes, you can store 1000 char values in an array, like char s[1000] as Steve Summit suggested.
Naturally, if you have 1000 chars, this will mean there will be duplicates (since there are only 256 unique characters possible).

Powerpivot 2016 measure using DAX to sum an array

I want to sum the 7 preceding values of a row as a measure like so:
| Wk_number | Value A | Measure | Array |
-------------------------------------------
| 01 | 1 | N/A# | N/A# |
| 02 | 1 | 1 | {01} |
| 03 | 10 | 2 | {01-02} |
| 04 | 3 | 12 | {01-03} |
| 05 | 5 | 15 | {01-04} |
| 06 | 10 | 20 | {01-05} |
| 07 | 1 | 30 | {01-06} |
| 08 | 4 | 31 | {01-07} |
| 09 | -10 | 34 | {02-08} |
| 10 | 3 | 26 | {03-09} |
| 11 | 2 | 18 | {04-10} |
etc...
I added the array column just to clarify the example how of the sum is comprised, notice that from wk09 it's not simply a running total.
How to do this using DAX statements?
Two ways to do this: you can either create a calculated column, or a measure.
For the column:
=CALCULATE(SUM([Value A]),FILTER(Table,Table[Wk_number]<EARLIER(Table[Wk_number]) && Table[Wk_number] >= (EARLIER(Table[Wk_number])-7)))
For the measure, it's a very similar formula but instead of using EARLIER(), we use MAX():
=CALCULATE(SUM([Value A]),FILTER(ALL(Table3),Table3[Wk_number]<MAX(Table3[Wk_number]) && Table3[Wk_number] >= (MAX(Table3[Wk_number])-7)))
Below is a screenshot of the results. A few of the numbers in your example table seem to be off based on the math:

Windows 10 all icon resolutions on all DPI settings? Format? Pixel art as icon? Large size icon in start menu medium tile?

Just skip to the answer at the answer section, the question part has speculations and mistakes. The answer is based on experiment and it is accurate.
For a long time I have used a single png packed 256px ico file for my Visual Studio projects, and it worked well, cause scaling works fine on those icons and they take almost no space, and I did not care that much before.
But now I have an icon that needs to "retain hard edges", it is "pixel art".
If I build with a 256px version downscales terribly or if I build with 16px upscales slightly less terribly but not good enough. So my questions are:
What are the sizes I have to generate to merge into the ico (I don't care about pre win7 icons)?
If I got that list, do I have to generate 1.25x, 1.5x and 2.0x versions for high dpi settings?
Finally, some apps like firefox has a large icon on start menu inside the medium square block, my apps have a smaller one in the center like Visual Studio does, how can I put a large icon in the start menu medium sized square?
I did found it: Unfortunately VS says: VisualElements is not supported in a Windows Presentation Foundation (WPF) project. Is there a way around this?
I looked around and collected possible sizes #1x(96DPI):
16, 20, 24, 30, 32, 40, 48, 50, 64, 128, 150, 256, 512, 768
Mostly I collected these from Which icon sizes should my Windows application's icon include?.
Not that bad, but if I add 1.25x, 1.5x, 2.0x then we get:
16, 20, 24, 25, 30, 32, 36, 38, 40, 45, 48, 50, 60, 62, 64, 72, 75, 80, 96, 100, 128, 150, 160, 188, 192, 225, 256, 300, 320, 384, 512, 640, 768, 960, 1024, 1152, 1536 In my case it makes a 500k ico file and as it seems the 1024 is the max resolution you can put into an ico file, my icon is pixelated so compresses really well with png and still ~500k.
I also made an ico has all of the above resolutions in rgba, and every one has its size on it, so you can see which windows loads on which dpi setting. you can download it from here and use it in a vs project to test.
As I understand everything under 256px can't be png compressed, is this right?
And do I need all these sizes to retain a pixel perfect icon? Are only 32bit(RGBA) pngs okay? I hope I don't need to include other depths.
After i wrote an ico writer from the spec I realized that pngs can have 0 for resolution cause 1 byte is available for x or y(but i have never seen an ico that is non square, maybe curs can be non square), in this case probably the first one in the file with zeros for resolution going to be used...This is not sure but I think its not far from the truth. See images. Rescaling issues are still confusing me, if I'll have some time tomorrow I'll test it. A pixel perfect icon seems to be imposible to do: having one image to rescale to anything above 256px.
The answers:
Are PNGs are acceptable under 256px inside ICO file?
Microsoft states that the sizes under 256px should be a BMP without the first 14 bytes.
But at least in the case of windows 10, the answer is YES.
Can you add larger than 1024px image into the ICO?
YES. As long as it is a PNG it can be as big as you want.
Note the "one icon over 255px" limitation:
You can only add one image larger than 255px ( you can add more but windows will only read the first image block in the ICO head where the resolution is 0,0). The format specifies 1 byte for each dimension. See table #2.
What sizes to include for all DPI setting?
Windows 10 uses the following icon sizes (see table below):
16, 20, 24, 28, 30, 31, 32, 40, 42, 47, 48, 56, 60, 63, 84 and one larger than 255px.
Note that Windows RT apps do not use ICO files, they use PNGs or Fonts, this is from Firefox's source:
<Application xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<VisualElements
ShowNameOnSquare150x150Logo='on'
Square150x150Logo='browser\VisualElements\VisualElements_150.png'
Square70x70Logo='browser\VisualElements\VisualElements_70.png'
ForegroundText='light'
BackgroundColor='#0996f8'/>
</Application>
So how Firefox has a large icon on start menu in the medium tile?
Well its include this above file in the exe directory before the shortcut added to start menu, this article explains it how. My app has an example.
If you make icons for Windows 10 you are better off with my tool and photoshop (or something like that) than anything else, I tried editors and they suck.
win10iconTools by me
You can create ICO files (as MS recommendation or not) or create icons with resolution printed on them, the latter is what I used to make the table.
Supports multiple resize modes including nearest neighbor.
If you want to you can use it on other windows versions, it works with .net2, test another windows, send me the results and I extend the table for the good of mankind.
As for pixel art in icons it is not possible to be perfect :(, unless we can change the scaling algorithm in windows 10.
So a wide range 84-256 gets the scaled to "0" (see above), so there is no real point adding something bigger that 256 as I see it now you should create a 256px image for "0".
(See table why)
If Windows gets all icons 16 to 255 + the 1 larger than 255 (0 in the table) chooses these sizes:
(so no markdown tables here?, its kind of wide, the tables are in the app readme also)
| | Windows 10 |
| | 96DPI | 120DPI | 144DPI | 168DPI |
| icon |disp.|load|disp.|load|disp.|load|disp.|load|
|-------------------------------------------|-----|----|-----|----|-----|----|-----|----|
| alt-tab | 24 | 32 | 30 | 32 | 36 | 32 | 42 | 32 |
| desktop large | 96 | 0 | 120 | 0 | 144 | 0 | 168 | 0 |
| desktop medium | 48 | 48 | 60 | 60 | 72 | 72 | 84 | 84 |
| desktop small | 32 | 32 | 40 | 40 | 48 | 48 | 56 | 56 |
| explorer content, inc0 | 32 | 32 | 40 | 40 | 48 | 48 | 56 | 56 |
| explorer extra large | 256 | 0 | 256 | 0 | 256 | 0 | 256 | 0 |
| explorer large | 96 | 0 | 120 | 0 | 144 | 0 | 168 | 0 |
| explorer medium | 48 | 48 | 60 | 60 | 72 | 72 | 84 | 84 |
| explorer small:inc4,list:inc3,details:inc2| 16 | 16 | 20 | 20 | 24 | 24 | 28 | 28 |
| explorer tiles, inc1 | 48 | 48 | 60 | 60 | 72 | 72 | 84 | 84 |
| startmenu medium | 32 | 32 | 40 | 40 | 48 | 48 | 56 | 63 |
| startmenu programs | 24 | 24 | 30 | 30 | 36 | 36 | 42 | 42 |
| startmenu search | 32 | 60 | 40 | 60 | 48 | 60 | 56 | 0 |
| startmenu tile small | 24 | 24 | 30 | 31 | 36 | 39 | 42 | 47 |
| taskbar normal | 24 | 32 | 30 | 40 | 36 | 48 | 42 | 56 |
| taskbar small | 16 | 16 | 20 | 20 | 24 | 24 | 28 | 28 |
| window icon | 16 | 16 | 20 | 16 | 24 | 16 | 28 | 16 |
| desktop inc0 | 16 | 16 | 20 | 20 | 24 | 24 | 28 | 28 |
| desktop inc1 | 18 | 32 | 23 | 40 | 27 | 48 | 32 | 56 |
| desktop inc2 | 20 | 30 | 25 | 40 | 30 | 48 | 35 | 56 |
| desktop inc3 | 22 | 32 | 28 | 40 | 33 | 48 | 39 | 56 |
| desktop inc4 | 24 | 32 | 30 | 40 | 36 | 48 | 42 | 56 |
| desktop inc5 | 27 | 32 | 34 | 40 | 41 | 48 | 47 | 56 |
| desktop inc6 | 30 | 32 | 38 | 40 | 45 | 48 | 53 | 56 |
| desktop inc7 | 33 | 48 | 41 | 60 | 50 | 72 | 58 | 84 |
| desktop inc8 | 37 | 48 | 46 | 60 | 56 | 72 | 65 | 84 |
| desktop inc9 | 41 | 48 | 51 | 60 | 62 | 72 | 72 | 84 |
| desktop inc10 | 46 | 48 | 58 | 60 | 69 | 72 | 82 | 84 |
| desktop inc11 | 51 | 0 | 64 | 0 | 77 | 0 | 89 | 0 |
| desktop inc12 | 57 | 0 | 71 | 0 | 86 | 0 | 100 | 0 |
| desktop inc13 | 63 | 0 | 79 | 0 | 95 | 0 | 110 | 0 |
| desktop inc14 | 70 | 0 | 88 | 0 | 105 | 0 | 123 | 0 |
| desktop inc15 | 78 | 0 | 98 | 0 | 117 | 0 | 137 | 0 |
| desktop inc16 | 87 | 0 | 109 | 0 | 131 | 0 | 152 | 0 |
| desktop inc17 | 97 | 0 | 121 | 0 | 146 | 0 | 170 | 0 |
| desktop inc18 | 108 | 0 | 135 | 0 | 162 | 0 | 189 | 0 |
| desktop inc19 | 120 | 0 | 150 | 0 | 180 | 0 | 210 | 0 |
| desktop inc20 | 133 | 0 | 166 | 0 | 200 | 0 | 233 | 0 |
| desktop inc21 | 148 | 0 | 185 | 0 | 222 | 0 | 256 | 0 |
| desktop inc22 | 164 | 0 | 205 | 0 | 246 | 0 | 256 | 0 |
| desktop inc23 | 182 | 0 | 228 | 0 | 256 | 0 | 256 | 0 |
| desktop inc24 | 202 | 0 | 253 | 0 | 256 | 0 | 256 | 0 |
| desktop inc25 | 224 | 0 | 256 | 0 | 256 | 0 | 256 | 0 |
| desktop inc26 | 249 | 0 | 256 | 0 | 256 | 0 | 256 | 0 |
| explorer inc5 | 18 | 32 | 23 | | | | | |
| explorer inc6 | 20 | 32 | 25 | | | | | |
| explorer inc7 | 22 | 32 | 28 | | | | | |
| explorer inc8 | 23 | 32 | 29 | | | | | |
| explorer inc9 | 25 | 32 | 31 | | | | | |
| explorer inc10 | 27 | 32 | 34 | | | | | |
| explorer inc11 | 29 | 32 | 36 | | | | | |
| explorer inc12 | 31 | 32 | 39 | | | | | |
| explorer inc13 | 33 | 48 | 41 | | | | | |
| explorer inc14 | 35 | 48 | 44 | | | | | |
| explorer inc15 | 38 | 48 | 48 | | | | | |
| explorer inc16 | 41 | 48 | 51 | | | | | |
| explorer inc17 | 44 | 48 | 55 | | | | | |
| explorer inc18 | 47 | 48 | 59 | | | | | |
| explorer inc19 | 50 | 0 | 63 | | | | | |
| explorer inc20 | 54 | 0 | 68 | | | | | |
| explorer inc44 | 239 | 0 | 256 | 0 | | | | |
| explorer inc45 | 256 | 0 | 256 | 0 | | | | |
There are 27 zoom increments on desktop
and 45 zoom increments on explorer (including the defaults from the menu on the "bottom level")
Icon format specification:
|**block** |**offset** |**offset** |**length** |**description** |
|-----------|-----------|-----------|-----------|-------------------------------|
|main header| 0 | | 2 |Reserved=0 |
| | 2 | | 2 |Image type: 1(.ICO) 2(.CUR) |
| | 4 | | 2 |Number of images in container |
|image head1| 6 | 0 | 1 |Pixel width |
| | 7 | 1 | 1 |Pixel height |
| | 8 | 2 | 1 |Color palette size or 0 |
| | 9 | 3 | 1 |Reserved=0 |
| | A | 4 | 2 |Color planes=0 or 1 |
| | C | 6 | 2 |Bits per Pixel |
| | E | 8 | 4 |Image raw size |
| | 12 | C | 4 |Offset of imageblock from BOF |
|image head2| 16 | 0 | 1 |Pixel width |
| ... | ... | ... | ... |... |
|imageblock1| ... | ... | ... |all image data goes here: |
| | ... | ... | ... | pngs included in whole |
| | ... | ... | ... | bmps missing first 14 bytes |
The icons you see in Windows 10 are packed into a icon font named Segoe MDL2 Assets & all built-in UWP apps like Groove Music are using this font for icons. Also some apps in the Windows store using it.

use ((c1^c2) & ~32) to test if c1 and c2 are the same character in different case

I saw some code like this
if( ((c1^c2) & ~32)==0 )
{
...
}
In this snippet the code likely mean that if the if statement is true, then c1 and c2 are the same character in different case, meaning that one of those is +32 or -32 away from the other. Why is that?
I did test myself and discover that in some case it is true while in others not:
printf("%d", (65^97)& ~32); //output is 0. right
printf("%d", (97^65)& ~32); //output is 0. right
printf("%d", (50^82)& ~32); //output is 64!! not the same though 82-50=32
Why is that? what is the magic in it?
(c1^c2) & ~32) xors c1 and c2, the result contains the bits that are in both characters and & with ~32 clears (ignores) the bit 5. (It is zeroed whether it was same in both or not). Comparing this with zero, checks if all the bits other than bit 5 are same.
This can be used to check if 2 letters are equal ignoring their case in ascii representation if you are sure that atleast c1 or c2 is a valid latin character(a-z, A-Z).
To understand this, let's pick 2 characters with different case and compare them:
+---+---+---+---+---+---+---+---+
a | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 |
+---+---+---+---+---+---+---+---+
| x | | | | | |
+---+---+---+---+---+---+---+---+
A | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 |
+---+---+---+---+---+---+---+---+
+---+---+---+---+---+---+---+---+
a ^ A | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
+---+---+---+---+---+---+---+---+
+---+---+---+---+---+---+---+---+
32 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
+---+---+---+---+---+---+---+---+
+---+---+---+---+---+---+---+---+
~32 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
+---+---+---+---+---+---+---+---+
+---+---+---+---+---+---+---+---+
& | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+---+---+---+---+---+---+---+---+
You can try the same with j v/s J or t v/s z.
So there is no magic involved, only this logic.
Sometimes this condition is also written as:
if (ch1 == ch2 || (ch1 ^ 32) == ch2)
{
...
}

Resources